- 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)
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)
# 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
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)
#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()
#include <OSD_Environment.hxx>
+#include <Standard_WarningsDisable.hxx>
#include <QAction>
#include <QApplication>
#include <QDir>
#include <QMainWindow>
#include <QToolBar>
+#include <Standard_WarningsRestore.hxx>
#include <set>
#include <inspector/TInspector_Communicator.hxx>
+#include <Standard_WarningsDisable.hxx>
#include <QApplication>
#include <QCompleter>
#include <QDir>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
const int FONT_POINT_SIZE = 18;
const int ICON_SIZE = 40;
if (aFileName.isEmpty())
return; // do nothing, left the previous value
- mySelectedName->setText (aFileName);
- onNameChanged (aFileName);
+
+ myFileName = aFileName;
+ accept();
}
// =======================================================================
#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>
#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;
// 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()),
#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;
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
//! @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
#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;
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;
+}
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
#include <inspector/DFBrowser_SearchView.hxx>
#include <inspector/DFBrowser_Window.hxx>
+#include <inspector/ViewControl_Tools.hxx>
+
#include <TDF_Attribute.hxx>
#include <Standard_WarningsDisable.hxx>
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);
else
{
QItemSelectionModel* aSelectionModel = myModule->GetOCAFViewSelectionModel();
- QModelIndex anIndex = DFBrowser_Window::SingleSelected (aSelectionModel->selectedIndexes(), 0);
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (aSelectionModel->selectedIndexes(), 0);
SetCurrentItem (anIndex);
}
}
//! \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(); }
#include <QObject>
#include <Standard_WarningsRestore.hxx>
-const int INFO_LENGHT = 60;
-
// =======================================================================
// function : hasAttribute
// purpose :
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)
#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>
: 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);
{
GetAttributesStack()->GetSearchView()->Reset();
- QModelIndex anIndex = DFBrowser_Window::SingleSelected (theSelected.indexes(), 0);
+ QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (theSelected.indexes(), 0);
myAttributesStack->SetCurrentItem (anIndex);
}
#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>
connect (myLineControl, SIGNAL (returnPressed()), this, SLOT (onReturnPressed()));
connect (mySearchButton, SIGNAL (clicked()), this, SLOT (onSearchButtonClicked()));
- DFBrowser_Window::SetWhiteBackground (this);
+ ViewControl_Tools::SetWhiteBackground (this);
}
// =======================================================================
#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>
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);
aLayout->addWidget (myTableView);
- DFBrowser_Window::SetWhiteBackground (myTableView);
+ ViewControl_Tools::SetWhiteBackground (myTableView);
myTableView->setGridStyle (Qt::NoPen);
}
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);
{
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());
+++ /dev/null
-// 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_Shortcut.hxx>
-
-#include <inspector/DFBrowser_Module.hxx>
-
-#include <Standard_WarningsDisable.hxx>
-#include <QApplication>
-#include <QKeyEvent>
-#include <Standard_WarningsRestore.hxx>
-
-// =======================================================================
-// function : Constructor
-// purpose :
-// =======================================================================
-DFBrowser_Shortcut::DFBrowser_Shortcut (QObject* theParent)
-: QObject (theParent), myModule (0)
-{
- qApp->installEventFilter (this);
-}
-
-// =======================================================================
-// function : eventFilter
-// purpose :
-// =======================================================================
-bool DFBrowser_Shortcut::eventFilter (QObject* theObject, QEvent* theEvent)
-{
- if (!myModule || theEvent->type() != QEvent::KeyRelease)
- return QObject::eventFilter (theObject, theEvent);
-
- QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*> (theEvent);
- switch (aKeyEvent->key())
- {
- case Qt::Key_F5:
- {
- myModule->UpdateTreeModel();
- return true;
- }
- default: break;
- }
- return QObject::eventFilter (theObject, theEvent);
-}
+++ /dev/null
-// 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_Shortcut_H
-#define DFBrowser_Shortcut_H
-
-#include <Standard.hxx>
-#include <Standard_Macro.hxx>
-
-#include <Standard_WarningsDisable.hxx>
-#include <QObject>
-#include <Standard_WarningsRestore.hxx>
-
-class DFBrowser_Module;
-class QEvent;
-
-//! \class DFBrowser_Shortcut
-//! Listens application KeyRelease event. Processes key event:
-//! - <Key_F5>: updates tree view model
-class DFBrowser_Shortcut : public QObject
-{
-public:
-
- //! Constructor
- Standard_EXPORT DFBrowser_Shortcut (QObject* theParent);
-
- //! Destructor
- virtual ~DFBrowser_Shortcut() {}
-
- //! Sets the current module
- //! \param theModule a module
- void SetModule (DFBrowser_Module* theModule) { myModule = theModule; }
-
- //! 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
-};
-
-
-#endif
#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>
{
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);
- }
}
// =======================================================================
//! 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();
+++ /dev/null
-// 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);
-}
+++ /dev/null
-// 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
#include <inspector/DFBrowserPane_Tools.hxx>
+#include <inspector/TreeModel_ModelBase.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
#include <Standard_WarningsDisable.hxx>
#include <QAbstractItemModel>
#include <QFrame>
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);
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);
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));
}
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/TreeModel_ModelBase.hxx>
+#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QItemSelectionModel>
#include <QGridLayout>
connect (myTableView, SIGNAL (doubleClicked (const QModelIndex&)),
this, SLOT (onTableDoubleClicked (const QModelIndex&)));
- DFBrowser_Window::SetWhiteBackground (myTableView);
+ ViewControl_Tools::SetWhiteBackground (myTableView);
myTableView->setGridStyle (Qt::NoPen);
}
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())
#include <QAbstractItemModel>
#include <Standard_WarningsRestore.hxx>
+const int COLUMN_NAME_WIDTH = 300;
+
// =======================================================================
// function : Constructor
// purpose :
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 :
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:
+++ /dev/null
-// 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_TreeView.hxx>
-
-// =======================================================================
-// function : SetPredefinedSize
-// purpose :
-// =======================================================================
-void DFBrowser_TreeView::SetPredefinedSize (int theDefaultWidth, int theDefaultHeight)
-{
- myDefaultWidth = theDefaultWidth;
- myDefaultHeight = theDefaultHeight;
-}
-
-// =======================================================================
-// function : sizeHint
-// purpose :
-// =======================================================================
-QSize DFBrowser_TreeView::sizeHint() const
-{
- if (myDefaultWidth > 0 && myDefaultHeight > 0)
- return QSize (myDefaultWidth, myDefaultHeight);
- return QTreeView::sizeHint();
-}
+++ /dev/null
-// 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_TreeView_H
-#define DFBrowser_TreeView_H
-
-#include <Standard.hxx>
-#include <Standard_Macro.hxx>
-
-#include <Standard_WarningsDisable.hxx>
-#include <QTreeView>
-#include <Standard_WarningsRestore.hxx>
-
-//! \class DFBrowser_TreeView
-//! Extended tree view control with possibility to set predefined size.
-class DFBrowser_TreeView : public QTreeView
-{
-public:
-
- //! Constructor
- Standard_EXPORT DFBrowser_TreeView (QWidget* theParent)
- : QTreeView (theParent), myDefaultWidth (-1), myDefaultHeight (-1) {}
-
- //! Destructor
- virtual ~DFBrowser_TreeView() {}
-
- //! Sets default size of control, that is used by the first control show
- //! \param theDefaultWidth the width value
- //! \param theDefaultHeight the height value
- Standard_EXPORT void SetPredefinedSize(int theDefaultWidth, int theDefaultHeight);
-
- //! Returns predefined size if both values are positive, otherwise parent size hint
- Standard_EXPORT 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
-};
-
-#endif
#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>
#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>
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;
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);
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();
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);
}
// =======================================================================
}
}
+// =======================================================================
+// 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 :
myTreeLevelLine->GetSearchLine()->SetModule (myModule);
myPropertyPanel->GetAttributesStack()->GetSearchView()->InitModels();
- myShortcut->SetModule (myModule);
- myThread->SetModule (myModule);
-
connect (myModule, SIGNAL (beforeUpdateTreeModel()), this, SLOT (onBeforeUpdateTreeModel()));
if (!aContext.IsNull())
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);
// =======================================================================
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 :
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 :
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 :
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();
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());
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;
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;
//! \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();
//! 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
//! \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;
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
};
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
DFBrowser_TreeLevelViewModel.hxx
DFBrowser_TreeModel.cxx
DFBrowser_TreeModel.hxx
-DFBrowser_TreeView.cxx
-DFBrowser_TreeView.hxx
DFBrowser_Window.cxx
DFBrowser_Window.hxx
//! 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
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);
}
// =======================================================================
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
<< 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()
#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>
// 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)
if (aShape.IsNull())
return;
theParameters.Append (aShape.TShape());
+ theItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
}
// =======================================================================
//! 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
#include <inspector/DFBrowserPane_TableView.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
#include <Standard_WarningsDisable.hxx>
#include <QAbstractTableModel>
#include <QHeaderView>
// =======================================================================
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();
#include <TopoDS_Shape.hxx>
#include <Standard_WarningsDisable.hxx>
-#include <QApplication>
#include <QString>
-#include <QStyle>
#include <QString>
#include <QVariant>
#include <Standard_WarningsRestore.hxx>
//! \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
//! 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
// 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);
}
// =======================================================================
//! 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
ShapeView_Tools.hxx
ShapeView_TreeModel.cxx
ShapeView_TreeModel.hxx
+ShapeView_VisibilityState.cxx
+ShapeView_VisibilityState.hxx
ShapeView_Window.cxx
ShapeView_Window.hxx
#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
{
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();
-}
-
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
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(); }
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 :
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;
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:
+ {
+ 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:
{
- 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_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;
}
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);
-}
//! \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
#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 :
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));
- m_pRootItem = myRootItems[0];
+ 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];
}
// =======================================================================
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 :
}
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();
-}
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
--- /dev/null
+// 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();
+}
--- /dev/null
+// 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
#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>
#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;
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);
}
}
+// =======================================================================
+// 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 :
{
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
myViewWindow->SetContext (View_ContextType_External, aContext);
theParameters = aParameters;
+ myParameters->SetSelectedNames (aPluginName, NCollection_List<TCollection_AsciiString>());
}
// =======================================================================
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;
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 :
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);
}
// =======================================================================
void ShapeView_Window::onBREPView()
{
- if (myTemporaryDirectory.IsEmpty())
+ if (GetTemporaryDirectory().IsEmpty())
return;
QItemSelectionModel* aModel = myTreeView->selectionModel();
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());
}
}
-// =======================================================================
-// 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 :
// =======================================================================
void ShapeView_Window::removeBREPFiles()
{
- QDir aDir (myTemporaryDirectory.ToCString());
+ QDir aDir (GetTemporaryDirectory().ToCString());
QStringList anEntries = aDir.entryList();
QString aPrefix(viewBREPPrefix().ToCString());
}
}
-// =======================================================================
-// 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 :
#include <QTreeView>
#include <Standard_WarningsRestore.hxx>
-class View_Displayer;
class View_Window;
class QAction;
public:
//! Constructor
- Standard_EXPORT ShapeView_Window (QWidget* theParent, const TCollection_AsciiString& theTemporaryDirectory);
+ Standard_EXPORT ShapeView_Window (QWidget* theParent);
//! Destructor
Standard_EXPORT virtual ~ShapeView_Window();
//! \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();
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();
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();
//! \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
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
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/item_algo_folder.png</file>
+ <file>icons/plugin_actions.png</file>
</qresource>
</RCC>
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);
}
QApplication::processEvents();
#endif
}
+
+// =======================================================================
+// function : Move
+// purpose :
+// =======================================================================
+void TInspector_Communicator::Move (const int theXPosition, const int theYPosition)
+{
+ myWindow->GetMainWindow()->move (theXPosition, theYPosition);
+}
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
#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
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);
+}
#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
public:
//! Constructor
- Standard_EXPORT TInspector_PluginParameters (TInspector_Window* theWindow) : myWindow (theWindow) {}
+ Standard_EXPORT TInspector_PluginParameters (TInspector_Window* theWindow);
//! Destructor
virtual ~TInspector_PluginParameters() Standard_OVERRIDE {}
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
--- /dev/null
+// 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();
+ }
+}
--- /dev/null
+// 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
--- /dev/null
+// 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_Shortcut.hxx>
+
+#include <inspector/TInspector_Window.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QApplication>
+#include <QKeyEvent>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+TInspector_Shortcut::TInspector_Shortcut (QObject* theParent, TInspector_Window* theWindow)
+: QObject (theParent), myWindow (theWindow)
+{
+ qApp->installEventFilter (this);
+}
+
+// =======================================================================
+// function : eventFilter
+// purpose :
+// =======================================================================
+bool TInspector_Shortcut::eventFilter (QObject* theObject, QEvent* theEvent)
+{
+ if (!myWindow || theEvent->type() != QEvent::KeyRelease)
+ return QObject::eventFilter (theObject, theEvent);
+
+ QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*> (theEvent);
+ switch (aKeyEvent->key())
+ {
+ case Qt::Key_F5:
+ {
+ myWindow->UpdateContent();
+ return true;
+ }
+ default: break;
+ }
+ return QObject::eventFilter (theObject, theEvent);
+}
--- /dev/null
+// 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_Shortcut_H
+#define TInspector_Shortcut_H
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QObject>
+#include <Standard_WarningsRestore.hxx>
+
+class TInspector_Window;
+class QEvent;
+
+//! \class TInspector_Shortcut
+//! Listens application KeyRelease event. Processes key event:
+//! - <Key_F5>: updates content (tree view model) of the active plugin
+class TInspector_Shortcut : public QObject
+{
+public:
+
+ //! Constructor
+ Standard_EXPORT TInspector_Shortcut (QObject* theParent, TInspector_Window* theWindow);
+
+ //! Destructor
+ 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:
+ TInspector_Window* myWindow; //!< the current window
+};
+
+
+#endif
// 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>
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);
myMainWindow->setDockOptions (QMainWindow::VerticalTabs);
myParameters = new TInspector_PluginParameters (this);
+
+ myDefaultDirectory = defaultTemporaryDirectory();
+ myParameters->SetTemporaryDirectory (myDefaultDirectory);
+
+ applyPreferences();
+
+ myShortcut = new TInspector_Shortcut (myMainWindow, this);
}
// =======================================================================
{
TInspector_ToolInfo anInfo;
int aToolId;
- if (FindPlugin (thePluginName, anInfo, aToolId))
+ if (findPlugin (thePluginName, anInfo, aToolId))
return;
myToolNames.append (TInspector_ToolInfo (thePluginName));
TInspector_ToolInfo anInfo;
int aToolId;
- if (!FindPlugin (thePluginName, anInfo, aToolId))
+ if (!findPlugin (thePluginName, anInfo, aToolId))
return;
if (anInfo.myButton)
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;
}
return;
TInspector_ToolInfo anInfo = myToolNames[aToolIndex];
+ bool isPluginLoaded = false;
if (!anInfo.myWidget)
{
if (!LoadPlugin (thePluginName, anInfo))
anInfo.myButton->setEnabled (false);
return;
}
+ isPluginLoaded = true;
myToolsStack->addWidget (anInfo.myWidget);
myToolNames[aToolIndex] = anInfo;
}
myOpenButton->setObjectName (thePluginName.ToCString());
anInfo.myCommunicator->UpdateContent();
+ if (isPluginLoaded)
+ {
+ // apply preferences
+ TInspectorAPI_PreferencesDataMap aPreferences;
+ myParameters->GetPreferences (thePluginName, aPreferences);
+ anInfo.myCommunicator->SetPreferences (aPreferences);
+ }
onCommuncatorNameChanged();
}
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);
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);
{
myOpenButton = theButton;
TInspector_ToolInfo anInfo;
- if (ActiveToolInfo (anInfo))
+ if (activeToolInfo (anInfo))
myOpenButton->setObjectName (anInfo.myName.ToCString());
myButtonLay->insertWidget (0, theButton);
}
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;
void TInspector_Window::UpdateContent()
{
TInspector_ToolInfo anInfo;
- if (!ActiveToolInfo (anInfo) || !anInfo.myCommunicator)
- return;
-
- anInfo.myCommunicator->UpdateContent();
+ if (activeToolInfo (anInfo) && anInfo.myCommunicator)
+ anInfo.myCommunicator->UpdateContent();
}
// =======================================================================
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 :
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);
}
// =======================================================================
{
#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)
}
// =======================================================================
-// 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++)
return false;
}
-
\ No newline at end of file
+
+// =======================================================================
+// 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;
+}
#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:
//! \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();
//! 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
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
TInspectorAPI_Communicator.hxx
TInspectorAPI_PluginParameters.cxx
TInspectorAPI_PluginParameters.hxx
+TInspectorAPI_PreferencesDataMap.hxx
//! \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;
IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient)
#endif
-// =======================================================================
-// function : Constructor
-// purpose :
-// =======================================================================
-TInspectorAPI_PluginParameters::TInspectorAPI_PluginParameters()
-{
-}
-
// =======================================================================
// function : SetParameters
// purpose :
void TInspectorAPI_PluginParameters::AddFileName (const TCollection_AsciiString& thePluginName,
const TCollection_AsciiString& theFileName)
{
- if (myFileNames.IsBound(thePluginName))
- myFileNames.ChangeFind(thePluginName).Append (theFileName);
+ if (myFileNames.IsBound (thePluginName))
+ myFileNames.ChangeFind (thePluginName).Append (theFileName);
else
{
NCollection_List<TCollection_AsciiString> aNames;
// =======================================================================
bool TInspectorAPI_PluginParameters::FindParameters (const TCollection_AsciiString& thePluginName)
{
- return myParameters.IsBound(thePluginName);
+ return myParameters.IsBound (thePluginName);
}
// =======================================================================
// =======================================================================
bool TInspectorAPI_PluginParameters::FindFileNames (const TCollection_AsciiString& thePluginName)
{
- return myFileNames.IsBound(thePluginName);
+ return myFileNames.IsBound (thePluginName);
}
// =======================================================================
// =======================================================================
bool TInspectorAPI_PluginParameters::FindSelectedNames (const TCollection_AsciiString& thePluginName)
{
- return mySelectedItemNames.IsBound(thePluginName);
+ return mySelectedItemNames.IsBound (thePluginName);
}
// =======================================================================
{
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);
+}
#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)
public:
//! Constructs the container.
- Standard_EXPORT TInspectorAPI_PluginParameters();
+ Standard_EXPORT TInspectorAPI_PluginParameters() {}
//! Destructor
Standard_EXPORT virtual ~TInspectorAPI_PluginParameters() Standard_OVERRIDE {}
//! 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
//! 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
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
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
--- /dev/null
+// 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
-TKTInspectorAPI
TKernel
+TKTInspectorAPI
+TKTreeModel
CSF_QT
\ No newline at end of file
+TKG3d
TKernel
-TKLCAF
\ No newline at end of file
+TKLCAF
+TKMath
\ No newline at end of file
// 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>
#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
// 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)
{
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;
if (aParam.IsEqual ("-plugins")) // [-plugins {name1 [name2] ... [name3] | all}]
{
anIt++;
- getArgumentPlugins(theArgsNb, theArgs, anIt, aPlugins);
+ getArgumentPlugins (theArgsNb, theArgs, anIt, aPlugins);
}
else if (aParam.IsEqual ("-activate")) // [-activate name]
{
return 1;
}
NCollection_List<TCollection_AsciiString> anArgPlugins;
- getArgumentPlugins(theArgsNb, theArgs, anIt, anArgPlugins);
+ getArgumentPlugins (theArgsNb, theArgs, anIt, anArgPlugins);
+
if (anArgPlugins.IsEmpty())
- aDefaultParameters.Append(aShape.TShape());
+ {
+ aDefaultParameters.Append (aShape.TShape());
+ anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
+ }
else
{
for (NCollection_List<TCollection_AsciiString>::Iterator anArgIt (anArgPlugins);
- anArgIt.More(); anArgIt.Next())
+ anArgIt.More(); anArgIt.Next())
{
NCollection_List<Handle(Standard_Transient)> aPluginParameters;
- aParameters.Find(anArgIt.Value(), aPluginParameters);
- aPluginParameters.Append(aShape.TShape());
+ aParameters.Find (anArgIt.Value(), aPluginParameters);
+ aPluginParameters.Append (aShape.TShape());
+ anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
aParameters.Bind (anArgIt.Value(), aPluginParameters);
}
}
anArgIt.More(); anArgIt.Next())
{
NCollection_List<Handle(Standard_Transient)> aPluginParameters;
- aParameters.Find(anArgIt.Value(), aPluginParameters);
- anOpenFileParameters.Bind(anArgIt.Value(), aFileName);
+ aParameters.Find (anArgIt.Value(), aPluginParameters);
+ anOpenFileParameters.Bind (anArgIt.Value(), aFileName);
}
}
}
+ 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;
TopoDS_Shape aShape = DBRep::Get (theArgs[anIt]);
if (!aShape.IsNull())
{
- anObjectsToSelect.Append(aShape.TShape());
+ anObjectsToSelect.Append (aShape.TShape());
+ anItemNamesToSelect.Append (TInspectorAPI_PluginParameters::ParametersToString (aShape));
}
// search prsentations with given name
- if (GetMapOfAIS().IsBound2(theArgs[anIt]))
+ if (GetMapOfAIS().IsBound2 (theArgs[anIt]))
{
Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast
(GetMapOfAIS().Find2 (theArgs[anIt]));
if (!anIO.IsNull())
- anObjectsToSelect.Append(anIO);
+ anObjectsToSelect.Append (anIO);
}
// give parameters as a container of names
aParam = TCollection_AsciiString (theArgs[anIt]);
if (!anApplication.IsNull())
{
NCollection_List<Handle(Standard_Transient)> aDFBrowserParameters;
- aParameters.Find("TKDFBrowser", aDFBrowserParameters);
- aDFBrowserParameters.Append(anApplication);
+ aParameters.Find ("TKDFBrowser", aDFBrowserParameters);
+ aDFBrowserParameters.Append (anApplication);
aParameters.Bind ("TKDFBrowser", aDFBrowserParameters);
}
{
if (aPlugins.IsEmpty())
{
- aPlugins.Append("TKDFBrowser");
- aPlugins.Append("TKShapeView");
- aPlugins.Append("TKVInspector");
+ aPlugins.Append ("TKDFBrowser");
+ aPlugins.Append ("TKShapeView");
+ aPlugins.Append ("TKVInspector");
}
aPluginNameToActivate = !aPluginNameToActivate.IsEmpty() ? aPluginNameToActivate : aPlugins.First();
}
NCollection_List<Handle(Standard_Transient)> aParameterValues;
aParameters.Find (aPluginName, aParameterValues);
- for (NCollection_List<Handle(Standard_Transient)>::Iterator aDefIt(aDefaultParameters);
+ for (NCollection_List<Handle(Standard_Transient)>::Iterator aDefIt (aDefaultParameters);
aDefIt.More(); aDefIt.Next())
aParameterValues.Append (aDefIt.Value());
MyCommunicator->Init (aPluginName, aParameterValues, Standard_True);
{
for (NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString >::Iterator anOpenIt
(anOpenFileParameters); anOpenIt.More(); anOpenIt.Next())
- MyCommunicator->OpenFile(anOpenIt.Key(), anOpenIt.Value());
+ MyCommunicator->OpenFile (anOpenIt.Key(), anOpenIt.Value());
}
else if (!aDefaultOpenFileParameter.IsEmpty()) // open file in active plugin
- MyCommunicator->OpenFile("", aDefaultOpenFileParameter);
+ MyCommunicator->OpenFile ("", aDefaultOpenFileParameter);
if (!anObjectsToSelect.IsEmpty())
- MyCommunicator->SetSelected(anObjectsToSelect);
+ MyCommunicator->SetSelected (anObjectsToSelect);
if (!anItemNamesToSelect.IsEmpty())
- MyCommunicator->SetSelected(anItemNamesToSelect);
+ MyCommunicator->SetSelected (anItemNamesToSelect);
+
+ if (aNeedDirectory)
+ MyCommunicator->SetTemporaryDirectory (aTemporaryDirectory);
if (aNeedToUpdateContent)
MyCommunicator->UpdateContent();
if (aNeedToHideInspector)
MyCommunicator->SetVisible (false);
+ if (aNeedToPrintState)
+ {
+ Standard_SStream aSStream;
+ MyCommunicator->Dump (aSStream);
+ di << aSStream << "\n";
+ }
+
return 0;
}
"\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."
"\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);
+
}
// =======================================================================
+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
\ No newline at end of file
--- /dev/null
+// 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
--- /dev/null
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>icons/item_invisible.png</file>
+ <file>icons/item_visible.png</file>
+ </qresource>
+</RCC>
--- /dev/null
+// 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
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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
--- /dev/null
+// 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
// commercial license or contractual agreement.
#include <inspector/TreeModel_ItemBase.hxx>
+
#include <inspector/TreeModel_ItemRole.hxx>
#include <Standard_WarningsDisable.hxx>
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);
}
// =======================================================================
// =======================================================================
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();
}
//! 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; };
//! \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
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
+++ /dev/null
-// 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_MessageDialog.hxx>
-
-#include <Standard_WarningsDisable.hxx>
-#include <QCheckBox>
-#include <QCursor>
-#include <QGridLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QWidget>
-#include <Standard_WarningsRestore.hxx>
-
-// =======================================================================
-// function : Constructor
-// purpose :
-// =======================================================================
-TreeModel_MessageDialog::TreeModel_MessageDialog (QWidget* theParent, const QString& theInformation,
- const QString& theQuestion)
-: QDialog (theParent), myDoNotShowItAgain (false), myPreviousAnswer (false), myInformation (theInformation),
- myQuestion (theQuestion)
-{
- setWindowTitle ("Information");
-
- QGridLayout* aLayout = new QGridLayout (this);
- QString anInformation = theInformation;
- if (!theQuestion.isEmpty())
- anInformation += QString("\n\n%2").arg (myQuestion);
- myInformationLabel = new QLabel (anInformation, this);
- myInformationLabel->setWordWrap (true);
- aLayout->addWidget (myInformationLabel, 0, 0, 1, 3);
-
- myDoNotShowCheckBox = new QCheckBox ("Don't show this dialog again. Do the same next time.", this);
- connect (myDoNotShowCheckBox, SIGNAL (toggled (bool)), this, SLOT (onDonNotShowToggled (bool) ));
- aLayout->addWidget (myDoNotShowCheckBox, 1, 0, 1, 3);
-
- myOkButton = new QPushButton ("Ok", this);
- myCancelButton = new QPushButton ("Cancel", this);
- connect (myOkButton, SIGNAL (clicked()), this, SLOT (onOkClicked() ));
- connect (myCancelButton, SIGNAL (clicked()), this, SLOT (onCancelClicked() ));
- aLayout->addWidget (myOkButton, 2, 1);
- aLayout->addWidget (myCancelButton, 2, 2);
-
- aLayout->setColumnStretch (0, 1);
-
- myCancelButton->setDefault (true);
-
- SetInformation (theInformation);
-}
-
-// =======================================================================
-// function : Start
-// purpose :
-// =======================================================================
-void TreeModel_MessageDialog::Start()
-{
- if (!myDoNotShowItAgain)
- {
- QString anInformation = myInformation;
- if (!myQuestion.isEmpty())
- anInformation += QString("\n\n%2").arg (myQuestion);
- myInformationLabel->setText (anInformation);
- exec();
- return;
- }
-
- if (IsAccepted())
- return;
-
- // tool tip information window
- QWidget* aWidget = new QWidget (this, Qt::Popup);
- QVBoxLayout* aLayout = new QVBoxLayout (aWidget);
- aLayout->addWidget (new QLabel(myInformation, aWidget));
- aWidget->move(QCursor::pos());
- aWidget->show();
-}
-
-// =======================================================================
-// function : onOkClicked
-// purpose :
-// =======================================================================
-void TreeModel_MessageDialog::onOkClicked()
-{
- myPreviousAnswer = true;
- if (myDoNotShowItAgain)
- setToolTipInfoMode();
-
- accept();
-}
-
-// =======================================================================
-// function : onCancelClicked
-// purpose :
-// =======================================================================
-void TreeModel_MessageDialog::onCancelClicked()
-{
- myPreviousAnswer = false;
- if (myDoNotShowItAgain)
- setToolTipInfoMode();
-
- reject();
-}
-
-// =======================================================================
-// function : setToolTipInfoMode
-// purpose :
-// =======================================================================
-void TreeModel_MessageDialog::setToolTipInfoMode()
-{
- //setWindowFlags (Qt::FramelessWindowHint);
- //myDoNotShowCheckBox->setVisible (false);
- //myOkButton->setVisible (false);
- //myCancelButton->setVisible (false);
-}
+++ /dev/null
-// 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_MessageDialog_H
-#define TreeModel_MessageDialog_H
-
-#include <Standard.hxx>
-#include <Standard_Macro.hxx>
-
-#include <Standard_WarningsDisable.hxx>
-#include <QCheckBox>
-#include <QDialog>
-#include <QLabel>
-#include <QPushButton>
-#include <QString>
-#include <Standard_WarningsRestore.hxx>
-
-class DFBrowser_Module;
-class QWidget;
-
-//! \class TreeModel_MessageDialog
-//! Dialog providing information and a question.
-//! It has a check box to do not the dialog again. In this case the previous value will be used as a result
-class TreeModel_MessageDialog : public QDialog
-{
- Q_OBJECT
-public:
-
- //! Constructor
- Standard_EXPORT TreeModel_MessageDialog (QWidget* theParent, const QString& theInformation, const QString& theQuestion);
-
- //! Destructor
- virtual ~TreeModel_MessageDialog() {}
-
- //! Fills message dialog with the information
- //! \param theInformation text
- void SetInformation (const QString& theInformation) { myInformation = theInformation; }
-
- //! Returns result of the dialog
- //! \bool true if the dialog was accepted
- bool IsAccepted() { return myPreviousAnswer; }
-
- //! Either perform exec() for the dialog or show tool tip information depending do not be shown again state
- Standard_EXPORT void Start();
-
-private slots:
- //! Processing this checkbox, store result in the dialog field to use by the next dialog start
- //! \param theState current changed state of the check box
- void onDonNotShowToggled (bool theState) { myDoNotShowItAgain = theState; }
-
- //! Processing action button. Stores accept choice, change dialog state if do not show it again is on
- void onOkClicked();
-
- //! Processing action button. Stores reject choice, change dialog state if do not show it again is on
- void onCancelClicked();
-
-private:
- //! Change state of the dialog to message tool tip. Only information control will be shown in the dialog
- void setToolTipInfoMode();
-
-private:
- bool myDoNotShowItAgain; //! state if the dialog should not be shown again, the latest result is used as answer
- bool myPreviousAnswer; //! the previous cached result of the dialog
-
- QString myInformation; //! the information text
- QString myQuestion; //! the question text
-
- QLabel* myInformationLabel; //! message control
- QCheckBox* myDoNotShowCheckBox; //! choice whether the dialog will be shown again
- QPushButton* myOkButton; //! accept button
- QPushButton* myCancelButton; //! reject button
-};
-
-
-#endif
#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)
{
}
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();
+ }
}
// =======================================================================
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);
}
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 :
}
// =======================================================================
-// function : emitLayoutChanged
+// function : EmitLayoutChanged
// purpose :
// =======================================================================
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 :
#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.
//! 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
//! \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.
//! \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
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
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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
--- /dev/null
+// 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_VisibilityState.hxx>
+
+// =======================================================================
+// function : OnClicked
+// purpose :
+// =======================================================================
+void TreeModel_VisibilityState::OnClicked (const QModelIndex& theIndex)
+{
+ if (theIndex.column() != TreeModel_ColumnType_Visibility)
+ return;
+
+ if (!CanBeVisible (theIndex))
+ return;
+
+ SetVisible (theIndex, !IsVisible (theIndex), true);
+ emit itemClicked (theIndex);
+}
--- /dev/null
+// 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
VInspector_ItemBase.hxx
VInspector_ItemContext.cxx
VInspector_ItemContext.hxx
+VInspector_ItemFolderObject.cxx
+VInspector_ItemFolderObject.hxx
VInspector_ItemEntityOwner.cxx
VInspector_ItemEntityOwner.hxx
VInspector_ItemHistoryElement.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
<!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>
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(); }
// 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
{
//! 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:
#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
// =======================================================================
if (Column() != 0)
return 0;
+ int aNbProperties = 1; // item to visualize Filters/Drawer information of context
+
int aNbPresentations = 0;
- if (!GetContext().IsNull())
- {
- AIS_ListOfInteractive aListOfIO;
- GetContext()->DisplayedObjects (aListOfIO);
- GetContext()->ErasedObjects(aListOfIO);
- aNbPresentations = aListOfIO.Extent();
- }
+ Handle(AIS_InteractiveContext) aContext = GetContext();
+ if (aContext.IsNull())
+ return 0;
+
+ AIS_ListOfInteractive 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);
-
- Handle(SelectMgr_EntityOwner) anOwner;
- for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
- anOwnersIt.More(); anOwnersIt.Next())
- {
- anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
- if (anOwner.IsNull())
- continue;
- Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
- if (anAISObj.IsNull())
- aRows++;
- }
- }
+ NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
+ aContext->MainSelector()->ActiveOwners(anActiveOwners);
- // owners in Global Context
- if (!aContext.IsNull())
+ Handle(SelectMgr_EntityOwner) anOwner;
+ for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(anActiveOwners);
+ anOwnersIt.More(); anOwnersIt.Next())
{
- NCollection_List<Handle(SelectBasics_EntityOwner)> anActiveOwners;
- aContext->MainSelector()->ActiveOwners(anActiveOwners);
+ anOwner = Handle(SelectMgr_EntityOwner)::DownCast(anOwnersIt.Value());
+ if (anOwner.IsNull())
+ continue;
+ Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
+ if (anAISObj.IsNull())
+ aRows++;
}
+ // owners in Global Context
+ 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;
}
// =======================================================================
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();
+ Handle(AIS_InteractiveObject) anEmptyIO;
+ int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false);
+ return aSelectedCount > 0 ? QString::number (aSelectedCount) : "";
}
+ case 6: return GetContext()->DeviationCoefficient();
default:
break;
}
// =======================================================================
TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn)
{
- return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);
+ if (theRow == 0)
+ return VInspector_ItemFolderObject::CreateItem (currentItem(), theRow, theColumn);
+ else
+ return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn);
}
//! \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:
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())
- {
- const TopoDS_Shape& aShape = BROwnr->Shape();
- if (!aShape.IsNull())
- return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
- }
- }
- break;
- }
- case 5:
- {
- if (theItemRole == Qt::ToolTipRole)
- return "TShape pointer";
- else
- {
- Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
- if (!BROwnr.IsNull())
- {
- const TopoDS_Shape& aShape = BROwnr->Shape();
- if (!aShape.IsNull())
- return VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString();
- }
- }
- break;
+ Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
+ if (BROwnr.IsNull())
+ return QVariant();
+
+ const TopoDS_Shape& aShape = BROwnr->Shape();
+ if (aShape.IsNull())
+ return QVariant();
+
+ return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
}
- case 8:
- {
- if (theItemRole == Qt::ToolTipRole)
- return "Shape Location : Shape Orientation";
- else
+ case 17:
+ case 18:
+ case 19:
{
- 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;
+ Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
+ if (BROwnr.IsNull())
+ return QVariant();
+
+ const TopoDS_Shape& aShape = BROwnr->Shape();
+ 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;
}
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())
{
--- /dev/null
+// 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());
+}
--- /dev/null
+// 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
//! Append new element
//! \param theInfo an information element
- void AddElement (const QList<QVariant>& theInfo) { myElements.append(theInfo); }
+ void AddElement (const QList<QVariant>& theInfo) { myElements.append (theInfo); }
VInspector_CallBackMode myMode; //!< history element mode
QList<QList<QVariant>> myElements; //!< container of elements information
// =======================================================================
QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const
{
+ if (Column() == 20 && theItemRole == Qt::BackgroundRole) {
+ Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
+ if (!anIO.IsNull() && anIO->HasColor())
+ {
+ Quantity_Color aColor;
+ anIO->Color(aColor);
+ return QColor ((int)(aColor.Red()*255.), (int)(aColor.Green()*255.), (int)(aColor.Blue()*255.));
+ }
+ }
+
if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole)
{
Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
}
case 4:
{
- if (theItemRole == Qt::ToolTipRole)
- return "SelectedOwners";
- else
+ int aNbSelected = VInspector_Tools::SelectedOwners (GetContext(), anIO, false);
+ return aNbSelected > 0 ? QString::number (aNbSelected) : "";
+ }
+ case 5:
+ {
+ TColStd_ListOfInteger aModes;
+ Handle(AIS_InteractiveContext) aContext = GetContext();
+ aContext->ActivatedModes(anIO, aModes);
+ TCollection_AsciiString aModesInfo;
+ for (TColStd_ListIteratorOfListOfInteger itr (aModes); itr.More(); itr.Next())
{
- Handle(AIS_InteractiveContext) aContext = GetContext();
- int aCount = VInspector_Tools::SelectedOwners (aContext, anIO, false);
- if (aCount > 0)
- return aCount;
+ if (!aModesInfo.IsEmpty())
+ aModesInfo += ", ";
+ aModesInfo += VInspector_Tools::GetShapeTypeInfo (AIS_Shape::SelectionType(itr.Value()));
}
- break;
+ return aModesInfo.ToCString();
+ }
+ break;
+ case 6:
+ {
+ double aDeviationCoefficient = 0;
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
+ if (!anAISShape.IsNull())
+ {
+ Standard_Real aPreviousCoefficient;
+ anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
+ }
+ return QString::number(aDeviationCoefficient);
+ }
+ case 7:
+ {
+ double aShapeDeflection = 0;
+ Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
+ if (!aShapeIO.IsNull())
+ {
+ const TopoDS_Shape& aShape = aShapeIO->Shape();
+ if (!aShape.IsNull())
+ aShapeDeflection = Prs3d::GetDeflection(aShape, anIO->Attributes());
+ }
+ return QString::number (aShapeDeflection);
}
case 8:
{
- if (theItemRole == Qt::ToolTipRole)
- return QString ("%1 / %2 / %3").arg ("OwnDeviationCoefficient")
- .arg ("ShapeDeflection")
- .arg ("IsAutoTriangulation");
- else
+ double aDeviationCoefficient = 0;
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
+ if (!anAISShape.IsNull())
{
- double aDeviationCoefficient = 0;
- Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast (anIO);
- if (!anAISShape.IsNull())
- {
- Standard_Real aPreviousCoefficient;
- anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
- }
- double aShapeDeflection = 0;
- Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
- if (!aShapeIO.IsNull())
- {
- const TopoDS_Shape& aShape = aShapeIO->Shape();
- if (!aShape.IsNull())
- aShapeDeflection = Prs3d::GetDeflection(aShape, anIO->Attributes());
- }
- bool anIsAutoTriangulation = anIO->Attributes()->IsAutoTriangulation();
- return QString ("%1 / %2 / %3").arg (aDeviationCoefficient)
- .arg (aShapeDeflection)
- .arg (anIsAutoTriangulation);
+ Standard_Real aPreviousCoefficient;
+ anAISShape->OwnDeviationCoefficient(aDeviationCoefficient, aPreviousCoefficient);
}
- break;
+ Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
+ bool anIsAutoTriangulation = aNullIO ? false : anIO->Attributes()->IsAutoTriangulation();
+ return anIsAutoTriangulation ? QString ("true") : QString ("false");
+ }
+ case 17:
+ case 18:
+ case 19:
+ {
+ Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO);
+ if (aShapeIO.IsNull())
+ return QVariant();
+ const TopoDS_Shape& aShape = aShapeIO->Shape();
+ 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;
}
int VInspector_ItemPresentableObject::initRowCount() const
{
Handle(AIS_InteractiveObject) anIO = GetInteractiveObject();
+#if OCC_VERSION_HEX < 0x070201
+ int aRows = 0;
+ if (anIO.IsNull())
+ return aRows;
+ // iteration through sensitive privitives
+ for (anIO->Init(); anIO->More(); anIO->Next())
+ aRows++;
+ return aRows;
+#else
return !anIO.IsNull()
? anIO->Selections().Size()
: 0;
+#endif
}
// =======================================================================
AIS_ListOfInteractive aListOfIO;
GetContext()->DisplayedObjects (aListOfIO); // the presentation is in displayed objects of Context
GetContext()->ErasedObjects (aListOfIO); // the presentation is in erased objects of Context
+ int aDeltaIndex = 1; // properties item
int aCurrentIndex = 0;
for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next(), aCurrentIndex++)
{
- if (aCurrentIndex != aRowId)
+ if (aCurrentIndex != aRowId - aDeltaIndex)
continue;
anIO = anIOIt.Value();
break;
--- /dev/null
+// 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_ItemSelectMgrFilter.hxx>
+#include <inspector/VInspector_ItemFolderObject.hxx>
+#include <inspector/VInspector_Tools.hxx>
+
+#include <SelectMgr_AndFilter.hxx>
+#include <SelectMgr_OrFilter.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QIcon>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : initValue
+// purpose :
+// =======================================================================
+QVariant VInspector_ItemSelectMgrFilter::initValue (int theItemRole) const
+{
+ if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole)
+ {
+ Handle(SelectMgr_Filter) aFilter = GetFilter();
+ switch (Column())
+ {
+ case 0: return theItemRole == Qt::ToolTipRole ? QVariant ("")
+ : QVariant (aFilter->DynamicType()->Name());
+ case 1: return rowCount() > 0 ? QVariant (rowCount()) : QVariant();
+ case 2: return VInspector_Tools::GetPointerInfo (aFilter, true).ToCString();
+ default: break;
+ }
+ }
+ if (Column() == 0 && theItemRole == Qt::DecorationRole)
+ {
+ Handle(SelectMgr_Filter) aFilter = GetFilter();
+ if (aFilter->IsKind (STANDARD_TYPE (SelectMgr_AndFilter))) return QIcon (":/icons/treeview_and.png");
+ if (aFilter->IsKind (STANDARD_TYPE (SelectMgr_OrFilter))) return QIcon (":/icons/treeview_or.png");
+ }
+ return QVariant();
+}
+
+// =======================================================================
+// function : initRowCount
+// purpose :
+// =======================================================================
+int VInspector_ItemSelectMgrFilter::initRowCount() const
+{
+ Handle(SelectMgr_Filter) aFilter = GetFilter();
+ if (aFilter->IsKind (STANDARD_TYPE (SelectMgr_CompositionFilter)))
+ {
+ Handle(SelectMgr_CompositionFilter) aCompositionFilter = Handle(SelectMgr_CompositionFilter)::DownCast (aFilter);
+ return aCompositionFilter->StoredFilters().Size();
+ }
+ return 0;
+}
+
+// =======================================================================
+// function : createChild
+// purpose :
+// =======================================================================
+TreeModel_ItemBasePtr VInspector_ItemSelectMgrFilter::createChild (int theRow, int theColumn)
+{
+ return VInspector_ItemSelectMgrFilter::CreateItem(currentItem(), theRow, theColumn);
+}
+
+// =======================================================================
+// function : Init
+// purpose :
+// =======================================================================
+void VInspector_ItemSelectMgrFilter::Init()
+{
+ Handle(AIS_InteractiveContext) aContext = GetContext();
+
+ Handle(SelectMgr_Filter) aFilter;
+
+ Handle(SelectMgr_CompositionFilter) aParentCompositeFilter;
+ VInspector_ItemSelectMgrFilterPtr aParentSelectMgrItem = itemDynamicCast<VInspector_ItemSelectMgrFilter> (Parent());
+ if (aParentSelectMgrItem)
+ aParentCompositeFilter = Handle(SelectMgr_CompositionFilter)::DownCast (aParentSelectMgrItem->GetFilter());
+
+ int aRowId = Row();
+ const SelectMgr_ListOfFilter& aFilters = !aParentCompositeFilter.IsNull() ? aParentCompositeFilter->StoredFilters()
+ : aContext->Filters();
+ int aCurrentIndex = 0;
+ for (SelectMgr_ListOfFilter::Iterator aFiltersIt (aFilters); aFiltersIt.More(); aFiltersIt.Next(), aCurrentIndex++)
+ {
+ if (aCurrentIndex != aRowId)
+ continue;
+ aFilter = aFiltersIt.Value();
+ break;
+ }
+ setFilter (aFilter);
+ TreeModel_ItemBase::Init(); // to use getFilter() without circling initialization
+}
+
+// =======================================================================
+// function : Reset
+// purpose :
+// =======================================================================
+void VInspector_ItemSelectMgrFilter::Reset()
+{
+ VInspector_ItemBase::Reset();
+
+ setFilter (NULL);
+}
+
+// =======================================================================
+// function : initItem
+// purpose :
+// =======================================================================
+void VInspector_ItemSelectMgrFilter::initItem() const
+{
+ if (IsInitialized())
+ return;
+ const_cast<VInspector_ItemSelectMgrFilter*>(this)->Init();
+}
+
+// =======================================================================
+// function : GetInteractiveObject
+// purpose :
+// =======================================================================
+Handle(SelectMgr_Filter) VInspector_ItemSelectMgrFilter::GetFilter() const
+{
+ initItem();
+ return myFilter;
+}
--- /dev/null
+// 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_ItemSelectMgrFilter_H
+#define VInspector_ItemSelectMgrFilter_H
+
+#include <Standard.hxx>
+#include <inspector/VInspector_ItemBase.hxx>
+
+#include <SelectMgr_Filter.hxx>
+
+class QItemSelectionModel;
+
+class VInspector_ItemSelectMgrFilter;
+typedef QExplicitlySharedDataPointer<VInspector_ItemSelectMgrFilter> VInspector_ItemSelectMgrFilterPtr;
+
+//! \class VInspector_ItemSelectMgrFilter
+//! Item presents information about SelectMgr_Filter.
+//! Parent is item folder, children are sub filter if the filter is a composition filter.
+class VInspector_ItemSelectMgrFilter : public VInspector_ItemBase
+{
+
+public:
+
+ //! Creates an item wrapped by a shared pointer
+ static VInspector_ItemSelectMgrFilterPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ { return VInspector_ItemSelectMgrFilterPtr (new VInspector_ItemSelectMgrFilter (theParent, theRow, theColumn)); }
+ //! Destructor
+ virtual ~VInspector_ItemSelectMgrFilter() Standard_OVERRIDE {};
+
+ //! Returns the current filter, init item if it was not initialized yet
+ //! \return filter object
+ Standard_EXPORT Handle(SelectMgr_Filter) GetFilter() const;
+
+ //! 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:
+
+ //! Set filter into the current item
+ //! \param theFilter a filter
+ void setFilter (Handle(SelectMgr_Filter) theFilter) { myFilter = theFilter; }
+
+private:
+
+ //! Constructor
+ //! param theParent a parent item
+ VInspector_ItemSelectMgrFilter (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
+ : VInspector_ItemBase (theParent, theRow, theColumn) {}
+
+protected:
+
+ Handle(SelectMgr_Filter) myFilter; //!< the current filter
+};
+
+#endif
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_SensitiveEntity.hxx>
+#include <Standard_Version.hxx>
#include <inspector/VInspector_ItemContext.hxx>
#include <inspector/VInspector_ItemPresentableObject.hxx>
#include <inspector/VInspector_ItemSensitiveEntity.hxx>
#include <inspector/VInspector_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
-#include <QColor>
#include <QStringList>
+
+#include <QColor>
#include <Standard_WarningsRestore.hxx>
// =======================================================================
int VInspector_ItemSelection::initRowCount() const
{
Handle(SelectMgr_Selection) aSelection = getSelection();
+#if OCC_VERSION_HEX < 0x070201
+ int aRows = 0;
+ for (aSelection->Init(); aSelection->More(); aSelection->Next())
+ aRows++;
+ return aRows;
+#else
return aSelection->Entities().Size();
+#endif
}
// =======================================================================
if (aState == SelectMgr_SOS_Activated || aState == SelectMgr_SOS_Any)
{
Handle(AIS_InteractiveContext) aContext = GetContext();
+#if OCC_VERSION_HEX < 0x070201
+ for (mySelection->Init(); mySelection->More(); mySelection->Next())
+ {
+ const Handle(SelectBasics_EntityOwner)& anOwner = mySelection->Sensitive()->BaseSensitive()->OwnerId();
+#else
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (mySelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
{
const Handle(SelectBasics_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
+#endif
if (VInspector_Tools::IsOwnerSelected(aContext, anOwner))
aNbSelected++;
}
}
- QString aStateValue = VInspector_Tools::ToName (VInspector_SelectionType_StateOfSelection, aState).ToCString();
- return QVariant (aNbSelected > 0 ? QString ("%1 : %2").arg (aStateValue).arg (aNbSelected) : aStateValue);
+ return aNbSelected > 0 ? QString::number (aNbSelected) : "";
}
}
- case 6: return theItemRole == Qt::ToolTipRole ? "Sensitivity" : QString::number (getSelection()->Sensitivity());
- case 8:
+ case 9:
{
- if (theItemRole == Qt::ToolTipRole)
- return QString ("%1 / %2").arg ("SelectMgr_TypeOfUpdate").arg ("SelectMgr_TypeOfBVHUpdate");
- else
- return QString ("%1 / %2").arg (VInspector_Tools::ToName (VInspector_SelectionType_TypeOfUpdate,
- getSelection()->UpdateStatus()).ToCString())
- .arg (VInspector_Tools::ToName (VInspector_SelectionType_TypeOfBVHUpdate,
- getSelection()->BVHUpdateStatus()).ToCString());
+ SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState();
+ return VInspector_Tools::ToName (VInspector_SelectionType_StateOfSelection, aState).ToCString();
}
+ case 10: return QString::number (getSelection()->Sensitivity());
+ case 11:
+ return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfUpdate,
+ getSelection()->UpdateStatus()).ToCString();
+ case 12:
+ return VInspector_Tools::ToName (VInspector_SelectionType_TypeOfBVHUpdate,
+ getSelection()->BVHUpdateStatus()).ToCString();
default:
break;
}
int aRowId = Row();
int aCurrentId = 0;
+#if OCC_VERSION_HEX < 0x070201
+ for (anIO->Init(); anIO->More(); anIO->Next(), aCurrentId++)
+#else
for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anIO->Selections()); aSelIter.More(); aSelIter.Next(), aCurrentId++)
+#endif
{
if (aCurrentId != aRowId)
continue;
+#if OCC_VERSION_HEX < 0x070201
+ mySelection = anIO->CurrentSelection();
+#else
mySelection = aSelIter.Value();
+#endif
break;
}
TreeModel_ItemBase::Init();
{
switch (Column())
{
- case 0:
- return myEntity->DynamicType()->Name();
- case 2:
- {
- return theItemRole == Qt::ToolTipRole ? "Owner pointer" : VInspector_Tools::GetPointerInfo (
- GetSensitiveEntity()->BaseSensitive()->OwnerId(), true).ToCString();
- }
+ case 0: return myEntity->DynamicType()->Name();
+ case 2: return VInspector_Tools::GetPointerInfo (GetSensitiveEntity()->BaseSensitive()->OwnerId(), 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())
- {
- const TopoDS_Shape& aShape = BROwnr->Shape();
- if (!aShape.IsNull())
- return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
- }
- }
- break;
+ Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
+ if (BROwnr.IsNull())
+ return QVariant();
+
+ const TopoDS_Shape& aShape = BROwnr->Shape();
+ if (aShape.IsNull())
+ return QVariant();
+
+ return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString();
}
- case 4: return theItemRole == Qt::ToolTipRole ? "IsActiveForSelection"
+ case 13: return
#if OCC_VERSION_HEX <= 0x060901
- : ("none");
+ ("none");
#else
- : myEntity->IsActiveForSelection() ? QString ("true") : QString ("false");
+ myEntity->IsActiveForSelection() ? QString ("true") : QString ("false");
#endif
- case 5: return theItemRole == Qt::ToolTipRole ? "SelectBasics_SensitiveEntity"
- : getEntityOwner()->DynamicType()->Name();
- case 6: return theItemRole == Qt::ToolTipRole ? "SensitivityFactor"
- : QString::number (GetSensitiveEntity()->BaseSensitive()->SensitivityFactor());
- case 7: return theItemRole == Qt::ToolTipRole ? "NbSubElements"
- : QString::number (GetSensitiveEntity()->BaseSensitive()->NbSubElements());
- case 8:
+ case 14: return QString::number (GetSensitiveEntity()->BaseSensitive()->SensitivityFactor());
+ case 15: return QString::number (GetSensitiveEntity()->BaseSensitive()->NbSubElements());
+ case 16:
{
- if (theItemRole == Qt::ToolTipRole)
- return "Owner priority";
- else
- {
- Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
- if (!BROwnr.IsNull())
- return anOwner->Priority();
- }
- break;
+ Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner);
+ if (BROwnr.IsNull())
+ return QVariant();
+ return anOwner->Priority();
}
default:
break;
int aRowId = Row();
int aCurrentId = 0;
+#if OCC_VERSION_HEX < 0x070201
+ for (aSelection->Init(); aSelection->More(); aSelection->Next(), aCurrentId++)
+#else
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next(), aCurrentId++)
+#endif
{
if (aCurrentId != aRowId)
continue;
+#if OCC_VERSION_HEX < 0x070201
+ myEntity = aSelection->Sensitive();
+#else
myEntity = aSelEntIter.Value();
+#endif
break;
}
TreeModel_ItemBase::Init();
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_ListOfInteractive.hxx>
+#if OCC_VERSION_HEX < 0x060901
+#include <AIS_LocalContext.hxx>
+#endif
#include <AIS_Selection.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Trihedron.hxx>
Handle(AIS_InteractiveObject) anIO = aIt.Value();
if (anIO.IsNull())
continue;
+#if OCC_VERSION_HEX < 0x070201
+ for (anIO->Init(); anIO->More(); anIO->Next())
+ {
+ Handle(SelectMgr_Selection) aSelection = anIO->CurrentSelection();
+ if (aSelection.IsNull())
+ continue;
+ for (aSelection->Init(); aSelection->More(); aSelection->Next())
+ {
+ Handle(SelectMgr_SensitiveEntity) anEntity = aSelection->Sensitive();
+#else
for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anIO->Selections()); aSelIter.More(); aSelIter.Next())
{
Handle(SelectMgr_Selection) aSelection = aSelIter.Value();
for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
{
Handle(SelectMgr_SensitiveEntity) anEntity = aSelEntIter.Value();
+#endif
if (anEntity.IsNull())
continue;
const Handle(SelectBasics_SensitiveEntity)& aBase = anEntity->BaseSensitive();
theContext->UnhilightSelected(Standard_False);
+ //TODO: processing in local context only
+#if OCC_VERSION_HEX < 0x060901
+ Handle(AIS_LocalContext) aLContext = theContext->LocalContext();
+ TCollection_AsciiString aSelectionName = aLContext->SelectionName();
+ aLContext->UnhilightPicked(Standard_False);
+#endif
+
for (NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt(theOwners);
anOwnersIt.More(); anOwnersIt.Next())
{
Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
+#if OCC_VERSION_HEX > 0x060901
theContext->AddOrRemoveSelected (anOwner, Standard_False);
+#else
+ AIS_Selection::Selection(aSelectionName.ToCString())->Select(anOwner);
+ anOwner->SetSelected(Standard_True);
+#endif
}
theContext->UpdateCurrentViewer();
}
#include <inspector/VInspector_ViewModel.hxx>
+#include <inspector/TreeModel_Tools.hxx>
#include <inspector/VInspector_ItemContext.hxx>
#include <inspector/VInspector_ItemEntityOwner.hxx>
#include <inspector/VInspector_ItemPresentableObject.hxx>
#include <QStringList>
#include <Standard_WarningsRestore.hxx>
+const int COLUMN_NAME_WIDTH = 260;
+const int COLUMN_SIZE_WIDTH = 30;
+const int COLUMN_POINTER_WIDTH = 70;
+const int COLUMN_SHAPE_TYPE_WIDTH = 75;
+
// =======================================================================
// function : Constructor
// purpose :
VInspector_ViewModel::VInspector_ViewModel (QObject* theParent)
: TreeModel_ModelBase (theParent)
{
- for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++)
- myRootItems.insert (aColumnId, VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, aColumnId));
+ SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
+ SetHeaderItem (1, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH));
+ SetHeaderItem (2, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH));
+ SetHeaderItem (3, TreeModel_HeaderSection ("ShapeType", COLUMN_SHAPE_TYPE_WIDTH)); // ItemPresentableObject, ItemSelection
+ SetHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); // ItemContext, ItemPresentableObject, ItemSelection
+ SetHeaderItem (5, TreeModel_HeaderSection ("ActivatedModes", -1)); // ItemPresentableObject
+ SetHeaderItem (6, TreeModel_HeaderSection ("DeviationCoefficient", -1, true)); // ItemContext, ItemPresentableObject
+ SetHeaderItem (7, TreeModel_HeaderSection ("Deflection", -1, true)); // ItemPresentableObject
+ SetHeaderItem (8, TreeModel_HeaderSection ("IsAutoTriangulation", -1, true)); // ItemPresentableObject
+
+ SetHeaderItem (9, TreeModel_HeaderSection ("SelectionState", -1)); // ItemSelection
+ SetHeaderItem (10, TreeModel_HeaderSection ("Sensitivity", -1, true)); // ItemSelection
+ SetHeaderItem (11, TreeModel_HeaderSection ("UpdateStatus", -1, true)); // ItemSelection
+ SetHeaderItem (12, TreeModel_HeaderSection ("BVHUpdateStatus", -1, true)); // ItemSelection
+
+ SetHeaderItem (13, TreeModel_HeaderSection ("IsActiveForSelection", -1, true)); // ItemSensitiveEntity
+ SetHeaderItem (14, TreeModel_HeaderSection ("SensitivityFactor", -1, true)); // ItemSensitiveEntity
+ SetHeaderItem (15, TreeModel_HeaderSection ("NbSubElements", -1, true)); // ItemSensitiveEntity
+ SetHeaderItem (16, TreeModel_HeaderSection ("Priority", -1, true)); // ItemSensitiveEntity
+
+ SetHeaderItem (17, TreeModel_HeaderSection ("TShape", COLUMN_POINTER_WIDTH, true)); // ItemEntityOwner
+ SetHeaderItem (18, TreeModel_HeaderSection ("Orientation", -1, true)); // ItemEntityOwner
+ SetHeaderItem (19, TreeModel_HeaderSection ("Location", -1, true)); // ItemEntityOwner
- m_pRootItem = myRootItems[0];
+ SetHeaderItem (20, TreeModel_HeaderSection ("Color", -1)); // ItemPresentableObject
+}
+
+// =======================================================================
+// function : createRootItem
+// purpose :
+// =======================================================================
+void VInspector_ViewModel::createRootItem (const int theColumnId)
+{
+ myRootItems.insert (theColumnId, VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId));
+ if (theColumnId == 0)
+ m_pRootItem = myRootItems[0];
}
// =======================================================================
// function : GetContext
// purpose :
// =======================================================================
-const Handle(AIS_InteractiveContext)& VInspector_ViewModel::GetContext() const
+Handle(AIS_InteractiveContext) VInspector_ViewModel::GetContext() const
{
- return itemDynamicCast<VInspector_ItemContext>(RootItem (0))->GetContext();
+ return itemDynamicCast<VInspector_ItemContext> (RootItem (0))->GetContext();
}
// =======================================================================
return QModelIndex();
}
-// =======================================================================
-// function : headerData
-// purpose :
-// =======================================================================
-QVariant VInspector_ViewModel::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 "Shape type";
- case 4: return "Selection";
- case 5: return "Base Sensitive";
- case 6: return "Sensitivity";
- case 7: return "SubElements";
- case 8: return "Deviation/Deflectiton/Update/Priority";
- //Auto Triangulation
- default: break;
- }
- return QVariant();
-}
-
// =======================================================================
// function : GetSelectedOwners
// purpose :
theOwners.Append (anEntityOwner);
}
}
+
+// =======================================================================
+// function : UpdateTreeModel
+// purpose :
+// =======================================================================
+void VInspector_ViewModel::UpdateTreeModel()
+{
+ Reset();
+ EmitLayoutChanged();
+}
//! Initialize the model by the given context
//! \param theContext viewer context
- Standard_EXPORT const Handle(AIS_InteractiveContext)& GetContext() const;
-
+ Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const;
+
//! Initialize the model by the given context
//! \param theContext viewer context
Standard_EXPORT void SetContext (const Handle(AIS_InteractiveContext)& theContext);
//! Returns root item by column
//! \param theColumn an index of the column
//! \return root item instance
- Standard_EXPORT virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const Standard_OVERRIDE
+ 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
- Standard_EXPORT virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
- { (void)theParent; return 9; }
-
- //! 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 select owners for tree view selected items
//! \param theSelectionModel a selection model
//! \param theOwners an output list of owners
Standard_EXPORT static void GetSelectedOwners (QItemSelectionModel* theSelectionModel,
NCollection_List<Handle(SelectBasics_EntityOwner)>& theOwners);
+ //! Updates tree model
+ Standard_EXPORT void UpdateTreeModel();
+
+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
#include <QStringList>
#include <Standard_WarningsRestore.hxx>
+const int COLUMN_NAME_WIDTH = 230;
+const int COLUMN_SIZE_WIDTH = 30;
+const int COLUMN_POINTER_WIDTH = 70;
+const int COLUMN_SHAPE_TYPE_WIDTH = 75;
+const int COLUMN_AIS_NAME_WIDTH = 75;
+const int COLUMN_SELECTED_WIDTH = 75;
+
+const int COLUMN_5_WIDTH = 120;
+const int COLUMN_6_WIDTH = 65;
+const int COLUMN_7_WIDTH = 70;
+
+const int HISTORY_AIS_NAME_COLUMN_WIDTH = 140;
+
+
// =======================================================================
// function : Constructor
// purpose :
VInspector_ViewModelHistory::VInspector_ViewModelHistory (QObject* theParent, const int theHistoryTypesMaxAmount)
: TreeModel_ModelBase (theParent)
{
+ SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
+ SetHeaderItem (1, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH));
+ SetHeaderItem (2, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH));
+ SetHeaderItem (3, TreeModel_HeaderSection ("Shape type", COLUMN_SHAPE_TYPE_WIDTH));
+ SetHeaderItem (4, TreeModel_HeaderSection ("AIS Name", COLUMN_AIS_NAME_WIDTH));
+ SetHeaderItem (5, TreeModel_HeaderSection ("Selected/Highlighted", -1));
+
for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++)
{
- myRootItems.insert(aColumnId, VInspector_ItemHistoryRoot::CreateItem(TreeModel_ItemBasePtr(), 0, aColumnId));
- VInspector_ItemHistoryRootPtr aRootItem = itemDynamicCast<VInspector_ItemHistoryRoot>(myRootItems[aColumnId]);
- aRootItem->SetHistoryTypesMaxAmount(theHistoryTypesMaxAmount);
+ VInspector_ItemHistoryRootPtr aRootItem = itemDynamicCast<VInspector_ItemHistoryRoot> (myRootItems[aColumnId]);
+ aRootItem->SetHistoryTypesMaxAmount (theHistoryTypesMaxAmount);
}
- m_pRootItem = myRootItems[0];
+}
+
+
+// =======================================================================
+// function : createRootItem
+// purpose :
+// =======================================================================
+void VInspector_ViewModelHistory::createRootItem (const int theColumnId)
+{
+ myRootItems.insert (theColumnId, VInspector_ItemHistoryRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId));
+ if (theColumnId == 0)
+ m_pRootItem = myRootItems[0];
}
// =======================================================================
}
return aPointers;
}
-
-// =======================================================================
-// function : headerData
-// purpose :
-// =======================================================================
-QVariant VInspector_ViewModelHistory::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 "Shape type";
- case 4: return "AIS Name";
- case 5: return "Selected/Highlighted";
- default: break;
- }
- return QVariant();
-}
//! \return root item instance
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 6; }
-
- //! 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;
+protected:
+
+ //! Creates root item
+ //! \param theColumnId index of a column
+ virtual void createRootItem (const int theColumnId) Standard_OVERRIDE;
private:
#include <AIS_Shape.hxx>
-#include <inspector/TreeModel_MessageDialog.hxx>
+#include <inspector/TreeModel_ColumnType.hxx>
+#include <inspector/TreeModel_ContextMenu.hxx>
+#include <inspector/TreeModel_Tools.hxx>
+
+#include <inspector/ViewControl_MessageDialog.hxx>
+#include <inspector/ViewControl_Tools.hxx>
#include <inspector/VInspector_ItemPresentableObject.hxx>
#include <inspector/VInspector_ToolBar.hxx>
#include <inspector/VInspector_Tools.hxx>
#include <inspector/VInspector_ViewModel.hxx>
-#include <inspector/VInspector_ViewModelHistory.hxx>
#include <inspector/VInspector_CallBack.hxx>
#include <inspector/VInspector_Communicator.hxx>
#include <inspector/VInspector_ItemEntityOwner.hxx>
#include <inspector/VInspector_ViewModel.hxx>
#include <inspector/VInspector_ViewModelHistory.hxx>
+#include <inspector/ViewControl_TreeView.hxx>
+
#include <inspector/View_Widget.hxx>
#include <inspector/View_Window.hxx>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
-const int FIRST_COLUMN_WIDTH = 230;
-
-const int COLUMN_1_WIDTH = 30;
-const int COLUMN_2_WIDTH = 70;
-const int COLUMN_3_WIDTH = 70;
-const int COLUMN_4_WIDTH = 75;
-const int COLUMN_5_WIDTH = 120;
-const int COLUMN_6_WIDTH = 65;
-const int COLUMN_7_WIDTH = 70;
-
-const int HISTORY_AIS_NAME_COLUMN_WIDTH = 140;
-
const int VINSPECTOR_DEFAULT_WIDTH = 1250;
const int VINSPECTOR_DEFAULT_HEIGHT = 800;
const int VINSPECTOR_DEFAULT_VIEW_POSITION_X = 200 + 900 + 100; // TINSPECTOR_DEFAULT_POSITION_X + TINSPECTOR_DEFAULT_WIDTH + 100
const int VINSPECTOR_DEFAULT_VIEW_POSITION_Y = 60; // TINSPECTOR_DEFAULT_POSITION_Y + 50
-//! \class Vinspector_TreeView
-//! Extended tree view control with possibility to set predefined size.
-class Vinspector_TreeView : public QTreeView
-{
-public:
- //! Constructor
- Vinspector_TreeView (QWidget* theParent) : QTreeView (theParent), myDefaultWidth (-1), myDefaultHeight (-1) {}
-
- //! Destructor
- virtual ~Vinspector_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 Vinspector_TreeView::SetPredefinedSize (int theDefaultWidth, int theDefaultHeight)
-{
- myDefaultWidth = theDefaultWidth;
- myDefaultHeight = theDefaultHeight;
-}
-
-// =======================================================================
-// function : sizeHint
-// purpose :
-// =======================================================================
-QSize Vinspector_TreeView::sizeHint() const
-{
- if (myDefaultWidth > 0 && myDefaultHeight > 0)
- return QSize (myDefaultWidth, myDefaultHeight);
- return QTreeView::sizeHint();
-}
-
// =======================================================================
// function : Constructor
// purpose :
aParentLay->setContentsMargins (0, 0, 0, 0);
aParentLay->setSpacing(0);
- // tool bar: on the bottom of the window
+ // restore state of tool bar: on the bottom of the window
myToolBar = new VInspector_ToolBar(aCentralWidget);
connect (myToolBar, SIGNAL (actionClicked (int)), this, SLOT (onToolBarActionClicked (int)));
aParentLay->addWidget (myToolBar->GetControl(), 0, 0);
myTreeView->setSelectionMode (QAbstractItemView::ExtendedSelection);
myTreeView->header()->setStretchLastSection (true);
myTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
+ VInspector_ViewModel* aTreeModel = new VInspector_ViewModel (myTreeView);
+ myTreeView->setModel (aTreeModel);
+ // hide Visibility column
+ TreeModel_HeaderSection anItem = aTreeModel->GetHeaderItem ((int)TreeModel_ColumnType_Visibility);
+ anItem.SetIsHidden (true);
+ aTreeModel->SetHeaderItem ((int)TreeModel_ColumnType_Visibility, anItem);
+
connect (myTreeView, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT (onTreeViewContextMenuRequested(const QPoint&)));
+ new TreeModel_ContextMenu (myTreeView);
+
+ QItemSelectionModel* aSelModel = new QItemSelectionModel (myTreeView->model(), myTreeView);
+ myTreeView->setSelectionModel (aSelModel);
+ connect (aSelModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
+ this, SLOT (onSelectionChanged (const QItemSelection&, const QItemSelection&)));
+
aParentLay->addWidget(myTreeView, 1, 0);
aParentLay->setRowStretch (1, 1);
myMainWindow->setCentralWidget (aCentralWidget);
- // history view in bottom dock widget
- myHistoryView = new Vinspector_TreeView (aCentralWidget);
+ myHistoryView = new ViewControl_TreeView (myMainWindow);
myHistoryView->setSelectionBehavior (QAbstractItemView::SelectRows);
- ((Vinspector_TreeView*)myHistoryView)->SetPredefinedSize (VINSPECTOR_DEFAULT_HISTORY_VIEW_WIDTH,
- VINSPECTOR_DEFAULT_HISTORY_VIEW_HEIGHT);
+ ((ViewControl_TreeView*)myHistoryView)->SetPredefinedSize (QSize (VINSPECTOR_DEFAULT_HISTORY_VIEW_WIDTH,
+ VINSPECTOR_DEFAULT_HISTORY_VIEW_HEIGHT));
+ myHistoryView->setContextMenuPolicy (Qt::CustomContextMenu);
+ myHistoryView->header()->setStretchLastSection (true);
+ new TreeModel_ContextMenu (myHistoryView);
myHistoryView->setSelectionMode (QAbstractItemView::ExtendedSelection);
VInspector_ViewModelHistory* aHistoryModel = new VInspector_ViewModelHistory (myHistoryView);
myHistoryView->setModel (aHistoryModel);
- QItemSelectionModel* aSelectionModel = new QItemSelectionModel (myHistoryView->model());
+ QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aHistoryModel);
myHistoryView->setSelectionModel (aSelectionModel);
connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
- this, SLOT (onHistoryViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
+ this, SLOT (onHistoryViewSelectionChanged (const QItemSelection&, const QItemSelection&)));
+
+ anItem = aHistoryModel->GetHeaderItem (0);
+ TreeModel_Tools::UseVisibilityColumn (myHistoryView, false);
+ // hide Visibility column
+ anItem = aHistoryModel->GetHeaderItem ((int)TreeModel_ColumnType_Visibility);
+ anItem.SetIsHidden (true);
+ aHistoryModel->SetHeaderItem ((int)TreeModel_ColumnType_Visibility, anItem);
- myHistoryView->setColumnWidth (0, FIRST_COLUMN_WIDTH);
- myHistoryView->setColumnWidth (1, COLUMN_1_WIDTH);
- myHistoryView->setColumnWidth (2, COLUMN_2_WIDTH);
- myHistoryView->setColumnWidth (3, COLUMN_3_WIDTH);
- myHistoryView->setColumnWidth (4, HISTORY_AIS_NAME_COLUMN_WIDTH);
+ QModelIndex aParentIndex = myHistoryView->model()->index (0, 0);
+ myHistoryView->setExpanded (aParentIndex, true);
QDockWidget* aHistoryDockWidget = new QDockWidget (tr ("HistoryView"), myMainWindow);
+ aHistoryDockWidget->setObjectName (aHistoryDockWidget->windowTitle());
aHistoryDockWidget->setTitleBarWidget (new QWidget(myMainWindow));
aHistoryDockWidget->setWidget (myHistoryView);
myMainWindow->addDockWidget (Qt::BottomDockWidgetArea, aHistoryDockWidget);
aLayout->addWidget (GetMainWindow());
}
+// =======================================================================
+// function : FillActionsMenu
+// purpose :
+// =======================================================================
+void VInspector_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 VInspector_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);
+ 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());
+ }
+
+ anItems.clear();
+ TreeModel_Tools::SaveState (myHistoryView, anItems, "history_view_");
+ 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 VInspector_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& theItem)
+{
+ if (theItem.IsEmpty())
+ {
+ TreeModel_Tools::SetDefaultHeaderSections (myTreeView);
+ TreeModel_Tools::SetDefaultHeaderSections (myHistoryView);
+ 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 (TreeModel_Tools::RestoreState (myHistoryView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString(),
+ "history_view_"))
+ continue;
+ }
+}
+
// =======================================================================
// function : UpdateContent
// purpose :
{
TCollection_AsciiString aName = "TKVInspector";
+ bool isModelUpdated = false;
if (myParameters->FindParameters (aName))
- Init(myParameters->Parameters (aName));
- if (myParameters->FindFileNames(aName))
+ isModelUpdated = Init (myParameters->Parameters (aName));
+ if (myParameters->FindFileNames (aName))
{
- for (NCollection_List<TCollection_AsciiString>::Iterator aFileNamesIt(myParameters->FileNames(aName));
+ for (NCollection_List<TCollection_AsciiString>::Iterator aFileNamesIt (myParameters->FileNames (aName));
aFileNamesIt.More(); aFileNamesIt.Next())
- OpenFile (aFileNamesIt.Value());
+ isModelUpdated = OpenFile (aFileNamesIt.Value()) || isModelUpdated;
NCollection_List<TCollection_AsciiString> aNames;
- myParameters->SetFileNames(aName, aNames);
+ myParameters->SetFileNames (aName, aNames);
}
+ if (!isModelUpdated)
+ UpdateTreeModel();
// make AIS_InteractiveObject selected selected if exist in select parameters
NCollection_List<Handle(Standard_Transient)> anObjects;
// function : Init
// purpose :
// =======================================================================
-void VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>& theParameters)
+bool VInspector_Window::Init (const NCollection_List<Handle(Standard_Transient)>& theParameters)
{
Handle(AIS_InteractiveContext) aContext;
Handle(VInspector_CallBack) aCallBack;
aCallBack = Handle(VInspector_CallBack)::DownCast (anObject);
}
if (aContext.IsNull())
- return;
- SetContext (aContext);
+ return false;
+ VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
+ if (aViewModel && aViewModel->GetContext() == aContext)
+ UpdateTreeModel();
+ else
+ SetContext (aContext);
- if (!aCallBack.IsNull())
+ if (!aCallBack.IsNull() && aCallBack != myCallBack)
{
myCallBack = aCallBack;
- VInspector_ViewModelHistory* aHistoryModel = dynamic_cast<VInspector_ViewModelHistory*>
- (myHistoryView->model());
- myCallBack->SetContext (aContext);
- myCallBack->SetHistoryModel(aHistoryModel);
}
+ return true;
}
// =======================================================================
// =======================================================================
void VInspector_Window::SetContext (const Handle(AIS_InteractiveContext)& theContext)
{
- VInspector_ViewModel* aViewModel = new VInspector_ViewModel (myTreeView);
+ VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
aViewModel->SetContext (theContext);
- myTreeView->setModel (aViewModel);
-
myTreeView->setExpanded (aViewModel->index (0, 0), true);
- myTreeView->setColumnWidth (0, FIRST_COLUMN_WIDTH);
if (!myCallBack.IsNull())
myCallBack->SetContext (theContext);
-
- QItemSelectionModel* aSelModel = new QItemSelectionModel (aViewModel, myTreeView);
- myTreeView->setSelectionModel (aSelModel);
- connect (aSelModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)),
- this, SLOT (onSelectionChanged (const QItemSelection&, const QItemSelection&)));
-
- myTreeView->setColumnWidth (1, COLUMN_1_WIDTH);
- myTreeView->setColumnWidth (2, COLUMN_2_WIDTH);
- myTreeView->setColumnWidth (3, COLUMN_3_WIDTH);
- myTreeView->setColumnWidth (4, COLUMN_4_WIDTH);
- myTreeView->setColumnWidth (5, COLUMN_5_WIDTH);
- myTreeView->setColumnWidth (6, COLUMN_6_WIDTH);
- myTreeView->setColumnWidth (7, COLUMN_7_WIDTH);
}
// =======================================================================
// function : OpenFile
// purpose :
// =======================================================================
-void VInspector_Window::OpenFile(const TCollection_AsciiString& theFileName)
+bool VInspector_Window::OpenFile(const TCollection_AsciiString& theFileName)
{
VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
if (!aViewModel)
+ return false;
+
+ Handle(AIS_InteractiveContext) aContext = aViewModel->GetContext();
+ bool isModelUpdated = false;
+ if (aContext.IsNull())
{
- Handle(AIS_InteractiveContext) aContext = createView();
+ aContext = createView();
SetContext (aContext);
- aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
+ isModelUpdated = true;
}
- if (!aViewModel)
- return;
-
- Handle(AIS_InteractiveContext) aContext = aViewModel->GetContext();
- if (!aContext)
- return;
TopoDS_Shape aShape = VInspector_Tools::ReadShape (theFileName);
if (aShape.IsNull())
- return;
+ return isModelUpdated;
Handle(AIS_Shape) aPresentation = new AIS_Shape (aShape);
aContext->Display (aPresentation, false);
UpdateTreeModel();
myTreeView->setExpanded (aViewModel->index (0, 0), true);
+ return true;
}
// =======================================================================
void VInspector_Window::onTreeViewContextMenuRequested(const QPoint& thePosition)
{
QMenu* aMenu = new QMenu (GetMainWindow());
- aMenu->addAction (createAction (tr ("Export to ShapeView"), SLOT(onExportToShapeView())));
- aMenu->addAction (createAction (tr ("Show"), SLOT(onShow())));
- aMenu->addAction (createAction (tr ("Hide"), SLOT(onHide())));
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Export to ShapeView"), SLOT (onExportToShapeView()), GetMainWindow(), this));
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Show"), SLOT (onShow()), GetMainWindow(), this));
+ aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Hide"), SLOT (onHide()), GetMainWindow(), this));
QPoint aPoint = myTreeView->mapToGlobal (thePosition);
aMenu->exec(aPoint);
}
if (myParameters->FindParameters (aPluginName))
aParameters = myParameters->Parameters (aPluginName);
+ NCollection_List<TCollection_AsciiString> anItemNames;
+ if (myParameters->FindSelectedNames (aPluginName))
+ anItemNames = myParameters->GetSelectedNames (aPluginName);
+
QStringList anExportedPointers;
for (NCollection_List<Handle(AIS_InteractiveObject)>::Iterator anIOIt (aSelectedPresentations); anIOIt.More(); anIOIt.Next())
{
if (aShape.IsNull())
continue;
aParameters.Append (aShape.TShape());
+ anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString(aShape));
anExportedPointers.append (VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString());
}
if (anExportedPointers.empty())
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());
}
void VInspector_Window::UpdateTreeModel()
{
VInspector_ViewModel* aViewModel = dynamic_cast<VInspector_ViewModel*> (myTreeView->model());
- if (!aViewModel)
- return;
- aViewModel->Reset();
- aViewModel->EmitLayoutChanged();
-}
-
-// =======================================================================
-// function : createAction
-// purpose :
-// =======================================================================
-QAction* VInspector_Window::createAction(const QString& theText, const char* theSlot)
-{
- QAction* anAction = new QAction(theText, GetMainWindow());
- connect(anAction, SIGNAL(triggered(bool)), this, theSlot);
- return anAction;
+ if (aViewModel)
+ aViewModel->UpdateTreeModel();
}
// =======================================================================
#include <NCollection_List.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <Standard.hxx>
+
#include <inspector/TInspectorAPI_PluginParameters.hxx>
#include <inspector/VInspector_CallBack.hxx>
#include <QMainWindow>
#include <Standard_WarningsRestore.hxx>
-class TreeModel_MessageDialog;
+class ViewControl_MessageDialog;
class VInspector_ToolBar;
class View_Window;
//! \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 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();
//! Fills controls of the plugin by parameters:
//! - Fine AIS_InteractiveObject and fills View if it if it differs from the current context
//! \param theParameters a parameters container
- void Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
+ bool Init (const NCollection_List<Handle(Standard_Transient)>& theParameters);
//! Read BREP file, creates AIS presentation for the shape and visualize it in the current context
//! \param theFileName a name of BREP file
- void OpenFile (const TCollection_AsciiString& theFileName);
+ bool OpenFile (const TCollection_AsciiString& theFileName);
private slots:
//! Updates tree model
void UpdateTreeModel();
- //! 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);
-
//! Set selected in tree view presentations displayed or erased in the current context. Note that erased presentations
//! still belongs to the current context until Remove is called.
//! \param theToDisplay if true, presentation is displayed otherwise erased
QTreeView* myHistoryView; //!< history of AIS context calls
Handle(VInspector_CallBack) myCallBack; //!< AIS context call back, if set
- TreeModel_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
+ ViewControl_MessageDialog* myExportToShapeViewDialog; //!< dialog about exporting TopoDS_Shape to ShapeView plugin
View_Window* myViewWindow; //!< temporary view window, it is created if Open is called but context is still NULL
Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container
View_ToolActionType.hxx
View_ToolBar.cxx
View_ToolBar.hxx
+View_ToolButton.hxx
+View_Tools.cxx
+View_Tools.hxx
View_ViewActionType.hxx
View_Viewer.cxx
View_Viewer.hxx
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_Shape.hxx>
+#include <AIS_Trihedron.hxx>
+#include <Prs3d_PointAspect.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <inspector/View_Viewer.hxx>
// purpose :
// =======================================================================
View_Displayer::View_Displayer()
-: myIsKeepPresentations (false), myDisplayMode (-1)
+: myIsKeepPresentations (false), myFitAllActive (false), myDisplayMode (-1)
{
}
aDisplayed.Append (aPresentation);
}
- if (!myIsKeepPresentations)
- {
- Handle(V3d_View) aView = GetView();
- if (!aView.IsNull())
- {
- aView->FitAll();
- aView->Redraw();
- }
- }
+ if (!myIsKeepPresentations || myFitAllActive)
+ fitAllView();
+
myDisplayed.Bind (theType, aDisplayed);
if (theToUpdateViewer)
UpdateViewer();
}
+// =======================================================================
+// function : RedisplayPresentation
+// purpose :
+// =======================================================================
+void View_Displayer::RedisplayPresentation (const Handle(Standard_Transient)& thePresentation,
+ const bool theToUpdateViewer)
+{
+ Handle(AIS_InteractiveObject) aPresentation = Handle(AIS_InteractiveObject)::DownCast (thePresentation);
+ if (aPresentation.IsNull() || aPresentation->GetContext().IsNull())
+ return;
+
+ GetContext()->Redisplay (aPresentation, false);
+
+ if (myFitAllActive)
+ fitAllView();
+
+ if (theToUpdateViewer)
+ UpdateViewer();
+}
+
// =======================================================================
// function : EraseAllPresentations
// purpose :
DisplayedPresentations (aDisplayed, theType);
for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
+ {
+ if (aDisplayedIt.Value()->IsKind(STANDARD_TYPE (AIS_Trihedron)))
+ continue;
+
GetContext()->Remove (aDisplayedIt.Value(), Standard_False);
+ }
+
+ aDisplayed.Clear();
+ myDisplayed.Bind (theType, aDisplayed);
if (theToUpdateViewer)
UpdateViewer();
}
+// =======================================================================
+// function : ErasePresentation
+// purpose :
+// =======================================================================
+void View_Displayer::ErasePresentation (const Handle(Standard_Transient)& thePresentation,
+ const View_PresentationType theType,
+ const bool theToUpdateViewer)
+{
+ if (GetContext().IsNull())
+ return;
+
+ Handle(AIS_InteractiveObject) aPresentation = Handle(AIS_InteractiveObject)::DownCast (thePresentation);
+ if (aPresentation.IsNull())
+ return;
+
+ GetContext()->Remove (aPresentation, Standard_False);
+
+ NCollection_Shared<AIS_ListOfInteractive> aDisplayed;
+ DisplayedPresentations (aDisplayed, theType);
+ aDisplayed.Remove (aPresentation);
+ myDisplayed.Bind (theType, aDisplayed);
+
+ if (myFitAllActive)
+ fitAllView();
+
+ if (theToUpdateViewer)
+ UpdateViewer();
+}
+
+// =======================================================================
+// function : SetVisible
+// purpose :
+// =======================================================================
+void View_Displayer::SetVisible (const TopoDS_Shape& theShape, const bool theState, const View_PresentationType theType)
+{
+ if (theShape.IsNull())
+ return;
+
+ if (theState)
+ DisplayPresentation (CreatePresentation (theShape), View_PresentationType_Main, Standard_False);
+ else
+ {
+ Handle(AIS_InteractiveObject) aPresentation = FindPresentation (theShape, theType);
+ if (!aPresentation.IsNull())
+ ErasePresentation (aPresentation, theType, Standard_False);
+ }
+
+ UpdateViewer();
+}
+
+// =======================================================================
+// function : IsVisible
+// purpose :
+// =======================================================================
+bool View_Displayer::IsVisible (const TopoDS_Shape& theShape, const View_PresentationType theType) const
+{
+ Handle(AIS_InteractiveObject) aPresentation = FindPresentation (theShape, theType);
+ return !aPresentation.IsNull();
+}
+
// =======================================================================
// function : UpdateViewer
// purpose :
// purpose :
// =======================================================================
void View_Displayer::DisplayedPresentations (NCollection_Shared<AIS_ListOfInteractive>& thePresentations,
- const View_PresentationType theType)
+ const View_PresentationType theType) const
{
myDisplayed.Find (theType, thePresentations);
}
}
return aView;
}
+
+// =======================================================================
+// function : FindPresentation
+// purpose :
+// =======================================================================
+Handle(AIS_InteractiveObject) View_Displayer::FindPresentation (const TopoDS_Shape& theShape,
+ const View_PresentationType theType) const
+{
+ if (theShape.IsNull())
+ return Handle(AIS_InteractiveObject)();
+
+ NCollection_Shared<AIS_ListOfInteractive> aDisplayed;
+ DisplayedPresentations (aDisplayed, theType);
+
+ for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next())
+ {
+ Handle(AIS_Shape) aPresentation = Handle(AIS_Shape)::DownCast (aDisplayedIt.Value());
+ if (aPresentation->Shape().IsEqual (theShape))
+ return aPresentation;
+ }
+
+ return Handle(AIS_InteractiveObject)();
+}
+
+// =======================================================================
+// function : CreatePresentation
+// purpose :
+// =======================================================================
+Handle(Standard_Transient) View_Displayer::CreatePresentation (const TopoDS_Shape& theShape)
+{
+ Handle(AIS_Shape) aShape = new AIS_Shape (theShape);
+
+ aShape->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0));
+
+ return aShape;
+}
+
+// =======================================================================
+// function : fitAllView
+// purpose :
+// =======================================================================
+void View_Displayer::fitAllView()
+{
+ Handle(V3d_View) aView = GetView();
+ if (!aView.IsNull())
+ {
+ aView->FitAll();
+ aView->Redraw();
+ }
+}
\ No newline at end of file
#include <NCollection_DataMap.hxx>
#include <NCollection_Shared.hxx>
+#include <TopoDS_Shape.hxx>
#include <Quantity_Color.hxx>
#include <inspector/View_PresentationType.hxx>
//! \param theToKeepPresentation boolean state
void KeepPresentations (const bool theToKeepPresentations) { myIsKeepPresentations = theToKeepPresentations; }
+ //! Stores flag whether the FitAll shoud be done automatically for each display
+ //! \param theFitAllActive boolean value
+ void SetFitAllActive (const bool theFitAllActive) { myFitAllActive = theFitAllActive; }
+
//! Stores display mode and changes display mode of displayed presentations
//! \param theDisplayMode a mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
//! \param theType presentation type
const View_PresentationType theType = View_PresentationType_Main,
const bool theToUpdateViewer = true);
+ //! Redisplays the parameter presentation in current context
+ //! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
+ //! \param isToUpdateView boolean state if viewer should be updated
+ Standard_EXPORT void RedisplayPresentation (const Handle(Standard_Transient)& thePresentation,
+ const bool theToUpdateViewer = true);
+
//! Erases all presentations from viewer. Iterates by internal map of displayed presentations and
//! erase these presentations.
//! \param isToUpdateView boolean state if viewer should be updated
Standard_EXPORT void ErasePresentations (const View_PresentationType theType = View_PresentationType_Main,
const bool theToUpdateViewer = true);
+ //! Erase presentation from viewer
+ //! \param thePresentation a presentation, it will be casted to AIS_InteractiveObject
+ //! \param theType presentation type
+ //! \param isToUpdateView boolean state if viewer should be updated
+ Standard_EXPORT void ErasePresentation (const Handle(Standard_Transient)& thePresentation,
+ const View_PresentationType theType = View_PresentationType_Main,
+ const bool theToUpdateViewer = true);
+
+ //! Sets shape visible/invisible
+ //! \theShape shape instance
+ //! \theState visibility state
+ Standard_EXPORT void SetVisible (const TopoDS_Shape& theShape, const bool theState,
+ const View_PresentationType theType = View_PresentationType_Main);
+
+ //! Returns visibility state value
+ //! \theShape shape instance
+ Standard_EXPORT bool IsVisible (const TopoDS_Shape& theShape,
+ const View_PresentationType theType = View_PresentationType_Main) const;
+
//! Calls UpdateCurrentViewer of context
Standard_EXPORT void UpdateViewer();
//! \param thePresentations a container to be filled
//! \param theType presentation type
Standard_EXPORT void DisplayedPresentations (NCollection_Shared<AIS_ListOfInteractive>& thePresentations,
- const View_PresentationType theType = View_PresentationType_Main);
+ const View_PresentationType theType = View_PresentationType_Main) const;
//! Returns all displayed by the trihedron objects
const NCollection_DataMap<View_PresentationType, NCollection_Shared<AIS_ListOfInteractive>>& GetDisplayed() const { return myDisplayed; }
+ //! Returns presentation if there is displayed AIS_Shape presentation for the parameter shape
+ //! \param theShape a shape instance
+ //! \param theType presentation type
+ //! \return presentation instance or NULL
+ Standard_EXPORT Handle(AIS_InteractiveObject) FindPresentation (const TopoDS_Shape& theShape,
+ const View_PresentationType theType = View_PresentationType_Main) const;
+
+ //! Creates AIS_Shape for the shape
+ //! \param theShape a shape
+ //! \return presentation
+ Standard_EXPORT static Handle(Standard_Transient) CreatePresentation (const TopoDS_Shape& theShape);
+
private:
//! Returns the current context
//! Returns 3d view
Handle(V3d_View) GetView() const;
+ //! Fit all view
+ void fitAllView();
+
private:
Handle(AIS_InteractiveContext) myContext; //!< context, where the displayer works
NCollection_DataMap<View_PresentationType, Quantity_Color> myColorAttributes; //!< color properties of presentations
bool myIsKeepPresentations; //!< flag if previously shown presentations stays in the context by displaying a new one
+ bool myFitAllActive; //!< flag if Fit All should be peformed automatically by each Display
int myDisplayMode; //!< display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded
};
// function : Constructor
// purpose :
// =======================================================================
-View_ToolBar::View_ToolBar (QWidget* theParent)
+View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView)
: QObject (theParent)
{
myMainWindow = new QWidget (theParent);
myViewContexts[View_ContextType_Own] = Handle(AIS_InteractiveContext)();
myViewContexts[View_ContextType_External] = Handle(AIS_InteractiveContext)();
- myActionsMap[View_ToolActionType_KeepViewId] = new QToolButton (theParent);
- myActionsMap[View_ToolActionType_KeepViewId]->setIcon (QIcon (":/icons/keep_view_on.png"));
- myActionsMap[View_ToolActionType_KeepViewId]->setText (tr ("Multi"));
- myActionsMap[View_ToolActionType_KeepViewId]->setToolTip (tr ("Keep View On: does not clear previously shown presentation"));
- myActionsMap[View_ToolActionType_KeepViewId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- myActionsMap[View_ToolActionType_KeepViewId]->setCheckable (true);
- myActionsMap[View_ToolActionType_KeepViewId]->setChecked (false);
-
- myActionsMap[View_ToolActionType_KeepViewOffId] = new QToolButton (theParent);
- myActionsMap[View_ToolActionType_KeepViewOffId]->setIcon (QIcon (":/icons/keep_view_off.png"));
- myActionsMap[View_ToolActionType_KeepViewOffId]->setText (QObject::tr ("Single"));
- myActionsMap[View_ToolActionType_KeepViewOffId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- myActionsMap[View_ToolActionType_KeepViewOffId]->setToolTip (tr ("Keep View Off: clear previously shown presentation"));
- myActionsMap[View_ToolActionType_KeepViewOffId]->setCheckable (true);
- myActionsMap[View_ToolActionType_KeepViewOffId]->setChecked (true);
-
+ if (isUseKeepView)
+ {
+ myActionsMap[View_ToolActionType_KeepViewId] = new QToolButton (theParent);
+ myActionsMap[View_ToolActionType_KeepViewId]->setIcon (QIcon (":/icons/keep_view_on.png"));
+ myActionsMap[View_ToolActionType_KeepViewId]->setText (tr ("Multi"));
+ myActionsMap[View_ToolActionType_KeepViewId]->setToolTip (tr ("Keep View On: does not clear previously shown presentation"));
+ myActionsMap[View_ToolActionType_KeepViewId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ myActionsMap[View_ToolActionType_KeepViewId]->setCheckable (true);
+ myActionsMap[View_ToolActionType_KeepViewId]->setChecked (false);
+
+ myActionsMap[View_ToolActionType_KeepViewOffId] = new QToolButton (theParent);
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setIcon (QIcon (":/icons/keep_view_off.png"));
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setText (QObject::tr ("Single"));
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setToolTip (tr ("Keep View Off: clear previously shown presentation"));
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setCheckable (true);
+ myActionsMap[View_ToolActionType_KeepViewOffId]->setChecked (true);
+ }
+
myActionsMap[View_ToolActionType_ClearViewId] = new QToolButton (theParent);
myActionsMap[View_ToolActionType_ClearViewId]->setIcon (QIcon (":/icons/view_clear.png"));
myActionsMap[View_ToolActionType_ClearViewId]->setText (tr ( "Clear View"));
public:
//! Constructor
- Standard_EXPORT View_ToolBar (QWidget* theParent);
+ Standard_EXPORT View_ToolBar (QWidget* theParent, const bool isUseKeepView = true);
//! Destructor
virtual ~View_ToolBar() Standard_OVERRIDE {}
--- /dev/null
+// 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 View_ToolButton_H
+#define View_ToolButton_H
+
+#include <Standard_WarningsDisable.hxx>
+#include <QToolButton>
+#include <QMouseEvent>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+//! \class View_Widget
+//! \brief It is a Qt control that implements change checked state for button by double click event
+//! Button becomes checked by double click mouse pressed and unchecked by the next press mouse
+class View_ToolButton : public QToolButton
+{
+ Q_OBJECT
+
+public:
+ View_ToolButton (QWidget* theParent) : QToolButton (theParent) {}
+ ~View_ToolButton() {}
+
+ //! Sets the button checkable, set whether the button checkable or not
+ //! \param theChecked boolean value
+ void SetButtonChecked (const bool theChecked) {setCheckable (theChecked); setChecked (theChecked); emit checkedStateChanged (theChecked); }
+
+signals:
+ //! Sends a signal about checked state is changed
+ //! \param theState the checked state
+ void checkedStateChanged (bool theState);
+
+protected:
+ //! Sets the button unchecked if it was checked
+ virtual void mousePressEvent (QMouseEvent* theEvent)
+ {
+ if (isChecked())
+ SetButtonChecked (false);
+ else
+ QToolButton::mousePressEvent (theEvent);
+ }
+
+ //! Sets the button checked if it was unchecked
+ virtual void mouseDoubleClickEvent (QMouseEvent* theEvent)
+ {
+ QToolButton::mouseDoubleClickEvent (theEvent);
+ if (!isChecked())
+ SetButtonChecked (true);
+ }
+};
+
+#endif
--- /dev/null
+// 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/View_Tools.hxx>
+#include <inspector/View_Viewer.hxx>
+#include <inspector/View_Widget.hxx>
+#include <inspector/View_Window.hxx>
+
+#include <V3d_View.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QAction>
+#include <QObject>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : CreateAction
+// purpose :
+// =======================================================================
+QAction* View_Tools::CreateAction (const QString& theText, const char* theSlot, QObject* theParent, QObject* theContext)
+{
+ QAction* anAction = new QAction (theText, theParent);
+ QObject::connect (anAction, SIGNAL (triggered (bool)), theContext, theSlot);
+ return anAction;
+}
+
+// =======================================================================
+// function : SaveState
+// purpose :
+// =======================================================================
+void View_Tools::SaveState (View_Window* theView, QMap<QString, QString>& theItems,
+ const QString& thePrefix)
+{
+ QStringList aCameraDirection;
+ Standard_Real aVX, aVY, aVZ;
+ theView->GetView()->GetViewer()->GetView()->Proj (aVX, aVY, aVZ);
+ aCameraDirection << QString::number (aVX) << QString::number (aVY) << QString::number (aVZ);
+
+ theItems[thePrefix + "view_camera_direction"] = aCameraDirection.join (",");
+}
+
+// =======================================================================
+// function : RestoreState
+// purpose :
+// =======================================================================
+bool View_Tools::RestoreState (View_Window* theView, const QString& theKey, const QString& theValue,
+ const QString& thePrefix)
+{
+ if (theKey == thePrefix + "view_camera_direction")
+ {
+ QStringList aValues = theValue.split (",");
+ if (aValues.size() == 3)
+ {
+ Standard_Real aVX = aValues.at (0).toDouble();
+ Standard_Real aVY = aValues.at (1).toDouble();
+ Standard_Real aVZ = aValues.at (2).toDouble();
+
+ theView->GetView()->SetInitProj (aVX, aVY, aVZ);
+ }
+ }
+ else
+ return false;
+ return true;
+}
--- /dev/null
+// 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 View_Tools_H
+#define View_Tools_H
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QMap>
+#include <QString>
+#include <Standard_WarningsRestore.hxx>
+
+class View_Window;
+
+class QAction;
+class QObject;
+
+//! \class View_Tools
+//! \brief The tool that gives auxiliary methods for qt elements manipulation
+class View_Tools
+{
+public:
+
+ //! 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
+ //! \param theParent a parent object
+ //! \param theContext listener of the action toggle
+ //! \return a new action
+ Standard_EXPORT static QAction* CreateAction (const QString& theText, const char* theSlot,
+ QObject* theParent, QObject* theContext);
+
+ //! 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 (View_Window* theView, 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 (View_Window* theView, const QString& theKey, const QString& theValue,
+ const QString& thePrefix = QString());
+};
+
+#endif
#include <inspector/View_Widget.hxx>
+#include <AIS_Trihedron.hxx>
+#include <Geom_Axis2Placement.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Standard_Version.hxx>
+
+#include <inspector/View_ToolButton.hxx>
#include <inspector/View_ViewActionType.hxx>
#include <inspector/View_Viewer.hxx>
// function : Constructor
// purpose :
// =======================================================================
-View_Widget::View_Widget (QWidget* theParent)
+View_Widget::View_Widget (QWidget* theParent, const bool isFitAllActive)
: QWidget (theParent), myCurrentMode (View_CurrentAction3d_Nothing), myFirst (true), myDefaultWidth (-1),
myDefaultHeight (-1), myViewIsEnabled (true), myXmin (0), myYmin (0), myXmax (0), myYmax (0), myDragButtonDownX (0),
- myDragButtonDownY (0), myDragMultiButtonDownX (0), myDragMultiButtonDownY (0), myIsRectVisible (false), myRectBand (0)
+ myDragButtonDownY (0), myDragMultiButtonDownX (0), myDragMultiButtonDownY (0), myIsRectVisible (false), myRectBand (0),
+ myHasInitProj (Standard_False), myInitVx (0), myInitVy (0), myInitVz (0)
{
myViewer = new View_Viewer (View_Viewer::DefaultColor());
myViewer->InitStandardViewer();
+ myViewer->GetContext()->Display(new AIS_Trihedron (new Geom_Axis2Placement (gp::XOY())), Standard_True);
+
setAttribute (Qt::WA_PaintOnScreen);
setAttribute (Qt::WA_NoSystemBackground);
setFocusPolicy (Qt::StrongFocus);
initViewActions();
+ ((View_ToolButton*)myFitAllAction)->SetButtonChecked (isFitAllActive);
initCursors();
}
myViewer->GetView()->SetBackgroundColor (View_Viewer::DefaultColor());
myViewer->GetView()->MustBeResized();
+
+ if (myHasInitProj)
+ myViewer->GetView()->SetProj (myInitVx, myInitVy, myInitVz);
}
// =======================================================================
// =======================================================================
void View_Widget::paintEvent (QPaintEvent* /*theEvent*/)
{
-#if QT_VERSION < 0x050000
+#if (QT_VERSION < 0x050000 || QT_VERSION >= 0x050700)
if (myFirst)
{
Init();
myFirst = false;
}
#endif
+
if (myViewer->GetView())
myViewer->GetView()->Redraw();
}
// =======================================================================
void View_Widget::resizeEvent (QResizeEvent* /*theEvent*/)
{
-#if QT_VERSION > 0x050000
+#if (QT_VERSION > 0x050000 && QT_VERSION < 0x050700)
if (myFirst)
{
Init();
if (myViewer->GetView())
myViewer->GetView()->SetBackgroundColor (theIsEnabled ? View_Viewer::DefaultColor()
: View_Viewer::DisabledColor());
- for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
+ for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
GetViewAction ((View_ViewActionType)anActionId)->setEnabled (theIsEnabled);
}
+// =======================================================================
+// function : onCheckedStateChanged
+// purpose :
+// =======================================================================
+void View_Widget::onCheckedStateChanged (bool isOn)
+{
+ QWidget* aSentByAction = (QWidget*)sender();
+
+ if (aSentByAction == myFitAllAction)
+ emit checkedStateChanged(View_ViewActionType_FitAllId, isOn);
+}
+
// =======================================================================
// function : OnUpdateToggled
// purpose :
// =======================================================================
void View_Widget::OnUpdateToggled (bool isOn)
{
- QAction* sentBy = (QAction*)sender();
+ QAction* aSentByAction = (QAction*)sender();
- if (sentBy == myViewActions[View_ViewActionType_DisplayModeId])
+ if (aSentByAction == myViewActions[View_ViewActionType_DisplayModeId])
{
- sentBy->setIcon (isOn ? QIcon (":/icons/view_dm_wireframe.png")
+ aSentByAction->setIcon (isOn ? QIcon (":/icons/view_dm_wireframe.png")
: QIcon (":/icons/view_dm_shading.png"));
return;
}
if (!isOn)
return;
- for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_RotationId; anActionId++)
+ for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_RotationId; anActionId++)
{
QAction* anAction = myViewActions[(View_ViewActionType)anActionId];
if ((anAction == myViewActions[View_ViewActionType_FitAreaId]) ||
(anAction == myViewActions[View_ViewActionType_PanId]) ||
(anAction == myViewActions[View_ViewActionType_RotationId]))
{
- if (anAction && (anAction != sentBy))
+ if (anAction && (anAction != aSentByAction))
{
anAction->setChecked (false);
}
else
{
- if (sentBy == myViewActions[View_ViewActionType_FitAreaId])
+ if (aSentByAction == myViewActions[View_ViewActionType_FitAreaId])
setActiveCursor (View_CursorMode_HandCursor);
- else if (sentBy == myViewActions[View_ViewActionType_ZoomId])
+ else if (aSentByAction == myViewActions[View_ViewActionType_ZoomId])
setActiveCursor (View_CursorMode_ZoomCursor);
- else if (sentBy == myViewActions[View_ViewActionType_PanId])
+ else if (aSentByAction == myViewActions[View_ViewActionType_PanId])
setActiveCursor (View_CursorMode_PanCursor);
- else if (sentBy == myViewActions[View_ViewActionType_RotationId])
+ else if (aSentByAction == myViewActions[View_ViewActionType_RotationId])
setActiveCursor (View_CursorMode_RotationCursor);
else
setActiveCursor (View_CursorMode_DefaultCursor);
if (!myViewActions.empty())
return;
+ myFitAllAction = new View_ToolButton (this); //!< action for automatic fit all
+ connect (myFitAllAction, SIGNAL (checkedStateChanged(bool)), this, SLOT (onCheckedStateChanged(bool)));
createAction (View_ViewActionType_FitAllId, ":/icons/view_fitall.png", tr ("Fit All"), SLOT (OnFitAll()));
+ myFitAllAction->setDefaultAction (GetViewAction (View_ViewActionType_FitAllId));
+
createAction (View_ViewActionType_FitAreaId, ":/icons/view_fitarea.png", tr ("Fit Area"), SLOT (OnFitArea()), true);
createAction (View_ViewActionType_ZoomId, ":/icons/view_zoom.png", tr ("Zoom"), SLOT (OnZoom()), true);
createAction (View_ViewActionType_PanId, ":/icons/view_pan.png", tr ("Pan"), SLOT (OnPan()), true);
// =======================================================================
void View_Widget::processMoveEvent (const Standard_Integer theX, const Standard_Integer theY)
{
- myViewer->GetContext()->MoveTo (theX, theY, myViewer->GetView(), Standard_True);
+ if (myViewer->GetView())
+ myViewer->GetContext()->MoveTo (theX, theY, myViewer->GetView(), Standard_True);
}
// =======================================================================
#include <QAction>
#include <QMap>
#include <QString>
+#include <QToolButton>
#include <QWidget>
#include <Standard_WarningsRestore.hxx>
public:
//! Constructor
- Standard_EXPORT View_Widget (QWidget* theParent);
+ Standard_EXPORT View_Widget (QWidget* theParent, const bool isFitAllActive);
//! Destructor
virtual ~View_Widget() {}
Standard_EXPORT void Init();
//! Returns an action for the given action type
- //! \param theActionId an action indes
+ //! \param theActionId an action index
QAction* GetViewAction (const View_ViewActionType theActionId) const { return myViewActions[theActionId]; };
+ //! Retuns an action widget if exist. Implemented for fit all widget.
+ //! \param theActionId an action index
+ QWidget* GetWidget (const View_ViewActionType theActionId) const { return theActionId == View_ViewActionType_FitAllId ? myFitAllAction : 0; };
+
//! \returns 0 - AIS_WireFrame, 1 - AIS_Shaded
Standard_EXPORT int GetDisplayMode() const;
//! \param theIsEnabled boolean value
Standard_EXPORT void SetEnabledView (const bool theIsEnabled);
+ //!< widget for fit all, processed double click to perform action automatically
+ //! \param theIsEnabled boolean value
+ bool IsActionChecked (const View_ViewActionType theActionId) { if (theActionId == View_ViewActionType_FitAllId) return myFitAllAction->isChecked(); }
+
+ //!< Setx initial camera position
+ //! \param theVx direction on Ox
+ //! \param theVy direction on Oy
+ //! \param theVz direction on Oz
+ void SetInitProj (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
+ { myHasInitProj = Standard_True; myInitVx = theVx; myInitVy = theVy; myInitVz = theVz; }
+
//! Get paint engine for the OpenGL viewer. Avoid default execution of Qt Widget.
virtual QPaintEngine* paintEngine() const Standard_OVERRIDE { return 0; }
//! Sends a signal about display mode change
void displayModeClicked();
+ //! Sends a signal about checked state is changed
+ //! \param theActionId an action index
+ //! \param theState the checked state
+ void checkedStateChanged (const int theActionId, bool theState);
+
public slots:
//! Fits all the V3d view and redraw view
//! Stores state about onRotate to use it by the mouse move
void OnRotate() { myCurrentMode = View_CurrentAction3d_DynamicRotation; }
+ //! Updates states of widget actions
+ //!
+ //! - if the state is checked, uncheck all other actions
+ Standard_EXPORT void onCheckedStateChanged (bool isOn);
+
//! Updates states of tool actions:
//! - if the action is display mode, it changes an icon for action(wireframe or shading)
//! - if the state is checked, uncheck all other actions
void drawRectangle (const Standard_Integer theMinX, const Standard_Integer theMinY, const Standard_Integer theMaxX,
const Standard_Integer theMaxY, const Standard_Boolean theToDraw);
private:
-
//! Creates action and stores it in a map of actions
//! \param theActionId an identifier of action in internal map
//! \param theIcon an icon name and place according to qrc resource file, e.g. ":/icons/view_fitall.png"
private:
View_Viewer* myViewer; //!< connector to context, V3d viewer and V3d View
+ QToolButton* myFitAllAction; //!< widget for fit all, processed double click to perform action automatically
QMap<View_ViewActionType, QAction*> myViewActions; //!< tool bar view actions
QMap<View_CursorMode, QCursor> myCursors; //!< possible cursors for view actions
View_CurrentAction3d myCurrentMode; //!< an active action mode for viewer
- bool myFirst; //!< flag to Init view by the first resize/paint call
- int myDefaultWidth; //!< default width for the first sizeHint
- int myDefaultHeight; //!< default height for the first sizeHint
- bool myViewIsEnabled; //!< flag if the view and tool bar view actions are enabled/disabled
+ Standard_Boolean myFirst; //!< flag to Init view by the first resize/paint call
+ Standard_Integer myDefaultWidth; //!< default width for the first sizeHint
+ Standard_Integer myDefaultHeight; //!< default height for the first sizeHint
+ Standard_Boolean myViewIsEnabled; //!< flag if the view and tool bar view actions are enabled/disabled
Standard_Integer myXmin; //!< cached X minimal position by mouse press event
Standard_Integer myYmin; //!< cached Y minimal position by mouse press event
Standard_Integer myXmax; //!< cached X maximum position by mouse press event
Standard_Integer myDragMultiButtonDownY; //!< cached Y button down by multi drag event
Standard_Boolean myIsRectVisible; //!< true if rectangle is visible now
QRubberBand* myRectBand; //!< selection rectangle rubber band
+
+ Standard_Boolean myHasInitProj; //!< is initial camera position defined
+ Standard_Real myInitVx; //!< initial camera position on X
+ Standard_Real myInitVy; //!< initial camera position on Y
+ Standard_Real myInitVz; //!< initial camera position on Z
+
};
#endif
#include <inspector/View_Displayer.hxx>
#include <inspector/View_ToolBar.hxx>
+#include <inspector/View_Tools.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/View_Widget.hxx>
+#include <V3d.hxx>
+
#include <Standard_WarningsDisable.hxx>
#include <QComboBox>
#include <QDockWidget>
#include <QGridLayout>
+#include <QMenu>
#include <QToolBar>
#include <Standard_WarningsRestore.hxx>
// function : Constructor
// purpose :
// =======================================================================
-View_Window::View_Window (QWidget* theParent)
+View_Window::View_Window (QWidget* theParent, const bool isUseKeepView, const bool isFitAllActive)
: QWidget (theParent)
{
QGridLayout* aViewLayout = new QGridLayout (this);
aViewLayout->setContentsMargins (0, 0, 0, 0);
aViewLayout->setSpacing (DEFAULT_SPACING);
- myView = new View_Widget (this);
- myViewToolBar = new View_ToolBar (this);
+ myView = new View_Widget (this, isFitAllActive);
+ myViewToolBar = new View_ToolBar (this, isUseKeepView);
aViewLayout->addWidget (myViewToolBar->GetControl(), 0, 0, 1, 2);
connect (myViewToolBar, SIGNAL (contextChanged()), this, SLOT (onViewSelectorActivated()));
connect (myViewToolBar, SIGNAL (actionClicked (int)),
this, SLOT (onToolBarActionClicked (int)));
+ connect (myView, SIGNAL (checkedStateChanged(int, bool)), this, SLOT (onCheckedStateChanged (int, bool)));
+
+ myView->setContextMenuPolicy (Qt::CustomContextMenu);
+ connect (myView, SIGNAL (customContextMenuRequested (const QPoint&)),
+ this, SLOT (onViewContextMenuRequested (const QPoint&)));
+
myActionsToolBar = new QToolBar (this);
myActionsToolBar->layout()->setContentsMargins (0, 0, 0, 0);
myActionsToolBar->setOrientation (Qt::Vertical);
- for (int anActionId = View_ViewActionType_FitAllId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
+ myActionsToolBar->addWidget (myView-> GetWidget (View_ViewActionType_FitAllId));
+ for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++)
myActionsToolBar->addAction (myView->GetViewAction ((View_ViewActionType)anActionId));
+
aViewLayout->addWidget (myActionsToolBar, 1, 0);
aViewLayout->addWidget (myView, 1, 1);
aViewLayout->setRowStretch (1, 1);
myViewToolBar->SetContext (View_ContextType_Own, aContext);
myDisplayer = new View_Displayer();
+ if (!isUseKeepView)
+ myDisplayer->KeepPresentations (true);
+ myDisplayer->SetFitAllActive (isFitAllActive);
connect (myView, SIGNAL (displayModeClicked()), this, SLOT (onDisplayModeChanged()));
onViewSelectorActivated();
}
Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext();
myDisplayer->EraseAllPresentations (true);
+ emit eraseAllPerformed();
+
myDisplayer->SetContext (aContext);
}
case View_ToolActionType_ClearViewId:
{
myDisplayer->EraseAllPresentations (true);
+ emit eraseAllPerformed();
break;
}
default:
}
}
+// =======================================================================
+// function : onCheckedStateChanged
+// purpose :
+// =======================================================================
+void View_Window::onCheckedStateChanged (int theActionId, bool theState)
+{
+ if (theActionId == View_ViewActionType_FitAllId)
+ myDisplayer->SetFitAllActive (theState);
+}
+
+// =======================================================================
+// function : onViewContextMenuRequested
+// purpose :
+// =======================================================================
+void View_Window::onViewContextMenuRequested (const QPoint& thePosition)
+{
+ QMenu* aMenu = new QMenu (this);
+ QMenu* anOrientationSubMenu = aMenu->addMenu ("Set View Orientation");
+
+ for (int i = 0; i < (int)V3d_XnegYnegZneg; i++)
+ {
+ V3d_TypeOfOrientation anOrientationType = (V3d_TypeOfOrientation)i;
+ anOrientationSubMenu->addAction (View_Tools::CreateAction (V3d::TypeOfOrientationToString (anOrientationType),
+ SLOT (onSetOrientation()), this, this));
+ }
+ aMenu->addMenu (anOrientationSubMenu);
+
+ QPoint aPoint = myView->mapToGlobal (thePosition);
+ aMenu->exec (aPoint);
+}
+
+// =======================================================================
+// function : onSetOrientation
+// purpose :
+// =======================================================================
+void View_Window::onSetOrientation()
+{
+ QAction* anAction = (QAction*)(sender());
+
+ TCollection_AsciiString anOrientationStr (anAction->text().toStdString().c_str());
+
+ V3d_TypeOfOrientation anOrientationType;
+ if (!V3d::TypeOfOrientationFromString (anOrientationStr.ToCString(), anOrientationType))
+ return;
+
+ Handle(V3d_View) aView = myView->GetViewer()->GetView();
+ if (aView.IsNull())
+ return;
+
+ aView->SetProj (anOrientationType);
+ aView->FitAll();
+ aView->Redraw();
+}
+
// =======================================================================
// function : onDisplayModeChanged
// purpose :
public:
//! Constructor
- Standard_EXPORT View_Window (QWidget* theParent);
+ Standard_EXPORT View_Window (QWidget* theParent, const bool isUseKeepView = true, const bool isFitAllActive = true);
//! Destructor
virtual ~View_Window() {}
//! \param theContext an AIS context
Standard_EXPORT void SetContext (View_ContextType theType, const Handle(AIS_InteractiveContext)& theContext);
+signals:
+ //! Signals about calling erasing all presentations in context
+ void eraseAllPerformed();
+
protected slots:
//! Processing context change:
//! - sets the current view enabled only if a current context type is View_ContextType_Own
void onViewSelectorActivated();
+ //! Processing widget action checked state changed: for Fit All action, if checked, displayer do FitAll automatically
+ //! \param theActionId a clicked action
+ //! \param theState a result checked state
+ void onCheckedStateChanged (int theActionId, bool theState);
+
//! Processing window tool bar actions
void onToolBarActionClicked (const int theActionId);
+ //! Shows context menu for view. It contains set view orientation actions.
+ //! \param thePosition a clicked point
+ void onViewContextMenuRequested (const QPoint& thePosition);
+
+ //! Sets the view scene orientation by the text of selected action
+ void onSetOrientation();
+
//! Sets selected display mode in the current context
void onDisplayModeChanged();
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- id="svg4136"
- version="1.1"
- inkscape:version="0.91 r13725"
- width="16"
- height="16"
- viewBox="0 0 16 16"
- sodipodi:docname="keep_view_off.svg"
- shape-rendering="crispEdges"
- inkscape:export-filename="D:\Projects\OInspector\Dev\DFBrowser_1.5\src\DFView\icons\keep_view_off.png"
- inkscape:export-xdpi="90"
- inkscape:export-ydpi="90">
- <metadata
- id="metadata4142">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- <dc:title></dc:title>
- </cc:Work>
- </rdf:RDF>
- </metadata>
- <defs
- id="defs4140" />
- <sodipodi:namedview
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1"
- objecttolerance="10"
- gridtolerance="10"
- guidetolerance="10"
- inkscape:pageopacity="0"
- inkscape:pageshadow="2"
- inkscape:window-width="1310"
- inkscape:window-height="884"
- id="namedview4138"
- showgrid="false"
- inkscape:zoom="24.625"
- inkscape:cx="0.32877433"
- inkscape:cy="7.9357725"
- inkscape:window-x="1874"
- inkscape:window-y="21"
- inkscape:window-maximized="0"
- inkscape:current-layer="svg4136" />
- <rect
- style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
- id="rect4178"
- width="13.238579"
- height="11.939087"
- x="1.3807107"
- y="2.0710659" />
-</svg>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
- id="svg4136"
- version="1.1"
- inkscape:version="0.91 r13725"
- width="16"
- height="16"
- viewBox="0 0 16 16"
- sodipodi:docname="keep_view_on.svg"
- shape-rendering="crispEdges"
- inkscape:export-filename="D:\Projects\OInspector\Dev\DFBrowser_1.5\src\DFView\icons\keep_view_on.png"
- inkscape:export-xdpi="99.009903"
- inkscape:export-ydpi="99.009903">
- <metadata
- id="metadata4142">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- <dc:title></dc:title>
- </cc:Work>
- </rdf:RDF>
- </metadata>
- <defs
- id="defs4140" />
- <sodipodi:namedview
- pagecolor="#ffffff"
- bordercolor="#666666"
- borderopacity="1"
- objecttolerance="10"
- gridtolerance="10"
- guidetolerance="10"
- inkscape:pageopacity="0"
- inkscape:pageshadow="2"
- inkscape:window-width="1310"
- inkscape:window-height="884"
- id="namedview4138"
- showgrid="false"
- inkscape:zoom="24.625"
- inkscape:cx="0.32877433"
- inkscape:cy="7.9357725"
- inkscape:window-x="1858"
- inkscape:window-y="40"
- inkscape:window-maximized="1"
- inkscape:current-layer="svg4136" />
- <rect
- style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
- id="rect4178"
- width="6.8223352"
- height="5.7664976"
- x="1.1370559"
- y="2.0710659" />
- <rect
- style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
- id="rect4188"
- width="6.7817259"
- height="6.6598983"
- x="4.9543152"
- y="5.3197966" />
- <rect
- style="fill:none;fill-opacity:1;stroke:#133f49;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98039216"
- id="rect4190"
- width="6.0913706"
- height="5.5228424"
- x="8.8527918"
- y="9.5837564" />
-</svg>
--- /dev/null
+ViewControl_MessageDialog.cxx
+ViewControl_MessageDialog.hxx
+ViewControl_Tools.cxx
+ViewControl_Tools.hxx
+ViewControl_TreeView.hxx
\ No newline at end of file
--- /dev/null
+// 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/ViewControl_MessageDialog.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QCheckBox>
+#include <QCursor>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : Constructor
+// purpose :
+// =======================================================================
+ViewControl_MessageDialog::ViewControl_MessageDialog (QWidget* theParent, const QString& theInformation,
+ const QString& theQuestion)
+: QDialog (theParent), myDoNotShowItAgain (false), myPreviousAnswer (false), myInformation (theInformation),
+ myQuestion (theQuestion)
+{
+ setWindowTitle ("Information");
+
+ QGridLayout* aLayout = new QGridLayout (this);
+ QString anInformation = theInformation;
+ if (!theQuestion.isEmpty())
+ anInformation += QString("\n\n%2").arg (myQuestion);
+ myInformationLabel = new QLabel (anInformation, this);
+ myInformationLabel->setWordWrap (true);
+ aLayout->addWidget (myInformationLabel, 0, 0, 1, 3);
+
+ myDoNotShowCheckBox = new QCheckBox ("Don't show this dialog again. Do the same next time.", this);
+ connect (myDoNotShowCheckBox, SIGNAL (toggled (bool)), this, SLOT (onDonNotShowToggled (bool) ));
+ aLayout->addWidget (myDoNotShowCheckBox, 1, 0, 1, 3);
+
+ myOkButton = new QPushButton ("Ok", this);
+ myCancelButton = new QPushButton ("Cancel", this);
+ connect (myOkButton, SIGNAL (clicked()), this, SLOT (onOkClicked() ));
+ connect (myCancelButton, SIGNAL (clicked()), this, SLOT (onCancelClicked() ));
+ aLayout->addWidget (myOkButton, 2, 1);
+ aLayout->addWidget (myCancelButton, 2, 2);
+
+ aLayout->setColumnStretch (0, 1);
+
+ myCancelButton->setDefault (true);
+
+ SetInformation (theInformation);
+}
+
+// =======================================================================
+// function : Start
+// purpose :
+// =======================================================================
+void ViewControl_MessageDialog::Start()
+{
+ if (!myDoNotShowItAgain)
+ {
+ QString anInformation = myInformation;
+ if (!myQuestion.isEmpty())
+ anInformation += QString("\n\n%2").arg (myQuestion);
+ myInformationLabel->setText (anInformation);
+ exec();
+ return;
+ }
+
+ if (IsAccepted())
+ return;
+
+ // tool tip information window
+ QWidget* aWidget = new QWidget (this, Qt::Popup);
+ QVBoxLayout* aLayout = new QVBoxLayout (aWidget);
+ aLayout->addWidget (new QLabel(myInformation, aWidget));
+ aWidget->move(QCursor::pos());
+ aWidget->show();
+}
+
+// =======================================================================
+// function : onOkClicked
+// purpose :
+// =======================================================================
+void ViewControl_MessageDialog::onOkClicked()
+{
+ myPreviousAnswer = true;
+ if (myDoNotShowItAgain)
+ setToolTipInfoMode();
+
+ accept();
+}
+
+// =======================================================================
+// function : onCancelClicked
+// purpose :
+// =======================================================================
+void ViewControl_MessageDialog::onCancelClicked()
+{
+ myPreviousAnswer = false;
+ if (myDoNotShowItAgain)
+ setToolTipInfoMode();
+
+ reject();
+}
+
+// =======================================================================
+// function : setToolTipInfoMode
+// purpose :
+// =======================================================================
+void ViewControl_MessageDialog::setToolTipInfoMode()
+{
+ //setWindowFlags (Qt::FramelessWindowHint);
+ //myDoNotShowCheckBox->setVisible (false);
+ //myOkButton->setVisible (false);
+ //myCancelButton->setVisible (false);
+}
--- /dev/null
+// 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 ViewControl_MessageDialog_H
+#define ViewControl_MessageDialog_H
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QCheckBox>
+#include <QDialog>
+#include <QLabel>
+#include <QPushButton>
+#include <QString>
+#include <Standard_WarningsRestore.hxx>
+
+class QWidget;
+
+//! \class ViewControl_MessageDialog
+//! Dialog providing information and a question.
+//! It has a check box to do not the dialog again. In this case the previous value will be used as a result
+class ViewControl_MessageDialog : public QDialog
+{
+ Q_OBJECT
+public:
+
+ //! Constructor
+ Standard_EXPORT ViewControl_MessageDialog (QWidget* theParent, const QString& theInformation, const QString& theQuestion);
+
+ //! Destructor
+ virtual ~ViewControl_MessageDialog() {}
+
+ //! Fills message dialog with the information
+ //! \param theInformation text
+ void SetInformation (const QString& theInformation) { myInformation = theInformation; }
+
+ //! Returns result of the dialog
+ //! \bool true if the dialog was accepted
+ bool IsAccepted() { return myPreviousAnswer; }
+
+ //! Either perform exec() for the dialog or show tool tip information depending do not be shown again state
+ Standard_EXPORT void Start();
+
+private slots:
+ //! Processing this checkbox, store result in the dialog field to use by the next dialog start
+ //! \param theState current changed state of the check box
+ void onDonNotShowToggled (bool theState) { myDoNotShowItAgain = theState; }
+
+ //! Processing action button. Stores accept choice, change dialog state if do not show it again is on
+ void onOkClicked();
+
+ //! Processing action button. Stores reject choice, change dialog state if do not show it again is on
+ void onCancelClicked();
+
+private:
+ //! Change state of the dialog to message tool tip. Only information control will be shown in the dialog
+ void setToolTipInfoMode();
+
+private:
+ bool myDoNotShowItAgain; //! state if the dialog should not be shown again, the latest result is used as answer
+ bool myPreviousAnswer; //! the previous cached result of the dialog
+
+ QString myInformation; //! the information text
+ QString myQuestion; //! the question text
+
+ QLabel* myInformationLabel; //! message control
+ QCheckBox* myDoNotShowCheckBox; //! choice whether the dialog will be shown again
+ QPushButton* myOkButton; //! accept button
+ QPushButton* myCancelButton; //! reject button
+};
+
+
+#endif
--- /dev/null
+// 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/ViewControl_Tools.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QAction>
+#include <QObject>
+#include <QPalette>
+#include <QWidget>
+#include <Standard_WarningsRestore.hxx>
+
+// =======================================================================
+// function : CreateAction
+// purpose :
+// =======================================================================
+QAction* ViewControl_Tools::CreateAction (const QString& theText, const char* theSlot, QObject* theParent, QObject* theContext)
+{
+ QAction* anAction = new QAction (theText, theParent);
+ QObject::connect (anAction, SIGNAL (triggered (bool)), theContext, theSlot);
+ return anAction;
+}
+
+// =======================================================================
+// function : SetWhiteBackground
+// purpose :
+// =======================================================================
+void ViewControl_Tools::SetWhiteBackground (QWidget* theControl)
+{
+ QPalette aPalette = theControl->palette();
+ aPalette.setColor (QPalette::All, QPalette::Foreground, Qt::white);
+ theControl->setPalette (aPalette);
+}
--- /dev/null
+// 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 ViewControl_Tools_H
+#define ViewControl_Tools_H
+
+#include <Standard.hxx>
+#include <Standard_Macro.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QString>
+#include <Standard_WarningsRestore.hxx>
+
+class QAction;
+class QObject;
+class QWidget;
+
+//! \class ViewControl_Tools
+//! \brief The tool that gives auxiliary methods for qt elements manipulation
+class ViewControl_Tools
+{
+public:
+
+ //! 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
+ //! \param theParent a parent object
+ //! \param theContext listener of the action toggle
+ //! \return a new action
+ Standard_EXPORT static QAction* CreateAction (const QString& theText, const char* theSlot,
+ QObject* theParent, QObject* theContext);
+
+ //! Change palette of the widget to have white foreground
+ //! \param theControl a widget to be modified
+ Standard_EXPORT static void SetWhiteBackground (QWidget* theControl);
+
+};
+
+#endif
--- /dev/null
+// 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 ViewControl_TreeView_H
+#define ViewControl_TreeView_H
+
+#include <Standard.hxx>
+
+#include <Standard_WarningsDisable.hxx>
+#include <QSize>
+#include <QTreeView>
+#include <Standard_WarningsRestore.hxx>
+
+class QWidget;
+
+//! \class ViewControl_TreeView
+//! Extended tree view control with possibility to set predefined size.
+class ViewControl_TreeView : public QTreeView
+{
+public:
+ //! Constructor
+ ViewControl_TreeView (QWidget* theParent) : QTreeView (theParent) {}
+
+ //! Destructor
+ virtual ~ViewControl_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 (const QSize& theSize) { myDefaultSize = theSize;}
+
+ //! Returns predefined size if both values are positive, otherwise parent size hint
+ virtual QSize sizeHint() const Standard_OVERRIDE { return myDefaultSize.isValid() ? myDefaultSize : QTreeView::sizeHint(); }
+
+private:
+ QSize myDefaultSize; //! default size, empty isze if it should not be used
+};
+
+#endif