From: nds Date: Fri, 31 Jan 2020 10:12:45 +0000 (+0300) Subject: 0030268: Inspectors - improvements in VInspector plugin X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=03f3900b2d8ed181fda0a56acde81da29fad31b4;p=occt-copy.git 0030268: Inspectors - improvements in VInspector plugin - Convert package creation. It is used to prepare some auxiliary presentations/methods to prepare variables for inspector based on occt classes. - ViewControl package improvement: Classes for property view, table, table model are implemented to visualize view of properties. This view is filled by selection in tree if the selected object has implemented DumpJson functionality. - TreeModel package improvements: Method InitColumn is implemented in TreeModel_TreeModel to fill default columns in base model. The default columns are: Name, Visibility, Rows. Additional columns should be added in successors. Container of root items is moved into the base class - View package imrovements: Store preferences: display mode, fit all checked state and type of external context View_DisplayPreview is added to process preview for selected in tree view objects hide actions Clear, Multi, Single by default (as selection in tree view or Visibility state of item define which presentations should be displayed or erased) - ShapeView plugin improvements: Property View content based on DumpJson (columns in tree view for properties are removed), Properties for TopoDS_Shape are displayed Explode shape action in tree view to see content of shape by selected shape type. Type of displayed shapes is only preview, it is not used in export action. Export shape into BREP. The previous implementation about BREP files in some directory and default view is removed. - VInspector plugin imrovements: Property View content based on DumpJson (columns in tree view for properties are removed), Properties for AIS_InteractiveContext and AIS_InteractiveObject are displayed obsolete classes to provide properties are removed. - DFBrowser plugin improvements: Property View content based on DumpJson is not used yet. But there is the USE_DUMPJSON macro. It's switch off by default. If switch ON, it creates a Property View filled with DumpJson. It's a way of DFBrowser moving on this property view. Init uses static variable CDF_Session::CurrentSession()->CurrentApplication to fill plugin if application in plugin is not set but OCAF application exists - OCC_VERSION_HEX variable used for previous OCCT versions support (before 6.9.0 or 7.2.0) is removed --- diff --git a/tools/Convert/Convert_Tools.cxx b/tools/Convert/Convert_Tools.cxx new file mode 100644 index 0000000000..47b640738d --- /dev/null +++ b/tools/Convert/Convert_Tools.cxx @@ -0,0 +1,54 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 +#include + +#include +#include + +// ======================================================================= +// function : ReadShape +// purpose : +// ======================================================================= +TopoDS_Shape Convert_Tools::ReadShape (const TCollection_AsciiString& theFileName) +{ + TopoDS_Shape aShape; + + BRep_Builder aBuilder; + BRepTools::Read (aShape, theFileName.ToCString(), aBuilder); + return aShape; +} + +//======================================================================= +//function : ConvertStreamToPresentations +//purpose : +//======================================================================= +void Convert_Tools::ConvertStreamToPresentations (const Standard_SStream&, + const Standard_Integer, + const Standard_Integer, + NCollection_List&) +{ +} + +//======================================================================= +//function : ConvertStreamToColor +//purpose : +//======================================================================= +Standard_Boolean Convert_Tools::ConvertStreamToColor (const Standard_SStream&, + Quantity_Color&) +{ + return Standard_False; +} diff --git a/tools/Convert/Convert_Tools.hxx b/tools/Convert/Convert_Tools.hxx new file mode 100644 index 0000000000..3145c77cce --- /dev/null +++ b/tools/Convert/Convert_Tools.hxx @@ -0,0 +1,54 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 Convert_Tools_H +#define Convert_Tools_H + +#include +#include +#include +#include +#include +#include +#include + +//! \class Convert_Tools +//! \brief The tool that gives auxiliary methods converting. +class Convert_Tools +{ +public: + //! Reads Shape using BREP reader + //! \param theFileName a file name + //! \return shape or NULL + Standard_EXPORT static TopoDS_Shape ReadShape (const TCollection_AsciiString& theFileName); + + + //! Creates shape presentations on the stream if possible. Tries to init some OCCT base for a new presentation + //! \param theStream source of presentation + //! \param thePresentations container to collect new presentations + Standard_EXPORT static void ConvertStreamToPresentations (const Standard_SStream& theSStream, + const Standard_Integer theStartPos, + const Standard_Integer theLastPos, + NCollection_List& thePresentations); + + //! Converts stream to color if possible. It processes Quantity_Color, Quantity_ColorRGBA + //! \param theStream source of presentation + //! \param theColor [out] converted color + //! \returns true if done + Standard_EXPORT static Standard_Boolean ConvertStreamToColor (const Standard_SStream& theSStream, + Quantity_Color& theColor); +}; + +#endif diff --git a/tools/Convert/Convert_TransientShape.hxx b/tools/Convert/Convert_TransientShape.hxx new file mode 100644 index 0000000000..b3e20b48dc --- /dev/null +++ b/tools/Convert/Convert_TransientShape.hxx @@ -0,0 +1,51 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 Convert_TransientShape_H +#define Convert_TransientShape_H + +#include +#include +#include +#include +#include + +#include + +//! \class Convert_TransientShape +//! \brief An interface to covert a shape into a transient object to use it in arguments +class Convert_TransientShape : public Standard_Transient +{ +public: + + //! Constructor + Convert_TransientShape (const TopoDS_Shape& theShape) { SetShape (theShape); } + + //! Destructor + virtual ~Convert_TransientShape() {} + + //! Returns current shape + const TopoDS_Shape Shape() const { return myShape; } + + //! Fills current shape + void SetShape (const TopoDS_Shape& theShape) { myShape = theShape; } + + DEFINE_STANDARD_RTTI_INLINE (Convert_TransientShape, Standard_Transient) + +private: + TopoDS_Shape myShape; //!< the shape +}; + +#endif diff --git a/tools/Convert/FILES b/tools/Convert/FILES new file mode 100644 index 0000000000..77362ef432 --- /dev/null +++ b/tools/Convert/FILES @@ -0,0 +1,3 @@ +Convert_Tools.cxx +Convert_Tools.hxx +Convert_TransientShape.hxx diff --git a/tools/DFBrowser/DFBrowser_AttributePaneStack.cxx b/tools/DFBrowser/DFBrowser_AttributePaneStack.cxx index e602209316..10bd0fd059 100644 --- a/tools/DFBrowser/DFBrowser_AttributePaneStack.cxx +++ b/tools/DFBrowser/DFBrowser_AttributePaneStack.cxx @@ -80,7 +80,7 @@ void DFBrowser_AttributePaneStack::SetPaneMode (const DFBrowser_AttributePaneTyp myPaneMode = theMode; if (myPaneMode == DFBrowser_AttributePaneType_SearchView) { - //! clear highlight in tree model + // clear highlight in tree model DFBrowser_TreeModel* aModel = dynamic_cast (myModule->GetOCAFViewModel()); if (aModel && aModel->HasHighlighted()) aModel->SetHighlighted (QModelIndexList()); @@ -103,7 +103,7 @@ void DFBrowser_AttributePaneStack::SetCurrentItem (const QModelIndex& theIndex) if (myPaneMode != DFBrowser_AttributePaneType_ItemView) return; - //! clear highlight in tree model + // clear highlight in tree model DFBrowser_TreeModel* aModel = dynamic_cast (myModule->GetOCAFViewModel()); if (aModel && aModel->HasHighlighted()) aModel->SetHighlighted (QModelIndexList()); diff --git a/tools/DFBrowser/DFBrowser_Communicator.hxx b/tools/DFBrowser/DFBrowser_Communicator.hxx index a1c0b6c37e..8281348f9a 100644 --- a/tools/DFBrowser/DFBrowser_Communicator.hxx +++ b/tools/DFBrowser/DFBrowser_Communicator.hxx @@ -38,7 +38,7 @@ public: Standard_EXPORT DFBrowser_Communicator(); //! Destructor - virtual ~DFBrowser_Communicator() Standard_OVERRIDE {} + virtual ~DFBrowser_Communicator() {} //! Provides the container with a parent where this container should be inserted. //! If Qt implementation, it should be QWidget with QLayout set inside @@ -49,7 +49,7 @@ public: //! \param theParameters a parameters container Standard_EXPORT virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE; - //! Provide container for actions available in inspector on general level + //! Provides 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); } diff --git a/tools/DFBrowser/DFBrowser_DumpView.hxx b/tools/DFBrowser/DFBrowser_DumpView.hxx index 95c35f86f3..a174c83e5e 100644 --- a/tools/DFBrowser/DFBrowser_DumpView.hxx +++ b/tools/DFBrowser/DFBrowser_DumpView.hxx @@ -38,14 +38,14 @@ public: DFBrowser_DumpView (QWidget* theParent) : QObject(theParent), myTextEdit( new QPlainTextEdit(theParent) ) {} //! Destructor - virtual ~DFBrowser_DumpView() Standard_OVERRIDE {} + virtual ~DFBrowser_DumpView() {} //! \return the text edit control QWidget* GetControl() const { return myTextEdit; } public slots: - //! Slots listen selection change and update the current control content by selection + //! Listens selection change and update the current control content by selection //! \param theSelected container of selected items //! \param theDeselected container of items that become deselected Standard_EXPORT void OnTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); diff --git a/tools/DFBrowser/DFBrowser_HighlightDelegate.hxx b/tools/DFBrowser/DFBrowser_HighlightDelegate.hxx index 5106821b9c..351154ab05 100644 --- a/tools/DFBrowser/DFBrowser_HighlightDelegate.hxx +++ b/tools/DFBrowser/DFBrowser_HighlightDelegate.hxx @@ -33,9 +33,9 @@ public: DFBrowser_HighlightDelegate (QObject* theParent = 0) : QItemDelegate (theParent) {} //! Destructor - virtual ~DFBrowser_HighlightDelegate() Standard_OVERRIDE {} + virtual ~DFBrowser_HighlightDelegate() {} - //! Redefine of the parent virtual method to color the cell rectangle in highlight style + //! Redefines of the parent virtual method to color the cell rectangle in highlight style //! \param thePainter a painter //! \param theOption a paint options //! \param theIndex a view index diff --git a/tools/DFBrowser/DFBrowser_Item.cxx b/tools/DFBrowser/DFBrowser_Item.cxx index 1f0ea229ef..28f482ac3c 100644 --- a/tools/DFBrowser/DFBrowser_Item.cxx +++ b/tools/DFBrowser/DFBrowser_Item.cxx @@ -31,6 +31,8 @@ #include #include +//#define USE_DUMPJSON + // ======================================================================= // function : hasAttribute // purpose : @@ -147,6 +149,24 @@ QVariant DFBrowser_Item::initValue (const int theItemRole) const return DFBrowser_Module::GetAttributeInfo (GetAttribute(), GetModule(), theItemRole, Column()); } +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void DFBrowser_Item::initStream (Standard_OStream& theOStream) const +{ + if (!HasAttribute()) + return; + +#ifdef USE_DUMPJSON + Handle(TDF_Attribute) anAttribute = GetAttribute(); + if (!anAttribute.IsNull()) + anAttribute->DumpJson (theOStream); +#else + (void)theOStream; +#endif +} + // ======================================================================= // function : GetAttributeInfo // purpose : diff --git a/tools/DFBrowser/DFBrowser_Item.hxx b/tools/DFBrowser/DFBrowser_Item.hxx index 5b9220ceb4..c2d4b55889 100644 --- a/tools/DFBrowser/DFBrowser_Item.hxx +++ b/tools/DFBrowser/DFBrowser_Item.hxx @@ -38,14 +38,14 @@ class DFBrowser_Item : public DFBrowser_ItemBase public: //! Creates an item wrapped by a shared pointer - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item //! \return the pointer to the created item static DFBrowser_ItemPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) { return DFBrowser_ItemPtr (new DFBrowser_Item (theParent, theRow, theColumn)); } //! Destructor - virtual ~DFBrowser_Item() Standard_OVERRIDE {}; + virtual ~DFBrowser_Item() {} //! \return true if the attribute is set in the item, otherwise it is initialized by a label Standard_EXPORT bool HasAttribute() const; @@ -59,7 +59,7 @@ public: //! Resets the cached item values, set null attribute and calls reset of the parent class Standard_EXPORT virtual void Reset() Standard_OVERRIDE; - //! Init item and calls cachedValue() for the role + //! Inits item and calls cachedValue() for the role //! \param theItemRole a value role //! \return the value Standard_EXPORT QVariant GetAttributeInfo(int theRole) const; @@ -69,21 +69,25 @@ protected: //! \return number of children. virtual int initRowCount() const Standard_OVERRIDE; - //! Return data value for the role: + //! Returns data value for the role: //! - if content is label, calls DFBrowser_ItemBase; //! - if content is attribute, if the fole is extended display, asks additional info text or ask module about info //! \param theItemRole a value role //! \return the value virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; + //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item DFBrowser_Item (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : DFBrowser_ItemBase (theParent, theRow, theColumn) {} - //! Initialize the current item. It creates a backup of the specific item information + //! Initializes the current item. It creates a backup of the specific item information void initItem() const; //! Sets the item attribute diff --git a/tools/DFBrowser/DFBrowser_ItemApplication.hxx b/tools/DFBrowser/DFBrowser_ItemApplication.hxx index dbc675f385..a50d503b2a 100644 --- a/tools/DFBrowser/DFBrowser_ItemApplication.hxx +++ b/tools/DFBrowser/DFBrowser_ItemApplication.hxx @@ -35,7 +35,7 @@ public: { return DFBrowser_ItemApplicationPtr (new DFBrowser_ItemApplication (theParent)); } //! Destructor - virtual ~DFBrowser_ItemApplication() Standard_OVERRIDE {}; + virtual ~DFBrowser_ItemApplication() {} //! Sets the item label //! \param theLabel an object where the child items structure is found @@ -67,7 +67,7 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item DFBrowser_ItemApplication(TreeModel_ItemBasePtr theParent) : DFBrowser_ItemBase(theParent, 0, 0) {} private: diff --git a/tools/DFBrowser/DFBrowser_ItemBase.cxx b/tools/DFBrowser/DFBrowser_ItemBase.cxx index 89d58b98bd..e1d696b63e 100644 --- a/tools/DFBrowser/DFBrowser_ItemBase.cxx +++ b/tools/DFBrowser/DFBrowser_ItemBase.cxx @@ -113,7 +113,7 @@ QVariant DFBrowser_ItemBase::initValue (const int theItemRole) const if (DFBrowser_Tools::IsEmptyLabel(GetLabel())) aValue = QColor (Qt::lightGray); else - { //! TEMPORARY HERE : should be moved in the pane of TDataStd_Name kind of attribute + { // TEMPORARY HERE : should be moved in the pane of TDataStd_Name kind of attribute Handle(TDataStd_Name) aName; if (useAdditionalInfo() && myLabel.FindAttribute (TDataStd_Name::GetID(), aName)) aValue = QColor (Qt::darkGreen); diff --git a/tools/DFBrowser/DFBrowser_ItemBase.hxx b/tools/DFBrowser/DFBrowser_ItemBase.hxx index c1ef3b6e94..c87ca1d081 100644 --- a/tools/DFBrowser/DFBrowser_ItemBase.hxx +++ b/tools/DFBrowser/DFBrowser_ItemBase.hxx @@ -48,7 +48,7 @@ public: //! \return the current module DFBrowser_Module* GetModule() const { return myModule; } - //! Change using of additional information in item. It it does not use additional info, + //! Changes using of additional information in item. If it does not use additional info, //! it will not return extended text in initValue(). //! \param theValue a new value //! \return the previous value @@ -84,15 +84,15 @@ protected: //! \return the created item virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; - //! Initialize the current item. It creates a backup of the specific item information - virtual void initItem() const {}; + //! Initializes the current item. It creates a backup of the specific item information + virtual void initItem() const {} protected: //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item DFBrowser_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn); private: diff --git a/tools/DFBrowser/DFBrowser_ItemDocument.hxx b/tools/DFBrowser/DFBrowser_ItemDocument.hxx index 52b516ae85..3f5984da2d 100644 --- a/tools/DFBrowser/DFBrowser_ItemDocument.hxx +++ b/tools/DFBrowser/DFBrowser_ItemDocument.hxx @@ -32,14 +32,14 @@ class DFBrowser_ItemDocument : public DFBrowser_ItemBase public: //! Creates an item wrapped by a shared pointer - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item //! \return the pointer to the created item static DFBrowser_ItemDocumentPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) { return DFBrowser_ItemDocumentPtr (new DFBrowser_ItemDocument (theParent, theRow, theColumn)); } //! Destructor - virtual ~DFBrowser_ItemDocument() Standard_OVERRIDE {}; + virtual ~DFBrowser_ItemDocument() {} //! Returns the current label //! \return a label @@ -65,10 +65,10 @@ public: protected: - //! Initialize the current item. It is empty because Reset() is also empty. + //! Initializes the current item. It is empty because Reset() is also empty. virtual void initItem() const Standard_OVERRIDE; - //! + //! Initializes the current item. It creates a backup of the specific item information virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; protected: @@ -82,7 +82,7 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item DFBrowser_ItemDocument(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : DFBrowser_ItemBase (theParent, theRow, theColumn) {} diff --git a/tools/DFBrowser/DFBrowser_Module.cxx b/tools/DFBrowser/DFBrowser_Module.cxx index 2aff65e7f1..ec353e724b 100644 --- a/tools/DFBrowser/DFBrowser_Module.cxx +++ b/tools/DFBrowser/DFBrowser_Module.cxx @@ -53,7 +53,9 @@ DFBrowser_Module::DFBrowser_Module() // ======================================================================= void DFBrowser_Module::CreateViewModel (void* theParent) { - myOCAFViewModel = new DFBrowser_TreeModel ((QWidget*)theParent, this); + myOCAFViewModel = new DFBrowser_TreeModel ((QWidget*)theParent); + myOCAFViewModel->InitColumns(); + myOCAFViewModel->SetModule (this); } // ======================================================================= @@ -152,7 +154,7 @@ DFBrowserPane_AttributePaneAPI* DFBrowser_Module::GetAttributePane (Handle(TDF_A // function : GetAttributePane // purpose : // ======================================================================= -DFBrowserPane_AttributePaneAPI* DFBrowser_Module::GetAttributePane (const Standard_CString& theAttributeName) +DFBrowserPane_AttributePaneAPI* DFBrowser_Module::GetAttributePane (Standard_CString theAttributeName) { DFBrowserPane_AttributePaneAPI* aPane = 0; @@ -197,7 +199,7 @@ QVariant DFBrowser_Module::GetAttributeInfo (Handle(TDF_Attribute) theAttribute, // function : GetAttributeInfo // purpose : // ======================================================================= -QVariant DFBrowser_Module::GetAttributeInfo (const Standard_CString& theAttributeName, DFBrowser_Module* theModule, +QVariant DFBrowser_Module::GetAttributeInfo (Standard_CString theAttributeName, DFBrowser_Module* theModule, int theRole, int theColumnId) { DFBrowserPane_AttributePane* anAttributePane = 0; @@ -222,7 +224,7 @@ QVariant DFBrowser_Module::GetAttributeInfo (const Standard_CString& theAttribut // function : CreateAttributePane // purpose : // ======================================================================= -DFBrowserPane_AttributePaneAPI* DFBrowser_Module::CreateAttributePane (const Standard_CString& theAttributeName) +DFBrowserPane_AttributePaneAPI* DFBrowser_Module::CreateAttributePane (Standard_CString theAttributeName) { DFBrowserPane_AttributePaneAPI* aPane = 0; // iteration should be performed from the tail of the list, as latest added creator has diff --git a/tools/DFBrowser/DFBrowser_Module.hxx b/tools/DFBrowser/DFBrowser_Module.hxx index e75fbb0f34..b8f2a481d1 100644 --- a/tools/DFBrowser/DFBrowser_Module.hxx +++ b/tools/DFBrowser/DFBrowser_Module.hxx @@ -55,7 +55,7 @@ public: Standard_EXPORT DFBrowser_Module(); //! Destructor - virtual ~DFBrowser_Module() Standard_OVERRIDE {}; + virtual ~DFBrowser_Module() {} //! Creates tree model for OCAF application Standard_EXPORT void CreateViewModel (void* theParent); @@ -85,7 +85,7 @@ public: //! \return an application instance Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const; - //! Rebuild an OCAF tree view model + //! Rebuilds an OCAF tree view model Standard_EXPORT void UpdateTreeModel(); //! Sets initial selection in OCAF tree view, it is an application(root) item @@ -96,7 +96,7 @@ public: //! \return an attribute Standard_EXPORT Handle(TDF_Attribute) FindAttribute (const QModelIndex& theIndex); - //! Append creator of a pane by attribute type + //! Appends creator of a pane by attribute type //! \param thePaneCreator void RegisterPaneCreator (DFBrowserPane_AttributePaneCreatorAPI* thePaneCreator) { myPaneCreators.append (thePaneCreator); } @@ -111,7 +111,7 @@ public: //! internal map and the module processes this kind of attribute //! \param theAttributeGUID an attribute key //! \return attribute pane - Standard_EXPORT DFBrowserPane_AttributePaneAPI* GetAttributePane (const Standard_CString& theAttributeName); + Standard_EXPORT DFBrowserPane_AttributePaneAPI* GetAttributePane (Standard_CString theAttributeName); //! Finds the attribute pane according to the give attribute and returns its information //! \param theAttribute a source attribute @@ -127,7 +127,7 @@ public: //! \param theRole a role of information, used by tree model (e.g. DisplayRole, icon, background and so on) //! \param theColumnId a tree model column //! \return value, interpreted by tree model depending on the role - Standard_EXPORT static QVariant GetAttributeInfo (const Standard_CString& theAttributeName, DFBrowser_Module* theModule, + Standard_EXPORT static QVariant GetAttributeInfo (Standard_CString theAttributeName, DFBrowser_Module* theModule, int theRole, int theColumnId); signals: @@ -139,7 +139,7 @@ protected: //! Tries to create attribute pane for the attribute name using registered attribute pane creators //! \param theAttributeName a source attribute //! \return attribute pane or NULL - DFBrowserPane_AttributePaneAPI* CreateAttributePane (const Standard_CString& theAttributeName); + DFBrowserPane_AttributePaneAPI* CreateAttributePane (Standard_CString theAttributeName); private: diff --git a/tools/DFBrowser/DFBrowser_OpenApplication.cxx b/tools/DFBrowser/DFBrowser_OpenApplication.cxx index 65785a7518..f915f91ad3 100644 --- a/tools/DFBrowser/DFBrowser_OpenApplication.cxx +++ b/tools/DFBrowser/DFBrowser_OpenApplication.cxx @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -48,7 +47,6 @@ namespace DFBrowser_OpenApplication return anApplication; } -#if OCC_VERSION_HEX > 0x060901 // Load static variables for STEPCAF (ssv; 16.08.2012) STEPCAFControl_Controller::Init(); @@ -74,7 +72,6 @@ namespace DFBrowser_OpenApplication PCDM_ReaderStatus aStatus = anApplication->Open (theFileName, aDocument); if (aStatus != PCDM_RS_OK) return Handle(TDocStd_Application)(); -#endif return anApplication; } diff --git a/tools/DFBrowser/DFBrowser_OpenApplication.hxx b/tools/DFBrowser/DFBrowser_OpenApplication.hxx index ccff70860c..4e1311729a 100644 --- a/tools/DFBrowser/DFBrowser_OpenApplication.hxx +++ b/tools/DFBrowser/DFBrowser_OpenApplication.hxx @@ -24,7 +24,7 @@ namespace DFBrowser_OpenApplication { - //! Open the application by the name. + //! Opens the application by the name. //! \param theFileName a name of the file initialized the application //! \param isSTEPFile an output parameter, true if the file name is a STEP file //! \return an opened application diff --git a/tools/DFBrowser/DFBrowser_PropertyPanel.hxx b/tools/DFBrowser/DFBrowser_PropertyPanel.hxx index 1a55af76f8..acc8312630 100644 --- a/tools/DFBrowser/DFBrowser_PropertyPanel.hxx +++ b/tools/DFBrowser/DFBrowser_PropertyPanel.hxx @@ -41,7 +41,7 @@ public: Standard_EXPORT DFBrowser_PropertyPanel (QWidget* theParent); //! Destructor - virtual ~DFBrowser_PropertyPanel() Standard_OVERRIDE {} + virtual ~DFBrowser_PropertyPanel() {} //! Returns main control QWidget* GetControl() const { return myMainWindow; } @@ -57,7 +57,7 @@ public: const QItemSelection& theDeselected); private: - QWidget* myMainWindow; //! < parent of attribute stack control - DFBrowser_AttributePaneStack* myAttributesStack; //! < panes stack + QWidget* myMainWindow; //!< parent of attribute stack control + DFBrowser_AttributePaneStack* myAttributesStack; //!< panes stack }; #endif diff --git a/tools/DFBrowser/DFBrowser_SearchLine.hxx b/tools/DFBrowser/DFBrowser_SearchLine.hxx index 54c3ae15d3..91fc567911 100644 --- a/tools/DFBrowser/DFBrowser_SearchLine.hxx +++ b/tools/DFBrowser/DFBrowser_SearchLine.hxx @@ -47,7 +47,7 @@ public: Standard_EXPORT DFBrowser_SearchLine (QWidget* theParent); //! Destructor - virtual ~DFBrowser_SearchLine() Standard_OVERRIDE {} + virtual ~DFBrowser_SearchLine() {} //! Creates search line model filled by the module. It is necessary for auto completion of line edit //! \param theModule a current module @@ -66,10 +66,10 @@ public: Standard_EXPORT void ClearValues(); //! Returns completer model - Standard_EXPORT QAbstractItemModel* GetModel() { return myLineControl->completer()->model(); } + QAbstractItemModel* GetModel() { return myLineControl->completer()->model(); } //! Returns completion completer model - Standard_EXPORT QAbstractItemModel* GetCompletionModel() { return myLineControl->completer()->completionModel(); } + QAbstractItemModel* GetCompletionModel() { return myLineControl->completer()->completionModel(); } //! Returns the current line edit text QString Text() const { return myLineControl->text(); } @@ -87,15 +87,17 @@ private slots: //! Updates icon of search button depending on text is empty and emits searchActivated signal void onTextChanged (const QString& theText); - //! Set completion prefix in completer model + + //! Sets completion prefix in completer model void onReturnPressed() { myLineControl->completer()->setCompletionPrefix (myLineControl->text()); } - //! Set empty text if the current text is not empty: new search is started + + //! Sets empty text if the current text is not empty: new search is started void onSearchButtonClicked(); private: QLineEdit* myLineControl; //!< line editor control - QToolButton* mySearchButton; //! < search button + QToolButton* mySearchButton; //!< search button }; #endif diff --git a/tools/DFBrowser/DFBrowser_SearchLineModel.hxx b/tools/DFBrowser/DFBrowser_SearchLineModel.hxx index 3aeb9eae7c..b7e73631d2 100644 --- a/tools/DFBrowser/DFBrowser_SearchLineModel.hxx +++ b/tools/DFBrowser/DFBrowser_SearchLineModel.hxx @@ -49,7 +49,7 @@ public: Standard_EXPORT DFBrowser_SearchLineModel (QObject* theParent, DFBrowser_Module* theModule); //! Destructor - virtual ~DFBrowser_SearchLineModel() Standard_OVERRIDE {} + virtual ~DFBrowser_SearchLineModel() {} //! Separator as attribute name is divided from the label entry in information text static QString SplitSeparator() { return ": "; } @@ -87,7 +87,6 @@ public: //! Returns the data stored under the given role for the item referred to by the index. //! \param theIndex a model index //! \param theRole an enumeration value of role for data obtaining - Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; //! Returns the number of rows under the given parent. @@ -96,10 +95,10 @@ public: virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE { (void)theParent; return myRowCount; } + //! Returns the number of columns for the children of the given parent. //! \param theParent a parent model index //! \return the number of columns - virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE { (void)theParent; return 3; } diff --git a/tools/DFBrowser/DFBrowser_SearchView.hxx b/tools/DFBrowser/DFBrowser_SearchView.hxx index dd5b482143..8e4abdf7a1 100644 --- a/tools/DFBrowser/DFBrowser_SearchView.hxx +++ b/tools/DFBrowser/DFBrowser_SearchView.hxx @@ -41,7 +41,7 @@ public: Standard_EXPORT DFBrowser_SearchView (QWidget* theParent); //! Destructor - virtual ~DFBrowser_SearchView() Standard_OVERRIDE {} + virtual ~DFBrowser_SearchView() {} //! Returns search parent control QWidget* GetControl() const { return myMainWindow; } diff --git a/tools/DFBrowser/DFBrowser_Thread.cxx b/tools/DFBrowser/DFBrowser_Thread.cxx index 00e6649cfa..75996be31a 100644 --- a/tools/DFBrowser/DFBrowser_Thread.cxx +++ b/tools/DFBrowser/DFBrowser_Thread.cxx @@ -34,7 +34,7 @@ public: DFBrowser_QThread (QObject* theParent) : QThread (theParent), myItem (0) {} //! Destructor - virtual ~DFBrowser_QThread() Standard_OVERRIDE {} + virtual ~DFBrowser_QThread() {} //! Sets thread item to be processed //! \param theItem a thread item diff --git a/tools/DFBrowser/DFBrowser_ThreadItemSearch.hxx b/tools/DFBrowser/DFBrowser_ThreadItemSearch.hxx index 5b73d2b635..674eedbbdc 100644 --- a/tools/DFBrowser/DFBrowser_ThreadItemSearch.hxx +++ b/tools/DFBrowser/DFBrowser_ThreadItemSearch.hxx @@ -48,10 +48,10 @@ public: //! internal containers for search functionality Standard_EXPORT virtual void Run() Standard_OVERRIDE; - //! Set filled containers into search line + //! Sets filled containers into search line Standard_EXPORT virtual void ApplyValues() Standard_OVERRIDE; - //! Clear search line values + //! Clears search line values Standard_EXPORT static void ClearValues (DFBrowser_SearchLine* theSearchLine); private: @@ -73,7 +73,7 @@ private: void addLabel (const TDF_Label& theLabel, const QStringList& theCurrentPath, QMap& theValues, QStringList& theInfoValues); - //! Add attribute information, it is either attribute kind or attribure value for TDataStd_Name or TDataStd_Comment + //! Adds attribute information, it is either attribute kind or attribure value for TDataStd_Name or TDataStd_Comment //! \parm theAttribute a current attribute //! \param theCurrentPath it contains the current path to the label (stores in container) //! \param theValues container of document item values diff --git a/tools/DFBrowser/DFBrowser_TreeLevelLine.hxx b/tools/DFBrowser/DFBrowser_TreeLevelLine.hxx index 2de8bfe3e6..7b305d51db 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelLine.hxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelLine.hxx @@ -54,7 +54,7 @@ public: Standard_EXPORT DFBrowser_TreeLevelLine (QWidget* theParent); //! Destructor - virtual ~DFBrowser_TreeLevelLine() Standard_OVERRIDE {} + virtual ~DFBrowser_TreeLevelLine() {} //! Clears history of selected items Standard_EXPORT void ClearHistory(); diff --git a/tools/DFBrowser/DFBrowser_TreeLevelLineDelegate.hxx b/tools/DFBrowser/DFBrowser_TreeLevelLineDelegate.hxx index c97c078a33..65d6b74323 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelLineDelegate.hxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelLineDelegate.hxx @@ -38,7 +38,7 @@ public: //! Destructor virtual ~DFBrowser_TreeLevelLineDelegate() {} - //! Draw an icon in the cell and highlight cell if mouse is over the cell + //! Draws an icon in the cell and highlight cell if mouse is over the cell //! \param thePainter a painter //! \param theOption a paint options //! \param theIndex a view index diff --git a/tools/DFBrowser/DFBrowser_TreeLevelLineModel.cxx b/tools/DFBrowser/DFBrowser_TreeLevelLineModel.cxx index 16e2964232..9bb3069ec2 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelLineModel.cxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelLineModel.cxx @@ -59,14 +59,17 @@ QVariant DFBrowser_TreeLevelLineModel::data (const QModelIndex& theIndex, int th if (theRole == Qt::DecorationRole) //! do not show icons presented in tree view return aValue; TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (aTreeIndex); - if (anItemBase) - { - DFBrowser_ItemBasePtr aDBrowserItem = itemDynamicCast (anItemBase); - bool aPrevValue = aDBrowserItem->SetUseAdditionalInfo (false); - aValue = aDBrowserItem->data (aTreeIndex, theRole); - aDBrowserItem->SetUseAdditionalInfo (aPrevValue); + if (!anItemBase) + return aValue; + + DFBrowser_ItemBasePtr aDBrowserItem = itemDynamicCast (anItemBase); + if (!aDBrowserItem) + return aValue; + + bool aPrevValue = aDBrowserItem->SetUseAdditionalInfo (false); + aValue = aDBrowserItem->data (aTreeIndex, theRole); + aDBrowserItem->SetUseAdditionalInfo (aPrevValue); - } if (theRole == Qt::DisplayRole) aValue = aValue.toString() + " "; //! TEMPORARY to leave place for the action icon } diff --git a/tools/DFBrowser/DFBrowser_TreeLevelLineModel.hxx b/tools/DFBrowser/DFBrowser_TreeLevelLineModel.hxx index 667f208d8b..e8f4e51ed6 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelLineModel.hxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelLineModel.hxx @@ -40,7 +40,7 @@ public: //! Destructor virtual ~DFBrowser_TreeLevelLineModel() {} - //! + //! Resets the cached values void Reset() { myLevelItems.clear(); } //! Inits the model by the index @@ -50,7 +50,7 @@ public: //! Returns true if the tree model index is filled bool IsInitialized() const { return myTreeIndex.isValid(); } - //! Return OCAF tree view model index on level defined by column of the parameter index + //! Returns OCAF tree view model index on level defined by column of the parameter index //! \param theIndex a tree level view model index //! \return model index const QModelIndex& GetTreeViewIndex (const QModelIndex& theIndex) const @@ -82,7 +82,7 @@ public: private: QModelIndex myTreeIndex; //!< the current OCAF tree view model index - QList myLevelItems; //! cached parent indices of myTreeIndex for quick access to item information + QList myLevelItems; //!< cached parent indices of myTreeIndex for quick access to item information }; #endif diff --git a/tools/DFBrowser/DFBrowser_TreeLevelView.hxx b/tools/DFBrowser/DFBrowser_TreeLevelView.hxx index ae961a9644..5878545f4e 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelView.hxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelView.hxx @@ -42,12 +42,12 @@ public: Standard_EXPORT DFBrowser_TreeLevelView (QWidget* theParent); //! Destructor - virtual ~DFBrowser_TreeLevelView() Standard_OVERRIDE {} + virtual ~DFBrowser_TreeLevelView() {} //! Returns parent control QWidget* GetControl() const { return myMainWindow; } - //! Clear selection of the table view selection model + //! Clears selection of the table view selection model Standard_EXPORT void ClearSelection(); //! Returns true if this control may be filled by the index @@ -56,7 +56,7 @@ public: //! \return boolean result Standard_EXPORT static bool ProcessItem (const QModelIndex& theIndex); - //! Init view by the first selected item in OCAF tree view + //! Inits view by the first selected item in OCAF tree view //! \param theSelected selected items //! \param theDeselected deselected items Standard_EXPORT void UpdateByTreeSelectionChanged (const QItemSelection& theSelected, diff --git a/tools/DFBrowser/DFBrowser_TreeLevelViewModel.cxx b/tools/DFBrowser/DFBrowser_TreeLevelViewModel.cxx index 63802ba1aa..59c6a7f14f 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelViewModel.cxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelViewModel.cxx @@ -92,6 +92,9 @@ QVariant DFBrowser_TreeLevelViewModel::data (const QModelIndex& theIndex, int th if (theIndex.column() == 0) { DFBrowser_ItemBasePtr aDBrowserItem = itemDynamicCast (anItemBase); + if (!aDBrowserItem) + return QVariant(); + bool aPrevValue = aDBrowserItem->SetUseAdditionalInfo (false); aValue = anItemBase->data (anIndex, theRole); aDBrowserItem->SetUseAdditionalInfo (aPrevValue); diff --git a/tools/DFBrowser/DFBrowser_TreeLevelViewModel.hxx b/tools/DFBrowser/DFBrowser_TreeLevelViewModel.hxx index 5c564f348f..a2c06136d0 100644 --- a/tools/DFBrowser/DFBrowser_TreeLevelViewModel.hxx +++ b/tools/DFBrowser/DFBrowser_TreeLevelViewModel.hxx @@ -37,9 +37,9 @@ public: DFBrowser_TreeLevelViewModel (QObject* theParent) : QAbstractTableModel (theParent), myRowCount (0) {} //! Destructor - virtual ~DFBrowser_TreeLevelViewModel() Standard_OVERRIDE {} + virtual ~DFBrowser_TreeLevelViewModel() {} - //! Reset OCAF tree model index + //! Resets OCAF tree model index void Reset() { myIndex = QModelIndex(); } //! Fills OCAF tree model index @@ -49,7 +49,7 @@ public: //! Returns true if the index is filled bool IsInitialized() const { return myIndex.isValid(); } - //! Return OCAF tree view model index on level defined by column of the parameter index + //! Returns OCAF tree view model index on level defined by column of the parameter index //! \param theIndex a tree level view model index //! \return model index Standard_EXPORT QModelIndex GetTreeViewIndex (const QModelIndex& theIndex) const; @@ -57,7 +57,7 @@ public: //! Emits the layoutChanged signal from outside of this class void EmitLayoutChanged() { emit layoutChanged(); } - //! It returns value only for DisplayRole for column = 1 + //! Returns value only for DisplayRole for column = 1 //! \param theSection an index of value in the container //! \param theIndex a model index //! \param theRole a view role diff --git a/tools/DFBrowser/DFBrowser_TreeModel.cxx b/tools/DFBrowser/DFBrowser_TreeModel.cxx index 16fe10485e..23ab2c2aa8 100644 --- a/tools/DFBrowser/DFBrowser_TreeModel.cxx +++ b/tools/DFBrowser/DFBrowser_TreeModel.cxx @@ -38,12 +38,27 @@ const int COLUMN_NAME_WIDTH = 300; // function : Constructor // purpose : // ======================================================================= -DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule) +DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); +} - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void DFBrowser_TreeModel::InitColumns() +{ + SetHeaderItem (0, TreeModel_HeaderSection ("Name")); +} + +// ======================================================================= +// function : SetModule +// purpose : +// ======================================================================= +void DFBrowser_TreeModel::SetModule (DFBrowser_Module* theModule) +{ + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); aRootItem->SetModule (theModule); } @@ -51,9 +66,9 @@ DFBrowser_TreeModel::DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* // function : createRootItem // purpose : // ======================================================================= -void DFBrowser_TreeModel::createRootItem (const int) +TreeModel_ItemBasePtr DFBrowser_TreeModel::createRootItem (const int) { - m_pRootItem = DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr()); + return DFBrowser_ItemApplication::CreateItem (TreeModel_ItemBasePtr()); } // ======================================================================= @@ -62,7 +77,7 @@ void DFBrowser_TreeModel::createRootItem (const int) // ======================================================================= void DFBrowser_TreeModel::Init (const Handle(TDocStd_Application)& theApplication) { - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); Reset(); aRootItem->SetApplication (theApplication); EmitLayoutChanged(); @@ -74,7 +89,7 @@ void DFBrowser_TreeModel::Init (const Handle(TDocStd_Application)& theApplicatio // ======================================================================= Handle(TDocStd_Application) DFBrowser_TreeModel::GetTDocStdApplication() const { - DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (m_pRootItem); + DFBrowser_ItemApplicationPtr aRootItem = itemDynamicCast (RootItem (0)); return aRootItem->GetApplication(); } @@ -179,7 +194,7 @@ QModelIndex DFBrowser_TreeModel::FindIndexByPath (const QStringList& theLabelEnt if (aPathId == aPathCount && anItem->HasAttribute()) { // processing attribute in theValue - DFBrowser_ItemApplicationPtr aRootAppItem = itemDynamicCast(m_pRootItem); + DFBrowser_ItemApplicationPtr aRootAppItem = itemDynamicCast(RootItem (0)); QString anAttributeInfo = DFBrowser_Module::GetAttributeInfo (anItem->GetAttribute(), aRootAppItem->GetModule(), Qt::DisplayRole, 0).toString(); if (anAttributeInfo == anEntry) diff --git a/tools/DFBrowser/DFBrowser_TreeModel.hxx b/tools/DFBrowser/DFBrowser_TreeModel.hxx index 6182c25b56..c1e1f0523b 100644 --- a/tools/DFBrowser/DFBrowser_TreeModel.hxx +++ b/tools/DFBrowser/DFBrowser_TreeModel.hxx @@ -45,14 +45,20 @@ class DFBrowser_TreeModel : public TreeModel_ModelBase public: //! Constructor - Standard_EXPORT DFBrowser_TreeModel (QObject* theParent, DFBrowser_Module* theModule); + Standard_EXPORT DFBrowser_TreeModel (QObject* theParent); //! Destructor - virtual ~DFBrowser_TreeModel() Standard_OVERRIDE {}; + virtual ~DFBrowser_TreeModel() {} + + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; //! Fills the root item by the application Standard_EXPORT void Init (const Handle(TDocStd_Application)& theApplication); + //! Fills root item by the module + Standard_EXPORT void SetModule (DFBrowser_Module* theModule); + //! Returns an OCAF application or NULL //! \return an application instance Standard_EXPORT Handle(TDocStd_Application) GetTDocStdApplication() const; @@ -98,7 +104,7 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId); + Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: diff --git a/tools/DFBrowser/DFBrowser_Window.cxx b/tools/DFBrowser/DFBrowser_Window.cxx index 5801326f84..01b100b189 100644 --- a/tools/DFBrowser/DFBrowser_Window.cxx +++ b/tools/DFBrowser/DFBrowser_Window.cxx @@ -47,10 +47,9 @@ #include #include +#include #include -#include - #include #include #include @@ -102,6 +101,8 @@ const int DFBROWSER_DEFAULT_POSITION_Y = 60; const int DEFAULT_PROPERTY_PANEL_HEIGHT = 200; const int DEFAULT_BROWSER_HEIGHT = 800; +//#define USE_DUMPJSON + // ======================================================================= // function : Constructor // purpose : @@ -161,12 +162,24 @@ DFBrowser_Window::DFBrowser_Window() connect (aLevelView, SIGNAL (indexDoubleClicked (const QModelIndex&)), this, SLOT (onLevelDoubleClicked (const QModelIndex&))); + // property widget 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); + // property view +#ifdef USE_DUMPJSON + myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel (DumpJson)"), myMainWindow); + myPropertyView = new ViewControl_PropertyView (myMainWindow, + QSize(DFBROWSER_DEFAULT_VIEW_WIDTH, DFBROWSER_DEFAULT_VIEW_HEIGHT)); + myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle()); + myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow)); + myPropertyPanelWidget->setWidget (myPropertyView->GetControl()); + myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget); +#endif + // dump view window QWidget* aDumpWidget = new QWidget(myMainWindow); QVBoxLayout* aDumpLay = new QVBoxLayout(aDumpWidget); @@ -181,20 +194,26 @@ DFBrowser_Window::DFBrowser_Window() // view myViewWindow = new View_Window (myMainWindow); - myViewWindow->GetView()->SetPredefinedSize (DFBROWSER_DEFAULT_VIEW_WIDTH, DFBROWSER_DEFAULT_VIEW_HEIGHT); + myViewWindow->ViewWidget()->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->setTitleBarWidget (myViewWindow->ViewToolBar()->GetControl()); aViewDockWidget->setWidget (myViewWindow); 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); + myViewWindow->Displayer()->SetAttributeColor (Quantity_Color(aHColor.red() / 255., aHColor.green() / 255., + aHColor.blue() / 255., Quantity_TOC_sRGB), View_PresentationType_Additional); - myMainWindow->splitDockWidget(aPropertyPanelWidget, aViewDockWidget, Qt::Vertical); + myMainWindow->splitDockWidget (aPropertyPanelWidget, aViewDockWidget, Qt::Vertical); + +#ifdef USE_DUMPJSON + myMainWindow->tabifyDockWidget (aDumpDockWidget, myPropertyPanelWidget); + myMainWindow->tabifyDockWidget (myPropertyPanelWidget, aViewDockWidget); +#else myMainWindow->tabifyDockWidget (aDumpDockWidget, aViewDockWidget); +#endif myTreeView->resize (DFBROWSER_DEFAULT_TREE_VIEW_WIDTH, DFBROWSER_DEFAULT_TREE_VIEW_HEIGHT); @@ -254,7 +273,7 @@ void DFBrowser_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem QMap anItems; TreeModel_Tools::SaveState (myTreeView, anItems); - View_Tools::SaveState(myViewWindow, anItems); + View_Window::SaveState(myViewWindow, anItems); for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); @@ -278,7 +297,7 @@ void DFBrowser_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& t 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())) + else if (View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) continue; } } @@ -420,6 +439,11 @@ void DFBrowser_Window::Init (const NCollection_List& } return; } + else + { + if (anApplication.IsNull() && CDF_Session::Exists()) + anApplication = Handle(TDocStd_Application)::DownCast (CDF_Session::CurrentSession()->CurrentApplication()); + } myModule = new DFBrowser_Module(); myModule->CreateViewModel (myMainWindow); @@ -659,7 +683,7 @@ void DFBrowser_Window::onExpand() for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) { int aLevels = 2; - setExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); } QApplication::restoreOverrideCursor(); } @@ -677,7 +701,7 @@ void DFBrowser_Window::onExpandAll() for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) { int aLevels = -1; - setExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); } QApplication::restoreOverrideCursor(); } @@ -692,7 +716,7 @@ void DFBrowser_Window::onCollapseAll() QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes(); for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) { int aLevels = -1; - setExpanded (myTreeView, aSelectedIndices[aSelectedId], false, aLevels); + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], false, aLevels); } } @@ -705,6 +729,12 @@ void DFBrowser_Window::onTreeViewSelectionChanged (const QItemSelection& theSele { if (!myModule) return; + +#ifdef USE_DUMPJSON + if (myPropertyPanelWidget->toggleViewAction()->isChecked()) + myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel())); +#endif + // previuos selection should be cleared in the panel selectors DFBrowser_AttributePaneStack* anAttributePaneStack = myPropertyPanel->GetAttributesStack(); anAttributePaneStack->GetPaneSelector()->ClearSelected(); @@ -716,7 +746,7 @@ void DFBrowser_Window::onTreeViewSelectionChanged (const QItemSelection& theSele QModelIndex aSelectedIndex = TreeModel_ModelBase::SingleSelected (aSelectedIndices, 0); myTreeView->scrollTo (aSelectedIndex); - View_Displayer* aDisplayer = myViewWindow->GetDisplayer(); + View_Displayer* aDisplayer = myViewWindow->Displayer(); aDisplayer->ErasePresentations (View_PresentationType_Additional, false); aDisplayer->DisplayPresentation (findPresentation (aSelectedIndex), View_PresentationType_Main); @@ -765,7 +795,7 @@ void DFBrowser_Window::onPaneSelectionChanged (const QItemSelection&, { TCollection_AsciiString aPluginShortName = aPluginName.SubString (3, aPluginName.Length()); QString aMessage = QString ("TShape %1 is sent to %2.") - .arg (DFBrowserPane_Tools::GetPointerInfo (aParameters.Last()).ToCString()) + .arg (Standard_Dump::GetPointerInfo (aParameters.Last()).ToCString()) .arg (aPluginShortName.ToCString()); QString aQuestion = QString ("Would you like to activate %1 immediately?\n") .arg (aPluginShortName.ToCString()).toStdString().c_str(); @@ -793,7 +823,7 @@ void DFBrowser_Window::onPaneSelectionChanged (const QItemSelection&, // make the shape visualized QModelIndex aSelectedIndex = aSelectedIndices.first(); - View_Displayer* aDisplayer = myViewWindow->GetDisplayer(); + View_Displayer* aDisplayer = myViewWindow->Displayer(); aDisplayer->DisplayPresentation (findPresentation (aSelectedIndex), View_PresentationType_Main); // highlight and scroll to the referenced item if it exists @@ -894,7 +924,7 @@ void DFBrowser_Window::onLevelSelected (const QModelIndex& theIndex) QModelIndexList anIndices; anIndices.append (theIndex); highlightIndices (anIndices); - View_Displayer* aDisplayer = myViewWindow->GetDisplayer(); + View_Displayer* aDisplayer = myViewWindow->Displayer(); aDisplayer->ErasePresentations (View_PresentationType_Additional, false); aDisplayer->DisplayPresentation (findPresentation (theIndex), View_PresentationType_Main); } @@ -988,26 +1018,3 @@ void DFBrowser_Window::findPresentations (const QModelIndexList& theIndices, AIS thePresentations.Append (aPresentation); } } - -// ======================================================================= -// function : setExpanded -// purpose : -// ======================================================================= -void DFBrowser_Window::setExpanded (QTreeView* theTreeView, const QModelIndex& theIndex, const bool isExpanded, - int& theLevels) -{ - bool isToExpand = theLevels == -1 || theLevels > 0; - if (!isToExpand) - return; - - theTreeView->setExpanded (theIndex, isExpanded); - if (theLevels != -1) - theLevels--; - - QAbstractItemModel* aModel = theTreeView->model(); - for (int aRowId = 0, aRows = aModel->rowCount (theIndex); aRowId < aRows; aRowId++) - { - int aLevels = theLevels; - setExpanded (theTreeView, aModel->index (aRowId, 0, theIndex), isExpanded, aLevels); - } -} diff --git a/tools/DFBrowser/DFBrowser_Window.hxx b/tools/DFBrowser/DFBrowser_Window.hxx index 93fb3d7e0c..17b2f21c4d 100644 --- a/tools/DFBrowser/DFBrowser_Window.hxx +++ b/tools/DFBrowser/DFBrowser_Window.hxx @@ -39,12 +39,14 @@ class DFBrowser_Thread; class DFBrowser_TreeLevelLine; class ViewControl_MessageDialog; +class ViewControl_PropertyView; class View_ToolBar; class View_Window; class QAbstractItemModel; class QAction; +class QDockWidget; class QTreeView; class QWidget; @@ -62,7 +64,7 @@ public: Standard_EXPORT DFBrowser_Window(); //! Destructor - Standard_EXPORT virtual ~DFBrowser_Window() Standard_OVERRIDE; + Standard_EXPORT virtual ~DFBrowser_Window(); //! Appends main window into layout of the parent if the parent is child of QWidget //! \param theParent a parent class @@ -72,7 +74,7 @@ public: //! \param theParameters a parameters container void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; } - //! Provide container for actions available in inspector on general level + //! Provides 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); @@ -125,13 +127,13 @@ private slots: //! \param thePosition a clicked point void onTreeViewContextMenuRequested (const QPoint& thePosition); - //! Expand two next levels for all selected item + //! Expands two next levels for all selected item void onExpand(); - //! Expand all levels for all selected items + //! Expands all levels for all selected items void onExpandAll(); - //! Collapse all levels for all selected items + //! Collapses all levels for all selected items void onCollapseAll(); //! Udpates all controls by changed selection in OCAF tree view @@ -206,13 +208,6 @@ protected: //! \return container of presentations or NULL void findPresentations (const QModelIndexList& theIndices, AIS_ListOfInteractive& thePresentations); - //! Recursive items expanding in tree view staring from the index - //! \param theTreeView an OCAF tree view - //! \param theParentIndex an index which children should be expanded - //! \param isExpanded a boolean state if the item should be expanded or collapsed - //! \param theLevels a number of levels to be expanded, or -1 for all levels - static void setExpanded (QTreeView* theTreeView, const QModelIndex& theParentIndex, const bool isExpanded, int& theLevels); - private: DFBrowser_Module* myModule; //!< current module @@ -220,7 +215,9 @@ private: QMainWindow* myMainWindow; //!< main control for all components DFBrowser_TreeLevelLine* myTreeLevelLine; //!< navigate line of tree levels to the selected item QTreeView* myTreeView; //!< OCAF tree view + QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget DFBrowser_PropertyPanel* myPropertyPanel; //!< property panel shows full information about attribute or search view + ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist 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 diff --git a/tools/DFBrowserPane/DFBrowserPane.hxx b/tools/DFBrowserPane/DFBrowserPane.hxx deleted file mode 100644 index be7be47031..0000000000 --- a/tools/DFBrowserPane/DFBrowserPane.hxx +++ /dev/null @@ -1,33 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef DFBROWSERPANE_H -#define DFBROWSERPANE_H - -#ifdef __DFBrowserPane_DLL - #ifdef _WIN32 - #define DFBROWSERPANE_EXPORT __declspec(dllexport) - #else - #define DFBROWSERPANE_EXPORT - #endif -#else - #ifdef _WIN32 - #define DFBROWSERPANE_EXPORT __declspec(dllimport) - #else - #define DFBROWSERPANE_EXPORT - #endif -#endif - -#endif diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePane.cxx b/tools/DFBrowserPane/DFBrowserPane_AttributePane.cxx index 9468629a8b..2bf6f29dbb 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePane.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePane.cxx @@ -140,7 +140,7 @@ void DFBrowserPane_AttributePane::GetShortAttributeInfo (const Handle(TDF_Attrib // function : GetAttributeInfoByType // purpose : // ======================================================================= -QVariant DFBrowserPane_AttributePane::GetAttributeInfoByType (const Standard_CString& theAttributeName, +QVariant DFBrowserPane_AttributePane::GetAttributeInfoByType (Standard_CString theAttributeName, int theRole, int theColumnId) { if (theColumnId != 0) diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePane.hxx b/tools/DFBrowserPane/DFBrowserPane_AttributePane.hxx index c312d15668..2a3d1a9218 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePane.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePane.hxx @@ -74,7 +74,7 @@ public: //! \param theRole a role of information, used by tree model (e.g. DisplayRole, icon, background and so on) //! \param theColumnId a tree model column //! \return value, interpreted by tree model depending on the role - Standard_EXPORT static QVariant GetAttributeInfoByType(const Standard_CString& theAttributeName, int theRole, int theColumnId); + Standard_EXPORT static QVariant GetAttributeInfoByType(Standard_CString theAttributeName, int theRole, int theColumnId); //! Returns information for the given attribute //! \param theAttribute a current attribute diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.cxx b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.cxx index 9869790ed4..872a590ac5 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.cxx @@ -126,8 +126,7 @@ // function : Constructor // purpose : // ======================================================================= -DFBrowserPane_AttributePaneAPI* DFBrowserPane_AttributePaneCreator::CreateAttributePane ( - const Standard_CString& theAttributeName) +DFBrowserPane_AttributePaneAPI* DFBrowserPane_AttributePaneCreator::CreateAttributePane (Standard_CString theAttributeName) { DFBrowserPane_AttributePaneAPI* aPane = 0; if (theAttributeName == STANDARD_TYPE (TDF_Reference)->Name()) diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.hxx b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.hxx index 5e4fdb89bd..0b6a64e241 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreator.hxx @@ -38,7 +38,7 @@ public: //! Creates attribute pane for TDF, TDataStd, TDocStd, TPrsStd, TNaming and TFunction attribute types //! \param theAttributeName a standard type of attribute //! \return an attribute pane if it can be created for this type - Standard_EXPORT virtual DFBrowserPane_AttributePaneAPI* CreateAttributePane(const Standard_CString& theAttributeName) Standard_OVERRIDE; + Standard_EXPORT virtual DFBrowserPane_AttributePaneAPI* CreateAttributePane(Standard_CString theAttributeName) Standard_OVERRIDE; }; #endif diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreatorAPI.hxx b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreatorAPI.hxx index e818c4dc51..1537b69691 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreatorAPI.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePaneCreatorAPI.hxx @@ -36,7 +36,7 @@ public: //! Creates attribute pane for attribute types //! \param theAttributeName a standard type of attribute //! \return an attribute pane if it can be created for this type - virtual DFBrowserPane_AttributePaneAPI* CreateAttributePane (const Standard_CString& theAttributeName) = 0; + virtual DFBrowserPane_AttributePaneAPI* CreateAttributePane (Standard_CString theAttributeName) = 0; }; #endif diff --git a/tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.hxx b/tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.hxx index a578052794..69c64f4ec5 100644 --- a/tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_AttributePaneModel.hxx @@ -42,7 +42,7 @@ public: virtual ~DFBrowserPane_AttributePaneModel() {} //! Sets direction of the values applying, whether it should be placed by rows or by columns - //! \param theOrientation if horizontal, the values are applyed by rows, otherwise by columns + //! \param theOrientation if horizontal, the values are applied by rows, otherwise by columns void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; } //! Returns table orientation for setting data values diff --git a/tools/DFBrowserPane/DFBrowserPane_HelperExport.hxx b/tools/DFBrowserPane/DFBrowserPane_HelperExport.hxx index dac03024a3..0715326798 100644 --- a/tools/DFBrowserPane/DFBrowserPane_HelperExport.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_HelperExport.hxx @@ -16,7 +16,6 @@ #ifndef DFBrowserPane_HelperExport_H #define DFBrowserPane_HelperExport_H -#include #include #include @@ -29,7 +28,7 @@ //! It contains a conainer of shapes for model indices. If button is pressed for index where the //! shape exists, this shape is exported to BREP file. //! It contains a container of shapes, it is important to clear this helper after using. -class DFBROWSERPANE_EXPORT DFBrowserPane_HelperExport : public QObject +class DFBrowserPane_HelperExport : public QObject { Q_OBJECT public: @@ -55,7 +54,7 @@ public: //! Returns shape for the index //! \param theIndex a model view index //! \return a cached shape - const TopoDS_Shape& GetShape (const QModelIndex& theIndex) { return myShapes[theIndex]; } + const TopoDS_Shape& Shape (const QModelIndex& theIndex) { return myShapes[theIndex]; } public slots: diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx index 0e79829114..a903cf3f25 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.cxx @@ -41,6 +41,7 @@ DFBrowserPane_TDataStdTreeNode::DFBrowserPane_TDataStdTreeNode() : DFBrowserPane_AttributePane(), myTreeNodeView (0) { myModel = new DFBrowserPane_TDataStdTreeNodeModel (0); + myModel->InitColumns(); mySelectionModels.clear(); // do not use selection model of parent pane mySelectionModels.push_back (new QItemSelectionModel (myModel)); } @@ -99,15 +100,14 @@ void DFBrowserPane_TDataStdTreeNode::Init (const Handle(TDF_Attribute)& theAttri } - DFBrowserPane_TDataStdTreeNodeModel* aModel = dynamic_cast (myModel); - aModel->Reset(); + myModel->Reset(); if (!aTreeNode.IsNull()) { Handle(TDataStd_TreeNode) aRootItem = aTreeNode->Root(); - aModel->SetAttribute (aRootItem); + myModel->SetAttribute (aRootItem); - QModelIndex anIndex = aModel->FindIndex (theAttribute, QModelIndex()); + QModelIndex anIndex = myModel->FindIndex (theAttribute, QModelIndex()); if (myTreeNodeView && anIndex.isValid()) { myTreeNodeView->setExpanded (anIndex.parent(), true); @@ -119,7 +119,7 @@ void DFBrowserPane_TDataStdTreeNode::Init (const Handle(TDF_Attribute)& theAttri anAttributeNodeItem->setCurrentAttribute (true); } } - aModel->EmitLayoutChanged(); + myModel->EmitLayoutChanged(); } // ======================================================================= diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx index 9057060869..50d676a419 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNode.hxx @@ -20,7 +20,7 @@ #include -class QAbstractItemModel; +class DFBrowserPane_TDataStdTreeNodeModel; class QTreeView; //! \class DFBrowserPane_TDataStdTreeNode @@ -66,7 +66,7 @@ public: private: - QAbstractItemModel* myModel; + DFBrowserPane_TDataStdTreeNodeModel* myModel; QTreeView* myTreeNodeView; }; diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeItem.hxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeItem.hxx index 2c3818f9cd..9570aea1b6 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeItem.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeItem.hxx @@ -39,15 +39,15 @@ class DFBrowserPane_TDataStdTreeNodeItem : public TreeModel_ItemBase public: //! Creates an item wrapped by a shared pointer - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item //! \return the pointer to the created item static DFBrowserPane_TDataStdTreeNodeItemPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) { return DFBrowserPane_TDataStdTreeNodeItemPtr (new DFBrowserPane_TDataStdTreeNodeItem (theParent, theRow, theColumn)); } //!Destructor - virtual ~DFBrowserPane_TDataStdTreeNodeItem() Standard_OVERRIDE {}; + virtual ~DFBrowserPane_TDataStdTreeNodeItem() Standard_OVERRIDE {} //! Store a current attribute //! \param theAttribute an attribute @@ -90,13 +90,13 @@ protected: protected: //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item DFBrowserPane_TDataStdTreeNodeItem(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : TreeModel_ItemBase (theParent, theRow, theColumn), myIsCurrentItem (false) {} - //! Initialize the current item. It creates a backup of the specific item information + //! Initializes the current item. It creates a backup of the specific item information void initItem() const; //! Returns number of children attributes, initializes item is necessary diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx index aaa62b23b5..4f8a4847f0 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.cxx @@ -29,16 +29,24 @@ DFBrowserPane_TDataStdTreeNodeModel::DFBrowserPane_TDataStdTreeNodeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - createRootItem(0); +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void DFBrowserPane_TDataStdTreeNodeModel::InitColumns() +{ + SetHeaderItem (0, TreeModel_HeaderSection ("Name")); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) { - m_pRootItem = DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); + return DFBrowserPane_TDataStdTreeNodeItem::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= @@ -47,7 +55,7 @@ void DFBrowserPane_TDataStdTreeNodeModel::createRootItem (const int theColumnId) // ======================================================================= void DFBrowserPane_TDataStdTreeNodeModel::SetAttribute (const Handle(TDF_Attribute)& theAttribute) { - DFBrowserPane_TDataStdTreeNodeItemPtr aRootItem = itemDynamicCast(m_pRootItem); + DFBrowserPane_TDataStdTreeNodeItemPtr aRootItem = itemDynamicCast(RootItem (0)); Reset(); aRootItem->SetAttribute (theAttribute); EmitLayoutChanged(); diff --git a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx index 9223cfa19b..b5acae2c79 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDataStdTreeNodeModel.hxx @@ -38,7 +38,10 @@ public: Standard_EXPORT DFBrowserPane_TDataStdTreeNodeModel (QObject* theParent); //! Destructor - virtual ~DFBrowserPane_TDataStdTreeNodeModel() Standard_OVERRIDE {}; + virtual ~DFBrowserPane_TDataStdTreeNodeModel() Standard_OVERRIDE {} + + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; //! Initializes the tree model by the attribute //! \param theAttribute a current attribute @@ -59,7 +62,7 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: diff --git a/tools/DFBrowserPane/DFBrowserPane_TDocStdOwner.cxx b/tools/DFBrowserPane/DFBrowserPane_TDocStdOwner.cxx index 590af0b64b..61f48d334f 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TDocStdOwner.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TDocStdOwner.cxx @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -56,7 +55,7 @@ void DFBrowserPane_TDocStdOwner::GetValues (const Handle(TDF_Attribute)& theAttr if (aDocument.IsNull()) return; - TCollection_AsciiString aDocumentInfo = DFBrowserPane_Tools::GetPointerInfo (aDocument).ToCString(); + TCollection_AsciiString aDocumentInfo = Standard_Dump::GetPointerInfo (aDocument).ToCString(); TColStd_SequenceOfExtendedString anExtensions; aDocument->Extensions(anExtensions); TCollection_AsciiString aSeparationStr = "---------------------------"; @@ -100,7 +99,7 @@ void DFBrowserPane_TDocStdOwner::GetValues (const Handle(TDF_Attribute)& theAttr // TDocStd_Document methods TCollection_AsciiString aDocumentDataInfo = !aDocument->GetData().IsNull() - ? DFBrowserPane_Tools::GetPointerInfo (aDocument->GetData()).ToCString() : ""; + ? Standard_Dump::GetPointerInfo (aDocument->GetData()).ToCString() : ""; theValues << aSeparationStr.ToCString() << aSeparationStr.ToCString() << STANDARD_TYPE (TDocStd_Document)->Name() << "" << aSeparationStr.ToCString() << aSeparationStr.ToCString() @@ -119,9 +118,7 @@ void DFBrowserPane_TDocStdOwner::GetValues (const Handle(TDF_Attribute)& theAttr << "GetUndos" << convertToString (aDocument->GetUndos()) << "GetAvailableRedos" << QString::number (aDocument->GetAvailableRedos()) << "GetRedos" << convertToString (aDocument->GetRedos()) -#if OCC_VERSION_HEX > 0x070100 << "EmptyLabelsSavingMode" << DFBrowserPane_Tools::BoolToStr (aDocument->EmptyLabelsSavingMode()) -#endif << "IsNestedTransactionMode" << DFBrowserPane_Tools::BoolToStr (aDocument->IsNestedTransactionMode()) << "ModificationMode" << DFBrowserPane_Tools::BoolToStr (aDocument->ModificationMode()); } diff --git a/tools/DFBrowserPane/DFBrowserPane_TNamingNamedShape.cxx b/tools/DFBrowserPane/DFBrowserPane_TNamingNamedShape.cxx index bd40910bb5..e9220e56bc 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TNamingNamedShape.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TNamingNamedShape.cxx @@ -154,7 +154,7 @@ void DFBrowserPane_TNamingNamedShape::Init (const Handle(TDF_Attribute)& theAttr aFreeRows << 0 << 1; TopoDS_Shape aShape = aShapeAttr->Get(); - TCollection_AsciiString aShapeInfo = !aShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()) : ""; + TCollection_AsciiString aShapeInfo = !aShape.IsNull() ? Standard_Dump::GetPointerInfo (aShape.TShape()) : ""; aValues << "Shape" << aShapeInfo.ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (aShape) << "" << ""; aShapes.Append (aShape); if (aShape.IsNull()) @@ -162,7 +162,7 @@ void DFBrowserPane_TNamingNamedShape::Init (const Handle(TDF_Attribute)& theAttr TopoDS_Shape aCurrentShape = TNaming_Tool::CurrentShape (aShapeAttr); TCollection_AsciiString aCurrentShapeInfo = !aCurrentShape.IsNull() ? - DFBrowserPane_Tools::GetPointerInfo (aCurrentShape.TShape()) : ""; + Standard_Dump::GetPointerInfo (aCurrentShape.TShape()) : ""; aValues << "CurrentShape" << aCurrentShapeInfo.ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (aCurrentShape) << "" << ""; aShapes.Append (aCurrentShape); @@ -171,7 +171,7 @@ void DFBrowserPane_TNamingNamedShape::Init (const Handle(TDF_Attribute)& theAttr TopoDS_Shape anOriginalShape = TNaming_Tool::OriginalShape (aShapeAttr); TCollection_AsciiString anOriginalShapeInfo = !anOriginalShape.IsNull() ? - DFBrowserPane_Tools::GetPointerInfo (anOriginalShape.TShape()) : ""; + Standard_Dump::GetPointerInfo (anOriginalShape.TShape()) : ""; aValues << "OriginalShape" << anOriginalShapeInfo.ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (anOriginalShape) << "" << ""; aShapes.Append (anOriginalShape); @@ -227,14 +227,14 @@ void DFBrowserPane_TNamingNamedShape::Init (const Handle(TDF_Attribute)& theAttr aLabelInfo = QString (DFBrowserPane_Tools::GetEntry (anOldLabel).ToCString()); } if (!aNewShape.IsNull()) - aValues << DFBrowserPane_Tools::GetPointerInfo (aNewShape.TShape()->This()).ToCString() + aValues << Standard_Dump::GetPointerInfo (aNewShape.TShape()->This()).ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (aNewShape) << ""; else aValues << "-" << "-" << ""; aValues << "Old:"; if (!anOldShape.IsNull()) - aValues << DFBrowserPane_Tools::GetPointerInfo (anOldShape.TShape()->This()).ToCString() + aValues << Standard_Dump::GetPointerInfo (anOldShape.TShape()->This()).ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (anOldShape) << aLabelInfo << ""; @@ -382,7 +382,7 @@ void DFBrowserPane_TNamingNamedShape::GetSelectionParameters (QItemSelectionMode if (aSelectedIndex.column() != 4) return; - const TopoDS_Shape& aShape = myHelperExport.GetShape (aSelectedIndex); + const TopoDS_Shape& aShape = myHelperExport.Shape (aSelectedIndex); if (aShape.IsNull()) return; theParameters.Append (aShape.TShape()); @@ -467,7 +467,7 @@ TopoDS_Shape DFBrowserPane_TNamingNamedShape::getSelectedShapes() QModelIndex anIndex = *anIt; if (!myHelperExport.HasShape (anIndex)) continue; - aBuilder.Add (aComp, myHelperExport.GetShape (anIndex)); + aBuilder.Add (aComp, myHelperExport.Shape (anIndex)); aHasShapes = true; } @@ -480,7 +480,7 @@ TopoDS_Shape DFBrowserPane_TNamingNamedShape::getSelectedShapes() QModelIndex anIndex = *anIt; if (!myHelperExport.HasShape (anIndex)) continue; - aBuilder.Add (aComp, myHelperExport.GetShape (anIndex)); + aBuilder.Add (aComp, myHelperExport.Shape (anIndex)); aHasShapes = true; } if (aHasShapes) diff --git a/tools/DFBrowserPane/DFBrowserPane_TNamingNaming.cxx b/tools/DFBrowserPane/DFBrowserPane_TNamingNaming.cxx index a70d5f2e6f..afd1cbe085 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TNamingNaming.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TNamingNaming.cxx @@ -124,7 +124,7 @@ void DFBrowserPane_TNamingNaming::GetValues (const Handle(TDF_Attribute)& theAtt theValues.append (QString::number (aNamingName.Index())); TopoDS_Shape aShape = aNamingName.Shape(); theValues.append ("Shape(TShape)"); - theValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString() : ""); + theValues.append (!aShape.IsNull() ? Standard_Dump::GetPointerInfo (aShape.TShape()->This()).ToCString() : ""); TDF_Label aContextLabel = aNamingName.ContextLabel(); theValues.append ("ContextLabel"); theValues.append (!aContextLabel.IsNull() ? DFBrowserPane_Tools::GetEntry (aContextLabel).ToCString() : ""); diff --git a/tools/DFBrowserPane/DFBrowserPane_TNamingUsedShapes.cxx b/tools/DFBrowserPane/DFBrowserPane_TNamingUsedShapes.cxx index 19d54ad8d4..6f5f6c1269 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TNamingUsedShapes.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TNamingUsedShapes.cxx @@ -80,7 +80,7 @@ void DFBrowserPane_TNamingUsedShapes::GetValues (const Handle(TDF_Attribute)& th if (!aShape.IsNull()) { theValues.append(DFBrowserPane_Tools::ToName(DB_SHAPE_TYPE, aShape.ShapeType()).ToCString()); - theValues.append(DFBrowserPane_Tools::GetPointerInfo(aShape.TShape()->This()).ToCString()); + theValues.append(Standard_Dump::GetPointerInfo(aShape.TShape()->This()).ToCString()); } else theValues << "EMPTY SHAPE" << ""; @@ -89,7 +89,7 @@ void DFBrowserPane_TNamingUsedShapes::GetValues (const Handle(TDF_Attribute)& th { theValues.append(DFBrowserPane_Tools::GetEntry(aPtrRefShape->Label()).ToCString()); const TopoDS_Shape& aValueShape = aPtrRefShape->Shape(); - theValues.append(!aValueShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo(aValueShape.TShape()->This()).ToCString() : ""); + theValues.append(!aValueShape.IsNull() ? Standard_Dump::GetPointerInfo(aValueShape.TShape()->This()).ToCString() : ""); } else theValues << "" << ""; diff --git a/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISPresentation.cxx b/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISPresentation.cxx index 3b210443a4..4a3e75989f 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISPresentation.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISPresentation.cxx @@ -63,7 +63,7 @@ void DFBrowserPane_TPrsStdAISPresentation::GetValues (const Handle(TDF_Attribute << "GetAIS" << (anIO.IsNull() ? "Null" : anAttribute->DynamicType()->Name()) << "IsDisplayed" << DFBrowserPane_Tools::BoolToStr (anAttribute->IsDisplayed()) << "GetContext()" << ((!anIO.IsNull() && !anIO->GetContext().IsNull()) ? - DFBrowserPane_Tools::GetPointerInfo (anIO->GetContext()).ToCString() : "") + Standard_Dump::GetPointerInfo (anIO->GetContext()).ToCString() : "") << "HasOwnMaterial" << DFBrowserPane_Tools::BoolToStr (anAttribute->HasOwnMaterial()) << "Material" << (anAttribute->HasOwnMaterial() ? DFBrowserPane_Tools::ToName (DB_MATERIAL_TYPE, anAttribute->Material()) : "").ToCString() diff --git a/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISViewer.cxx b/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISViewer.cxx index 6037bb2d82..eecf1ee30f 100644 --- a/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISViewer.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_TPrsStdAISViewer.cxx @@ -35,7 +35,7 @@ void DFBrowserPane_TPrsStdAISViewer::GetValues (const Handle(TDF_Attribute)& the Handle(AIS_InteractiveContext) aContext = aViewerAttribute->GetInteractiveContext(); TCollection_AsciiString aPointerInfo = !aContext.IsNull() - ? DFBrowserPane_Tools::GetPointerInfo (aContext).ToCString() : ""; + ? Standard_Dump::GetPointerInfo (aContext).ToCString() : ""; theValues << "GetInteractiveContext" << aPointerInfo.ToCString(); diff --git a/tools/DFBrowserPane/DFBrowserPane_Tools.cxx b/tools/DFBrowserPane/DFBrowserPane_Tools.cxx index 3deb0ba70f..8abacd84a3 100644 --- a/tools/DFBrowserPane/DFBrowserPane_Tools.cxx +++ b/tools/DFBrowserPane/DFBrowserPane_Tools.cxx @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -70,30 +69,6 @@ TCollection_AsciiString DFBrowserPane_Tools::GetEntry (const TDF_Label& theLabel return anAsciiEntry; } -// ======================================================================= -// function : GetPointerInfo -// purpose : -// ======================================================================= -TCollection_AsciiString DFBrowserPane_Tools::GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) -{ - std::ostringstream aPtrStr; - aPtrStr << thePointer.operator->(); - if (!isShortInfo) - return aPtrStr.str().c_str(); - - TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); - for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) - { - if (anInfoPtr.Value(aSymbolId) != '0') - { - anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); - anInfoPtr.Prepend("0x"); - return anInfoPtr; - } - } - return aPtrStr.str().c_str(); -} - // ======================================================================= // function : ShapeTypeInfo // purpose : diff --git a/tools/DFBrowserPane/DFBrowserPane_Tools.hxx b/tools/DFBrowserPane/DFBrowserPane_Tools.hxx index cb194777a9..892bc7e10b 100644 --- a/tools/DFBrowserPane/DFBrowserPane_Tools.hxx +++ b/tools/DFBrowserPane/DFBrowserPane_Tools.hxx @@ -48,13 +48,6 @@ public: //! \return the string value Standard_EXPORT static TCollection_AsciiString GetEntry (const TDF_Label& theLabel); - //! Convert pointer to string value - //! \param thePointer a pointer - //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped - //! \return the string value - Standard_EXPORT static TCollection_AsciiString GetPointerInfo (const Handle(Standard_Transient)& thePointer, - const bool isShortInfo = true); - //! Returns string value corresponded to the shape type if it is not null. //! \param theShape a checked shape //! \return string value or empty string value diff --git a/tools/DFBrowserPane/FILES b/tools/DFBrowserPane/FILES index 1ea8358f9e..de80d10eb0 100644 --- a/tools/DFBrowserPane/FILES +++ b/tools/DFBrowserPane/FILES @@ -1,4 +1,3 @@ -DFBrowserPane.hxx DFBrowserPane.qrc DFBrowserPane_AttributePane.cxx DFBrowserPane_AttributePane.hxx diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.cxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.cxx index b531305725..35e15aed73 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.cxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.cxx @@ -52,7 +52,7 @@ DFBrowserPaneXDE_AttributeCommonPane::DFBrowserPaneXDE_AttributeCommonPane (DFBr // function : ProcessAttribute // purpose : // ======================================================================= -bool DFBrowserPaneXDE_AttributeCommonPane::ProcessAttribute (const Standard_CString& theAttributeType) +bool DFBrowserPaneXDE_AttributeCommonPane::ProcessAttribute (Standard_CString theAttributeType) { if (AttributeTypes.empty()) { diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.hxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.hxx index dd34d91db3..c15e30c2b1 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.hxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributeCommonPane.hxx @@ -46,7 +46,7 @@ public: //! have difference in presentation (TDataStd_TreeNode, TDF_Reference, TNaming_NamedShape and TDataStd_UAttribute). //! Also it contains XCAFDoc attributes (should be implemented in this package or pane will be empty) //! \param theAttributeType an attribute type - Standard_EXPORT static bool ProcessAttribute (const Standard_CString& theAttributeType); + Standard_EXPORT static bool ProcessAttribute (Standard_CString theAttributeType); //! Creates table view and call create widget of array table helper //! \param theParent a parent widget diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.cxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.cxx index 8c0641fe11..7ace10af55 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.cxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.cxx @@ -34,17 +34,13 @@ #include #include -#include - #include #include #include #include #include -#if OCC_VERSION_HEX > 0x060901 #include #include -#endif #include #include #include @@ -71,7 +67,7 @@ DFBrowserPaneXDE_AttributePaneCreator::DFBrowserPaneXDE_AttributePaneCreator( // function : CreateAttributePane // purpose : // ======================================================================= -DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::CreateAttributePane (const Standard_CString& theAttributeName) +DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::CreateAttributePane (Standard_CString theAttributeName) { DFBrowserPane_AttributePaneAPI* aPane = 0; if (DFBrowserPaneXDE_AttributeCommonPane::ProcessAttribute (theAttributeName)) @@ -91,7 +87,7 @@ DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::CreateAtt // function : createXDEPane // purpose : // ======================================================================= -DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::createXDEPane (const Standard_CString& theAttributeName) +DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::createXDEPane (Standard_CString theAttributeName) { DFBrowserPane_AttributePaneAPI* aPane = 0; if (theAttributeName == STANDARD_TYPE (XCAFDoc_ShapeMapTool)->Name()) @@ -106,20 +102,16 @@ DFBrowserPane_AttributePaneAPI* DFBrowserPaneXDE_AttributePaneCreator::createXDE aPane = new DFBrowserPaneXDE_XCAFDocColorTool(); else if (theAttributeName == STANDARD_TYPE (XCAFDoc_Datum)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocDatum(); -#if OCC_VERSION_HEX > 0x060901 else if (theAttributeName == STANDARD_TYPE (XCAFDoc_Dimension)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocDimension(); -#endif else if (theAttributeName == STANDARD_TYPE (XCAFDoc_DimTol)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocDimTol(); else if (theAttributeName == STANDARD_TYPE (XCAFDoc_DimTolTool)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocDimTolTool(); else if (theAttributeName == STANDARD_TYPE (XCAFDoc_DocumentTool)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocDocumentTool(); -#if OCC_VERSION_HEX > 0x060901 else if (theAttributeName == STANDARD_TYPE (XCAFDoc_GeomTolerance)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocGeomTolerance(); -#endif else if (theAttributeName == STANDARD_TYPE (XCAFDoc_GraphNode)->Name()) aPane = new DFBrowserPaneXDE_XCAFDocGraphNode(); else if (theAttributeName == STANDARD_TYPE (XCAFDoc_LayerTool)->Name()) diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.hxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.hxx index 2520a02651..00e3a86670 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.hxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_AttributePaneCreator.hxx @@ -43,14 +43,14 @@ public: //! \param theAttributeName a type of attribute //! \return an attribute pane if it can be created for this type Standard_EXPORT virtual DFBrowserPane_AttributePaneAPI* CreateAttributePane - (const Standard_CString& theAttributeName) Standard_OVERRIDE; + (Standard_CString theAttributeName) Standard_OVERRIDE; protected: //! Cretates pane for XCAFDoc attribute name //! \param theAttributeName a type of attribute //! \return an attribute pane if it can be created for this type - DFBrowserPane_AttributePaneAPI* createXDEPane (const Standard_CString& theAttributeName); + DFBrowserPane_AttributePaneAPI* createXDEPane (Standard_CString theAttributeName); private: diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocDatum.cxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocDatum.cxx index f9e64d7695..437a9b4016 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocDatum.cxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocDatum.cxx @@ -17,13 +17,10 @@ #include -#include #include #include -#if OCC_VERSION_HEX > 0x060901 #include -#endif // ======================================================================= // function : Constructor @@ -50,13 +47,11 @@ void DFBrowserPaneXDE_XCAFDocDatum::GetValues (const Handle(TDF_Attribute)& theA << "Description" << (!aDescription.IsNull() ? aDescription->ToCString() : QString ("")) << "Indentification" << (!anIndentification.IsNull() ? anIndentification->ToCString() : QString ("")); -#if OCC_VERSION_HEX > 0x060901 Handle(XCAFDimTolObjects_DatumObject) anObject = anAttr->GetObject(); Handle(TCollection_HAsciiString) anObjectName; if (!anObject.IsNull()) anObjectName = anObject->GetName(); theValues << "Object" << (!anObjectName.IsNull() ? anObjectName->ToCString() : "Empty Name"); -#endif } // ======================================================================= diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocShapeMapTool.cxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocShapeMapTool.cxx index 7fc6cef64c..7cec914b78 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocShapeMapTool.cxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XCAFDocShapeMapTool.cxx @@ -116,7 +116,7 @@ void DFBrowserPaneXDE_XCAFDocShapeMapTool::GetValues (const Handle(TDF_Attribute const TopoDS_Shape& aShape = aShapeMap(aShapeValueId); if (!aShape.IsNull()) - theValues << DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString() + theValues << Standard_Dump::GetPointerInfo (aShape.TShape()->This()).ToCString() << DFBrowserPane_Tools::ShapeTypeInfo (aShape) << ""; else diff --git a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XDEDRAW.cxx b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XDEDRAW.cxx index 17280152c4..a3b7632c3b 100644 --- a/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XDEDRAW.cxx +++ b/tools/DFBrowserPaneXDE/DFBrowserPaneXDE_XDEDRAW.cxx @@ -42,11 +42,8 @@ #include #include #include -#include -#if OCC_VERSION_HEX > 0x060901 #include #include -#endif #include #include #include @@ -247,7 +244,6 @@ TCollection_AsciiString DFBrowserPaneXDE_XDEDRAW::GetAttributeInfo (Handle(TDF_A else if ( att->ID() == XCAFDoc::DatumTolRefGUID() ) { type = "DatumToler Link"; } -#if OCC_VERSION_HEX > 0x060901 else if ( att->ID() == XCAFDoc::DimensionRefFirstGUID() ) { type = "Dimension Link First"; } @@ -257,7 +253,6 @@ TCollection_AsciiString DFBrowserPaneXDE_XDEDRAW::GetAttributeInfo (Handle(TDF_A else if ( att->ID() == XCAFDoc::GeomToleranceRefGUID() ){ type = "GeomTolerance Link"; } -#endif else return TCollection_AsciiString(); diff --git a/tools/ShapeView/FILES b/tools/ShapeView/FILES index 895416efc1..09979b4e83 100644 --- a/tools/ShapeView/FILES +++ b/tools/ShapeView/FILES @@ -1,7 +1,6 @@ ShapeView.qrc ShapeView_Communicator.cxx ShapeView_Communicator.hxx -ShapeView_ItemBase.hxx ShapeView_ItemRoot.cxx ShapeView_ItemRoot.hxx ShapeView_ItemShape.cxx diff --git a/tools/ShapeView/ShapeView_Communicator.hxx b/tools/ShapeView/ShapeView_Communicator.hxx index babb61b0fe..1850cff1b7 100644 --- a/tools/ShapeView/ShapeView_Communicator.hxx +++ b/tools/ShapeView/ShapeView_Communicator.hxx @@ -29,7 +29,7 @@ public: ShapeView_Communicator() : TInspectorAPI_Communicator(), myWindow (new ShapeView_Window (0)) {} //! Destructor - virtual ~ShapeView_Communicator() Standard_OVERRIDE { myWindow->RemoveAllShapes(); } + virtual ~ShapeView_Communicator() { myWindow->RemoveAllShapes(); } //! Provides the container with a parent where this container should be inserted. //! If Qt implementation, it should be QWidget with QLayout set inside @@ -41,9 +41,9 @@ public: virtual void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) Standard_OVERRIDE { myWindow->SetParameters (theParameters); } - //! Provide container for actions available in inspector on general level + //! Provides 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); } + virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); } //! Returns plugin preferences, empty implementation by default //! \param theItem container of preference elements diff --git a/tools/ShapeView/ShapeView_ItemBase.hxx b/tools/ShapeView/ShapeView_ItemBase.hxx deleted file mode 100644 index 3e0559c501..0000000000 --- a/tools/ShapeView/ShapeView_ItemBase.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef ShapeView_ItemBase_H -#define ShapeView_ItemBase_H - -#include -#include -#include - -class ShapeView_ItemBase; -typedef QExplicitlySharedDataPointer ShapeView_ItemBasePtr; - -//! \class ShapeView_ItemBase -// \brief Declaration of the tree model base item. -class ShapeView_ItemBase : public TreeModel_ItemBase -{ -public: - - //! Resets cached values - virtual void Reset() Standard_OVERRIDE { TreeModel_ItemBase::Reset(); } - -protected: - - //! Initialize the current item. It creates a backup of the specific item information - virtual void initItem() const {}; - - //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item - ShapeView_ItemBase(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : TreeModel_ItemBase (theParent, theRow, theColumn) {} -}; - -#endif \ No newline at end of file diff --git a/tools/ShapeView/ShapeView_ItemRoot.cxx b/tools/ShapeView/ShapeView_ItemRoot.cxx index 64d1dbec32..d9f5cb269d 100644 --- a/tools/ShapeView/ShapeView_ItemRoot.cxx +++ b/tools/ShapeView/ShapeView_ItemRoot.cxx @@ -18,10 +18,10 @@ #include // ======================================================================= -// function : GetShape +// function : Shape // purpose : // ======================================================================= -const TopoDS_Shape& ShapeView_ItemRoot::GetShape (const int theRowId) +const TopoDS_Shape& ShapeView_ItemRoot::Shape (const int theRowId) { NCollection_List::Iterator aShapesIt (myShapes); for (int aRowId = 0; aShapesIt.More(); aShapesIt.Next(), aRowId++) diff --git a/tools/ShapeView/ShapeView_ItemRoot.hxx b/tools/ShapeView/ShapeView_ItemRoot.hxx index 370ab5b272..c05495dfd2 100644 --- a/tools/ShapeView/ShapeView_ItemRoot.hxx +++ b/tools/ShapeView/ShapeView_ItemRoot.hxx @@ -17,7 +17,7 @@ #define ShapeView_ItemRoot_H #include -#include +#include #include #include @@ -28,7 +28,7 @@ typedef QExplicitlySharedDataPointer ShapeView_ItemRootPtr; //! Collects shapes that should be visualized in tree view. Shapes are cached and if shapes are not needed, //! cache should be cleared using RemoveAllShapes. //! Parent is NULL, children are ShapeView_ItemShape items. -class ShapeView_ItemRoot : public ShapeView_ItemBase +class ShapeView_ItemRoot : public TreeModel_ItemBase { public: @@ -37,7 +37,7 @@ public: { return ShapeView_ItemRootPtr (new ShapeView_ItemRoot (theParent, theRow, theColumn)); } //! Destructor - virtual ~ShapeView_ItemRoot() Standard_OVERRIDE {}; + virtual ~ShapeView_ItemRoot() {} //! Appends new shape //! \param theShape a shape instance @@ -48,11 +48,11 @@ public: //! Returns shape by the number //! \param theRowId an index of the shape in the internal container. - Standard_EXPORT const TopoDS_Shape& GetShape (const int theRowId); + Standard_EXPORT const TopoDS_Shape& Shape (const int theRowId); protected: - //! Return data value for the role. + //! Returns data value for the role. //! \param theItemRole a value role //! \return the value virtual QVariant initValue(const int theItemRole) const; @@ -69,9 +69,9 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item ShapeView_ItemRoot(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : ShapeView_ItemBase (theParent, theRow, theColumn) {} + : TreeModel_ItemBase (theParent, theRow, theColumn) {} private: diff --git a/tools/ShapeView/ShapeView_ItemShape.cxx b/tools/ShapeView/ShapeView_ItemShape.cxx index 952534ba4a..7a69f45ffd 100644 --- a/tools/ShapeView/ShapeView_ItemShape.cxx +++ b/tools/ShapeView/ShapeView_ItemShape.cxx @@ -15,21 +15,17 @@ #include -#include -#include -#include - -#include -#include -#include - #include #include + +#include + +#include #include -#include -#include #include -#include + +#include +#include #include #include @@ -37,166 +33,32 @@ #include // ======================================================================= -// function : ToString -// purpose : -// ======================================================================= -QString ToString (const Standard_Boolean& theValue) -{ - return theValue ? "1" : "0"; -} - -// ======================================================================= -// function : ToString -// purpose : -// ======================================================================= -QString ToString (const gp_Pnt& thePoint) -{ - return QString ("(%1, %2, %3)").arg (thePoint.X()).arg (thePoint.Y()).arg (thePoint.Z()); -} - -// ======================================================================= -// function : ToName -// purpose : -// ======================================================================= -QString ToName (const TopAbs_ShapeEnum& theShapeType) -{ - Standard_SStream aSStream; - TopAbs::Print (theShapeType, aSStream); - return QString (aSStream.str().c_str()); -} - -// ======================================================================= -// function : ToName -// purpose : -// ======================================================================= -QString ToName (const TopAbs_Orientation& theOrientation) -{ - Standard_SStream aSStream; - TopAbs::Print(theOrientation, aSStream); - return QString (aSStream.str().c_str()); -} - -// ======================================================================= -// function : ToName +// function : Shape // purpose : // ======================================================================= -QString ToName (const GeomAbs_Shape& theType) +TopoDS_Shape ShapeView_ItemShape::Shape (const int theRowId) const { - switch (theType) + if (myChildShapes.IsEmpty()) { - case GeomAbs_C0: return "GeomAbs_C0"; - case GeomAbs_G1: return "GeomAbs_G1"; - case GeomAbs_C1: return "GeomAbs_C1"; - case GeomAbs_G2: return "GeomAbs_G2"; - case GeomAbs_C2: return "GeomAbs_C2"; - case GeomAbs_C3: return "GeomAbs_C3"; - case GeomAbs_CN: return "GeomAbs_CN"; - default: break; - } - return QString(); -} + ShapeView_ItemShape* aThis = (ShapeView_ItemShape*)this; -// ======================================================================= -// function : ToOtherInfo -// purpose : -// ======================================================================= -void ToOtherInfo (const TopoDS_Shape& theShape, QVariant& theValue, QVariant& theInfo) -{ - switch (theShape.ShapeType()) - { - case TopAbs_COMPOUND: - case TopAbs_COMPSOLID: - case TopAbs_SOLID: - case TopAbs_SHELL: - case TopAbs_FACE: - case TopAbs_WIRE: - break; - case TopAbs_EDGE: + if (myExplodeType != TopAbs_SHAPE) { - TopoDS_Edge anEdge = TopoDS::Edge(theShape); - 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; - - QStringList aValues, anInfo; - aValues.append (QString::number (GCPnts_AbscissaPoint::Length(*anAdaptor3d))); - anInfo.append ("Length"); - - aValues.append (aCurve->DynamicType()->Name()); - anInfo.append ("DynamicType"); - - aValues.append (ToString (aFirstPnt)); - anInfo.append (QString ("First" + QString::number (aFirst))); - - aValues.append (ToString (aLastPnt)); - anInfo.append (QString ("Last" + QString::number (aLast))); - - aValues.append (ToName (aCurve->Continuity())); - anInfo.append ("Continuity"); - - aValues.append (ToString (aCurve->IsClosed())); - anInfo.append ("IsClosed"); - - if (aCurve->IsPeriodic()) { - aValues.append (QString::number (aCurve->Period())); - anInfo.append ("IsPeriodic"); - } - else + TopExp::MapShapes(myShape, myExplodeType, aThis->myChildShapes); + } + else + { + TopoDS_Iterator aSubShapeIt (myShape); + for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++) { - aValues.append (ToString (aCurve->IsPeriodic())); - anInfo.append ("IsPeriodic"); + aThis->myChildShapes.Add (aSubShapeIt.Value()); } - theValue = aValues.join (" / "); - theInfo = QString ("%1:\n%2").arg (anInfo.join (" / ")).arg (aValues.join ("\n")); - break; } - case TopAbs_SHAPE: - default: - break; } -} + if (myChildShapes.Extent() >= theRowId + 1) + return myChildShapes(theRowId + 1); -// ======================================================================= -// function : locationInfo -// purpose : -// ======================================================================= -QString locationInfo (const TopLoc_Location& theLocation) -{ - QString anInfo; - - gp_Trsf aTrsf = theLocation.Transformation(); - QStringList aValues, aRowValues; - for (int aRowId = 1; aRowId <= 3; aRowId++) - { - aRowValues.clear(); - for (int aColumnId = 1; aColumnId <= 4; aColumnId++) - aRowValues.append (QString::number (aTrsf.Value(aRowId, aColumnId))); - aValues.append (aRowValues.join (",")); - } - anInfo.append (aValues.join (" ")); - return anInfo; -} - -// ======================================================================= -// function : GetShape -// purpose : -// ======================================================================= -TopoDS_Shape ShapeView_ItemShape::GetShape (const int theRowId) const -{ - TopoDS_Iterator aSubShapeIt (myShape); - for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++) - { - if (aCurrentIndex != theRowId) - continue; - break; - } - return aSubShapeIt.Value(); + return TopoDS_Shape(); } // ======================================================================= @@ -205,6 +67,10 @@ TopoDS_Shape ShapeView_ItemShape::GetShape (const int theRowId) const // ======================================================================= QVariant ShapeView_ItemShape::initValue(const int theRole) const { + QVariant aParentValue = TreeModel_ItemBase::initValue (theRole); + if (aParentValue.isValid()) + return aParentValue; + TopoDS_Shape aShape = getShape(); if (aShape.IsNull()) return QVariant(); @@ -214,58 +80,7 @@ QVariant ShapeView_ItemShape::initValue(const int theRole) const switch (Column()) { - 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: - { - 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()); - } - } + case 0: return TopAbs::ShapeTypeToString (aShape.ShapeType()); default: break; } return QVariant(); @@ -282,11 +97,33 @@ int ShapeView_ItemShape::initRowCount() const return 0; int aRowsCount = 0; - for (TopoDS_Iterator aSubShapeIt(aShape); aSubShapeIt.More(); aSubShapeIt.Next()) - aRowsCount++; + if (myExplodeType != TopAbs_SHAPE) + { + TopTools_IndexedMapOfShape aSubShapes; + TopExp::MapShapes(aShape, myExplodeType, aSubShapes); + aRowsCount = aSubShapes.Extent(); + } + else + { + for (TopoDS_Iterator aSubShapeIt(aShape); aSubShapeIt.More(); aSubShapeIt.Next()) + aRowsCount++; + } return aRowsCount; } +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void ShapeView_ItemShape::initStream (Standard_OStream& theOStream) const +{ + TopoDS_Shape aShape = getShape(); + if (aShape.IsNull()) + return; + + aShape.DumpJson (theOStream); +} + // ======================================================================= // function : createChild // purpose : @@ -304,7 +141,9 @@ void ShapeView_ItemShape::Init() { ShapeView_ItemRootPtr aRootItem = itemDynamicCast (Parent()); ShapeView_ItemShapePtr aShapeItem = itemDynamicCast (Parent()); - myShape = aRootItem ? aRootItem->GetShape (Row()) : aShapeItem->GetShape (Row()); + myShape = aRootItem ? aRootItem->Shape (Row()) : aShapeItem->Shape (Row()); + + TreeModel_ItemBase::Init(); } // ======================================================================= @@ -317,30 +156,6 @@ TopoDS_Shape ShapeView_ItemShape::getShape() const return myShape; } -// ======================================================================= -// function : getPointerInfo -// purpose : -// ======================================================================= -TCollection_AsciiString ShapeView_ItemShape::getPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) -{ - std::ostringstream aPtrStr; - aPtrStr << thePointer.operator->(); - if (!isShortInfo) - return aPtrStr.str().c_str(); - - TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); - for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) - { - if (anInfoPtr.Value(aSymbolId) != '0') - { - anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); - anInfoPtr.Prepend("0x"); - return anInfoPtr; - } - } - return aPtrStr.str().c_str(); -} - // ======================================================================= // function : Reset // purpose : @@ -348,8 +163,10 @@ TCollection_AsciiString ShapeView_ItemShape::getPointerInfo (const Handle(Standa void ShapeView_ItemShape::Reset() { myFileName = QString(); + myChildShapes.Clear(); + myShape = TopoDS_Shape(); - ShapeView_ItemBase::Reset(); + TreeModel_ItemBase::Reset(); } // ======================================================================= @@ -362,4 +179,3 @@ void ShapeView_ItemShape::initItem() const return; const_cast(this)->Init(); } - diff --git a/tools/ShapeView/ShapeView_ItemShape.hxx b/tools/ShapeView/ShapeView_ItemShape.hxx index b04076956e..b6706d939d 100644 --- a/tools/ShapeView/ShapeView_ItemShape.hxx +++ b/tools/ShapeView/ShapeView_ItemShape.hxx @@ -16,9 +16,13 @@ #ifndef ShapeView_ItemShape_H #define ShapeView_ItemShape_H -#include +#include + +#include + #include #include +#include #include #include @@ -32,19 +36,26 @@ typedef QExplicitlySharedDataPointer ShapeView_ItemShapePtr //! \class ShapeView_ItemShape //! This item is connected to TopoDS_Shape. //! Parent is either ShapeView_ItemRoot or ShapeView_ItemShape, children are ShapeView_ItemShape or no children -class ShapeView_ItemShape : public ShapeView_ItemBase +class ShapeView_ItemShape : public TreeModel_ItemBase { public: //! Creates an item wrapped by a shared pointer - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item //! \return the pointer to the created item static ShapeView_ItemShapePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) { return ShapeView_ItemShapePtr (new ShapeView_ItemShape (theParent, theRow, theColumn)); } //! Destructor - virtual ~ShapeView_ItemShape() Standard_OVERRIDE {}; + virtual ~ShapeView_ItemShape() {} + + //! Returns explode type of the item + TopAbs_ShapeEnum ExplodeType() const { return myExplodeType; } + + //! Sets explore type + //! \param theType type of item explode. If TopAbs_SHAPE, no explode, only iteration by shape + void SetExplodeType (const TopAbs_ShapeEnum theType) { myExplodeType = theType; } //! Returns the current shape const TopoDS_Shape& GetItemShape() const { initItem(); return myShape; } @@ -52,7 +63,7 @@ public: //! Returns child(extracted) shape for the current shape by the index //! \param theRowId an index of child shape //! \returns shape instance or NULL - Standard_EXPORT TopoDS_Shape GetShape (const int theRowId) const; + Standard_EXPORT TopoDS_Shape Shape (const int theRowId) const; //! Returns name of BREP file for the shape if exists //! \return string valuie @@ -62,17 +73,13 @@ public: //! \return string valuie void SetFileName (const QString& theFileName) { myFileName = theFileName; } - //! Returns TShape pointer info of the current TopoDS Shape - //! \return string value - TCollection_AsciiString TShapePointer() const { return getPointerInfo (myShape.TShape()); } - //! Inits the item, fills internal containers Standard_EXPORT virtual void Init() Standard_OVERRIDE; //! Resets cached values Standard_EXPORT virtual void Reset() Standard_OVERRIDE; - //! Return data value for the role. + //! Returns data value for the role. //! \param theRole a value role //! \return the value Standard_EXPORT virtual QVariant initValue(const int theRole) const; @@ -80,9 +87,13 @@ public: //! \return number of children. Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE; + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; + protected: - //! Initialize the current item. It is empty because Reset() is also empty. + //! Initializes the current item. It is empty because Reset() is also empty. virtual void initItem() const Standard_OVERRIDE; //! Creates a child item in the given position. @@ -99,22 +110,19 @@ protected: //! \return shape value TopoDS_Shape getShape() const; - //! Convert pointer to string value - //! \param thePointer a pointer - //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped - //! \return the string value - static TCollection_AsciiString getPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo = true); - private: //! Constructor - ShapeView_ItemShape(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : ShapeView_ItemBase(theParent, theRow, theColumn) {} + ShapeView_ItemShape (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : TreeModel_ItemBase (theParent, theRow, theColumn), myExplodeType (TopAbs_SHAPE) {} private: + TopAbs_ShapeEnum myExplodeType; //!< type of explore own shape and get children TopoDS_Shape myShape; //!< current shape QString myFileName; //!< BREP file name + + TopTools_IndexedMapOfShape myChildShapes; //!< cached container of child shapes }; #endif diff --git a/tools/ShapeView/ShapeView_OpenFileDialog.hxx b/tools/ShapeView/ShapeView_OpenFileDialog.hxx index 306326b4f9..295078913b 100644 --- a/tools/ShapeView/ShapeView_OpenFileDialog.hxx +++ b/tools/ShapeView/ShapeView_OpenFileDialog.hxx @@ -135,9 +135,9 @@ private: QString myDataDir; //!< samples directory QString myFileName; //!< result file name - QTableView* mySamplesView; //! +#include -#include -#include +#include +#include + +#include +#include -#include // ======================================================================= -// function : ReadShape +// function : IsPossibleToExplode // purpose : // ======================================================================= -TopoDS_Shape ShapeView_Tools::ReadShape (const TCollection_AsciiString& theFileName) +Standard_Boolean ShapeView_Tools::IsPossibleToExplode (const TopoDS_Shape& theShape, + NCollection_List& theExplodeTypes) { - TopoDS_Shape aShape; + TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); + + if (!theExplodeTypes.Contains (aShapeType)) + theExplodeTypes.Append(aShapeType); + + if (theExplodeTypes.Extent() == TopAbs_SHAPE + 1) // all types are collected, stop + return Standard_True; - BRep_Builder aBuilder; - BRepTools::Read (aShape, theFileName.ToCString(), aBuilder); - return aShape; + TopoDS_Iterator aSubShapeIt (theShape); + for (int aCurrentIndex = 0; aSubShapeIt.More(); aSubShapeIt.Next(), aCurrentIndex++) + { + if (IsPossibleToExplode (aSubShapeIt.Value(), theExplodeTypes)) + return Standard_True; + } + return Standard_False; } diff --git a/tools/ShapeView/ShapeView_Tools.hxx b/tools/ShapeView/ShapeView_Tools.hxx index a922e42b36..fd8b4d45a5 100644 --- a/tools/ShapeView/ShapeView_Tools.hxx +++ b/tools/ShapeView/ShapeView_Tools.hxx @@ -18,20 +18,34 @@ #include +#include + +#include #include #include #include +#include + +#include +#include +#include +#include +#include + //! \class ShapeView_Tools //! It gives auxiliary methods for TopoDS_Shape manipulation class ShapeView_Tools { public: - //! Read Shape using BREP reader - //! \param theFileName a file name - //! \return shape or NULL - Standard_EXPORT static TopoDS_Shape ReadShape (const TCollection_AsciiString& theFileName); + //! Checks whether it is possible to explode the shape. The search is recursive until all types are collected. + //! \param theShape [in] source shape object + //! \param theExplodeTypes [out] container of possible shape types to be exploded + //! \return true if explode is finished, all types are collected. + Standard_EXPORT static Standard_Boolean IsPossibleToExplode(const TopoDS_Shape& theShape, + NCollection_List& theExplodeTypes); + }; #endif diff --git a/tools/ShapeView/ShapeView_TreeModel.cxx b/tools/ShapeView/ShapeView_TreeModel.cxx index bc29c119ae..288b20c6a0 100644 --- a/tools/ShapeView/ShapeView_TreeModel.cxx +++ b/tools/ShapeView/ShapeView_TreeModel.cxx @@ -19,14 +19,6 @@ #include #include -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 : @@ -34,40 +26,15 @@ const int COLUMN_LOCATION_WIDTH = 120; ShapeView_TreeModel::ShapeView_TreeModel (QObject* theParent) : TreeModel_ModelBase (theParent) { - SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); - // column 1 is reserved for visiblity state - SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); - SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); - SetHeaderItem (4, TreeModel_HeaderSection ("Orientation", COLUMN_ORIENTATION_WIDTH)); - SetHeaderItem (5, TreeModel_HeaderSection ("Location", COLUMN_LOCATION_WIDTH)); - - SetHeaderItem (6, TreeModel_HeaderSection ("Checked", -1, true)); - SetHeaderItem (7, TreeModel_HeaderSection ("Closed", -1, true)); - SetHeaderItem (8, TreeModel_HeaderSection ("Infinite", -1, true)); - SetHeaderItem (9, TreeModel_HeaderSection ("Locked", -1, true)); - SetHeaderItem (10, TreeModel_HeaderSection ("Modified", -1, true)); - SetHeaderItem (11, TreeModel_HeaderSection ("Orientable", -1, true)); - - SetHeaderItem (12, TreeModel_HeaderSection ("VERTEX: (X, Y, Z)", -1, true)); - - SetHeaderItem (13, TreeModel_HeaderSection ("EDGE: Length", -1, true)); - SetHeaderItem (14, TreeModel_HeaderSection ("DynamicType", -1, true)); - SetHeaderItem (15, TreeModel_HeaderSection ("First", -1, true)); - SetHeaderItem (16, TreeModel_HeaderSection ("Last", -1, true)); - SetHeaderItem (17, TreeModel_HeaderSection ("Continuity", -1, true)); - SetHeaderItem (18, TreeModel_HeaderSection ("IsClosed", -1, true)); - SetHeaderItem (19, TreeModel_HeaderSection ("IsPeriodic", -1, true)); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void ShapeView_TreeModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr ShapeView_TreeModel::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return ShapeView_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= diff --git a/tools/ShapeView/ShapeView_TreeModel.hxx b/tools/ShapeView/ShapeView_TreeModel.hxx index 7778ad535d..81b925b90a 100644 --- a/tools/ShapeView/ShapeView_TreeModel.hxx +++ b/tools/ShapeView/ShapeView_TreeModel.hxx @@ -16,7 +16,7 @@ #ifndef ShapeView_TreeModel_H #define ShapeView_TreeModel_H -#include +#include #include #include #include @@ -38,21 +38,15 @@ public: Standard_EXPORT ShapeView_TreeModel (QObject* theParent); //! Destructor - virtual ~ShapeView_TreeModel() Standard_OVERRIDE {}; + virtual ~ShapeView_TreeModel() {} - //! Add shape, append it to the model root item + //! Adds shape, append it to the model root item //! \param theShape a shape instance Standard_EXPORT void AddShape (const TopoDS_Shape& theShape); - //! Remove all shapes in the model root item + //! Removes all shapes in the model root item Standard_EXPORT void RemoveAllShapes(); - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem(const int theColumn) const Standard_OVERRIDE - { return myRootItems[theColumn]; } - //! Returns model index of the shape. //! \param theShape a shape object //! \return the model index @@ -61,10 +55,8 @@ public: protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; -private: - QMap myRootItems; //!< container of root items, for each column own root item }; #endif diff --git a/tools/ShapeView/ShapeView_VisibilityState.cxx b/tools/ShapeView/ShapeView_VisibilityState.cxx index 7e7e02f600..3b330f7f55 100644 --- a/tools/ShapeView/ShapeView_VisibilityState.cxx +++ b/tools/ShapeView/ShapeView_VisibilityState.cxx @@ -17,13 +17,23 @@ #include +// ======================================================================= +// function : OnClicked +// purpose : +// ======================================================================= +void ShapeView_VisibilityState::OnClicked (const QModelIndex& theIndex) +{ + processClicked (theIndex); + emit itemClicked (theIndex); +} + // ======================================================================= // function : SetVisible // purpose : // ======================================================================= bool ShapeView_VisibilityState::SetVisible (const QModelIndex& theIndex, const bool theState, const bool toEmitDataChanged) { - TopoDS_Shape aShape = GetShape (theIndex); + TopoDS_Shape aShape = Shape (theIndex); if (aShape.IsNull()) return false; @@ -35,10 +45,10 @@ bool ShapeView_VisibilityState::SetVisible (const QModelIndex& theIndex, const b } // ======================================================================= -// function : GetShape +// function : Shape // purpose : // ======================================================================= -TopoDS_Shape ShapeView_VisibilityState::GetShape (const QModelIndex& theIndex) const +TopoDS_Shape ShapeView_VisibilityState::Shape (const QModelIndex& theIndex) const { TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (theIndex); if (!anItemBase) diff --git a/tools/ShapeView/ShapeView_VisibilityState.hxx b/tools/ShapeView/ShapeView_VisibilityState.hxx index 4d384d61c2..f38229db25 100644 --- a/tools/ShapeView/ShapeView_VisibilityState.hxx +++ b/tools/ShapeView/ShapeView_VisibilityState.hxx @@ -28,8 +28,9 @@ class TreeModel_ModelBase; //! \class ShapeView_VisibilityState //! \brief Class provides connection between model and visualization control -class ShapeView_VisibilityState : public TreeModel_VisibilityState +class ShapeView_VisibilityState : public QObject, public TreeModel_VisibilityState { + Q_OBJECT public: //! Constructor ShapeView_VisibilityState (TreeModel_ModelBase* theModel) : TreeModel_VisibilityState (theModel), @@ -49,7 +50,7 @@ public: //! 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(); } + virtual bool CanBeVisible (const QModelIndex& theIndex) const Standard_OVERRIDE { return !Shape (theIndex).IsNull(); } //! Sets visibility state //! \theIndex tree model index @@ -60,17 +61,28 @@ public: //! Returns visibility state value virtual bool IsVisible (const QModelIndex& theIndex) const Standard_OVERRIDE - { return myDisplayer->IsVisible (GetShape (theIndex), myPresentationType); } + { return myDisplayer->IsVisible (Shape (theIndex), myPresentationType); } + +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: //! 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; + TopoDS_Shape Shape (const QModelIndex& theIndex) const; private: - View_Displayer* myDisplayer; //! view displayer - View_PresentationType myPresentationType; //! presentation type + View_Displayer* myDisplayer; //!< view displayer + View_PresentationType myPresentationType; //!< presentation type }; #endif diff --git a/tools/ShapeView/ShapeView_Window.cxx b/tools/ShapeView/ShapeView_Window.cxx index 76eaefa6b4..2ce7acb0ae 100644 --- a/tools/ShapeView/ShapeView_Window.cxx +++ b/tools/ShapeView/ShapeView_Window.cxx @@ -19,15 +19,17 @@ #include #include +#include + #include #include +#include #include #include #include #include -#include #include #include #include @@ -83,7 +85,7 @@ const int SHAPEVIEW_DEFAULT_VIEW_HEIGHT = 1000; // purpose : // ======================================================================= ShapeView_Window::ShapeView_Window (QWidget* theParent) -: QObject (theParent), myNextPosition (0) +: QObject (theParent) { myMainWindow = new QMainWindow (theParent); @@ -95,28 +97,48 @@ ShapeView_Window::ShapeView_Window (QWidget* theParent) this, SLOT (onTreeViewContextMenuRequested (const QPoint&))); new TreeModel_ContextMenu (myTreeView); ShapeView_TreeModel* aModel = new ShapeView_TreeModel (myTreeView); + aModel->InitColumns(); + myTreeView->setModel (aModel); ShapeView_VisibilityState* aVisibilityState = new ShapeView_VisibilityState (aModel); aModel->SetVisibilityState (aVisibilityState); TreeModel_Tools::UseVisibilityColumn (myTreeView); + QObject::connect (myTreeView, SIGNAL (clicked (const QModelIndex&)), + aVisibilityState, SLOT (OnClicked(const QModelIndex&))); + + QItemSelectionModel* aSelModel = new QItemSelectionModel (myTreeView->model(), myTreeView); + myTreeView->setSelectionModel (aSelModel); + connect (aSelModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), + this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&))); QModelIndex aParentIndex = myTreeView->model()->index (0, 0); myTreeView->setExpanded (aParentIndex, true); myMainWindow->setCentralWidget (myTreeView); + // property view + myPropertyView = new ViewControl_PropertyView (myMainWindow, + QSize(SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT)); + myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow); + myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle()); + myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow)); + myPropertyPanelWidget->setWidget (myPropertyView->GetControl()); + myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget); + // view - myViewWindow = new View_Window (myMainWindow, false); + myViewWindow = new View_Window (myMainWindow, NULL, false); connect (myViewWindow, SIGNAL(eraseAllPerformed()), this, SLOT(onEraseAllPerformed())); - aVisibilityState->SetDisplayer (myViewWindow->GetDisplayer()); + aVisibilityState->SetDisplayer (myViewWindow->Displayer()); aVisibilityState->SetPresentationType (View_PresentationType_Main); - myViewWindow->GetView()->SetPredefinedSize (SHAPEVIEW_DEFAULT_VIEW_WIDTH, SHAPEVIEW_DEFAULT_VIEW_HEIGHT); + myViewWindow->ViewWidget()->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()); + aViewDockWidget->setTitleBarWidget (myViewWindow->ViewToolBar()->GetControl()); myMainWindow->addDockWidget (Qt::RightDockWidgetArea, aViewDockWidget); + myMainWindow->splitDockWidget(myPropertyPanelWidget, aViewDockWidget, Qt::Vertical); + myMainWindow->resize (DEFAULT_SHAPE_VIEW_WIDTH, DEFAULT_SHAPE_VIEW_HEIGHT); myMainWindow->move (DEFAULT_SHAPE_VIEW_POSITION_X, DEFAULT_SHAPE_VIEW_POSITION_Y); } @@ -127,7 +149,6 @@ ShapeView_Window::ShapeView_Window (QWidget* theParent) // ======================================================================= ShapeView_Window::~ShapeView_Window() { - onCloseAllBREPViews(); } // ======================================================================= @@ -171,7 +192,7 @@ void ShapeView_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theItem QMap anItems; TreeModel_Tools::SaveState (myTreeView, anItems); - View_Tools::SaveState(myViewWindow, anItems); + View_Window::SaveState(myViewWindow, anItems); for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); } @@ -194,7 +215,7 @@ void ShapeView_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& t 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())) + else if (View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) continue; } } @@ -302,7 +323,7 @@ void ShapeView_Window::Init (NCollection_List& thePa // ======================================================================= void ShapeView_Window::OpenFile(const TCollection_AsciiString& theFileName) { - TopoDS_Shape aShape = ShapeView_Tools::ReadShape (theFileName); + TopoDS_Shape aShape = Convert_Tools::ReadShape (theFileName); if (!aShape.IsNull()) addShape(aShape); } @@ -315,8 +336,6 @@ void ShapeView_Window::RemoveAllShapes() { ShapeView_TreeModel* aModel = dynamic_cast (myTreeView->model()); aModel->RemoveAllShapes(); - - onCloseAllBREPViews(); } // ======================================================================= @@ -351,16 +370,52 @@ void ShapeView_Window::onTreeViewContextMenuRequested (const QPoint& thePosition aMenu->addAction (ViewControl_Tools::CreateAction ("Remove all shape items", SLOT (onClearView()), myMainWindow, this)); } else { - 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)); + aMenu->addAction (ViewControl_Tools::CreateAction ("Export to BREP", SLOT (onExportToBREP()), myMainWindow, this)); + ShapeView_ItemShapePtr aShapeItem = itemDynamicCast(anItemBase); + const TopoDS_Shape& aShape = aShapeItem->GetItemShape(); + TopAbs_ShapeEnum anExplodeType = aShapeItem->ExplodeType(); + NCollection_List anExplodeTypes; + ShapeView_Tools::IsPossibleToExplode (aShape, anExplodeTypes); + if (anExplodeTypes.Size() > 0) + { + QMenu* anExplodeMenu = aMenu->addMenu ("Explode"); + for (NCollection_List::Iterator anExpIterator (anExplodeTypes); anExpIterator.More(); + anExpIterator.Next()) + { + TopAbs_ShapeEnum aType = anExpIterator.Value(); + QAction* anAction = ViewControl_Tools::CreateAction (TopAbs::ShapeTypeToString (aType), SLOT (onExplode()), myMainWindow, this); + anExplodeMenu->addAction (anAction); + if (anExplodeType == aType) + { + anAction->setCheckable (true); + anAction->setChecked (true); + } + } + QAction* anAction = ViewControl_Tools::CreateAction ("NONE", SLOT (onExplode()), myMainWindow, this); + anExplodeMenu->addSeparator(); + anExplodeMenu->addAction (anAction); + } } QPoint aPoint = myTreeView->mapToGlobal (thePosition); aMenu->exec (aPoint); } +// ======================================================================= +// function : onTreeViewSelectionChanged +// purpose : +// ======================================================================= +void ShapeView_Window::onTreeViewSelectionChanged (const QItemSelection&, + const QItemSelection&) +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + + if (myPropertyPanelWidget->toggleViewAction()->isChecked()) + myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel())); + + QApplication::restoreOverrideCursor(); +} + // ======================================================================= // function : onEraseAllPerformed // purpose : @@ -376,17 +431,43 @@ void ShapeView_Window::onEraseAllPerformed() } // ======================================================================= -// function : onBREPDirectory +// function : onExplode // purpose : // ======================================================================= -void ShapeView_Window::onBREPDirectory() +void ShapeView_Window::onExplode() { - QString aFilter (tr ("BREP file (*.brep*)")); - QString aSelectedFilter; - QString aFileName = QFileDialog::getOpenFileName (0, tr ("Export shape to BREP file"), - GetTemporaryDirectory().ToCString(), aSelectedFilter); - if (!aFileName.isEmpty()) - viewFile (aFileName); + QItemSelectionModel* aModel = myTreeView->selectionModel(); + if (!aModel) + return; + + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected(aModel->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex(anIndex); + if (!anItemBase) + return; + + ShapeView_ItemShapePtr aShapeItem = itemDynamicCast(anItemBase); + if (!aShapeItem) + return; + + QAction* anAction = (QAction*)sender(); + if (!anAction) + return; + + QApplication::setOverrideCursor (Qt::WaitCursor); + TopAbs_ShapeEnum aShapeType; + if (anAction->text() == "NONE") + aShapeType = TopAbs_SHAPE; + else + aShapeType = TopAbs::ShapeTypeFromString(anAction->text().toStdString().c_str()); + + myViewWindow->Displayer()->EraseAllPresentations(); + aShapeItem->SetExplodeType(aShapeType); + + //anItemBase->Parent()->Reset(); - TODO (update only modified sub-tree) + ShapeView_TreeModel* aTreeModel = dynamic_cast (myTreeView->model()); + aTreeModel->Reset(); + aTreeModel->EmitLayoutChanged(); + QApplication::restoreOverrideCursor(); } // ======================================================================= @@ -399,18 +480,23 @@ void ShapeView_Window::onLoadFile() QString aFileName = ShapeView_OpenFileDialog::OpenFile(0, aDataDirName); aFileName = QDir().toNativeSeparators (aFileName); - if (!aFileName.isEmpty()) + if (aFileName.isEmpty()) + return; + + QApplication::setOverrideCursor (Qt::WaitCursor); onOpenFile(aFileName); + QApplication::restoreOverrideCursor(); } // ======================================================================= -// function : onBREPView +// function : onExportToBREP // purpose : // ======================================================================= -void ShapeView_Window::onBREPView() +void ShapeView_Window::onExportToBREP() { - if (GetTemporaryDirectory().IsEmpty()) - return; + QString aFilter (tr ("Boundary representation file (*.brep *)")); + QString aSelectedFilter; + QString aFileName = QFileDialog::getSaveFileName (0, tr ("Export shape to file"), QString(), aFilter, &aSelectedFilter); QItemSelectionModel* aModel = myTreeView->selectionModel(); if (!aModel) @@ -429,107 +515,9 @@ void ShapeView_Window::onBREPView() if (!anItem) return; - QString aFileName = anItem->GetFileName(); - QDir aDir; - if (aFileName.isEmpty() || !aDir.exists (aFileName)) - { - TCollection_AsciiString aFileNameIndiced = GetTemporaryDirectory() + TCollection_AsciiString ("\\") + - getNextTmpName (anItem->TShapePointer()); - const TopoDS_Shape& aShape = anItem->GetItemShape(); - BRepTools::Write (aShape, aFileNameIndiced.ToCString()); - anItem->SetFileName (aFileNameIndiced.ToCString()); - aFileName = aFileNameIndiced.ToCString(); - } - viewFile (aFileName); -} - -// ======================================================================= -// function : onCloseAllBREPViews -// purpose : -// ======================================================================= -void ShapeView_Window::onCloseAllBREPViews() -{ - removeBREPFiles(); - - for (int aViewId = myBREPViews.size()-1; aViewId >= 0; aViewId--) - delete myBREPViews[aViewId]; - - myBREPViews.clear(); -} - -// ======================================================================= -// function : onEditorDestroyed -// purpose : -// ======================================================================= -void ShapeView_Window::onEditorDestroyed(QObject* theObject) -{ - QWidget* aWidget = dynamic_cast (theObject); - - for (int aViewId = myBREPViews.size()-1; aViewId >= 0; aViewId--) - { - if (myBREPViews[aViewId] == aWidget) - myBREPViews.removeAll(aWidget); - } -} - -// ======================================================================= -// function : viewFile -// purpose : -// ======================================================================= -void ShapeView_Window::viewFile (const QString& theFileName) -{ - QApplication::setOverrideCursor (Qt::WaitCursor); - QString aFileText; - QFile aFile (theFileName); - if (aFile.open (QIODevice::ReadOnly | QIODevice::Text)) - { - QTextStream aStream(&aFile); - QString aLine = aStream.readLine(); - while (!aLine.isNull()) - { - aLine = aStream.readLine(); - aFileText.append (aLine + QString ("\n")); - } - if (!aFileText.isEmpty()) - { - QPlainTextEdit* anEditor = new QPlainTextEdit (0); - anEditor->setAttribute (Qt::WA_DeleteOnClose, true); - connect (anEditor, SIGNAL (destroyed(QObject*)), this, SLOT (onEditorDestroyed(QObject*))); - anEditor->setPlainText (aFileText); - anEditor->resize (DEFAULT_TEXT_VIEW_WIDTH, DEFAULT_TEXT_VIEW_HEIGHT); - anEditor->move (DEFAULT_TEXT_VIEW_POSITION_X + myNextPosition, DEFAULT_TEXT_VIEW_POSITION_Y); - myNextPosition += DEFAULT_TEXT_VIEW_DELTA; - anEditor->show(); - myBREPViews.append (anEditor); - } - } - QApplication::restoreOverrideCursor(); -} - -// ======================================================================= -// function : removeBREPFiles -// purpose : -// ======================================================================= -void ShapeView_Window::removeBREPFiles() -{ - QDir aDir (GetTemporaryDirectory().ToCString()); - - QStringList anEntries = aDir.entryList(); - QString aPrefix(viewBREPPrefix().ToCString()); - for (int anEntryId = 0, aSize = anEntries.size(); anEntryId < aSize; anEntryId++) - { - if (anEntries[anEntryId].contains (aPrefix)) - aDir.remove (anEntries[anEntryId]); - } -} - -// ======================================================================= -// function : getNextTmpName -// purpose : -// ======================================================================= -TCollection_AsciiString ShapeView_Window::getNextTmpName (const TCollection_AsciiString& thePointerInfo) -{ - TCollection_AsciiString aTmpName(viewBREPPrefix()); - aTmpName += thePointerInfo; - return aTmpName; + TCollection_AsciiString aFileNameIndiced = aFileName.toStdString().c_str(); + const TopoDS_Shape& aShape = anItem->GetItemShape(); + BRepTools::Write (aShape, aFileNameIndiced.ToCString()); + anItem->SetFileName (aFileNameIndiced.ToCString()); + aFileName = aFileNameIndiced.ToCString(); } diff --git a/tools/ShapeView/ShapeView_Window.hxx b/tools/ShapeView/ShapeView_Window.hxx index 39274f8939..950119326e 100644 --- a/tools/ShapeView/ShapeView_Window.hxx +++ b/tools/ShapeView/ShapeView_Window.hxx @@ -33,7 +33,10 @@ class View_Window; +class ViewControl_PropertyView; + class QAction; +class QDockWidget; class QMainWindow; class QWidget; @@ -59,7 +62,7 @@ public: //! \param theParameters a parameters container void SetParameters (const Handle(TInspectorAPI_PluginParameters)& theParameters) { myParameters = theParameters; } - //! Provide container for actions available in inspector on general level + //! Provides 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); @@ -80,9 +83,6 @@ public: //! Returns current tree view QTreeView* GetTreeView() const { return myTreeView; } - //! Returns path to temporary directory - TCollection_AsciiString GetTemporaryDirectory() const { return myParameters->GetTemporaryDirectory(); } - //! Removes all shapes in tree view model, remove all stored BREP files Standard_EXPORT void RemoveAllShapes(); @@ -98,7 +98,7 @@ private: //! \param theParameters a parameters container void Init (NCollection_List& theParameters); - //! Read Shape from the file name, add Shape into tree view + //! Reads Shape from the file name, add Shape into tree view //! \param theFileName BREP file name void OpenFile (const TCollection_AsciiString& theFileName); @@ -108,64 +108,47 @@ protected slots: //! \param thePosition a clicked point void onTreeViewContextMenuRequested (const QPoint& thePosition); + //! Processes selection in tree view: make presentation or owner selected in the context if corresponding + //! check box is checked + //! \param theSelected a selected items + //! \param theDeselected a deselected items + void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + //! Updates visibility states by erase all in context void onEraseAllPerformed(); - //! Exports shape to BREP file and view result file - void onBREPDirectory(); + //! Sets the shape item exploded + void onExplode(); //! Removes all shapes in tree view void onClearView() { RemoveAllShapes(); } - //! Load BREP file and updates tree model to have shape of the file + //! Loads BREP file and updates tree model to have shape of the file void onLoadFile(); - //! View BREP files of selected items if exist - void onBREPView(); - - //! Remove BREP views, close views - void onCloseAllBREPViews(); - - //! Remove all BREP Viewse excepting active - void onEditorDestroyed (QObject* theObject); + //! Views BREP files of selected items if exist + void onExportToBREP(); //! Convers file name to Ascii String and perform opeging file //! \param theFileName a file name to be opened void onOpenFile(const QString& theFileName) { OpenFile (TCollection_AsciiString (theFileName.toUtf8().data())); } protected: - - //! Views file name content in a text editor. It creates new Qt free control with content. - //! \param theFileName a file name - void viewFile (const QString& theFileName); - - //! Removes all BREP files in tmp directory - void removeBREPFiles(); - //! Creates new action and connect it to the given slot //! \param theText an action text //! \param theSlot a listener method QAction* createAction (const QString& theText, const char* theSlot); - //! Key that uses to generate BREP file name - //! \return string value - static TCollection_AsciiString viewBREPPrefix() { return "ShapeView_Window"; } - - //! Returns newxt temporary name using BREPPrefix and pointer information - //! \param thePointerInfo a pointer value - //! \return string value - TCollection_AsciiString getNextTmpName (const TCollection_AsciiString& thePointerInfo); - private: QMainWindow* myMainWindow; //!< main control, parent for all ShapeView controls + QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget + ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist + View_Window* myViewWindow; //!< OCC 3d view to visualize presentations QTreeView* myTreeView; //!< tree view visualized shapes - int myNextPosition; //!< delta of moving control of view BREP file - - QList myBREPViews; //!< list of view BREP file controls Handle(TInspectorAPI_PluginParameters) myParameters; //!< plugins parameters container }; diff --git a/tools/TInspector/FILES b/tools/TInspector/FILES index 21dba46d9d..471fd38cb1 100644 --- a/tools/TInspector/FILES +++ b/tools/TInspector/FILES @@ -1,6 +1,12 @@ TInspector.qrc TInspector_Communicator.cxx TInspector_Communicator.hxx +TInspector_OpenButton.cxx +TInspector_OpenButton.hxx +TInspector_OpenFileDialog.cxx +TInspector_OpenFileDialog.hxx +TInspector_OpenFileViewModel.cxx +TInspector_OpenFileViewModel.hxx TInspector_PluginParameters.cxx TInspector_PluginParameters.hxx TInspector_Preferences.cxx diff --git a/tools/TInspector/TInspector.qrc b/tools/TInspector/TInspector.qrc index 8fbf4bb7a5..439185f9fc 100644 --- a/tools/TInspector/TInspector.qrc +++ b/tools/TInspector/TInspector.qrc @@ -1,6 +1,7 @@ - icons/item_algo_folder.png - icons/plugin_actions.png + icons/folder_open.png + icons/folder_import.png + icons/plugin_actions.png diff --git a/tools/TInspector/TInspector_Communicator.hxx b/tools/TInspector/TInspector_Communicator.hxx index bd5fbc7b47..f2d8633878 100644 --- a/tools/TInspector/TInspector_Communicator.hxx +++ b/tools/TInspector/TInspector_Communicator.hxx @@ -64,13 +64,13 @@ public: const Standard_Boolean theAppend = Standard_False) { myWindow->Init (thePluginName, theParameters, theAppend); } - //! UpdateContent for the TInspector window + //! Updates content for the TInspector window void UpdateContent() { myWindow->UpdateContent(); } - //! SetOpenButton for the TInspector window + //! Sets open button for the TInspector window void SetOpenButton (QPushButton* theButton) { myWindow->SetOpenButton (theButton); } - //! OpenFile in TInspector window + //! Opens file in TInspector window void OpenFile (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theFileName) { myWindow->OpenFile (thePluginName, theFileName); } @@ -78,14 +78,13 @@ public: //! \param thePluginName a name of the plugin void Activate (const TCollection_AsciiString& thePluginName) { myWindow->ActivateTool (thePluginName); } - //! Set item selected in the active plugin + //! Sets item selected in the active plugin //! \param theItemName a containerr of name of items in plugin that should become selected void SetSelected (const NCollection_List& theItemNames) { myWindow->SetSelected (theItemNames); } //! Sets objects to be selected in the plugin //! \param theObjects an objects - Standard_EXPORT void SetSelected (const NCollection_List& theObjects) - { myWindow->SetSelected (theObjects); } + void SetSelected (const NCollection_List& theObjects) { myWindow->SetSelected (theObjects); } //! Sets path to a directory for temporary plugin files //! \param thePath a path @@ -95,11 +94,11 @@ public: //! \return path TCollection_AsciiString GetTemporaryDirectory() const { return myWindow->GetTemporaryDirectory(); } - //! Change window visibility + //! Changes window visibility //! \param theVisible boolean state Standard_EXPORT virtual void SetVisible (const bool theVisible); - //! Change window position + //! Changes 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); diff --git a/tools/TInspector/TInspector_OpenButton.cxx b/tools/TInspector/TInspector_OpenButton.cxx new file mode 100644 index 0000000000..6898f2a631 --- /dev/null +++ b/tools/TInspector/TInspector_OpenButton.cxx @@ -0,0 +1,96 @@ +// 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 + +#include +#include + +#include +#include +#include +#include +#include + +const int RECENT_FILES_CACHE_SIZE = 10; + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +TInspector_OpenButton::TInspector_OpenButton (QObject* theParent) + : QObject (theParent), myStartButton (0) +{ +} + +// ======================================================================= +// function : StartButton +// purpose : +// ======================================================================= +QPushButton* TInspector_OpenButton::StartButton() +{ + if (!myStartButton) + { + myStartButton = new QPushButton(); + myStartButton->setIcon (QIcon (":folder_open.png")); + connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked())); + } + return myStartButton; +} + +// ======================================================================= +// function : onStartButtonClicked +// purpose : +// ======================================================================= +void TInspector_OpenButton::onStartButtonClicked() +{ + QPushButton* aButton = (QPushButton*)sender(); + TCollection_AsciiString aPluginName (aButton->objectName().toStdString().c_str()); + if (aPluginName.IsEmpty()) + return; + + QStringList aPluginRecentlyOpenedFiles; + if (myRecentlyOpenedFiles.contains(aPluginName)) + { + QStringList aFileNames = myRecentlyOpenedFiles[aPluginName]; + for (int i = 0; i < aFileNames.size(); i++) + { + QFileInfo aFileInfo (aFileNames[i]); + if (aFileInfo.exists() && aFileInfo.isFile()) + aPluginRecentlyOpenedFiles.append(aFileInfo.absoluteFilePath()); + } + } + + QString aFileName = TInspector_OpenFileDialog::OpenFile (0, aPluginRecentlyOpenedFiles); + aFileName = QDir().toNativeSeparators (aFileName); + if (!aFileName.isEmpty()) { + QApplication::setOverrideCursor (Qt::WaitCursor); + TInspector_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data())); + + QFileInfo aFileInfo (aFileName); + if (!aPluginRecentlyOpenedFiles.contains (aFileInfo.absoluteFilePath())) + { + myRecentlyOpenedFiles[aPluginName].append (aFileInfo.absoluteFilePath()); + for (int i = 0; i < myRecentlyOpenedFiles[aPluginName].size() - RECENT_FILES_CACHE_SIZE; i++) + myRecentlyOpenedFiles[aPluginName].removeFirst(); + TInspector_OpenFileDialog::SetPluginRecentlyOpenedFiles (aPluginName, + TInspector_OpenFileDialog::Communicator(), myRecentlyOpenedFiles[aPluginName]); + + TInspector_OpenFileDialog::Communicator()->GetPluginParameters()->StorePreferences(); + } + + QApplication::restoreOverrideCursor(); + } +} diff --git a/tools/TInspector/TInspector_OpenButton.hxx b/tools/TInspector/TInspector_OpenButton.hxx new file mode 100644 index 0000000000..d7caaeca4b --- /dev/null +++ b/tools/TInspector/TInspector_OpenButton.hxx @@ -0,0 +1,65 @@ +// 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 TInspectorEXE_OpenButton_H +#define TInspectorEXE_OpenButton_H + +#include + +#include +#include +#include +#include +#include + +class QPushButton; + +//! \class TInspector_OpenButton +//! Class that contains push button and the button processing. It obtains a file name from the default or current +//! directory and gives the name into TInspector communicator +//! Object name of the button is the name of the plugin to get the default directory, or the current directory is used. +class TInspector_OpenButton : public QObject +{ + Q_OBJECT + +public: + + //! Constructor + Standard_EXPORT TInspector_OpenButton (QObject* theParent); + + //! Destructor + virtual ~TInspector_OpenButton() {} + + //! Returns the start button, if this is the first call, it creates the button and connect it to the slot + Standard_EXPORT QPushButton* StartButton(); + + //! Sets the default directory of plugin. + void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, + const QStringList& theRecentlyOpenedFiles) + { myRecentlyOpenedFiles[thePluginName] = theRecentlyOpenedFiles; } + +private slots: + + //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator + void onStartButtonClicked(); + +private: + + QPushButton* myStartButton; //!< processed button + //!< plugins recently opened files + QMap myRecentlyOpenedFiles; +}; + +#endif diff --git a/tools/TInspector/TInspector_OpenFileDialog.cxx b/tools/TInspector/TInspector_OpenFileDialog.cxx new file mode 100644 index 0000000000..622818ab83 --- /dev/null +++ b/tools/TInspector/TInspector_OpenFileDialog.cxx @@ -0,0 +1,281 @@ +// 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 + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int FONT_POINT_SIZE = 18; +const int ICON_SIZE = 40; + +const int OPEN_DIALOG_WIDTH = 550; +const int OPEN_DIALOG_HEIGHT = 200; + +const int MARGIN_DIALOG = 4; +const int SPACING_DIALOG = 2; + +const int RECENT_FILES_CACHE_SIZE = 10; + +TInspector_Communicator* MyCommunicator; + +// ======================================================================= +// function : changeMargins +// purpose : +// ======================================================================= +void changeMargins (QBoxLayout* theLayout) +{ + theLayout->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); + theLayout->setSpacing (SPACING_DIALOG); +} + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +TInspector_OpenFileDialog::TInspector_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles) +: QDialog (theParent), myRecentlyOpenedFiles (theRecentlyOpenedFiles) +{ + setWindowTitle (tr ("Open File")); + + QVBoxLayout* aDialogLay = new QVBoxLayout (this); + changeMargins (aDialogLay); + + // Samples View + QGroupBox* aSamplesBox = new QGroupBox (this); + aSamplesBox->setTitle (tr ("Recent files")); + aDialogLay->addWidget (aSamplesBox); + QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox); + changeMargins (aSampleLay); + mySamplesView = createTableView (theRecentlyOpenedFiles); + aSampleLay->addWidget (mySamplesView); + + // Select file + QGroupBox* aSelectFileBox = new QGroupBox (this); + aSelectFileBox->setTitle (tr ("Select file")); + aDialogLay->addWidget (aSelectFileBox); + QGridLayout* aSelectFileLay = new QGridLayout (aSelectFileBox); + aSelectFileLay->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); + + mySelectedName = new QLineEdit (aSelectFileBox); + QCompleter* aCompleter = new QCompleter(); + QFileSystemModel* aFileSystemModel = new QFileSystemModel; + aFileSystemModel->setRootPath (QDir::rootPath()); + aCompleter->setModel (aFileSystemModel); + mySelectedName->setCompleter (aCompleter); + aSelectFileLay->addWidget (mySelectedName, 1, 0); + + QToolButton* aSelectFileBtn = new QToolButton (aSelectFileBox); + aSelectFileBtn->setIcon (QIcon (":folder_open.png")); + aSelectFileLay->addWidget (aSelectFileBtn, 1, 1); + + connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked())); + connect (mySelectedName, SIGNAL (returnPressed()), this, SLOT (onApplySelectClicked())); + + resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT); +} + +// ======================================================================= +// function : OpenFile +// purpose : +// ======================================================================= +QString TInspector_OpenFileDialog::OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles) +{ + QString aFileName; + TInspector_OpenFileDialog* aDialog = new TInspector_OpenFileDialog (theParent, theRecentlyOpenedFiles); + if (aDialog->exec() == QDialog::Accepted) + aFileName = aDialog->GetFileName(); + + return aFileName; +} + +// ======================================================================= +// function : Communicator +// purpose : +// ======================================================================= +TInspector_Communicator* TInspector_OpenFileDialog::Communicator() +{ + if (!MyCommunicator) + MyCommunicator = new TInspector_Communicator(); + return MyCommunicator; +} + +// ======================================================================= +// function : GetPluginRecentlyOpenedFiles +// purpose : +// ======================================================================= +void TInspector_OpenFileDialog::GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, + TInspector_Communicator* theCommunicator, + QStringList& theFileNames) +{ + Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters(); + TInspectorAPI_PreferencesDataMap aPreferencesItem; + aParameters->GetPreferences (thePluginName, aPreferencesItem); + + for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (aPreferencesItem); anItemIt.More(); anItemIt.Next()) + { + if (!anItemIt.Key().IsEqual("recently_opened_files")) + continue; + theFileNames = QString(anItemIt.Value().ToCString()).split(";", QString::SkipEmptyParts); + if (theFileNames.size() > RECENT_FILES_CACHE_SIZE) + for (int i = 0; i < theFileNames.size() - RECENT_FILES_CACHE_SIZE; i++) + theFileNames.removeFirst(); + break; + } +} + +// ======================================================================= +// function : SetPluginRecentlyOpenedFiles +// purpose : +// ======================================================================= +void TInspector_OpenFileDialog::SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, + TInspector_Communicator* theCommunicator, + QStringList& theFileNames) +{ + Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters(); + + TInspectorAPI_PreferencesDataMap aPreferencesItem; + aParameters->GetPreferences (thePluginName, aPreferencesItem); + aPreferencesItem.Bind ("recently_opened_files", TCollection_AsciiString (theFileNames.join (";").toUtf8().data())); + + aParameters->SetPreferences (thePluginName, aPreferencesItem); +} + +// ======================================================================= +// function : onSampleSelectionChanged +// purpose : +// ======================================================================= +void TInspector_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& theSelected, + const QItemSelection&) +{ + QItemSelectionModel* aSelectionModel = (QItemSelectionModel*)sender(); + if (!aSelectionModel) + return; + if (theSelected.isEmpty()) + return; + + QModelIndex anIndex = theSelected.first().indexes().first(); + if (!anIndex.isValid()) + return; + + myFileName = aSelectionModel->model()->data (anIndex, Qt::ToolTipRole).toString(); + accept(); +} + +// ======================================================================= +// function : onSelectClicked +// purpose : +// ======================================================================= +void TInspector_OpenFileDialog::onSelectClicked() +{ + QString anEnteredPath; + QString aDirName = mySelectedName->text(); + if (!aDirName.isEmpty()) + { + QDir aDir (aDirName); + if (aDir.exists()) + anEnteredPath = aDirName; + } + + QString aFileName = QFileDialog::getOpenFileName (0, "Open document", anEnteredPath); + + if (aFileName.isEmpty()) + return; // do nothing, left the previous value + + + myFileName = aFileName; + accept(); +} + +// ======================================================================= +// function : onApplySelectClicked +// purpose : +// ======================================================================= +void TInspector_OpenFileDialog::onApplySelectClicked() +{ + QString aFileName = mySelectedName->text(); + + QFileInfo aFileInfo (aFileName); + if (!aFileInfo.exists() || !aFileInfo.isFile()) + return; + + myFileName = mySelectedName->text(); + accept(); +} + +// ======================================================================= +// function : createTableView +// purpose : +// ======================================================================= +QTableView* TInspector_OpenFileDialog::createTableView (const QStringList& theFileNames) +{ + QTableView* aTableView = new QTableView (this); + aTableView->setFrameStyle (QFrame::NoFrame); + QPalette aPalette = aTableView->viewport()->palette(); + QColor aWindowColor = aPalette.color (QPalette::Window); + aPalette.setBrush (QPalette::Base, aWindowColor); + aTableView->viewport()->setPalette (aPalette); + + aTableView->horizontalHeader()->setVisible (false); + aTableView->verticalHeader()->setVisible (false); + aTableView->setGridStyle (Qt::NoPen); + aTableView->setModel (createModel (theFileNames)); + aTableView->setItemDelegateForRow (0, new TInspectorEXE_OpenFileItemDelegate (aTableView, + aPalette.color (QPalette::Highlight))); + aTableView->viewport()->setAttribute (Qt::WA_Hover); + int aCellHeight = ICON_SIZE + aTableView->verticalHeader()->defaultSectionSize(); + aTableView->setRowHeight (0, aCellHeight); + int aScrollHeight = aTableView->horizontalScrollBar()->sizeHint().height(); + aTableView->setMinimumHeight (aCellHeight + aScrollHeight); + QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aTableView->model()); + connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), + this, SLOT (onSampleSelectionChanged (const QItemSelection&, const QItemSelection&))); + aTableView->setSelectionModel (aSelectionModel); + + return aTableView; +} + +// ======================================================================= +// function : createModel +// purpose : +// ======================================================================= +QAbstractItemModel* TInspector_OpenFileDialog::createModel (const QStringList& theFileNames) +{ + TInspector_OpenFileViewModel* aModel = new TInspector_OpenFileViewModel (this); + aModel->Init (theFileNames); + return aModel; +} diff --git a/tools/TInspector/TInspector_OpenFileDialog.hxx b/tools/TInspector/TInspector_OpenFileDialog.hxx new file mode 100644 index 0000000000..9776c43cf7 --- /dev/null +++ b/tools/TInspector/TInspector_OpenFileDialog.hxx @@ -0,0 +1,116 @@ +// 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 TInspectorEXE_OpenFileDialog_H +#define TInspectorEXE_OpenFileDialog_H + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +class TInspector_Communicator; + +class QAbstractItemModel; +class QLineEdit; +class QPushButton; +class QTableView; +class QToolButton; +class QWidget; + +//! \class TInspector_OpenFileDialog +//! Control that contains table view of samples and line to select a file name from other directory. +//! Click on element of samples table view calls this sample opening else after entering(or opening) file name +//! the import becomes active. Click on the button will open selected file if it is possible +class TInspector_OpenFileDialog : public QDialog +{ + Q_OBJECT +private: + + //! Constructor + Standard_EXPORT TInspector_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles); + +public: + + //! Destructor + virtual ~TInspector_OpenFileDialog() Standard_OVERRIDE {} + + //! Opens this file dialog using for samples view the given directory and try to open new file + //! \param theParent a parent for the new dialog + //! \param theDataDirName path to default samples directory + //! \returns a file name from the open file dialog + Standard_EXPORT static QString OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles); + + //! Returns selection name from the dialog + QString GetFileName() const { return myFileName; } + + //! Returns communicator, if this is the first call, create a communicator instance + Standard_EXPORT static TInspector_Communicator* Communicator(); + + //! Returns preferences: previous opened documents. + //! \param thePluginName name of the plugin + //! \param theCommunicator source of preferences + //! \param theFileNames [out] container of recently opened file names + Standard_EXPORT static void GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, + TInspector_Communicator* theCommunicator, + QStringList& theFileNames); + + //! Sets preferences: previous opened documents. + //! \param thePluginName name of the plugin + //! \param theCommunicator source of preferences + //! \param theFileNames container of recently opened file names to be set into communicator preferences + Standard_EXPORT static void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, + TInspector_Communicator* theCommunicator, + QStringList& theFileNames); + +private slots: + + //! Stores name of selected sample file + void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + + //! Opens file dialog to select a file name. Fills file name line, enable import button + void onSelectClicked(); + + //! Accepts open file dialog + void onApplySelectClicked(); + +private: + + //! Creates view of file names in samples directory + //! \param theFileNames a container of names + //! \return table view + QTableView* createTableView (const QStringList& theFileNames); + + //! Creates view model and fills it by the file names + //! \param theFileNames a container of names + //! \return model + QAbstractItemModel* createModel (const QStringList& theFileNames); + +private: + + QStringList myRecentlyOpenedFiles; //!< recently opened files + QString myFileName; //!< result file name + QTableView* mySamplesView; //!< view of sample file names + QLineEdit* mySelectedName; //!< alternative control to open file +}; + +#endif diff --git a/tools/TInspector/TInspector_OpenFileViewModel.cxx b/tools/TInspector/TInspector_OpenFileViewModel.cxx new file mode 100644 index 0000000000..d1e208a8c2 --- /dev/null +++ b/tools/TInspector/TInspector_OpenFileViewModel.cxx @@ -0,0 +1,75 @@ +// 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 + +#include +#include +#include +#include +#include +#include + +const int ICON_SIZE = 40; + +// ======================================================================= +// function : paint +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex) const +{ + // highlight cell + if (theOption.state & QStyle::State_MouseOver) + thePainter->fillRect (theOption.rect, myColor); + + // action icon for all indices before the last one + QIcon anIcon (":folder_import.png"); + QSize anIconSize (ICON_SIZE, ICON_SIZE); + int aDX = (theOption.rect.width() - anIconSize.width()) / 2; + int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); + thePainter->drawPixmap (QRect (theOption.rect.left() + aDX, + theOption.rect.top() + aMargin, + anIconSize.width(), + anIconSize.height()), + anIcon.pixmap(anIconSize.width(), anIconSize.height())); + // default paint + QItemDelegate::paint (thePainter, theOption, theIndex); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void TInspector_OpenFileViewModel::Init (const QStringList& theValues) +{ + myValues = theValues; +} + +// ======================================================================= +// function : data +// purpose : +// ======================================================================= +QVariant TInspector_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) + { + case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName(); + case Qt::ToolTipRole: return myValues[theIndex.column()]; + case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter); + default: break; + } + return QVariant(); +} diff --git a/tools/TInspector/TInspector_OpenFileViewModel.hxx b/tools/TInspector/TInspector_OpenFileViewModel.hxx new file mode 100644 index 0000000000..a7ec5b4e60 --- /dev/null +++ b/tools/TInspector/TInspector_OpenFileViewModel.hxx @@ -0,0 +1,98 @@ +// 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 TInspectorEXE_OpenFileViewModel_H +#define TInspectorEXE_OpenFileViewModel_H + +#include + +#include +#include +#include +#include +#include + +class QObject; +class QPainter; + +//! \class TInspectorEXE_OpenFileItemDelegate +//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button +class TInspectorEXE_OpenFileItemDelegate : public QItemDelegate +{ + +public: + + //! Constructor + TInspectorEXE_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlightColor) + : QItemDelegate (theParent), myColor(theHighlightColor) {} + + //! Destructor + virtual ~TInspectorEXE_OpenFileItemDelegate() {} + + //! Draws an icon in the cell + //! \param thePainter a painter + //! \param theOption a paint options + //! \param theIndex a view index + virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex) const Standard_OVERRIDE; + +private: + + QColor myColor; //!< highlight color +}; + +//! \class TInspector_OpenFileViewModel +//! Table model that visualizes container of string values (file names) +//! Table orientation is horizontal, it has 1 row, number of columns equals to number of values +class TInspector_OpenFileViewModel : public QAbstractTableModel +{ + +public: + + //! Constructor + TInspector_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} + + //! Destructor + virtual ~TInspector_OpenFileViewModel() {} + + //! Store values + //! \param theValues a container of values to fill model + void Init (const QStringList& theValues); + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! Returns number of rows + //! \param theParent an index of the parent item + //! \return an integer value + virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 1; } + + //! Returns number of columns + //! \param theParent an index of the parent item + //! \return an integer value + virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return myValues.size(); } + +private: + + QStringList myValues; //!< file names +}; + +#endif diff --git a/tools/TInspector/TInspector_PluginParameters.hxx b/tools/TInspector/TInspector_PluginParameters.hxx index 0f1810eff7..a46da81f24 100644 --- a/tools/TInspector/TInspector_PluginParameters.hxx +++ b/tools/TInspector/TInspector_PluginParameters.hxx @@ -35,7 +35,7 @@ public: Standard_EXPORT TInspector_PluginParameters (TInspector_Window* theWindow); //! Destructor - virtual ~TInspector_PluginParameters() Standard_OVERRIDE {} + virtual ~TInspector_PluginParameters() {} //! Stores the parameters for plugin //! \param thePluginName a plugin name @@ -62,10 +62,10 @@ public: const TInspectorAPI_PreferencesDataMap& theItem) Standard_OVERRIDE { myPreferences->SetPreferences (thePluginName, theItem); } - //! Store plugin preferences into a preferences file + //! Stores plugin preferences into a preferences file virtual void StorePreferences() Standard_OVERRIDE { myPreferences->StorePreferences(); } - //! Remove plugin preferences file + //! Removes plugin preferences file void RemovePreferences() { myPreferences->RemovePreferences(); } private: diff --git a/tools/TInspector/TInspector_Preferences.hxx b/tools/TInspector/TInspector_Preferences.hxx index 141cf2d98e..d0ebefc88e 100644 --- a/tools/TInspector/TInspector_Preferences.hxx +++ b/tools/TInspector/TInspector_Preferences.hxx @@ -57,17 +57,17 @@ public: void SetPreferences (const TCollection_AsciiString& thePluginName, const TInspectorAPI_PreferencesDataMap& theItem) { myLoadedPreferences.Bind(thePluginName, theItem); } - //! Store plugin preferences into a preferences file + //! Stores plugin preferences into a preferences file Standard_EXPORT void StorePreferences(); - //! Remove plugin preferences file + //! Removes 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 + //! Clears all internal containers with information of already loaded file void reset() { myLoadedPreferences.Clear(); myIsLoadedPreferences = Standard_False; } //! Reads plugin preferences and fill container diff --git a/tools/TInspector/TInspector_Window.cxx b/tools/TInspector/TInspector_Window.cxx index 8bb89ab31a..af22ab7709 100644 --- a/tools/TInspector/TInspector_Window.cxx +++ b/tools/TInspector/TInspector_Window.cxx @@ -83,7 +83,7 @@ TInspector_Window::TInspector_Window() myActionsWidget = new QToolButton(aCentralWidget); myActionsWidget->setPopupMode(QToolButton::InstantPopup); - myActionsWidget->setIcon (QIcon (":/icons/plugin_actions.png")); + myActionsWidget->setIcon (QIcon (":plugin_actions.png")); myActionsWidget->setIconSize (QSize (20, 20)); QMenu* anActionsMenu = new QMenu(myActionsWidget); myActionsWidget->setMenu(anActionsMenu); diff --git a/tools/TInspector/TInspector_Window.hxx b/tools/TInspector/TInspector_Window.hxx index 4e7e50bb7d..c0c802d0bf 100644 --- a/tools/TInspector/TInspector_Window.hxx +++ b/tools/TInspector/TInspector_Window.hxx @@ -68,7 +68,7 @@ public: Standard_EXPORT TInspector_Window(); //! Destructor - virtual ~TInspector_Window() Standard_OVERRIDE {} + virtual ~TInspector_Window() {} //! Appends the plugin names into internal conainer //! \param thePluginName a name of the plugin @@ -102,7 +102,7 @@ public: //! \param thePluginName a name of the plugin Standard_EXPORT void ActivateTool (const TCollection_AsciiString& thePluginName); - //! Set item selected in the active plugin + //! Sets item selected in the active plugin //! \param theItemNames a container of name of items in plugin that should become selected Standard_EXPORT void SetSelected (const NCollection_List& theItemNames); @@ -149,7 +149,7 @@ public slots: //! Stores preferences (current state) of all plugins into a preferences file Standard_EXPORT void OnStorePreferences(); - //! Remove preferences file + //! Removes preferences file Standard_EXPORT void OnRemovePreferences(); protected slots: @@ -180,7 +180,7 @@ protected: //! Applies desktop preferences to window void applyPreferences(); - //! Generate default temp directory by 'TEMP' or 'TMP' environment variables + //! Generates default temp directory by 'TEMP' or 'TMP' environment variables //! \return generated path TCollection_AsciiString defaultTemporaryDirectory() const; diff --git a/tools/TInspector/icons/folder_export.png b/tools/TInspector/icons/folder_export.png new file mode 100644 index 0000000000..5f45f993dc Binary files /dev/null and b/tools/TInspector/icons/folder_export.png differ diff --git a/tools/TInspector/icons/folder_import.png b/tools/TInspector/icons/folder_import.png new file mode 100644 index 0000000000..02743abe9b Binary files /dev/null and b/tools/TInspector/icons/folder_import.png differ diff --git a/tools/TInspector/icons/folder_open.png b/tools/TInspector/icons/folder_open.png new file mode 100644 index 0000000000..b0a139ebc6 Binary files /dev/null and b/tools/TInspector/icons/folder_open.png differ diff --git a/tools/TInspector/icons/item_algo_folder.png b/tools/TInspector/icons/item_algo_folder.png deleted file mode 100644 index 078dd3453f..0000000000 Binary files a/tools/TInspector/icons/item_algo_folder.png and /dev/null differ diff --git a/tools/TInspectorAPI/FILES b/tools/TInspectorAPI/FILES index dcb881a01b..63cf600d14 100644 --- a/tools/TInspectorAPI/FILES +++ b/tools/TInspectorAPI/FILES @@ -3,4 +3,3 @@ TInspectorAPI_Communicator.hxx TInspectorAPI_PluginParameters.cxx TInspectorAPI_PluginParameters.hxx TInspectorAPI_PreferencesDataMap.hxx -TInspectorAPI_Version.hxx diff --git a/tools/TInspectorAPI/TInspectorAPI_Communicator.hxx b/tools/TInspectorAPI/TInspectorAPI_Communicator.hxx index b25f4dbf0b..9c9cf8dd44 100644 --- a/tools/TInspectorAPI/TInspectorAPI_Communicator.hxx +++ b/tools/TInspectorAPI/TInspectorAPI_Communicator.hxx @@ -18,17 +18,14 @@ #include #include -#include -#if OCC_VERSION_HEX > 0x060901 - #include -#endif +#include #include //! The Communicator is an interface that should be implemented for a separate plugin //! It will be placed in layout of the given parent. After the plugin is created, it is possible to //! set container of parameters into plugin to provide the plugin's initialization by some external //! objects(e.g. Interactive Context or OCAF Application). If the parameters are changed, it may be -//! applyed in UpdateContent function. The communicator can change parameters in the following cases: +//! applied in UpdateContent function. The communicator can change parameters in the following cases: //! - the plugin removes own processed parameters (e.g. file names, that was opened by the plugin) //! - the plugin sends some parameters to another plugin(by name) (e.g. shape to be analized) //! (at the same time we should be careful here to do not change essential parameters of other plugins) @@ -50,9 +47,9 @@ public: //! \param theParent a parent class Standard_EXPORT virtual void SetParent (void* theParent) = 0; - //! Provide container for actions available in inspector on general level + //! Provides 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; } + virtual void FillActionsMenu (void* theMenu) { (void)theMenu; } //! Returns plugin preferences, empty implementation by default virtual void GetPreferences (TInspectorAPI_PreferencesDataMap&) {} diff --git a/tools/TInspectorAPI/TInspectorAPI_PluginParameters.cxx b/tools/TInspectorAPI/TInspectorAPI_PluginParameters.cxx index 9393949faf..53132b4271 100644 --- a/tools/TInspectorAPI/TInspectorAPI_PluginParameters.cxx +++ b/tools/TInspectorAPI/TInspectorAPI_PluginParameters.cxx @@ -14,14 +14,8 @@ // commercial license or contractual agreement. #include -#include -#if OCC_VERSION_HEX <= 0x060901 -IMPLEMENT_STANDARD_HANDLE (TInspectorAPI_PluginParameters, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient) -#else -IMPLEMENT_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient) -#endif // ======================================================================= // function : SetParameters @@ -275,7 +269,6 @@ void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiS return; anOrientationStr.Split (anOrientationStr.Length() - 1); -#if TINSPECTORAPI_VERSION_HEX > 0x070200 TopAbs_Orientation anOrientation; if (!TopAbs::ShapeOrientationFromString (anOrientationStr.ToCString(), anOrientation)) return; @@ -284,7 +277,4 @@ void TInspectorAPI_PluginParameters::ParametersToShape (const TCollection_AsciiS theShape.Location (aLocation); theShape.Orientation (anOrientation); -#else - (void)theValue; (void)theShape; -#endif } diff --git a/tools/TInspectorAPI/TInspectorAPI_PluginParameters.hxx b/tools/TInspectorAPI/TInspectorAPI_PluginParameters.hxx index c92b518bfc..c7975cde3f 100644 --- a/tools/TInspectorAPI/TInspectorAPI_PluginParameters.hxx +++ b/tools/TInspectorAPI/TInspectorAPI_PluginParameters.hxx @@ -18,16 +18,12 @@ #include #include -#include #include #include #include #include -class TInspectorAPI_PluginParameters; -DEFINE_STANDARD_HANDLE (TInspectorAPI_PluginParameters, Standard_Transient) - //! The container of parameters for all possible plugins. It stores list of parameters for each plugin, even //! it was not be loaded yet. There is a map of plugin name into plugin parameters. //! The parameters may be: @@ -41,7 +37,7 @@ public: Standard_EXPORT TInspectorAPI_PluginParameters() {} //! Destructor - Standard_EXPORT virtual ~TInspectorAPI_PluginParameters() Standard_OVERRIDE {} + Standard_EXPORT virtual ~TInspectorAPI_PluginParameters() {} //! Stores the parameters for plugin //! \param thePluginName a plugin name @@ -131,7 +127,7 @@ public: Standard_EXPORT virtual void SetPreferences (const TCollection_AsciiString& thePluginName, const TInspectorAPI_PreferencesDataMap& theItem) = 0; - //! Store plugin preferences into a preferences file + //! Stores plugin preferences into a preferences file Standard_EXPORT virtual void StorePreferences() = 0; //! Converts a Shape parameters excepting TShape into a string value @@ -145,11 +141,7 @@ public: Standard_EXPORT static void ParametersToShape (const TCollection_AsciiString& theValue, TopoDS_Shape& theShape); -#if OCC_VERSION_HEX <= 0x060901 - DEFINE_STANDARD_RTTI (TInspectorAPI_PluginParameters) -#else DEFINE_STANDARD_RTTIEXT (TInspectorAPI_PluginParameters, Standard_Transient) -#endif private: //! container of parameters NCollection_DataMap > myParameters; diff --git a/tools/TInspectorAPI/TInspectorAPI_Version.hxx b/tools/TInspectorAPI/TInspectorAPI_Version.hxx deleted file mode 100644 index 88bcc115a3..0000000000 --- a/tools/TInspectorAPI/TInspectorAPI_Version.hxx +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2018 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. - -/*====================================================================== -// -// Purpose: Defines macros identifying current version of Inspector -// The version is equal to current OCCT version and used to support compile compatibility -// to previous OCCT versions interface. -// To compile Inspector with earlier version of OCCT, change version variable here to needed OCCT version. -// -// TINSPECTORAPI_VERSION_MAJOR : (integer) number identifying major version -// TINSPECTORAPI_VERSION_MINOR : (integer) number identifying minor version -// TINSPECTORAPI_VERSION_MAINTENANCE : (integer) number identifying maintenance version -// TINSPECTORAPI_VERSION_HEX : (hex) complete number as hex, two positions per each of major, minor, and patch number -// -//======================================================================*/ - -#ifndef _TInspectorAPI_Version_HeaderFile -#define _TInspectorAPI_Version_HeaderFile - -#include - -// Primary definitions -#define TINSPECTORAPI_VERSION_MAJOR OCC_VERSION_MAJOR -#define TINSPECTORAPI_VERSION_MINOR OCC_VERSION_MINOR -#define TINSPECTORAPI_VERSION_MAINTENANCE 0//OCC_VERSION_MAINTENANCE - -// Derived: complete version as hex (0x0'major'0'minor'0'maintenance') -#define TINSPECTORAPI_VERSION_HEX (TINSPECTORAPI_VERSION_MAJOR << 16 | TINSPECTORAPI_VERSION_MINOR << 8 | TINSPECTORAPI_VERSION_MAINTENANCE) - -#endif /* _TInspectorAPI_Version_HeaderFile */ diff --git a/tools/TInspectorEXE/EXTERNLIB b/tools/TInspectorEXE/EXTERNLIB index 8f800f24cd..83dde91d4d 100644 --- a/tools/TInspectorEXE/EXTERNLIB +++ b/tools/TInspectorEXE/EXTERNLIB @@ -1 +1,4 @@ -TKTInspector \ No newline at end of file +TKTInspector +TKTInspectorAPI +TKernel +CSF_QT \ No newline at end of file diff --git a/tools/TInspectorEXE/FILES b/tools/TInspectorEXE/FILES index 68b0c79ed5..44a1d285c2 100644 --- a/tools/TInspectorEXE/FILES +++ b/tools/TInspectorEXE/FILES @@ -1,7 +1,2 @@ TInspectorEXE.cxx -TInspectorEXE_OpenFileDialog.cxx -TInspectorEXE_OpenFileDialog.hxx -TInspectorEXE_OpenFileViewModel.cxx -TInspectorEXE_OpenFileViewModel.hxx -TInspectorEXE.qrc EXTERNLIB diff --git a/tools/TInspectorEXE/PACKAGES b/tools/TInspectorEXE/PACKAGES deleted file mode 100644 index 1736c7de1e..0000000000 --- a/tools/TInspectorEXE/PACKAGES +++ /dev/null @@ -1 +0,0 @@ -TInspectorEXE diff --git a/tools/TInspectorEXE/TInspectorEXE.cxx b/tools/TInspectorEXE/TInspectorEXE.cxx index 10dcf4b845..73ab696359 100644 --- a/tools/TInspectorEXE/TInspectorEXE.cxx +++ b/tools/TInspectorEXE/TInspectorEXE.cxx @@ -14,7 +14,8 @@ // commercial license or contractual agreement. -#include +#include +#include #include @@ -50,10 +51,10 @@ TCollection_AsciiString fileNameInDataDir (const TCollection_AsciiString& theEnv // purpose : // ======================================================================= void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator, - TInspectorEXE_OpenButton* theButtonControl) + TInspector_OpenButton* theButtonControl) { QStringList aRecentlyOpenedFiles; - TInspectorEXE_OpenFileDialog::GetPluginRecentlyOpenedFiles (theName, theCommunicator, aRecentlyOpenedFiles); + TInspector_OpenFileDialog::GetPluginRecentlyOpenedFiles (theName, theCommunicator, aRecentlyOpenedFiles); TCollection_AsciiString aFileName, anAdditionalFileName; if (!aRecentlyOpenedFiles.isEmpty()) aFileName = TCollection_AsciiString (aRecentlyOpenedFiles.last().toUtf8().data()); @@ -107,14 +108,14 @@ int main (int argc, char** argv) NCollection_List aParameters; // Create tool communicator - TInspector_Communicator* aCommunicator = TInspectorEXE_OpenFileDialog::Communicator(); + TInspector_Communicator* aCommunicator = TInspector_OpenFileDialog::Communicator(); if (!aCommunicator) { std::cout << "Communicator can not be created" << std::endl; return 0; } - TInspectorEXE_OpenButton* aButtonControl = new TInspectorEXE_OpenButton (0); + TInspector_OpenButton* aButtonControl = new TInspector_OpenButton (0); TCollection_AsciiString anActivatedPluginName; if (aPlugins.empty()) { diff --git a/tools/TInspectorEXE/TInspectorEXE.qrc b/tools/TInspectorEXE/TInspectorEXE.qrc deleted file mode 100644 index 5b8eac8911..0000000000 --- a/tools/TInspectorEXE/TInspectorEXE.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - icons/folder_open.png - icons/folder_import.png - - diff --git a/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx b/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx deleted file mode 100644 index 239382726d..0000000000 --- a/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx +++ /dev/null @@ -1,339 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const int FONT_POINT_SIZE = 18; -const int ICON_SIZE = 40; - -const int OPEN_DIALOG_WIDTH = 550; -const int OPEN_DIALOG_HEIGHT = 200; - -const int MARGIN_DIALOG = 4; -const int SPACING_DIALOG = 2; - -const int RECENT_FILES_CACHE_SIZE = 10; - -TInspector_Communicator* MyCommunicator; - -// ======================================================================= -// function : StartButton -// purpose : -// ======================================================================= -QPushButton* TInspectorEXE_OpenButton::StartButton() -{ - if (!myStartButton) - { - myStartButton = new QPushButton(); - myStartButton->setIcon (QIcon (":folder_open.png")); - connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked())); - } - return myStartButton; -} - -// ======================================================================= -// function : onStartButtonClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenButton::onStartButtonClicked() -{ - QPushButton* aButton = (QPushButton*)sender(); - TCollection_AsciiString aPluginName (aButton->objectName().toStdString().c_str()); - if (aPluginName.IsEmpty()) - return; - - QStringList aPluginRecentlyOpenedFiles; - if (myRecentlyOpenedFiles.contains(aPluginName)) - { - QStringList aFileNames = myRecentlyOpenedFiles[aPluginName]; - for (int i = 0; i < aFileNames.size(); i++) - { - QFileInfo aFileInfo (aFileNames[i]); - if (aFileInfo.exists() && aFileInfo.isFile()) - aPluginRecentlyOpenedFiles.append(aFileInfo.absoluteFilePath()); - } - } - - QString aFileName = TInspectorEXE_OpenFileDialog::OpenFile (0, aPluginRecentlyOpenedFiles); - aFileName = QDir().toNativeSeparators (aFileName); - if (!aFileName.isEmpty()) { - QApplication::setOverrideCursor (Qt::WaitCursor); - TInspectorEXE_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data())); - - QFileInfo aFileInfo (aFileName); - if (!aPluginRecentlyOpenedFiles.contains (aFileInfo.absoluteFilePath())) - { - myRecentlyOpenedFiles[aPluginName].append (aFileInfo.absoluteFilePath()); - for (int i = 0; i < myRecentlyOpenedFiles[aPluginName].size() - RECENT_FILES_CACHE_SIZE; i++) - myRecentlyOpenedFiles[aPluginName].removeFirst(); - TInspectorEXE_OpenFileDialog::SetPluginRecentlyOpenedFiles (aPluginName, - TInspectorEXE_OpenFileDialog::Communicator(), myRecentlyOpenedFiles[aPluginName]); - - TInspectorEXE_OpenFileDialog::Communicator()->GetPluginParameters()->StorePreferences(); - } - - QApplication::restoreOverrideCursor(); - } -} - -// ======================================================================= -// function : changeMargins -// purpose : -// ======================================================================= -void changeMargins (QBoxLayout* theLayout) -{ - theLayout->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); - theLayout->setSpacing (SPACING_DIALOG); -} - -// ======================================================================= -// function : Constructor -// purpose : -// ======================================================================= -TInspectorEXE_OpenFileDialog::TInspectorEXE_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles) -: QDialog (theParent), myRecentlyOpenedFiles (theRecentlyOpenedFiles) -{ - setWindowTitle (tr ("Open File")); - - QVBoxLayout* aDialogLay = new QVBoxLayout (this); - changeMargins (aDialogLay); - - // Samples View - QGroupBox* aSamplesBox = new QGroupBox (this); - aSamplesBox->setTitle (tr ("Recent files")); - aDialogLay->addWidget (aSamplesBox); - QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox); - changeMargins (aSampleLay); - mySamplesView = createTableView (theRecentlyOpenedFiles); - aSampleLay->addWidget (mySamplesView); - - // Select file - QGroupBox* aSelectFileBox = new QGroupBox (this); - aSelectFileBox->setTitle (tr ("Select file")); - aDialogLay->addWidget (aSelectFileBox); - QGridLayout* aSelectFileLay = new QGridLayout (aSelectFileBox); - aSelectFileLay->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); - - mySelectedName = new QLineEdit (aSelectFileBox); - QCompleter* aCompleter = new QCompleter(); - QFileSystemModel* aFileSystemModel = new QFileSystemModel; - aFileSystemModel->setRootPath (QDir::rootPath()); - aCompleter->setModel (aFileSystemModel); - mySelectedName->setCompleter (aCompleter); - aSelectFileLay->addWidget (mySelectedName, 1, 0); - - QToolButton* aSelectFileBtn = new QToolButton (aSelectFileBox); - aSelectFileBtn->setIcon (QIcon (":folder_open.png")); - aSelectFileLay->addWidget (aSelectFileBtn, 1, 1); - - connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked())); - connect (mySelectedName, SIGNAL (returnPressed()), this, SLOT (onApplySelectClicked())); - - resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT); -} - -// ======================================================================= -// function : OpenFile -// purpose : -// ======================================================================= -QString TInspectorEXE_OpenFileDialog::OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles) -{ - QString aFileName; - TInspectorEXE_OpenFileDialog* aDialog = new TInspectorEXE_OpenFileDialog (theParent, theRecentlyOpenedFiles); - if (aDialog->exec() == QDialog::Accepted) - aFileName = aDialog->GetFileName(); - - return aFileName; -} - -// ======================================================================= -// function : Communicator -// purpose : -// ======================================================================= -TInspector_Communicator* TInspectorEXE_OpenFileDialog::Communicator() -{ - if (!MyCommunicator) - MyCommunicator = new TInspector_Communicator(); - return MyCommunicator; -} - -// ======================================================================= -// function : GetPluginRecentlyOpenedFiles -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, - TInspector_Communicator* theCommunicator, - QStringList& theFileNames) -{ - Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters(); - TInspectorAPI_PreferencesDataMap aPreferencesItem; - aParameters->GetPreferences (thePluginName, aPreferencesItem); - - for (TInspectorAPI_IteratorOfPreferencesDataMap anItemIt (aPreferencesItem); anItemIt.More(); anItemIt.Next()) - { - if (!anItemIt.Key().IsEqual("recently_opened_files")) - continue; - theFileNames = QString(anItemIt.Value().ToCString()).split(";", QString::SkipEmptyParts); - if (theFileNames.size() > RECENT_FILES_CACHE_SIZE) - for (int i = 0; i < theFileNames.size() - RECENT_FILES_CACHE_SIZE; i++) - theFileNames.removeFirst(); - break; - } -} - -// ======================================================================= -// function : SetPluginRecentlyOpenedFiles -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, - TInspector_Communicator* theCommunicator, - QStringList& theFileNames) -{ - Handle(TInspectorAPI_PluginParameters) aParameters = theCommunicator->GetPluginParameters(); - - TInspectorAPI_PreferencesDataMap aPreferencesItem; - aParameters->GetPreferences (thePluginName, aPreferencesItem); - aPreferencesItem.Bind ("recently_opened_files", TCollection_AsciiString (theFileNames.join (";").toUtf8().data())); - - aParameters->SetPreferences (thePluginName, aPreferencesItem); -} - -// ======================================================================= -// function : onSampleSelectionChanged -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& theSelected, - const QItemSelection&) -{ - QItemSelectionModel* aSelectionModel = (QItemSelectionModel*)sender(); - if (!aSelectionModel) - return; - if (theSelected.isEmpty()) - return; - - QModelIndex anIndex = theSelected.first().indexes().first(); - if (!anIndex.isValid()) - return; - - myFileName = aSelectionModel->model()->data (anIndex, Qt::ToolTipRole).toString(); - accept(); -} - -// ======================================================================= -// function : onSelectClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onSelectClicked() -{ - QString anEnteredPath; - QString aDirName = mySelectedName->text(); - if (!aDirName.isEmpty()) - { - QDir aDir (aDirName); - if (aDir.exists()) - anEnteredPath = aDirName; - } - - QString aFileName = QFileDialog::getOpenFileName (0, "Open document", anEnteredPath); - - if (aFileName.isEmpty()) - return; // do nothing, left the previous value - - - myFileName = aFileName; - accept(); -} - -// ======================================================================= -// function : onApplySelectClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onApplySelectClicked() -{ - QString aFileName = mySelectedName->text(); - - QFileInfo aFileInfo (aFileName); - if (!aFileInfo.exists() || !aFileInfo.isFile()) - return; - - myFileName = mySelectedName->text(); - accept(); -} - -// ======================================================================= -// function : createTableView -// purpose : -// ======================================================================= -QTableView* TInspectorEXE_OpenFileDialog::createTableView (const QStringList& theFileNames) -{ - QTableView* aTableView = new QTableView (this); - aTableView->setFrameStyle (QFrame::NoFrame); - QPalette aPalette = aTableView->viewport()->palette(); - QColor aWindowColor = aPalette.color (QPalette::Window); - aPalette.setBrush (QPalette::Base, aWindowColor); - aTableView->viewport()->setPalette (aPalette); - - aTableView->horizontalHeader()->setVisible (false); - aTableView->verticalHeader()->setVisible (false); - aTableView->setGridStyle (Qt::NoPen); - aTableView->setModel (createModel (theFileNames)); - aTableView->setItemDelegateForRow (0, new TInspectorEXE_OpenFileItemDelegate (aTableView, - aPalette.color (QPalette::Highlight))); - aTableView->viewport()->setAttribute (Qt::WA_Hover); - int aCellHeight = ICON_SIZE + aTableView->verticalHeader()->defaultSectionSize(); - aTableView->setRowHeight (0, aCellHeight); - int aScrollHeight = aTableView->horizontalScrollBar()->sizeHint().height(); - aTableView->setMinimumHeight (aCellHeight + aScrollHeight); - QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aTableView->model()); - connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), - this, SLOT (onSampleSelectionChanged (const QItemSelection&, const QItemSelection&))); - aTableView->setSelectionModel (aSelectionModel); - - return aTableView; -} - -// ======================================================================= -// function : createModel -// purpose : -// ======================================================================= -QAbstractItemModel* TInspectorEXE_OpenFileDialog::createModel (const QStringList& theFileNames) -{ - TInspectorEXE_OpenFileViewModel* aModel = new TInspectorEXE_OpenFileViewModel (this); - aModel->Init (theFileNames); - return aModel; -} diff --git a/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx b/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx deleted file mode 100644 index b4d63ee99c..0000000000 --- a/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx +++ /dev/null @@ -1,154 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef TInspectorEXE_OpenFileDialog_H -#define TInspectorEXE_OpenFileDialog_H - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -class TInspector_Communicator; - -class QAbstractItemModel; -class QLineEdit; -class QPushButton; -class QTableView; -class QToolButton; -class QWidget; - -//! \class TInspectorEXE_OpenButton -//! Class that contains push button and the button processing. It obtains a file name from the default or current -//! directory and gives the name into TInspector communicator -//! Object name of the button is the name of the plugin to get the default directory, or the current directory is used. -class TInspectorEXE_OpenButton : public QObject -{ - Q_OBJECT - -public: - - //! Constructor - TInspectorEXE_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {} - - //! Destructor - virtual ~TInspectorEXE_OpenButton() {} - - //! Returns the start button, if this is the first call, it creates the button and connect it to the slot - QPushButton* StartButton(); - - //! Sets the default directory of plugin. - void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, - const QStringList& theRecentlyOpenedFiles) - { myRecentlyOpenedFiles[thePluginName] = theRecentlyOpenedFiles; } - -private slots: - - //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator - void onStartButtonClicked(); - -private: - - QPushButton* myStartButton; //!< processed button - //!< plugins recently opened files - QMap myRecentlyOpenedFiles; -}; - -//! \class TInspectorEXE_OpenFileDialog -//! Control that contains table view of samples and line to select a file name from other directory. -//! Click on element of samples table view calls this sample opening else after entering(or opening) file name -//! the import becomes active. Click on the button will open selected file if it is possible -class TInspectorEXE_OpenFileDialog : public QDialog -{ - Q_OBJECT -private: - - //! Constructor - Standard_EXPORT TInspectorEXE_OpenFileDialog (QWidget* theParent, const QStringList& theRecentlyOpenedFiles); - -public: - - //! Destructor - virtual ~TInspectorEXE_OpenFileDialog() Standard_OVERRIDE {} - - //! Opens this file dialog using for samples view the given directory and try to open new file - //! \param theParent a parent for the new dialog - //! \param theDataDirName path to default samples directory - //! \returns a file name from the open file dialog - Standard_EXPORT static QString OpenFile (QWidget* theParent, const QStringList& theRecentlyOpenedFiles); - - //! Returns selection name from the dialog - QString GetFileName() const { return myFileName; } - - //! Returns communicator, if this is the first call, create a communicator instance - Standard_EXPORT static TInspector_Communicator* Communicator(); - - //! Returns preferences: previous opened documents. - //! \param thePluginName name of the plugin - //! \param theCommunicator source of preferences - //! \param theFileNames [out] container of recently opened file names - Standard_EXPORT static void GetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, - TInspector_Communicator* theCommunicator, - QStringList& theFileNames); - - //! Sets preferences: previous opened documents. - //! \param thePluginName name of the plugin - //! \param theCommunicator source of preferences - //! \param theFileNames container of recently opened file names to be set into communicator preferences - Standard_EXPORT static void SetPluginRecentlyOpenedFiles (const TCollection_AsciiString& thePluginName, - TInspector_Communicator* theCommunicator, - QStringList& theFileNames); - -private slots: - - //! Stores name of selected sample file - void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); - - //! Open file dialog to select a file name. Fills file name line, enable import button - void onSelectClicked(); - - //! Accepts open file dialog - void onApplySelectClicked(); - -private: - - //! Creates view of file names in samples directory - //! \param theFileNames a container of names - //! \return table view - QTableView* createTableView (const QStringList& theFileNames); - - //! Creates view model and fills it by the file names - //! \param theFileNames a container of names - //! \return model - QAbstractItemModel* createModel (const QStringList& theFileNames); - -private: - - QStringList myRecentlyOpenedFiles; //!< recently opened files - QString myFileName; //!< result file name - QTableView* mySamplesView; //! - -#include -#include -#include -#include -#include -#include - -const int ICON_SIZE = 40; - -// ======================================================================= -// function : paint -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex) const -{ - // highlight cell - if (theOption.state & QStyle::State_MouseOver) - thePainter->fillRect (theOption.rect, myColor); - - // action icon for all indices before the last one - QIcon anIcon (":folder_import.png"); - QSize anIconSize (ICON_SIZE, ICON_SIZE); - int aDX = (theOption.rect.width() - anIconSize.width()) / 2; - int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); - thePainter->drawPixmap (QRect (theOption.rect.left() + aDX, - theOption.rect.top() + aMargin, - anIconSize.width(), - anIconSize.height()), - anIcon.pixmap(anIconSize.width(), anIconSize.height())); - // default paint - QItemDelegate::paint (thePainter, theOption, theIndex); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileViewModel::Init (const QStringList& theValues) -{ - myValues = theValues; -} - -// ======================================================================= -// function : data -// purpose : -// ======================================================================= -QVariant TInspectorEXE_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const -{ - switch (theRole) - { - case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName(); - case Qt::ToolTipRole: return myValues[theIndex.column()]; - case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter); - default: break; - } - return QVariant(); -} diff --git a/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx b/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx deleted file mode 100644 index 42b6604e07..0000000000 --- a/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx +++ /dev/null @@ -1,98 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef TInspectorEXE_OpenFileViewModel_H -#define TInspectorEXE_OpenFileViewModel_H - -#include - -#include -#include -#include -#include -#include - -class QObject; -class QPainter; - -//! \class TInspectorEXE_OpenFileItemDelegate -//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button -class TInspectorEXE_OpenFileItemDelegate : public QItemDelegate -{ - -public: - - //! Constructor - TInspectorEXE_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlightColor) - : QItemDelegate (theParent), myColor(theHighlightColor) {} - - //! Destructor - virtual ~TInspectorEXE_OpenFileItemDelegate() {} - - //! Draw an icon in the cell - //! \param thePainter a painter - //! \param theOption a paint options - //! \param theIndex a view index - virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex) const Standard_OVERRIDE; - -private: - - QColor myColor; //!< highlight color -}; - -//! \class TInspectorEXE_OpenFileViewModel -//! Table model that visualizes container of string values (file names) -//! Table orientation is horizontal, it has 1 row, number of columns equals to number of values -class TInspectorEXE_OpenFileViewModel : public QAbstractTableModel -{ - -public: - - //! Constructor - TInspectorEXE_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} - - //! Destructor - virtual ~TInspectorEXE_OpenFileViewModel() {} - - //! Store values - //! \param theValues a container of values to fill model - void Init (const QStringList& theValues); - - //! Returns content of the model index for the given role, it is obtained from internal container of values - //! It returns value only for DisplayRole. - //! \param theIndex a model index - //! \param theRole a view role - //! \return value intepreted depending on the given role - virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; - - //! Returns number of rows - //! \param theParent an index of the parent item - //! \return an integer value - virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE - { (void)theParent; return 1; } - - //! Returns number of columns - //! \param theParent an index of the parent item - //! \return an integer value - virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE - { (void)theParent; return myValues.size(); } - -private: - - QStringList myValues; //!< file names -}; - -#endif diff --git a/tools/TInspectorEXE/icons/folder_export.png b/tools/TInspectorEXE/icons/folder_export.png deleted file mode 100644 index 5f45f993dc..0000000000 Binary files a/tools/TInspectorEXE/icons/folder_export.png and /dev/null differ diff --git a/tools/TInspectorEXE/icons/folder_import.png b/tools/TInspectorEXE/icons/folder_import.png deleted file mode 100644 index 02743abe9b..0000000000 Binary files a/tools/TInspectorEXE/icons/folder_import.png and /dev/null differ diff --git a/tools/TInspectorEXE/icons/folder_open.png b/tools/TInspectorEXE/icons/folder_open.png deleted file mode 100644 index b0a139ebc6..0000000000 Binary files a/tools/TInspectorEXE/icons/folder_open.png and /dev/null differ diff --git a/tools/TKShapeView/EXTERNLIB b/tools/TKShapeView/EXTERNLIB index a028066963..b9f14514bc 100644 --- a/tools/TKShapeView/EXTERNLIB +++ b/tools/TKShapeView/EXTERNLIB @@ -1,9 +1,11 @@ TKTInspectorAPI +TKernel TKMath TKBRep TKGeomBase TKG3d TKService TKTreeModel +TKV3d TKView CSF_QT diff --git a/tools/TKTInspectorAPI/EXTERNLIB b/tools/TKTInspectorAPI/EXTERNLIB index df0002f9af..0e517c2551 100644 --- a/tools/TKTInspectorAPI/EXTERNLIB +++ b/tools/TKTInspectorAPI/EXTERNLIB @@ -1,4 +1,8 @@ TKG3d TKernel TKLCAF -TKMath \ No newline at end of file +TKMath +TKBRep +TKTopAlgo +TKPrim +TKV3d diff --git a/tools/TKTInspectorAPI/PACKAGES b/tools/TKTInspectorAPI/PACKAGES index 7cb3cd210e..72bf985bde 100644 --- a/tools/TKTInspectorAPI/PACKAGES +++ b/tools/TKTInspectorAPI/PACKAGES @@ -1 +1,3 @@ +Convert TInspectorAPI + diff --git a/tools/TKToolsDraw/EXTERNLIB b/tools/TKToolsDraw/EXTERNLIB index 62a89ecedf..95df12df08 100644 --- a/tools/TKToolsDraw/EXTERNLIB +++ b/tools/TKToolsDraw/EXTERNLIB @@ -2,6 +2,7 @@ TKDraw TKDCAF TKTInspector TKTInspectorAPI +TKernel TKService TKV3d TKViewerTest diff --git a/tools/TKTreeModel/EXTERNLIB b/tools/TKTreeModel/EXTERNLIB index 893b52c708..74b7426c22 100644 --- a/tools/TKTreeModel/EXTERNLIB +++ b/tools/TKTreeModel/EXTERNLIB @@ -1 +1,6 @@ +TKernel +TKMath +TKPrim +TKTopAlgo +TKTInspectorAPI CSF_QT \ No newline at end of file diff --git a/tools/TKView/EXTERNLIB b/tools/TKView/EXTERNLIB index b5f64414c0..72cf33304f 100644 --- a/tools/TKView/EXTERNLIB +++ b/tools/TKView/EXTERNLIB @@ -4,4 +4,5 @@ TKMath TKService TKOpenGl TKV3d +TKTInspectorAPI CSF_QT \ No newline at end of file diff --git a/tools/ToolsDraw/ToolsDraw.cxx b/tools/ToolsDraw/ToolsDraw.cxx index e03dd5b61e..c0abd7766a 100644 --- a/tools/ToolsDraw/ToolsDraw.cxx +++ b/tools/ToolsDraw/ToolsDraw.cxx @@ -40,6 +40,15 @@ Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); static TInspector_Communicator* MyCommunicator; +// ======================================================================= +// function : Communicator +// purpose : defines plugin library name by the command argument +// ======================================================================= +TInspector_Communicator* ToolsDraw::Communicator() +{ + return MyCommunicator; +} + // ======================================================================= // function : convertToPluginName // purpose : defines plugin library name by the command argument @@ -386,7 +395,7 @@ void ToolsDraw::Commands(Draw_Interpretor& theCommands) "\n\t\t: Plugins order will be the same as defined in arguments." "\n\t\t: 'all' adds all available plugins in the order:" "\n\t\t: DFBrowser, VInspector and ShapeView." - "\n\t\t: If at the first call this option is not used, 'all' option is applyed;" + "\n\t\t: If at the first call this option is not used, 'all' option is applied;" "\n\t\t: -activate activates the plugin in the tool view." "\n\t\t: If at the first call this option is not used, the first plugin is activated;" "\n\t\t: -shape initializes plugin/s by the shape object. If 'name' is empty, initializes all plugins;" diff --git a/tools/ToolsDraw/ToolsDraw.hxx b/tools/ToolsDraw/ToolsDraw.hxx index b004ad50df..9b5dcf529c 100644 --- a/tools/ToolsDraw/ToolsDraw.hxx +++ b/tools/ToolsDraw/ToolsDraw.hxx @@ -20,6 +20,8 @@ #include #include +class TInspector_Communicator; + //! \class ToolsDraw //! \brief Registers DRAW commands to connect to TInspector tools class ToolsDraw @@ -32,10 +34,13 @@ public: //! \param theDI Draw interpretor Standard_EXPORT static void Factory (Draw_Interpretor& theDI); - //! Add all tools command in the Draw_Interpretor + //! Adds all tools command in the Draw_Interpretor //! \param theCommands Standard_EXPORT static void Commands (Draw_Interpretor& theCommands); + //! Returns default communicator used in DRAW commands + Standard_EXPORT static TInspector_Communicator* Communicator(); + private: }; diff --git a/tools/TreeModel/FILES b/tools/TreeModel/FILES index 2eeab8f369..45b20c9dc0 100644 --- a/tools/TreeModel/FILES +++ b/tools/TreeModel/FILES @@ -1,4 +1,3 @@ -TreeModel.hxx TreeModel.qrc TreeModel_ColumnType.hxx TreeModel_ContextMenu.cxx @@ -6,7 +5,11 @@ TreeModel_ContextMenu.hxx TreeModel_HeaderSection.hxx TreeModel_ItemBase.cxx TreeModel_ItemBase.hxx +TreeModel_ItemProperties.cxx +TreeModel_ItemProperties.hxx TreeModel_ItemRole.hxx +TreeModel_ItemStream.cxx +TreeModel_ItemStream.hxx TreeModel_ModelBase.cxx TreeModel_ModelBase.hxx TreeModel_Tools.cxx diff --git a/tools/TreeModel/TreeModel.hxx b/tools/TreeModel/TreeModel.hxx deleted file mode 100644 index 30ba380cd4..0000000000 --- a/tools/TreeModel/TreeModel.hxx +++ /dev/null @@ -1,33 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef 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 diff --git a/tools/TreeModel/TreeModel_ContextMenu.hxx b/tools/TreeModel/TreeModel_ContextMenu.hxx index 925185a679..c6df4238b4 100644 --- a/tools/TreeModel/TreeModel_ContextMenu.hxx +++ b/tools/TreeModel/TreeModel_ContextMenu.hxx @@ -47,7 +47,7 @@ protected slots: void onColumnVisibilityChanged(); private: - QTreeView* myTreeView; + QTreeView* myTreeView; //!< current tree view }; #endif diff --git a/tools/TreeModel/TreeModel_HeaderSection.hxx b/tools/TreeModel/TreeModel_HeaderSection.hxx index 5ea9ca1e4f..6e84d7ea06 100644 --- a/tools/TreeModel/TreeModel_HeaderSection.hxx +++ b/tools/TreeModel/TreeModel_HeaderSection.hxx @@ -41,6 +41,11 @@ public: //! Destructor ~TreeModel_HeaderSection() {} + //! Returns whether the header section is not initialized with values. + //! The check is empty value of the name text + //! \return boolean value + bool IsEmpty() const { return myName.isEmpty(); } + //! Sets text value //! \theName text value void SetName (const QString& theName) { myName = theName; } @@ -69,10 +74,10 @@ public: bool IsItalic() const { return myIsItalic; } private: - QString myName; //! text value - int myWidth; //! section width - bool myIsHidden; //! visibility - bool myIsItalic; //! italic + QString myName; //!< text value + int myWidth; //!< section width + bool myIsHidden; //!< visibility + bool myIsItalic; //!< italic }; #endif diff --git a/tools/TreeModel/TreeModel_ItemBase.cxx b/tools/TreeModel/TreeModel_ItemBase.cxx index 464a788863..38ef9b23ca 100644 --- a/tools/TreeModel/TreeModel_ItemBase.cxx +++ b/tools/TreeModel/TreeModel_ItemBase.cxx @@ -14,9 +14,11 @@ // commercial license or contractual agreement. #include - +#include #include +#include +#include #include #include #include @@ -26,7 +28,7 @@ // purpose : // ======================================================================= TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : m_bInitialized (false) + : m_iStreamChildren (0), m_bInitialized (false) { m_pParent = theParent; m_iRow = theRow; @@ -34,7 +36,7 @@ TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const i } // ======================================================================= -// function : reset +// function : Reset // purpose : // ======================================================================= void TreeModel_ItemBase::Reset() @@ -46,7 +48,12 @@ void TreeModel_ItemBase::Reset() anItem->Reset(); } m_bInitialized = false; + if (!myProperties.IsNull()) + { + myProperties->Reset(); + } myCachedValues.clear(); + myStream.str (""); } // ======================================================================= @@ -55,7 +62,7 @@ void TreeModel_ItemBase::Reset() // ======================================================================= void TreeModel_ItemBase::Reset (int theRole) { - if (!myCachedValues.contains (theRole)) + if (!myCachedValues.contains (theRole)) return; myCachedValues.remove (theRole); @@ -74,7 +81,11 @@ TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, cons TreeModel_ItemBasePtr anItem; if (isToCreate) { - anItem = createChild (theRow, theColumn); + if (theRow < m_iStreamChildren) + anItem = TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn); + else + anItem = createChild (theRow - m_iStreamChildren, theColumn); + if (anItem) m_ChildItems[aPos] = anItem; } @@ -99,8 +110,77 @@ QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const if (myCachedValues.contains (theItemRole)) return myCachedValues[theItemRole]; - const_cast(this)->myCachedValues.insert (theItemRole, - theItemRole == TreeModel_ItemRole_RowCountRole ? QVariant (initRowCount()) : initValue (theItemRole)); + QVariant aValueToCache; + if (theItemRole == TreeModel_ItemRole_RowCountRole) + aValueToCache = initRowCount() + const_cast(this)->initStreamRowCount(); + else + aValueToCache = initValue (theItemRole); + myCachedValues.insert (theItemRole, aValueToCache); return myCachedValues.contains (theItemRole) ? myCachedValues[theItemRole] : QVariant(); } + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void TreeModel_ItemBase::Init() +{ + m_bInitialized = true; + + initStream(myStream); + initStreamRowCount(); +} + +// ======================================================================= +// function : Object +// purpose : +// ======================================================================= +const Handle(Standard_Transient)& TreeModel_ItemBase::Object() const +{ + static Handle(Standard_Transient) aNullObject; + return aNullObject; +} + +// ======================================================================= +// function : initStreamRowCount +// purpose : +// ======================================================================= +int TreeModel_ItemBase::initStreamRowCount() +{ + int aStreamChildrenCount = 0; + if (Column() == 0) + { + Standard_SStream aStream; + initStream (aStream); + if (!Standard_Dump::Text (aStream).IsEmpty()) + { + if (!myProperties) + { + myProperties = new TreeModel_ItemProperties(); + myProperties->SetItem (currentItem()); + } + myProperties->Init(); + aStreamChildrenCount = myProperties->Children().Extent(); + } + } + m_iStreamChildren = aStreamChildrenCount; + return m_iStreamChildren; +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant TreeModel_ItemBase::initValue (const int theItemRole) const +{ + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + switch (Column()) + { + case 1: { return Row(); } + } + + return QVariant(); +} diff --git a/tools/TreeModel/TreeModel_ItemBase.hxx b/tools/TreeModel/TreeModel_ItemBase.hxx index 82ba6dc360..99f7d21068 100644 --- a/tools/TreeModel/TreeModel_ItemBase.hxx +++ b/tools/TreeModel/TreeModel_ItemBase.hxx @@ -18,6 +18,10 @@ #include #include +#include +#include +#include + #include #include @@ -32,6 +36,7 @@ #include class TreeModel_ItemBase; +class TreeModel_ItemProperties; typedef QExplicitlySharedDataPointer TreeModel_ItemBasePtr; @@ -81,7 +86,11 @@ public: //! Sets the item internal initialized state to the true. If the item has internal values, //! there should be initialized here. - virtual void Init() { m_bInitialized = true; } + Standard_EXPORT virtual void Init(); + + //! Returns data object of the item. + //! \return object + Standard_EXPORT virtual const Handle(Standard_Transient)& Object() const; //! Resets the item and the child items content. Sets the initialized state to false. //! If the item has internal values, there should be reseted here. @@ -91,6 +100,16 @@ public: //! \param theRole an item role Standard_EXPORT virtual void Reset(int theRole); + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + const Standard_SStream& Stream() const { return myStream; } + + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + virtual bool SetStream (const Standard_SStream& theSStream, Standard_Integer& theStartPos, + Standard_Integer& theLastPos) const + { (void)theSStream; (void)theStartPos; (void)theLastPos; return false; } + //! 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; }; @@ -115,7 +134,7 @@ public: //! 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); } + 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 @@ -127,18 +146,25 @@ public: //! \return the row count int rowCount() const { return cachedValue(TreeModel_ItemRole_RowCountRole).toInt(); } + //! Returns the item properties + const Handle(TreeModel_ItemProperties)& Properties() const { return myProperties; } + protected: //! \param theParent the parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item Standard_EXPORT TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn); + //! Initializes the current item. It creates a backup of the specific item information + virtual void initItem() const {} + //! 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) = 0; + virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) + { (void)theRow; (void)theColumn; return TreeModel_ItemBasePtr(); } //! Wraps the currrent item by shared pointer //! \return the shared pointer to the current item @@ -153,17 +179,29 @@ protected: //! \return number of children. It should be reimplemented in child virtual int initRowCount() const = 0; - //! Return data value for the role. It should be reimplemented in child + //! \return number of children. It should be reimplemented in child + Standard_EXPORT int initStreamRowCount(); + + //! Returns data value for the role. It should be reimplemented in child //! \param theItemRole a value role //! \return the value - virtual QVariant initValue (const int theItemRole) const = 0; + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const; + + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + virtual void initStream (Standard_OStream& theOStream) const { (void)theOStream; } + +protected: + Handle(TreeModel_ItemProperties) myProperties; //!< the properties + int m_iStreamChildren; //!< the count of stream items + Standard_SStream myStream; //!< stream value private: typedef QHash< QPair, TreeModel_ItemBasePtr > PositionToItemHash; PositionToItemHash m_ChildItems; //!< the hash of item children - QMap myCachedValues; //!< cached values, should be cleared by reset + mutable QMap 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 diff --git a/tools/TreeModel/TreeModel_ItemProperties.cxx b/tools/TreeModel/TreeModel_ItemProperties.cxx new file mode 100644 index 0000000000..631d2f2c18 --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemProperties.cxx @@ -0,0 +1,232 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(TreeModel_ItemProperties, Standard_Transient) + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void TreeModel_ItemProperties::Init () +{ + myRowValues.Clear(); + + const Standard_SStream& aStream = Item()->Stream(); + + NCollection_IndexedDataMap aValues; + TCollection_AsciiString aStreamText = Standard_Dump::Text (aStream); + Standard_Dump::SplitJson (aStreamText, aValues); + + TreeModel_ItemStreamPtr aStreamParent = itemDynamicCast(Item()); + TCollection_AsciiString aKey; + Standard_DumpValue aKeyValue; + if (!aStreamParent) + { + const Handle(Standard_Transient)& anItemObject = Item()->Object(); + aKey = anItemObject.IsNull() ? "Dump" : anItemObject->DynamicType()->Name(); + aKeyValue = Standard_DumpValue (aStreamText, 1); + + myKey = aKey; + myStreamValue = aKeyValue; + } + else + { + TCollection_AsciiString aValue; + if (Item()->Parent()) + { + const Handle(TreeModel_ItemProperties)& aParentProperties = Item()->Parent()->Properties(); + if (aParentProperties) + aParentProperties->ChildStream (Item()->Row(), aKey, aKeyValue); + } + myKey = aKey; + myStreamValue = aKeyValue; + + aValues.Clear(); + Standard_Dump::SplitJson (myStreamValue.myValue, aValues); + } + + for (Standard_Integer anIndex = 1; anIndex <= aValues.Size(); anIndex++) + { + Standard_DumpValue aValue = aValues.FindFromIndex (anIndex); + if (Standard_Dump::HasChildKey (aValue.myValue)) + myChildren.Add (aValues.FindKey (anIndex), aValue); + else + { + TreeModel_RowValue aRowValue (aValue.myStartPosition, aValues.FindKey (anIndex).ToCString(), aValue.myValue.ToCString()); + myRowValues.Add (myRowValues.Size() + 1, aRowValue); + } + } + if (myRowValues.Size() == 1) + { + Quantity_Color aColor; + if (Convert_Tools::ConvertStreamToColor (aStream, aColor)) + { + Standard_Real aRed, aGreen, aBlue; + aColor.Values (aRed, aGreen, aBlue, Quantity_TOC_sRGB); + + int aDelta = 255; + myRowValues.ChangeFromIndex (1).CustomValues.insert ((int)Qt::BackgroundRole, QColor((int)(aRed * aDelta), + (int)(aGreen * aDelta), (int)(aBlue * aDelta))); + } + } +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void TreeModel_ItemProperties::Reset() +{ + myKey = ""; + myStreamValue = Standard_DumpValue(); + + myChildren.Clear(); + myRowValues.Clear(); +} + +// ======================================================================= +// function : RowCount +// purpose : +// ======================================================================= +int TreeModel_ItemProperties::RowCount() const +{ + return RowValues().Size(); +} + +// ======================================================================= +// function : Data +// purpose : +// ======================================================================= +QVariant TreeModel_ItemProperties::Data (const int theRow, const int theColumn, int theRole) const +{ + if (theColumn == 1 && theRole == Qt::BackgroundRole) + { + const QMap& aCachedValues = RowValues().FindFromIndex (theRow + 1).CustomValues; + if (aCachedValues.contains ((int)theRole)) + return aCachedValues[(int)theRole]; + } + + if (theRole == Qt::FontRole) // method name is in italic + { + if (Data(theRow, 0, Qt::DisplayRole).toString().contains("className")) + { + QFont aFont = qApp->font(); + aFont.setItalic (true); + return aFont; + } + } + if (theRole == Qt::ForegroundRole) + { + if (Data(theRow, 0, Qt::DisplayRole).toString().contains("className")) + return QColor (Qt::darkGray).darker(150); + } + + if (theRole == Qt::DisplayRole || theRole == Qt::ToolTipRole) + { + if (theColumn == 0) return RowValues().FindFromIndex (theRow + 1).Key; + else if (theColumn == 1) return RowValues().FindFromIndex (theRow + 1).Value; + } + + return QVariant(); +} + +// ======================================================================= +// function : EditType +// purpose : +// ======================================================================= +ViewControl_EditType TreeModel_ItemProperties::EditType (const int, const int theColumn) const +{ + if (theColumn == 0) + return ViewControl_EditType_None; + + return ViewControl_EditType_Line; +} + +// ======================================================================= +// function : SetData +// purpose : +// ======================================================================= +bool TreeModel_ItemProperties::SetData (const int /*theRow*/, const int theColumn, const QVariant& /*theValue*/, int) +{ + if (theColumn == 0) + return false; + return false; +} + +// ======================================================================= +// function : Presentations +// purpose : +// ======================================================================= +void TreeModel_ItemProperties::Presentations (NCollection_List& thePresentations) +{ + const Standard_SStream& aStream = Item()->Stream(); + Convert_Tools::ConvertStreamToPresentations (aStream, 1, -1, thePresentations); +} + +// ======================================================================= +// function : TableFlags +// purpose : +// ======================================================================= +Qt::ItemFlags TreeModel_ItemProperties::TableFlags (const int, const int theColumn) const +{ + Qt::ItemFlags aFlags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; + + if (theColumn == 1) + aFlags = aFlags | Qt::ItemIsEditable; + + return aFlags; +} + +// ======================================================================= +// function : ChildStream +// purpose : +// ======================================================================= +void TreeModel_ItemProperties::ChildStream (const int theRowId, + TCollection_AsciiString& theKey, + Standard_DumpValue& theValue) const +{ + if (myChildren.Size() <= theRowId) + return; + + theKey = myChildren.FindKey (theRowId + 1); + theValue = myChildren.FindFromIndex (theRowId + 1); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void TreeModel_ItemProperties::initItem() const +{ + if (!Item()) + return; + if (Item()->IsInitialized()) + return; + Item()->Init(); +} diff --git a/tools/TreeModel/TreeModel_ItemProperties.hxx b/tools/TreeModel/TreeModel_ItemProperties.hxx new file mode 100644 index 0000000000..7f498d70e4 --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemProperties.hxx @@ -0,0 +1,162 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_ItemProperties_H +#define TreeModel_ItemProperties_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +//! \class TreeModel_ItemProperties +//! Class to manipulate properties of tree item. The properties are organized in table structure +class TreeModel_ItemProperties : public Standard_Transient +{ + //! enum defined the dimension type + enum TreeModel_DimType + { + TreeModel_DimType_Rows, //!< defines number of rows + TreeModel_DimType_Columns //!< defines number of columns + }; + + //! container of values in a row of property table + struct TreeModel_RowValue + { + TreeModel_RowValue (const Standard_Integer theValueStartPosition, const QVariant& theKey, QVariant theValue) + : ValueStartPosition (theValueStartPosition), Key (theKey), Value (theValue) {} + + Standard_Integer ValueStartPosition; //!< start position of the key + QVariant Key; //!< value in the first column + QVariant Value; //!< value in the second column + QMap CustomValues; //!< custom values, e.g. key is Background, value is a defined color + }; + +public: + //! Constructor + TreeModel_ItemProperties() {} + + //! Destructor + ~TreeModel_ItemProperties() {} + + //! Sets the current item + void SetItem (const TreeModel_ItemBasePtr& theItem) { myItem = theItem; } + + //! Returns the current item + TreeModel_ItemBasePtr Item() const { return myItem; } + + //! Fills internal containers by item stream values + Standard_EXPORT void Init(); + + //! If the item has internal values, there should be reseted here. + Standard_EXPORT virtual void Reset(); + + //! Returns number of table rows + //! \return an integer value + Standard_EXPORT int RowCount() const; + + //! Returns number of table columns + //! \return an integer value + int ColumnCount() const { return 2; } + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return value interpreted depending on the given role + Standard_EXPORT QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const; + + //! Returns type of edit control for the model index. By default, it is an empty control + //! \param theRow a model index row + //! \param theColumn a model index column + //! \return edit type + Standard_EXPORT ViewControl_EditType EditType (const int theRow, const int theColumn) const; + + //! Sets content of the model index for the given role, it is applied to internal container of values + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return true if the value is changed + Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue, + int theRole = Qt::DisplayRole); + + //! Returns presentation of the attribute to be visualized in the view + //! \thePresentations [out] container of presentation handles to be visualized + Standard_EXPORT virtual void Presentations (NCollection_List& thePresentations); + + //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable. + //! Additional flag for the column 1 is Qt::ItemIsEditable. + //! \param theIndex a model index + //! \return flags + Standard_EXPORT virtual Qt::ItemFlags TableFlags (const int theRow, const int theColumn) const; + + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT void ChildStream (const int theRowId, + TCollection_AsciiString& theKey, + Standard_DumpValue& theValue) const; + + //! Returns data object of the item. + //! \return object key + const TCollection_AsciiString& Key() const { return myKey; } + + //! Returns stream value of the item. + //! \return value + const TCollection_AsciiString& StreamValue() const { return myStreamValue.myValue; } + + //! Returns children stream values + //const NCollection_IndexedDataMap& Values() const { initItem(); return myValues; } + + //! Returns children stream values + const NCollection_IndexedDataMap& RowValues() const { initItem(); return myRowValues; } + + //! Returns children stream values + const NCollection_IndexedDataMap& Children() const { initItem(); return myChildren; } + + DEFINE_STANDARD_RTTIEXT (TreeModel_ItemProperties, Standard_Transient) + +protected: + //! Initializes the current item. It creates a backup of the specific item information + Standard_EXPORT void initItem() const; + +private: + TreeModel_ItemBasePtr myItem; //!< current item + + TCollection_AsciiString myKey; //!< the item key + Standard_DumpValue myStreamValue; //!< the stream value + NCollection_IndexedDataMap myChildren; //!< the children + NCollection_IndexedDataMap myRowValues; //!< the values +}; + +#endif \ No newline at end of file diff --git a/tools/TreeModel/TreeModel_ItemStream.cxx b/tools/TreeModel/TreeModel_ItemStream.cxx new file mode 100644 index 0000000000..efa8b36d53 --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemStream.cxx @@ -0,0 +1,120 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 + +#include + +#include + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +TreeModel_ItemStream::TreeModel_ItemStream (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + : TreeModel_ItemBase (theParent, theRow, theColumn) +{ +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void TreeModel_ItemStream::Init() +{ + TreeModel_ItemBase::Init(); + + int aStreamChildrenCount = 0; + if (Column() == 0) + { + if (!myProperties) + { + myProperties = new TreeModel_ItemProperties(); + myProperties->SetItem (currentItem()); + } + myProperties->Init(); + aStreamChildrenCount = myProperties->Children().Extent(); + } + m_iStreamChildren = aStreamChildrenCount; + initStream (myStream); +} + +// ======================================================================= +// function : Rest +// purpose : +// ======================================================================= +void TreeModel_ItemStream::Reset() +{ + myStream.str (""); + TreeModel_ItemBase::Reset(); +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant TreeModel_ItemStream::initValue (const int theItemRole) const +{ + QVariant aParentValue = TreeModel_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + + if (Column() != 0) + return QVariant(); + + if (theItemRole == Qt::ForegroundRole) + return QColor (Qt::darkBlue); + + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + switch (Column()) + { + case 0: return Properties() ? Properties()->Key().ToCString() : ""; + } + return QVariant(); +} + +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void TreeModel_ItemStream::initStream (Standard_OStream& theOStream) const +{ + if (!Properties()) + return; + + theOStream << Properties()->StreamValue(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void TreeModel_ItemStream::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + +// ======================================================================= +// function : createChild +// purpose : +// ======================================================================= +TreeModel_ItemBasePtr TreeModel_ItemStream::createChild (int theRow, int theColumn) +{ + return TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn); +} diff --git a/tools/TreeModel/TreeModel_ItemStream.hxx b/tools/TreeModel/TreeModel_ItemStream.hxx new file mode 100644 index 0000000000..3d3f13ea3c --- /dev/null +++ b/tools/TreeModel/TreeModel_ItemStream.hxx @@ -0,0 +1,89 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_ItemStream_H +#define TreeModel_ItemStream_H + +#include +#include +#include + +#include + +class TreeModel_ItemProperties; +class TreeModel_ItemStream; + +typedef QExplicitlySharedDataPointer TreeModel_ItemStreamPtr; + +//! \class TreeModel_ItemStream +//! 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 TreeModel_ItemStream : public TreeModel_ItemBase +{ +public: + + //! Creates an item wrapped by a shared pointer + static TreeModel_ItemStreamPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) + { return TreeModel_ItemStreamPtr (new TreeModel_ItemStream (theParent, theRow, theColumn)); } + + //! Destructor + virtual ~TreeModel_ItemStream() {} + + //! Sets the item internal initialized state to the true. If the item has internal values, + //! there should be initialized here. + Standard_EXPORT virtual void Init() Standard_OVERRIDE; + + //! Resets the item and the child items content. Sets the initialized state to false. + //! If the item has internal values, there should be reseted here. + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; + + //! Returns number of displayed presentations + //! \return rows count + virtual int initRowCount() const Standard_OVERRIDE { initItem(); return 0; } + + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + +protected: + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const; + + //! Initializes the current item. It creates a backup of the specific item information + //! Does nothing as context has been already set into item + Standard_EXPORT virtual void initItem() const Standard_OVERRIDE; + +protected: + + //! Creates a child item in the given position. + //! \param theRow the child row position + //! \param theColumn the child column position + //! \return the created item + Standard_EXPORT virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE; + +private: + + //! Constructor + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item + Standard_EXPORT TreeModel_ItemStream(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn); +}; + +#endif diff --git a/tools/TreeModel/TreeModel_ModelBase.cxx b/tools/TreeModel/TreeModel_ModelBase.cxx index 72acad8d01..a87cbe662e 100644 --- a/tools/TreeModel/TreeModel_ModelBase.cxx +++ b/tools/TreeModel/TreeModel_ModelBase.cxx @@ -19,18 +19,36 @@ #include #include +#include + #include #include #include +const int COLUMN_NAME_WIDTH = 260; +const int COLUMN_SIZE_WIDTH = 30; + // ======================================================================= // function : Constructor // purpose : // ======================================================================= TreeModel_ModelBase::TreeModel_ModelBase (QObject* theParent) -: QAbstractItemModel (theParent), m_pRootItem (0), m_pUseVisibilityColumn (false), +: QAbstractItemModel (theParent), m_pUseVisibilityColumn (false), myVisibilityState (0) { + myVisibleIcon = QIcon (":/icons/item_visible.png"); + myInvisibleIcon = QIcon (":/icons/item_invisible.png"); +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void TreeModel_ModelBase::InitColumns() +{ + SetHeaderItem (0, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH)); + SetHeaderItem (1, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth())); + SetHeaderItem (2, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH)); } // ======================================================================= @@ -104,14 +122,18 @@ QVariant TreeModel_ModelBase::data (const QModelIndex& theIndex, int theRole) co if (!myVisibilityState || !myVisibilityState->CanBeVisible (theIndex)) return QVariant(); - QVariant aValue = QIcon (myVisibilityState->IsVisible (theIndex) ? ":/icons/item_visible.png" - : ":/icons/item_invisible.png"); + QVariant aValue = myVisibilityState->IsVisible (theIndex) ? myVisibleIcon : myInvisibleIcon; anItem->SetCustomData (aValue, theRole); return aValue; } TreeModel_ItemBasePtr anItem = GetItemByIndex (theIndex); - return anItem->data (theIndex, theRole); + QVariant anItemData = anItem->data (theIndex, theRole); + + if (anItemData.isNull() && theRole == Qt::BackgroundRole && myHighlightedIndices.contains (theIndex)) + anItemData = TreeModel_Tools::LightHighlightColor(); + + return anItemData; } // ======================================================================= @@ -174,6 +196,9 @@ int TreeModel_ModelBase::rowCount (const QModelIndex& theParent) const else aParentItem = GetItemByIndex (theParent); + if (!aParentItem) + return 0; + return aParentItem ? aParentItem->rowCount() : 0; } @@ -207,21 +232,76 @@ void TreeModel_ModelBase::EmitDataChanged (const QModelIndex& theTopLeft, const } // ======================================================================= -// function : SingleSelected +// function : SetHeaderItem // purpose : // ======================================================================= -QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndices, const int theCellId, - const Qt::Orientation theOrientation) +void TreeModel_ModelBase::SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection) +{ + if (theSection.IsEmpty()) + { + // remove section + myHeaderValues.remove (theColumnId); + myRootItems.remove (theColumnId); + } + + myHeaderValues[theColumnId] = theSection; + createRoot (theColumnId); +} + +// ======================================================================= +// function : Selected +// purpose : +// ======================================================================= +QModelIndexList TreeModel_ModelBase::Selected (const QModelIndexList& theIndices, const int theCellId, + const Qt::Orientation theOrientation) { - QModelIndexList aFirstColumnSelectedIndices; + QModelIndexList aSelected; 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); + aSelected.append (anIndex); } - return aFirstColumnSelectedIndices.size() == 1 ? aFirstColumnSelectedIndices.first() : QModelIndex(); + return aSelected; +} + +// ======================================================================= +// function : SingleSelected +// purpose : +// ======================================================================= +QModelIndex TreeModel_ModelBase::SingleSelected (const QModelIndexList& theIndices, const int theCellId, + const Qt::Orientation theOrientation) +{ + QModelIndexList aSelected = Selected (theIndices, theCellId, theOrientation); + return aSelected.size() == 1 ? aSelected.first() : QModelIndex(); +} + +// ======================================================================= +// function : SelectedItems +// purpose : +// ======================================================================= +QList TreeModel_ModelBase::SelectedItems (const QModelIndexList& theIndices) +{ + QList anItems; + + for (QModelIndexList::const_iterator anIndicesIt = theIndices.begin(); anIndicesIt != theIndices.end(); anIndicesIt++) + { + TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt); + if (!anItem || anItems.contains (anItem)) + continue; + anItems.append (anItem); + } + return anItems; +} + +// ======================================================================= +// function : createRoot +// purpose : +// ======================================================================= +void TreeModel_ModelBase::createRoot (const int theColumnId) +{ + myRootItems.insert (theColumnId, createRootItem (theColumnId)); } // ======================================================================= diff --git a/tools/TreeModel/TreeModel_ModelBase.hxx b/tools/TreeModel/TreeModel_ModelBase.hxx index d304c164e5..b8a31e903e 100644 --- a/tools/TreeModel/TreeModel_ModelBase.hxx +++ b/tools/TreeModel/TreeModel_ModelBase.hxx @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -48,6 +50,10 @@ public: //! Destructor virtual ~TreeModel_ModelBase() {} + //! Creates model columns and root items. + //! Default columns are: [0] - Name, [1] - Visibility, [2] - Row + Standard_EXPORT virtual void InitColumns(); + //! Returns the item shared pointer by the model index //! if it is in the index internal pointer //! @param theIndex a model index @@ -59,7 +65,7 @@ public: //! Returns the model root item. //! It is realized for OCAFBrowser - virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const { (void)theColumn; return m_pRootItem; } + TreeModel_ItemBasePtr RootItem (const int theColumn) const { return myRootItems[theColumn]; } //! Emits the layoutChanged signal from outside of this class Standard_EXPORT void EmitLayoutChanged(); @@ -76,14 +82,21 @@ public: //! \param theState state bool IsUseVisibilityColumn() const { return m_pUseVisibilityColumn; } - //!< Fills visibility state checker - //!< \param theController the checker interface + //! Fills visibility state checker + //! \param theController the checker interface void SetVisibilityState (TreeModel_VisibilityState* theController) { myVisibilityState = theController; } - //!< Returns visibility state checker - //!< \return the checker interface + //! Returns visibility state checker + //! \return the checker interface TreeModel_VisibilityState* GetVisibilityState () const { return myVisibilityState; } + //! Returns true if the tree view model contains highlighted items. This highlight is set manually. + bool HasHighlighted() { return !myHighlightedIndices.isEmpty(); } + + //! Sets items of the indices highlighted in the model. + //! \param theIndices a list of tree model indices + void SetHighlighted (const QModelIndexList& theIndices = QModelIndexList()) { myHighlightedIndices = theIndices; } + //! 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 @@ -130,11 +143,10 @@ public: //! \return header section values container TreeModel_HeaderSection GetHeaderItem (const int theColumnId) const { return myHeaderValues[theColumnId]; } - //! Set header properties item. + //! Sets 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); } + Standard_EXPORT void SetHeaderItem (const int theColumnId, const TreeModel_HeaderSection& theSection); //! Returns count of columns in the model //! \param theParent an index of the parent item @@ -146,6 +158,14 @@ public: //! \return integer value static int ColumnVisibilityWidth() { return 20; } + //! Returns selected items in the cell of given orientation. + //! \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 indices from the list + Standard_EXPORT static QModelIndexList Selected (const QModelIndexList& theIndices, const int theCellId, + const Qt::Orientation theOrientation = Qt::Horizontal); + //! 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 @@ -155,24 +175,38 @@ public: Standard_EXPORT static QModelIndex SingleSelected (const QModelIndexList& theIndices, const int theCellId, const Qt::Orientation theOrientation = Qt::Horizontal); + //! Returns selected tree model items for indices. + //! \param theIndices a container of selected indices + //! \return model items from the list + Standard_EXPORT static QList SelectedItems (const QModelIndexList& theIndices); + protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) = 0; + virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) = 0; //! Converts the item shared pointer to void* type //! \param theItem //! \return an item pointer Standard_EXPORT static void* getIndexValue (const TreeModel_ItemBasePtr& theItem); +private: + //! Creates root item + //! \param theColumnId index of a column + Standard_EXPORT void createRoot (const int theColumnId); + protected: - TreeModel_ItemBasePtr m_pRootItem; //!< the model root item. It should be created in the + QMap myRootItems; //!< container of root items, for each column own root item QMap 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 + QIcon myVisibleIcon; //!< icon of visible state + QIcon myInvisibleIcon; //!< icon of invisible state + + QModelIndexList myHighlightedIndices; //!< tree model indices that should be visualized as highlighted }; #endif diff --git a/tools/TreeModel/TreeModel_Tools.cxx b/tools/TreeModel/TreeModel_Tools.cxx index c1b217b529..e3d8b2afa5 100644 --- a/tools/TreeModel/TreeModel_Tools.cxx +++ b/tools/TreeModel/TreeModel_Tools.cxx @@ -172,13 +172,7 @@ void TreeModel_Tools::UseVisibilityColumn (QTreeView* theTreeView, const bool th TreeModel_ModelBase* aModel = dynamic_cast (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&))); + aModel->SetUseVisibilityColumn (theActive); } // ======================================================================= @@ -211,3 +205,53 @@ QString TreeModel_Tools::CutString (const QString& theText, const int theWidth, return aLength < theText.length() ? theText.mid (0, aLength) + theTail : theText; } + +// ======================================================================= +// function : LightHighlightColor +// purpose : +// ======================================================================= +QColor TreeModel_Tools::LightHighlightColor() +{ + QWidget aWidget; + QPalette aPalette = aWidget.palette(); + return aPalette.highlight().color().lighter(); +} + +// ======================================================================= +// function : SetExpandedTo +// purpose : +// ======================================================================= +void TreeModel_Tools::SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex) +{ + QAbstractItemModel* aModel = theTreeView->model(); + + QModelIndex aParent = aModel->parent (theIndex); + while (aParent.isValid()) + { + theTreeView->setExpanded (aParent, true); + aParent = aModel->parent (aParent); + } +} + +// ======================================================================= +// function : setExpanded +// purpose : +// ======================================================================= +void TreeModel_Tools::SetExpanded (QTreeView* theTreeView, const QModelIndex& theIndex, const bool isExpanded, + int& theLevels) +{ + bool isToExpand = theLevels == -1 || theLevels > 0; + if (!isToExpand) + return; + + theTreeView->setExpanded (theIndex, isExpanded); + if (theLevels != -1) + theLevels--; + + QAbstractItemModel* aModel = theTreeView->model(); + for (int aRowId = 0, aRows = aModel->rowCount (theIndex); aRowId < aRows; aRowId++) + { + int aLevels = theLevels; + SetExpanded (theTreeView, aModel->index (aRowId, 0, theIndex), isExpanded, aLevels); + } +} diff --git a/tools/TreeModel/TreeModel_Tools.hxx b/tools/TreeModel/TreeModel_Tools.hxx index 39047a2f03..a202a51691 100644 --- a/tools/TreeModel/TreeModel_Tools.hxx +++ b/tools/TreeModel/TreeModel_Tools.hxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -49,22 +50,23 @@ public: //! Returns header margin, defined in style settings of application //! \return integer value - Standard_EXPORT static int HeaderSectionMargin() { return qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); } + 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, + //! Saves state of tree view in a container in form: key, value. It saves: + //! - visibility 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& theItems, const QString& thePrefix = QString()); - //! Restore state of three view by a container + + //! Restores state of tree 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 + //! \return boolean value whether the property is applied to the tree view Standard_EXPORT static bool RestoreState (QTreeView* theTreeView, const QString& theKey, const QString& theValue, const QString& thePrefix = QString()); @@ -90,6 +92,24 @@ public: //! \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 = "..."); + + //! Returns light highlight color + //! \returns Qt color + Standard_EXPORT static QColor LightHighlightColor(); + + //! Makes the view expanded from the root till the index + Standard_EXPORT static void SetExpandedTo (QTreeView* theTreeView, const QModelIndex& theIndex); + + //! Expands items in tree view staring from the index recursive in given number of levels + //! \param theTreeView an OCAF tree view + //! \param theParentIndex an index which children should be expanded + //! \param isExpanded a boolean state if the item should be expanded or collapsed + //! \param theLevels a number of levels to be expanded, or -1 for all levels + Standard_EXPORT static void SetExpanded (QTreeView* theTreeView, + const QModelIndex& theIndex, + const bool isExpanded, + int& theLevels); + }; #endif diff --git a/tools/TreeModel/TreeModel_VisibilityState.cxx b/tools/TreeModel/TreeModel_VisibilityState.cxx index 599e635fe5..0639291b78 100644 --- a/tools/TreeModel/TreeModel_VisibilityState.cxx +++ b/tools/TreeModel/TreeModel_VisibilityState.cxx @@ -19,14 +19,14 @@ // function : OnClicked // purpose : // ======================================================================= -void TreeModel_VisibilityState::OnClicked (const QModelIndex& theIndex) +bool TreeModel_VisibilityState::processClicked (const QModelIndex& theIndex) { if (theIndex.column() != TreeModel_ColumnType_Visibility) - return; + return false; if (!CanBeVisible (theIndex)) - return; + return false; SetVisible (theIndex, !IsVisible (theIndex), true); - emit itemClicked (theIndex); + return true; } diff --git a/tools/TreeModel/TreeModel_VisibilityState.hxx b/tools/TreeModel/TreeModel_VisibilityState.hxx index 9718b5962f..962e2421a6 100644 --- a/tools/TreeModel/TreeModel_VisibilityState.hxx +++ b/tools/TreeModel/TreeModel_VisibilityState.hxx @@ -16,25 +16,18 @@ #ifndef TreeModel_VisibilityState_H #define TreeModel_VisibilityState_H -#include #include #include #include #include -#include -#include -#include -#include - //! \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 +class TreeModel_VisibilityState { - Q_OBJECT public: //! Constructor TreeModel_VisibilityState (TreeModel_ModelBase* theModel) : myModel (theModel) {} @@ -59,23 +52,19 @@ public: //! \return boolean value virtual bool IsVisible (const QModelIndex& theIndex) const = 0; -public slots: +protected: //! 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); + //! \return true if click is processed + Standard_EXPORT bool processClicked (const QModelIndex& theIndex); protected: //! tree view model TreeModel_ModelBase* getModel() const { return myModel; } private: - TreeModel_ModelBase* myModel; //! tree view model + TreeModel_ModelBase* myModel; //!< tree view model }; #endif diff --git a/tools/VInspector/FILES b/tools/VInspector/FILES index 68312f8eb1..0394262f8d 100644 --- a/tools/VInspector/FILES +++ b/tools/VInspector/FILES @@ -1,4 +1,6 @@ VInspector.qrc +VInspectorAPI_CallBack.cxx +VInspectorAPI_CallBack.hxx VInspector_CallBack.cxx VInspector_CallBack.hxx VInspector_CallBackMode.hxx @@ -8,10 +10,6 @@ VInspector_ItemBase.cxx VInspector_ItemBase.hxx VInspector_ItemContext.cxx VInspector_ItemContext.hxx -VInspector_ItemFolderObject.cxx -VInspector_ItemFolderObject.hxx -VInspector_ItemEntityOwner.cxx -VInspector_ItemEntityOwner.hxx VInspector_ItemHistoryElement.cxx VInspector_ItemHistoryElement.hxx VInspector_ItemHistoryRoot.cxx @@ -21,13 +19,6 @@ VInspector_ItemHistoryType.hxx VInspector_ItemHistoryTypeInfo.hxx VInspector_ItemPresentableObject.cxx VInspector_ItemPresentableObject.hxx -VInspector_ItemSelection.cxx -VInspector_ItemSelection.hxx -VInspector_ItemSelectMgrFilter.cxx -VInspector_ItemSelectMgrFilter.hxx -VInspector_ItemSensitiveEntity.cxx -VInspector_ItemSensitiveEntity.hxx -VInspector_SelectionType.hxx VInspector_ToolActionType.hxx VInspector_ToolBar.cxx VInspector_ToolBar.hxx @@ -39,5 +30,3 @@ VInspector_ViewModelHistory.cxx VInspector_ViewModelHistory.hxx VInspector_Window.cxx VInspector_Window.hxx -VInspectorAPI_CallBack.cxx -VInspectorAPI_CallBack.hxx diff --git a/tools/VInspector/VInspectorAPI_CallBack.cxx b/tools/VInspector/VInspectorAPI_CallBack.cxx index bdb5fb3cfe..accb7a3975 100644 --- a/tools/VInspector/VInspectorAPI_CallBack.cxx +++ b/tools/VInspector/VInspectorAPI_CallBack.cxx @@ -15,12 +15,7 @@ #include -#if OCC_VERSION_HEX <= 0x060901 -IMPLEMENT_STANDARD_HANDLE(VInspectorAPI_CallBack, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(VInspectorAPI_CallBack, Standard_Transient) -#else -IMPLEMENT_STANDARD_RTTIEXT(VInspectorAPI_CallBack, Standard_Transient) -#endif // ======================================================================= // function : Constructor diff --git a/tools/VInspector/VInspectorAPI_CallBack.hxx b/tools/VInspector/VInspectorAPI_CallBack.hxx index fb63800087..0b8e812fea 100644 --- a/tools/VInspector/VInspectorAPI_CallBack.hxx +++ b/tools/VInspector/VInspectorAPI_CallBack.hxx @@ -18,20 +18,13 @@ #include #include -#include #include #include #include -#if OCC_VERSION_HEX > 0x060901 class AIS_InteractiveObject; -#else -#include -#endif class SelectMgr_EntityOwner; -DEFINE_STANDARD_HANDLE(VInspectorAPI_CallBack, Standard_Transient) - //! \class VInspectorAPI_CallBack //! API of AIS_InteractiveContext methods to provide information about the actions class VInspectorAPI_CallBack : public Standard_Transient @@ -96,11 +89,7 @@ public: //! Processing method of context virtual void ShiftSelect() = 0; -#if OCC_VERSION_HEX <= 0x060901 - DEFINE_STANDARD_RTTI(VInspectorAPI_CallBack) -#else DEFINE_STANDARD_RTTIEXT(VInspectorAPI_CallBack, Standard_Transient) -#endif }; #endif diff --git a/tools/VInspector/VInspector_CallBack.cxx b/tools/VInspector/VInspector_CallBack.cxx index 481ec6f6b2..a910141519 100644 --- a/tools/VInspector/VInspector_CallBack.cxx +++ b/tools/VInspector/VInspector_CallBack.cxx @@ -19,18 +19,12 @@ #include #include -#include #include #include #include -#if OCC_VERSION_HEX <= 0x060901 -IMPLEMENT_STANDARD_HANDLE(VInspector_CallBack, Standard_Transient) IMPLEMENT_STANDARD_RTTIEXT(VInspector_CallBack, VInspectorAPI_CallBack) -#else -IMPLEMENT_STANDARD_RTTIEXT(VInspector_CallBack, VInspectorAPI_CallBack) -#endif // ======================================================================= // function : Activate @@ -38,7 +32,18 @@ IMPLEMENT_STANDARD_RTTIEXT(VInspector_CallBack, VInspectorAPI_CallBack) // ======================================================================= void VInspector_CallBack::Activate (Handle(AIS_InteractiveObject) thePrs, const Standard_Integer theMode) { - QList anInfo = VInspector_Tools::GetInfo (thePrs); + if (!myHistoryModel) + return; + + QList anInfo; + if (!thePrs.IsNull()) + anInfo = VInspector_Tools::GetInfo (thePrs); + else + { + anInfo.append ("Activate"); + anInfo.append (""); + anInfo.append (""); + } anInfo[0] = QString ("%1: %2").arg (anInfo[0].toString()).arg (theMode); myHistoryModel->AddElement (VInspector_CallBackMode_Activate, anInfo); } @@ -49,6 +54,8 @@ void VInspector_CallBack::Activate (Handle(AIS_InteractiveObject) thePrs, const // ======================================================================= void VInspector_CallBack::AddOrRemoveSelected (const TopoDS_Shape& theShape) { + if (!myHistoryModel) + return; QList aValues; aValues.append (""); // Name aValues.append (""); // Pointer @@ -63,6 +70,8 @@ void VInspector_CallBack::AddOrRemoveSelected (const TopoDS_Shape& theShape) // ======================================================================= void VInspector_CallBack::AddOrRemoveSelected (Handle(AIS_InteractiveObject) thePrs) { + if (!myHistoryModel) + return; QList aValues = VInspector_Tools::GetInfo (thePrs); aValues.append (VInspector_Tools::GetSelectedInfoPointers (myContext)); // SelectionInfo myHistoryModel->AddElement (VInspector_CallBackMode_AddOrRemoveSelected, aValues); @@ -74,9 +83,11 @@ void VInspector_CallBack::AddOrRemoveSelected (Handle(AIS_InteractiveObject) the // ======================================================================= void VInspector_CallBack::AddOrRemoveSelected (Handle(SelectMgr_EntityOwner) theOwner) { + if (!myHistoryModel) + return; QList aValues; aValues.append (""); // Name - aValues.append (VInspector_Tools::GetPointerInfo (theOwner, true).ToCString()); // Pointer + aValues.append (Standard_Dump::GetPointerInfo (theOwner, true).ToCString()); // Pointer aValues.append (""); // Shape type aValues.append (VInspector_Tools::GetSelectedInfoPointers (myContext)); // SelectionInfo @@ -89,6 +100,8 @@ void VInspector_CallBack::AddOrRemoveSelected (Handle(SelectMgr_EntityOwner) the // ======================================================================= void VInspector_CallBack::ClearSelected() { + if (!myHistoryModel) + return; QList aValues; myHistoryModel->AddElement (VInspector_CallBackMode_ClearSelected, aValues); } @@ -99,6 +112,8 @@ void VInspector_CallBack::ClearSelected() // ======================================================================= void VInspector_CallBack::MoveTo (const Standard_Integer/* theXPix*/, const Standard_Integer/* theYPix*/) { + if (!myHistoryModel) + return; QList aValues; aValues = VInspector_Tools::GetHighlightInfo (myContext); myHistoryModel->AddElement (VInspector_CallBackMode_MoveTo, aValues); @@ -110,6 +125,8 @@ void VInspector_CallBack::MoveTo (const Standard_Integer/* theXPix*/, const Stan // ======================================================================= void VInspector_CallBack::Select() { + if (!myHistoryModel) + return; QList aValues; aValues = VInspector_Tools::GetSelectedInfo (myContext); myHistoryModel->AddElement (VInspector_CallBackMode_Select, aValues); @@ -121,6 +138,8 @@ void VInspector_CallBack::Select() // ======================================================================= void VInspector_CallBack::ShiftSelect() { + if (!myHistoryModel) + return; QList aValues; aValues = VInspector_Tools::GetSelectedInfo (myContext); myHistoryModel->AddElement (VInspector_CallBackMode_ShiftSelect, aValues); diff --git a/tools/VInspector/VInspector_CallBack.hxx b/tools/VInspector/VInspector_CallBack.hxx index 57bdeae4ff..668e1a88e7 100644 --- a/tools/VInspector/VInspector_CallBack.hxx +++ b/tools/VInspector/VInspector_CallBack.hxx @@ -26,8 +26,6 @@ class AIS_InteractiveObject; class SelectMgr_EntityOwner; -DEFINE_STANDARD_HANDLE(VInspector_CallBack, VInspectorAPI_CallBack) - //! \class VInspector_CallBack //! Updates inspector state on actions in context class VInspector_CallBack : public VInspectorAPI_CallBack @@ -38,27 +36,27 @@ public: VInspector_CallBack() : VInspectorAPI_CallBack() {} //! Destructor - virtual ~VInspector_CallBack() Standard_OVERRIDE {} + virtual ~VInspector_CallBack() {} //! Appends displayed presentation into history model //! \param thePrs the presentation virtual void Display (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_Display, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Display, VInspector_Tools::GetInfo (thePrs)); } //! Appends redisplayed presentation into history model //! \param thePrs the presentation virtual void Redisplay (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_Redisplay, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Redisplay, VInspector_Tools::GetInfo (thePrs)); } //! Appends removed presentation into history model //! \param thePrs the presentation virtual void Remove (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_Remove, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Remove, VInspector_Tools::GetInfo (thePrs)); } //! Appends loaded presentation into history model //! \param thePrs the presentation virtual void Load (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_Load, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Load, VInspector_Tools::GetInfo (thePrs)); } //! Appends information about modes activation //! \param thePrs the presentation @@ -75,13 +73,14 @@ public: //! Appends information about modes deactivation //! \param thePrs the presentation virtual void Deactivate (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_Deactivate, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Deactivate, VInspector_Tools::GetInfo (thePrs)); } //! Appends information about modes deactivation //! \param thePrs the presentation //! \param theMode the selection mode virtual void Deactivate (Handle(AIS_InteractiveObject) thePrs, const Standard_Integer theMode) Standard_OVERRIDE - { (void)theMode; myHistoryModel->AddElement (VInspector_CallBackMode_Deactivate, VInspector_Tools::GetInfo (thePrs)); } + { (void)theMode; + if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_Deactivate, VInspector_Tools::GetInfo (thePrs)); } //! Appends information about selection change //! \param theShape the selected shape @@ -101,7 +100,7 @@ public: //! Appends information about selection clear //! \param thePrs the selected presentation virtual void ClearSelected (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_ClearSelected, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_ClearSelected, VInspector_Tools::GetInfo (thePrs)); } //! Appends information about moving to point //! \param theXPix a pixels on horizontal @@ -111,7 +110,7 @@ public: //! Appends information about setting selection //! \param thePrs the selected presentation virtual void SetSelected (Handle(AIS_InteractiveObject) thePrs) Standard_OVERRIDE - { myHistoryModel->AddElement (VInspector_CallBackMode_SetSelected, VInspector_Tools::GetInfo (thePrs)); } + { if (myHistoryModel != 0) myHistoryModel->AddElement (VInspector_CallBackMode_SetSelected, VInspector_Tools::GetInfo (thePrs)); } //! Appends information about select Standard_EXPORT virtual void Select() Standard_OVERRIDE; @@ -126,11 +125,7 @@ public: //! Sets context, where actions happen //! \param theContext a context instance void SetContext (const Handle(AIS_InteractiveContext)& theContext) { myContext = theContext; } -#if OCC_VERSION_HEX <= 0x060901 - DEFINE_STANDARD_RTTI(VInspector_CallBack) -#else DEFINE_STANDARD_RTTIEXT(VInspector_CallBack, VInspectorAPI_CallBack) -#endif //! Returns string information of call back mode //! \param theMode type of AIS action diff --git a/tools/VInspector/VInspector_Communicator.hxx b/tools/VInspector/VInspector_Communicator.hxx index e0fe1f5147..8cdf7a933f 100644 --- a/tools/VInspector/VInspector_Communicator.hxx +++ b/tools/VInspector/VInspector_Communicator.hxx @@ -32,7 +32,7 @@ public: Standard_EXPORT VInspector_Communicator(); //! Destructor - virtual ~VInspector_Communicator() Standard_OVERRIDE {} + virtual ~VInspector_Communicator() {} //! Provides the container with a parent where this container should be inserted. //! If Qt implementation, it should be QWidget with QLayout set inside @@ -46,7 +46,7 @@ public: //! 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); } + virtual void FillActionsMenu(void* theMenu) Standard_OVERRIDE { myWindow->FillActionsMenu (theMenu); } //! Returns plugin preferences, empty implementation by default //! \param theItem container of preference elements diff --git a/tools/VInspector/VInspector_ItemBase.cxx b/tools/VInspector/VInspector_ItemBase.cxx index 8f1cee216e..591ecb0661 100644 --- a/tools/VInspector/VInspector_ItemBase.cxx +++ b/tools/VInspector/VInspector_ItemBase.cxx @@ -17,6 +17,35 @@ #include #include +#include + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemBase::Reset() +{ + myPresentationShape = TopoDS_Shape(); + TreeModel_ItemBase::Reset(); +} + +// ======================================================================= +// function : initValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemBase::initValue (const int theItemRole) const +{ + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole) + return QVariant(); + + switch (Column()) + { + case 3: return Standard_Dump::GetPointerInfo (Object(), true).ToCString(); + } + + return QVariant(); +} + // ======================================================================= // function : GetContext // purpose : @@ -49,3 +78,16 @@ Handle(AIS_InteractiveContext) VInspector_ItemBase::GetContext() const return myContext; } + +// ======================================================================= +// function : GetContext +// purpose : +// ======================================================================= +TopoDS_Shape VInspector_ItemBase::GetPresentationShape() const +{ + if (Column() != TreeModel_ColumnType_Name) + return TopoDS_Shape(); + + initItem(); + return myPresentationShape; +} diff --git a/tools/VInspector/VInspector_ItemBase.hxx b/tools/VInspector/VInspector_ItemBase.hxx index c0c268d395..4e35513625 100644 --- a/tools/VInspector/VInspector_ItemBase.hxx +++ b/tools/VInspector/VInspector_ItemBase.hxx @@ -18,6 +18,9 @@ #include #include +#include + +#include #include class VInspector_ItemBase; @@ -29,7 +32,7 @@ class VInspector_ItemBase : public TreeModel_ItemBase { public: //! Resets cached values - virtual void Reset() Standard_OVERRIDE { TreeModel_ItemBase::Reset(); } + Standard_EXPORT virtual void Reset() Standard_OVERRIDE; //! Sets the context //! \param theLabel an object where the child items structure is found @@ -43,23 +46,47 @@ public: //! \return a context Standard_EXPORT Handle(AIS_InteractiveContext) GetContext() const; + //! Returns item information for the given role. Fills internal container if it was not filled yet + //! \param theItemRole a value role + //! \return the value + Standard_EXPORT virtual QVariant initValue (const int theItemRole) const Standard_OVERRIDE; + + //! Returns presentation of the attribute to be visualized in the view + //! \thePresentations [out] container of presentation handles to be visualized + virtual void Presentations (NCollection_List& thePresentations) + { (void)thePresentations; } + + //! Returns transform persistent of the item or NULL + Handle(Graphic3d_TransformPers) TransformPersistence() const { return myTransformPersistence; } + + //! Returns shape of the item parameters + //! \return generated shape of the item parameters + Standard_EXPORT virtual TopoDS_Shape GetPresentationShape() const; + + //! Rebuild presentation shape if the item use it + //! \return generated shape of the item parameters + void UpdatePresentationShape() { myPresentationShape = buildPresentationShape(); } + protected: - //! Initialize the current item. It creates a backup of the specific item information - virtual void initItem() const {} + //! Build presentation shape + //! \return generated shape of the item parameters + virtual TopoDS_Shape buildPresentationShape() { return TopoDS_Shape(); } protected: //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item VInspector_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : TreeModel_ItemBase (theParent, theRow, theColumn), myContext (0) {} protected: Handle(AIS_InteractiveContext) myContext; //!< the current context + TopoDS_Shape myPresentationShape; //!< item presentation shape + Handle(Graphic3d_TransformPers) myTransformPersistence; //!< item cached persistent }; #endif \ No newline at end of file diff --git a/tools/VInspector/VInspector_ItemContext.cxx b/tools/VInspector/VInspector_ItemContext.cxx index 51770e4f0a..27400ac661 100644 --- a/tools/VInspector/VInspector_ItemContext.cxx +++ b/tools/VInspector/VInspector_ItemContext.cxx @@ -15,9 +15,9 @@ #include +#include #include #include -#include #include #include @@ -25,8 +25,6 @@ #include #include -//#define DEBUG_FREE_OWNERS - // ======================================================================= // function : initRowCount // purpose : @@ -36,47 +34,22 @@ int VInspector_ItemContext::initRowCount() const if (Column() != 0) return 0; - int aNbProperties = 1; // item to visualize Filters/Drawer information of context - - int aNbPresentations = 0; - Handle(AIS_InteractiveContext) aContext = GetContext(); + Handle(AIS_InteractiveContext) aContext = Handle(AIS_InteractiveContext)::DownCast (Object()); 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 - NCollection_List anActiveOwners; - aContext->MainSelector()->ActiveOwners(anActiveOwners); - - Handle(SelectMgr_EntityOwner) anOwner; - for (NCollection_List::Iterator anOwnersIt(anActiveOwners); anOwnersIt.More(); anOwnersIt.Next()) + int aNbPresentations = 0; + for (AIS_ListIteratorOfListOfInteractive aListOfIOIt (aListOfIO); aListOfIOIt.More(); aListOfIOIt.Next()) { - anOwner = anOwnersIt.Value(); - if (anOwner.IsNull()) - continue; - Handle(AIS_InteractiveObject) anAISObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); - if (anAISObj.IsNull()) - aRows++; + if (aListOfIOIt.Value()->Parent()) + continue; // child presentation + aNbPresentations++; } - // owners in Global Context - NCollection_List anActiveOwners; - aContext->MainSelector()->ActiveOwners(anActiveOwners); - if (aRows > 0) - aNbPresentations += aRows; - NCollection_List anEmptySelectableOwners; - NCollection_List anOwners = - VInspector_Tools::ActiveOwners (aContext, anEmptySelectableOwners); - if (anEmptySelectableOwners.Size() > 0) - aNbPresentations += 1; -#endif - return aNbProperties + aNbPresentations; + + return aNbPresentations; } // ======================================================================= @@ -85,37 +58,85 @@ int VInspector_ItemContext::initRowCount() const // ======================================================================= QVariant VInspector_ItemContext::initValue (const int theItemRole) const { + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; + if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole) return QVariant(); - if (GetContext().IsNull()) + Handle(AIS_InteractiveContext) aContext = Handle(AIS_InteractiveContext)::DownCast (Object()); + if (aContext.IsNull()) return Column() == 0 ? "Empty context" : ""; switch (Column()) { - case 0: return GetContext()->DynamicType()->Name(); - case 1: return rowCount(); + case 0: return aContext->DynamicType()->Name(); case 4: { Handle(AIS_InteractiveObject) anEmptyIO; - int aSelectedCount = VInspector_Tools::SelectedOwners (GetContext(), anEmptyIO, false); + int aSelectedCount = VInspector_Tools::SelectedOwners (aContext, anEmptyIO, false); return aSelectedCount > 0 ? QString::number (aSelectedCount) : ""; } - case 6: return GetContext()->DeviationCoefficient(); + case 6: return aContext->DeviationCoefficient(); default: break; } return QVariant(); } +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void VInspector_ItemContext::Init() +{ + Handle(AIS_InteractiveContext) aContext = GetContext(); + if (aContext.IsNull()) + return; + + TreeModel_ItemBase::Init(); +} + +// ======================================================================= +// function : Reset +// purpose : +// ======================================================================= +void VInspector_ItemContext::Reset() +{ + VInspector_ItemBase::Reset(); +} + +// ======================================================================= +// function : initItem +// purpose : +// ======================================================================= +void VInspector_ItemContext::initItem() const +{ + if (IsInitialized()) + return; + const_cast(this)->Init(); +} + // ======================================================================= // function : createChild // purpose : // ======================================================================= TreeModel_ItemBasePtr VInspector_ItemContext::createChild (int theRow, int theColumn) { - if (theRow == 0) - return VInspector_ItemFolderObject::CreateItem (currentItem(), theRow, theColumn); - else - return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn); + return VInspector_ItemPresentableObject::CreateItem (currentItem(), theRow, theColumn); } + +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void VInspector_ItemContext::initStream (Standard_OStream& theOStream) const +{ + Handle(AIS_InteractiveContext) aContext = GetContext(); + if (aContext.IsNull()) + return; + + aContext->DumpJson (theOStream); +} + diff --git a/tools/VInspector/VInspector_ItemContext.hxx b/tools/VInspector/VInspector_ItemContext.hxx index 166b8a6519..6308f59df6 100644 --- a/tools/VInspector/VInspector_ItemContext.hxx +++ b/tools/VInspector/VInspector_ItemContext.hxx @@ -36,7 +36,11 @@ public: { return VInspector_ItemContextPtr (new VInspector_ItemContext (theParent, theRow, theColumn)); } //! Destructor - virtual ~VInspector_ItemContext() Standard_OVERRIDE {}; + virtual ~VInspector_ItemContext() {} + + //! Returns data object of the item. + //! \return object + virtual const Handle(Standard_Transient)& Object() const { initItem(); return myContext; } //! Returns number of displayed presentations //! \return rows count @@ -47,11 +51,21 @@ public: //! \return the value Standard_EXPORT virtual QVariant initValue (const int theItemRole) const 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 creates a backup of the specific item information - //! Do nothing as context has been already set into item - virtual void initItem() const Standard_OVERRIDE {} + //! Initializes the current item. It creates a backup of the specific item information + //! Does nothing as context has been already set into item + virtual void initItem() const Standard_OVERRIDE; + + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; protected: @@ -64,9 +78,9 @@ protected: private: //! Constructor - //! param theParent a parent item - //! \param theRow the item row positition in the parent item - //! \param theColumn the item column positition in the parent item + //! \param theParent a parent item + //! \param theRow the item row position in the parent item + //! \param theColumn the item column position in the parent item VInspector_ItemContext(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : VInspector_ItemBase(theParent, theRow, theColumn) {} }; diff --git a/tools/VInspector/VInspector_ItemEntityOwner.cxx b/tools/VInspector/VInspector_ItemEntityOwner.cxx deleted file mode 100644 index 309bb45d3a..0000000000 --- a/tools/VInspector/VInspector_ItemEntityOwner.cxx +++ /dev/null @@ -1,186 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -// ======================================================================= -// function : initValue -// purpose : -// ======================================================================= -QVariant VInspector_ItemEntityOwner::initValue(int theItemRole) const -{ - switch (theItemRole) - { - case Qt::DisplayRole: - case Qt::EditRole: - case Qt::ToolTipRole: - { - Handle(SelectMgr_EntityOwner) anOwner = getEntityOwner(); - if (anOwner.IsNull()) - return QVariant(); - - switch (Column()) - { - case 0: return anOwner->DynamicType()->Name(); - case 2: return VInspector_Tools::GetPointerInfo (anOwner, true).ToCString(); - case 3: - { - 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 17: - case 18: - case 19: - { - 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; - } - break; - } - case Qt::BackgroundRole: - case Qt::ForegroundRole: - { - if (Column() == 2) - { - Handle(AIS_InteractiveContext) aContext = GetContext(); - if (!aContext.IsNull()) - { - if (VInspector_Tools::IsOwnerSelected(aContext, getEntityOwner())) - return (theItemRole == Qt::BackgroundRole) ? QColor (Qt::darkBlue) : QColor (Qt::white); - } - } - VInspector_ItemSensitiveEntityPtr aParentItem = itemDynamicCast(Parent()); - if (aParentItem) - return aParentItem->data(QModelIndex(), theItemRole); - break; - } - } - return QVariant(); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= -void VInspector_ItemEntityOwner::Init() -{ - Handle(SelectMgr_EntityOwner) anOwner; - - VInspector_ItemSensitiveEntityPtr aParentItem = itemDynamicCast(Parent()); - if (aParentItem) - { - Handle(SelectMgr_SensitiveEntity) anEntity = aParentItem->GetSensitiveEntity(); - anOwner = anEntity->BaseSensitive()->OwnerId(); - } - else - { - VInspector_ItemPresentableObjectPtr aPOItem = itemDynamicCast(Parent()); - if (aPOItem) - { - Handle(AIS_InteractiveObject) anIO = aPOItem->GetInteractiveObject(); - - 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::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More() && anOwner.IsNull(); aSelEntIter.Next()) - { - Handle(SelectMgr_SensitiveEntity) anEntity = aSelEntIter.Value(); -#endif - const Handle(Select3D_SensitiveEntity)& aBase = anEntity->BaseSensitive(); - if (!aBase.IsNull()) - { - if (aRowId == aCurrentIndex) - anOwner = aBase->OwnerId(); - aCurrentIndex++; - } - } - } - } - } - myOwner = anOwner; - TreeModel_ItemBase::Init(); -} - -// ======================================================================= -// function : Reset -// purpose : -// ======================================================================= -void VInspector_ItemEntityOwner::Reset() -{ - VInspector_ItemBase::Reset(); - SetContext (NULL); -} - -// ======================================================================= -// function : initItem -// purpose : -// ======================================================================= -void VInspector_ItemEntityOwner::initItem() const -{ - if (IsInitialized()) - return; - const_cast(this)->Init(); -} - -// ======================================================================= -// function : getEntityOwner -// purpose : -// ======================================================================= -Handle(SelectMgr_EntityOwner) VInspector_ItemEntityOwner::getEntityOwner() const -{ - initItem(); - return myOwner; -} diff --git a/tools/VInspector/VInspector_ItemEntityOwner.hxx b/tools/VInspector/VInspector_ItemEntityOwner.hxx deleted file mode 100644 index f00adc2ee3..0000000000 --- a/tools/VInspector/VInspector_ItemEntityOwner.hxx +++ /dev/null @@ -1,89 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_ItemEntityOwner_H -#define VInspector_ItemEntityOwner_H - -#include -#include -#include - -class QItemSelectionModel; - -class VInspector_ItemEntityOwner; -typedef QExplicitlySharedDataPointer VInspector_ItemEntityOwnerPtr; - -//! \class VInspector_ItemPresentableObject -//! Item for selection entity owner. The parent is sensitive entity item, there are no children -class VInspector_ItemEntityOwner : public VInspector_ItemBase -{ - -public: - - //! Creates an item wrapped by a shared pointer - static VInspector_ItemEntityOwnerPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - { return VInspector_ItemEntityOwnerPtr (new VInspector_ItemEntityOwner (theParent, theRow, theColumn)); } - - //! Destructor - virtual ~VInspector_ItemEntityOwner() 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; - - //! Returns the current entity owner - Handle(SelectMgr_EntityOwner) EntityOwner() const { return myOwner; } - -protected: - //! \return number of children. - virtual int initRowCount() const Standard_OVERRIDE{ return 0; } - - //! 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; - - //! Initialize the current item. It is empty because Reset() is also empty. - virtual void initItem() const Standard_OVERRIDE; - -protected: - - //! 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 - { (void)theRow; (void)theColumn; return TreeModel_ItemBasePtr(); } - -private: - - //! Constructor - //! param theParent a parent item - VInspector_ItemEntityOwner(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : VInspector_ItemBase(theParent, theRow, theColumn) {} - -private: - - //! Returns the current entity owner. Initializes the item if it was not initialized yet - Handle(SelectMgr_EntityOwner) getEntityOwner() const; - -private: - - Handle(SelectMgr_EntityOwner) myOwner; //!< the current entity owner -}; - -#endif diff --git a/tools/VInspector/VInspector_ItemFolderObject.cxx b/tools/VInspector/VInspector_ItemFolderObject.cxx deleted file mode 100644 index cbd413bc5c..0000000000 --- a/tools/VInspector/VInspector_ItemFolderObject.cxx +++ /dev/null @@ -1,93 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include - -// ======================================================================= -// 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 (this)->Init(); -} - -// ======================================================================= -// function : parentItemIsContext -// purpose : -// ======================================================================= -bool VInspector_ItemFolderObject::parentItemIsContext() const -{ - return itemDynamicCast (Parent()); -} diff --git a/tools/VInspector/VInspector_ItemFolderObject.hxx b/tools/VInspector/VInspector_ItemFolderObject.hxx deleted file mode 100644 index a0a754f8d8..0000000000 --- a/tools/VInspector/VInspector_ItemFolderObject.hxx +++ /dev/null @@ -1,86 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_ItemFolderObject_H -#define VInspector_ItemFolderObject_H - -#include -#include - -#include -#include -#include - -class QItemSelectionModel; - -class VInspector_ItemFolderObject; -typedef QExplicitlySharedDataPointer 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 diff --git a/tools/VInspector/VInspector_ItemHistoryElement.cxx b/tools/VInspector/VInspector_ItemHistoryElement.cxx index f6a6b1df65..ef57992759 100644 --- a/tools/VInspector/VInspector_ItemHistoryElement.cxx +++ b/tools/VInspector/VInspector_ItemHistoryElement.cxx @@ -26,15 +26,19 @@ // ======================================================================= QVariant VInspector_ItemHistoryElement::initValue(const int theRole) const { + QVariant aParentValue = VInspector_ItemBase::initValue (theRole); + if (aParentValue.isValid()) + return aParentValue; + if (theRole != Qt::DisplayRole && theRole != Qt::EditRole && theRole != Qt::ToolTipRole) return QVariant(); switch (Column()) { case 0: return getName(); - case 1: return QVariant(); - case 2: return GetPointerInfo(); - case 3: return GetShapeTypeInfo(); + case 2: return QVariant(); + case 3: return GetPointerInfo(); + case 4: return GetShapeTypeInfo(); default: break; } return QVariant(); diff --git a/tools/VInspector/VInspector_ItemHistoryElement.hxx b/tools/VInspector/VInspector_ItemHistoryElement.hxx index 07bdc0ade1..70a1977455 100644 --- a/tools/VInspector/VInspector_ItemHistoryElement.hxx +++ b/tools/VInspector/VInspector_ItemHistoryElement.hxx @@ -35,7 +35,7 @@ public: { return VInspector_ItemHistoryElementPtr (new VInspector_ItemHistoryElement (theParent, theRow, theColumn)); } //! Destructor - virtual ~VInspector_ItemHistoryElement() Standard_OVERRIDE {}; + virtual ~VInspector_ItemHistoryElement() {} //! Inits the item, fills internal containers Standard_EXPORT virtual void Init() Standard_OVERRIDE; @@ -78,7 +78,7 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item VInspector_ItemHistoryElement(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : VInspector_ItemBase(theParent, theRow, theColumn) {} diff --git a/tools/VInspector/VInspector_ItemHistoryRoot.cxx b/tools/VInspector/VInspector_ItemHistoryRoot.cxx index 7a5c2bd501..77f9512140 100644 --- a/tools/VInspector/VInspector_ItemHistoryRoot.cxx +++ b/tools/VInspector/VInspector_ItemHistoryRoot.cxx @@ -64,6 +64,11 @@ void VInspector_ItemHistoryRoot::AddElement (const VInspector_CallBackMode& theM const VInspector_ItemHistoryTypeInfo& VInspector_ItemHistoryRoot::GetTypeInfo (const int theChildRowIndex) { int anInfoMapIndex = theChildRowIndex + myFirstIndex; + + bool aReversed = true; + if (aReversed) + anInfoMapIndex = (myInfoMap.size() - myFirstIndex) - 1 - anInfoMapIndex; + return myInfoMap[anInfoMapIndex]; } @@ -73,13 +78,17 @@ const VInspector_ItemHistoryTypeInfo& VInspector_ItemHistoryRoot::GetTypeInfo (c // ======================================================================= QVariant VInspector_ItemHistoryRoot::initValue (const int theRole) const { + QVariant aParentValue = VInspector_ItemBase::initValue (theRole); + if (aParentValue.isValid()) + return aParentValue; + if (theRole != Qt::DisplayRole && theRole != Qt::EditRole && theRole != Qt::ToolTipRole) return QVariant(); switch (Column()) { case 0: return "History"; - case 1: return theRole == Qt::ToolTipRole ? QVariant ("Count of children") : QVariant (rowCount()); + case 2: return theRole == Qt::ToolTipRole ? QVariant ("Count of children") : QVariant (rowCount()); default: break; } diff --git a/tools/VInspector/VInspector_ItemHistoryRoot.hxx b/tools/VInspector/VInspector_ItemHistoryRoot.hxx index 42630670d4..d0b16d5c7e 100644 --- a/tools/VInspector/VInspector_ItemHistoryRoot.hxx +++ b/tools/VInspector/VInspector_ItemHistoryRoot.hxx @@ -37,7 +37,7 @@ public: { return VInspector_ItemHistoryRootPtr (new VInspector_ItemHistoryRoot (theParent, theRow, theColumn)); } //! Destructor - virtual ~VInspector_ItemHistoryRoot() Standard_OVERRIDE {}; + virtual ~VInspector_ItemHistoryRoot() {} //! Sets maximum count of history elements in internal container. //! \param theSize a size value @@ -72,7 +72,7 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item VInspector_ItemHistoryRoot(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn); private: diff --git a/tools/VInspector/VInspector_ItemHistoryType.cxx b/tools/VInspector/VInspector_ItemHistoryType.cxx index bd8f90a9a9..70ab2c9049 100644 --- a/tools/VInspector/VInspector_ItemHistoryType.cxx +++ b/tools/VInspector/VInspector_ItemHistoryType.cxx @@ -31,6 +31,8 @@ QString VInspector_ItemHistoryType::PointerInfo() const VInspector_ItemHistoryRootPtr aParentItem = itemDynamicCast(Parent()); const VInspector_ItemHistoryTypeInfo& aTypeInfo = aParentItem->GetTypeInfo(Row()); + if (aTypeInfo.myElements.size() < rowCount()) + return QString(); QList anElements = aTypeInfo.myElements[rowCount() - 1]; // the last item return anElements.size() > 1 ? anElements[1].toString() : QString(); } @@ -46,6 +48,8 @@ QString VInspector_ItemHistoryType::OwnerInfo() const VInspector_ItemHistoryRootPtr aParentItem = itemDynamicCast(Parent()); const VInspector_ItemHistoryTypeInfo& aTypeInfo = aParentItem->GetTypeInfo(Row()); + if ( aTypeInfo.myElements.size() < rowCount()) + return QString(); QList anElements = aTypeInfo.myElements[rowCount() - 1]; // the last item return anElements.size() > 3 ? anElements[3].toString() : QString(); } @@ -56,21 +60,29 @@ QString VInspector_ItemHistoryType::OwnerInfo() const // ======================================================================= QVariant VInspector_ItemHistoryType::initValue(const int theRole) const { + QVariant aParentValue = VInspector_ItemBase::initValue (theRole); + if (aParentValue.isValid()) + return aParentValue; + if (theRole != Qt::DisplayRole && theRole != Qt::EditRole && theRole != Qt::ToolTipRole) return QVariant(); VInspector_ItemHistoryRootPtr aParentItem = itemDynamicCast(Parent()); const VInspector_ItemHistoryTypeInfo& aTypeInfo = aParentItem->GetTypeInfo(Row()); + int aRowCount = rowCount(); + if (aRowCount <= 0 || aTypeInfo.myElements.size() < aRowCount) + return QVariant(); + QList anElements = rowCount() > 0 ? aTypeInfo.myElements[rowCount() - 1] : QList(); // the last item int anInfoSize = anElements.size(); switch (Column()) { case 0: return VInspector_CallBack::GetInfo(aTypeInfo.myMode); - case 1: return rowCount(); - case 2: return anInfoSize > 1 ? anElements[1].toString() : QVariant(); // pointer info - case 3: return anInfoSize > 2 ? anElements[2].toString() : QVariant(); // shape type - case 4: return anInfoSize > 0 ? anElements[0].toString() : QVariant(); // AIS name - case 5: return anInfoSize > 3 ? anElements[3].toString() : QVariant(); // owner info + case 3: return rowCount(); + case 4: return anInfoSize > 1 ? anElements[1].toString() : QVariant(); // pointer info + case 5: return anInfoSize > 2 ? anElements[2].toString() : QVariant(); // shape type + case 6: return anInfoSize > 0 ? anElements[0].toString() : QVariant(); // AIS name + case 7: return anInfoSize > 3 ? anElements[3].toString() : QVariant(); // owner info default: break; } return QVariant(); diff --git a/tools/VInspector/VInspector_ItemHistoryType.hxx b/tools/VInspector/VInspector_ItemHistoryType.hxx index 875a9b6418..1632e83e2a 100644 --- a/tools/VInspector/VInspector_ItemHistoryType.hxx +++ b/tools/VInspector/VInspector_ItemHistoryType.hxx @@ -35,7 +35,7 @@ public: { return VInspector_ItemHistoryTypePtr (new VInspector_ItemHistoryType (theParent, theRow, theColumn)); } //! Destructor - virtual ~VInspector_ItemHistoryType() Standard_OVERRIDE {}; + virtual ~VInspector_ItemHistoryType() {} //! Returns the pointer info of the first child item, initialize item if it has not been initialized yet. Standard_EXPORT QString PointerInfo() const; @@ -67,7 +67,7 @@ protected: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item VInspector_ItemHistoryType(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : VInspector_ItemBase(theParent, theRow, theColumn) {} diff --git a/tools/VInspector/VInspector_ItemPresentableObject.cxx b/tools/VInspector/VInspector_ItemPresentableObject.cxx index e1747f7f3f..135170ea1b 100644 --- a/tools/VInspector/VInspector_ItemPresentableObject.cxx +++ b/tools/VInspector/VInspector_ItemPresentableObject.cxx @@ -15,21 +15,23 @@ #include +#include #include #include #include + #include -#include -#include #include #include +#include +#include + #include #include #include -#include +#include #include -#include #include #include @@ -42,15 +44,9 @@ // ======================================================================= 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.)); - } - } + QVariant aParentValue = VInspector_ItemBase::initValue (theItemRole); + if (aParentValue.isValid()) + return aParentValue; if (theItemRole == Qt::DisplayRole || theItemRole == Qt::ToolTipRole) { @@ -67,45 +63,11 @@ QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const return theItemRole == Qt::ToolTipRole ? QVariant ("") : QVariant (anIO->DynamicType()->Name()); } - case 1: - return rowCount(); - case 2: - { - if (!aNullIO) - return VInspector_Tools::GetPointerInfo (anIO, true).ToCString(); - break; - } - case 3: - { - Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (anIO); - if (!aShapeIO.IsNull()) - { - const TopoDS_Shape& aShape = aShapeIO->Shape(); - if (!aShape.IsNull()) - return VInspector_Tools::GetShapeTypeInfo (aShape.ShapeType()).ToCString(); - } - break; - } case 4: { 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()) - { - if (!aModesInfo.IsEmpty()) - aModesInfo += ", "; - aModesInfo += VInspector_Tools::GetShapeTypeInfo (AIS_Shape::SelectionType(itr.Value())); - } - return aModesInfo.ToCString(); - } - break; case 6: { double aDeviationCoefficient = 0; @@ -117,18 +79,6 @@ QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const } 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: { double aDeviationCoefficient = 0; @@ -142,21 +92,6 @@ QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const 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; } } @@ -192,29 +127,7 @@ QVariant VInspector_ItemPresentableObject::initValue (int theItemRole) const // ======================================================================= 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 -} - -// ======================================================================= -// function : createChild -// purpose : -// ======================================================================= -TreeModel_ItemBasePtr VInspector_ItemPresentableObject::createChild (int theRow, int theColumn) -{ - return VInspector_ItemSelection::CreateItem(currentItem(), theRow, theColumn); + return 0; } // ======================================================================= @@ -234,18 +147,28 @@ void VInspector_ItemPresentableObject::Init() 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 + + std::vector aListOfIOSorted; + aListOfIOSorted.reserve (aListOfIO.Size()); + for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next()) + { + aListOfIOSorted.push_back (anIOIt.Value()); + } + std::sort (aListOfIOSorted.begin(), aListOfIOSorted.end()); + int aCurrentIndex = 0; - for (AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); anIOIt.More(); anIOIt.Next(), aCurrentIndex++) + for (std::vector::const_iterator anIOIt = aListOfIOSorted.begin(); anIOIt != aListOfIOSorted.end(); anIOIt++, aCurrentIndex++) { - if (aCurrentIndex != aRowId - aDeltaIndex) + if (aCurrentIndex != aRowId) continue; - anIO = anIOIt.Value(); + anIO = *anIOIt; break; } } setInteractiveObject (anIO); + myTransformPersistence = !anIO.IsNull() ? anIO->TransformPersistence() : NULL; + UpdatePresentationShape(); TreeModel_ItemBase::Init(); // to use getIO() without circling initialization } @@ -259,6 +182,7 @@ void VInspector_ItemPresentableObject::Reset() SetContext (NULL); setInteractiveObject (NULL); + myTransformPersistence = NULL; } // ======================================================================= @@ -273,13 +197,20 @@ void VInspector_ItemPresentableObject::initItem() const } // ======================================================================= -// function : GetInteractiveObject +// function : buildPresentationShape // purpose : // ======================================================================= -Handle(AIS_InteractiveObject) VInspector_ItemPresentableObject::GetInteractiveObject() const +TopoDS_Shape VInspector_ItemPresentableObject::buildPresentationShape() { - initItem(); - return myIO; + Handle(AIS_InteractiveObject) aPrs = myIO; + if (aPrs.IsNull()) + return TopoDS_Shape(); + + Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); + if (!aShapePrs.IsNull()) + return aShapePrs->Shape(); + + return TopoDS_Shape(); } // ======================================================================= @@ -288,44 +219,31 @@ Handle(AIS_InteractiveObject) VInspector_ItemPresentableObject::GetInteractiveOb // ======================================================================= QString VInspector_ItemPresentableObject::PointerInfo() const { - return VInspector_Tools::GetPointerInfo (GetInteractiveObject(), true).ToCString(); + return Standard_Dump::GetPointerInfo (GetInteractiveObject(), true).ToCString(); } // ======================================================================= -// function : GetSelectedPresentations +// function : Presentations // purpose : // ======================================================================= -NCollection_List VInspector_ItemPresentableObject::GetSelectedPresentations - (QItemSelectionModel* theSelectionModel) +void VInspector_ItemPresentableObject::Presentations (NCollection_List& thePresentations) { - NCollection_List aResultList; - if (!theSelectionModel) - return aResultList; - - QList anItems; - - QModelIndexList anIndices = theSelectionModel->selectedIndexes(); - for (QModelIndexList::const_iterator anIndicesIt = anIndices.begin(); anIndicesIt != anIndices.end(); anIndicesIt++) - { - TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt); - if (!anItem || anItems.contains (anItem)) - continue; - anItems.append (anItem); - } + if (Column() != 0) + return; - QList aSelectedIds; // Remember of selected address in order to avoid duplicates - for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); anItemIt++) - { - TreeModel_ItemBasePtr anItem = *anItemIt; - VInspector_ItemPresentableObjectPtr aPrsItem = itemDynamicCast(anItem); - if (!aPrsItem) - continue; - Handle(AIS_InteractiveObject) aPresentation = aPrsItem->GetInteractiveObject(); - if (aSelectedIds.contains ((size_t)aPresentation.operator->())) - continue; - aSelectedIds.append ((size_t)aPresentation.operator->()); - if (!aPresentation.IsNull()) - aResultList.Append (aPresentation); - } - return aResultList; + thePresentations.Append (GetInteractiveObject()); +} + +// ======================================================================= +// function : initStream +// purpose : +// ======================================================================= +void VInspector_ItemPresentableObject::initStream (Standard_OStream& theOStream) const +{ + Handle(AIS_InteractiveObject) anIO = GetInteractiveObject(); + if (anIO.IsNull()) + return; + + anIO->DumpJson (theOStream); } + diff --git a/tools/VInspector/VInspector_ItemPresentableObject.hxx b/tools/VInspector/VInspector_ItemPresentableObject.hxx index ed5765200f..28ea239953 100644 --- a/tools/VInspector/VInspector_ItemPresentableObject.hxx +++ b/tools/VInspector/VInspector_ItemPresentableObject.hxx @@ -39,11 +39,15 @@ public: static VInspector_ItemPresentableObjectPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) { return VInspector_ItemPresentableObjectPtr (new VInspector_ItemPresentableObject (theParent, theRow, theColumn)); } //! Destructor - virtual ~VInspector_ItemPresentableObject() Standard_OVERRIDE {}; + virtual ~VInspector_ItemPresentableObject() {} + + //! Returns data object of the item. + //! \return object + virtual const Handle(Standard_Transient)& Object() const { initItem(); return myIO; } //! Returns the current interactive object, init item if it was not initialized yet //! \return interactive object - Standard_EXPORT Handle(AIS_InteractiveObject) GetInteractiveObject() const; + Handle(AIS_InteractiveObject) GetInteractiveObject() const { return Handle(AIS_InteractiveObject)::DownCast (Object()); } //! Returns pointer information for the current interactive object, init item if it was not initialized yet //! \return string value @@ -55,11 +59,9 @@ public: //! Resets cached values Standard_EXPORT virtual void Reset() Standard_OVERRIDE; - //! Returns presentations, which items are selected in tree view - //! \param theSelectionModel a selection model - //! \return container of presentations - Standard_EXPORT static NCollection_List GetSelectedPresentations - (QItemSelectionModel* theSelectionModel); + //! Returns presentation of the attribute to be visualized in the view + //! \thePresentations [out] container of presentation handles to be visualized + Standard_EXPORT virtual void Presentations (NCollection_List& thePresentations); protected: @@ -75,13 +77,14 @@ protected: //! \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; + //! Returns stream value of the item to fulfill property panel. + //! \return stream value or dummy + Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE; -private: +protected: + //! Build presentation shape + //! \return generated shape of the item parameters + virtual TopoDS_Shape buildPresentationShape() Standard_OVERRIDE; //! Set interactive object into the current field //! \param theIO a presentation @@ -90,7 +93,7 @@ private: private: //! Constructor - //! param theParent a parent item + //! \param theParent a parent item VInspector_ItemPresentableObject(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) : VInspector_ItemBase(theParent, theRow, theColumn) {} diff --git a/tools/VInspector/VInspector_ItemSelectMgrFilter.cxx b/tools/VInspector/VInspector_ItemSelectMgrFilter.cxx deleted file mode 100644 index a274b05256..0000000000 --- a/tools/VInspector/VInspector_ItemSelectMgrFilter.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -#include -#include - -#include -#include -#include - -// ======================================================================= -// 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 (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(this)->Init(); -} - -// ======================================================================= -// function : GetInteractiveObject -// purpose : -// ======================================================================= -Handle(SelectMgr_Filter) VInspector_ItemSelectMgrFilter::GetFilter() const -{ - initItem(); - return myFilter; -} diff --git a/tools/VInspector/VInspector_ItemSelectMgrFilter.hxx b/tools/VInspector/VInspector_ItemSelectMgrFilter.hxx deleted file mode 100644 index 68408359e2..0000000000 --- a/tools/VInspector/VInspector_ItemSelectMgrFilter.hxx +++ /dev/null @@ -1,91 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_ItemSelectMgrFilter_H -#define VInspector_ItemSelectMgrFilter_H - -#include -#include - -#include - -class QItemSelectionModel; - -class VInspector_ItemSelectMgrFilter; -typedef QExplicitlySharedDataPointer 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 diff --git a/tools/VInspector/VInspector_ItemSelection.cxx b/tools/VInspector/VInspector_ItemSelection.cxx deleted file mode 100644 index 191232968f..0000000000 --- a/tools/VInspector/VInspector_ItemSelection.cxx +++ /dev/null @@ -1,200 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -// ======================================================================= -// function : getSelection -// purpose : -// ======================================================================= -Handle(SelectMgr_Selection) VInspector_ItemSelection::getSelection() const -{ - initItem(); - return mySelection; -} - -// ======================================================================= -// function : initRowCount -// purpose : -// ======================================================================= -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 -} - -// ======================================================================= -// function : initValue -// purpose : -// ======================================================================= -QVariant VInspector_ItemSelection::initValue (int theItemRole) const -{ - switch (theItemRole) - { - case Qt::DisplayRole: - case Qt::EditRole: - case Qt::ToolTipRole: - { - switch (Column()) - { - case 0: return getSelection()->DynamicType()->Name(); - case 1: return rowCount(); - case 3: - { - if (theItemRole == Qt::ToolTipRole) - return "Mode"; - else - { - VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast(Parent()); - return VInspector_Tools::SelectionModeToName(getSelection()->Mode(), aParentItem->GetInteractiveObject()).ToCString(); - } - } - case 4: - { - if (theItemRole == Qt::ToolTipRole) - return "SelectMgr_StateOfSelection"; - else { - int aNbSelected = 0; - SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState(); - 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(SelectMgr_EntityOwner)& anOwner = mySelection->Sensitive()->BaseSensitive()->OwnerId(); -#else - for (NCollection_Vector::Iterator aSelEntIter (mySelection->Entities()); aSelEntIter.More(); aSelEntIter.Next()) - { - const Handle(SelectMgr_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId(); -#endif - if (VInspector_Tools::IsOwnerSelected(aContext, anOwner)) - aNbSelected++; - } - } - return aNbSelected > 0 ? QString::number (aNbSelected) : ""; - } - } - case 9: - { - 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; - } - break; - } - case Qt::ForegroundRole: - { - SelectMgr_StateOfSelection aState = getSelection()->GetSelectionState(); - return QVariant (aState == SelectMgr_SOS_Activated ? QColor (Qt::black) : QColor (Qt::darkGray)); - } - } - return QVariant(); -} - -// ======================================================================= -// function : createChild -// purpose : -// ======================================================================= -TreeModel_ItemBasePtr VInspector_ItemSelection::createChild (int theRow, int theColumn) -{ - return VInspector_ItemSensitiveEntity::CreateItem (currentItem(), theRow, theColumn); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= -void VInspector_ItemSelection::Init() -{ - VInspector_ItemPresentableObjectPtr aParentItem = itemDynamicCast(Parent()); - - Handle(AIS_InteractiveObject) anIO = aParentItem->GetInteractiveObject(); - - 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(); -} - -// ======================================================================= -// function : Reset -// purpose : -// ======================================================================= -void VInspector_ItemSelection::Reset() -{ - // an empty method to don't clear the main label, otherwise the model will be empty - TreeModel_ItemBase::Reset(); - - mySelection = NULL; -} - -// ======================================================================= -// function : initItem -// purpose : -// ======================================================================= -void VInspector_ItemSelection::initItem() const -{ - if (IsInitialized()) - return; - const_cast(this)->Init(); - // an empty method to don't initialize the main label, as it was not cleared in Reset() -} diff --git a/tools/VInspector/VInspector_ItemSelection.hxx b/tools/VInspector/VInspector_ItemSelection.hxx deleted file mode 100644 index f1565a6c03..0000000000 --- a/tools/VInspector/VInspector_ItemSelection.hxx +++ /dev/null @@ -1,84 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_ItemSelection_H -#define VInspector_ItemSelection_H - -#include -#include - -#include - -class VInspector_ItemSelection; -typedef QExplicitlySharedDataPointer VInspector_ItemSelectionPtr; - -//! \class VInspector_ItemSelection -//! Item about SelectMgr_Selection. -//! Parent is presentable object item, children are sensitive entity items -class VInspector_ItemSelection : public VInspector_ItemBase -{ -public: - - //! Creates an item wrapped by a shared pointer - static VInspector_ItemSelectionPtr CreateItem(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - { return VInspector_ItemSelectionPtr (new VInspector_ItemSelection (theParent, theRow, theColumn)); } - - //! Destructor - virtual ~VInspector_ItemSelection() {}; - - //! \return current selection value - Standard_EXPORT Handle(SelectMgr_Selection) getSelection() 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: - - //! Initializes the current item. It is empty because Reset() is also empty. - virtual void initItem() const Standard_OVERRIDE; - - //! Initializes number of children - //! \return integer value - 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; - -protected: - - //! 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: - - //! Constructor - //! param theParent a parent item - VInspector_ItemSelection(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : VInspector_ItemBase(theParent, theRow, theColumn) {} - -private: - - Handle(SelectMgr_Selection) mySelection; //!< the current selection -}; - -#endif diff --git a/tools/VInspector/VInspector_ItemSensitiveEntity.cxx b/tools/VInspector/VInspector_ItemSensitiveEntity.cxx deleted file mode 100644 index b5f9d59174..0000000000 --- a/tools/VInspector/VInspector_ItemSensitiveEntity.cxx +++ /dev/null @@ -1,195 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -// ======================================================================= -// function : GetSensitiveEntity -// purpose : -// ======================================================================= -Handle(SelectMgr_SensitiveEntity) VInspector_ItemSensitiveEntity::GetSensitiveEntity() const -{ - initItem(); - return myEntity; -} - -// ======================================================================= -// function : initValue -// purpose : -// ======================================================================= -QVariant VInspector_ItemSensitiveEntity::initValue (int theItemRole) const -{ - Handle(SelectMgr_SensitiveEntity) aBase = GetSensitiveEntity(); - Handle(SelectMgr_EntityOwner) anOwner = aBase->BaseSensitive()->OwnerId(); - - switch (theItemRole) - { - case Qt::DisplayRole: - case Qt::EditRole: - case Qt::ToolTipRole: - { - switch (Column()) - { - case 0: return myEntity->DynamicType()->Name(); - case 2: return VInspector_Tools::GetPointerInfo (GetSensitiveEntity()->BaseSensitive()->OwnerId(), true).ToCString(); - case 3: - { - 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 13: return -#if OCC_VERSION_HEX <= 0x060901 - ("none"); -#else - myEntity->IsActiveForSelection() ? QString ("true") : QString ("false"); -#endif - case 14: return QString::number (GetSensitiveEntity()->BaseSensitive()->SensitivityFactor()); - case 15: return QString::number (GetSensitiveEntity()->BaseSensitive()->NbSubElements()); - case 16: - { - Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast (anOwner); - if (BROwnr.IsNull()) - return QVariant(); - return anOwner->Priority(); - } - default: - break; - } - break; - } - case Qt::BackgroundRole: - case Qt::ForegroundRole: - { - if (Column() == 2) - { - Handle(AIS_InteractiveContext) aContext = GetContext(); - if (!aContext.IsNull()) - { - if (VInspector_Tools::IsOwnerSelected(aContext, getEntityOwner())) - return QVariant ((theItemRole == Qt::BackgroundRole) ? QColor (Qt::darkBlue) : QColor (Qt::white)); - } - } - VInspector_ItemSelectionPtr aParentItem = itemDynamicCast(Parent()); - if (aParentItem) - return aParentItem->data(QModelIndex(), theItemRole); - break; - } - default: - break; - } - return QVariant(); -} - -// ======================================================================= -// function : createChild -// purpose : -// ======================================================================= -TreeModel_ItemBasePtr VInspector_ItemSensitiveEntity::createChild (int theRow, int theColumn) -{ - return VInspector_ItemEntityOwner::CreateItem (currentItem(), theRow, theColumn); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= -void VInspector_ItemSensitiveEntity::Init() -{ - VInspector_ItemSelectionPtr aParentItem = itemDynamicCast(Parent()); - - Handle(SelectMgr_Selection) aSelection = aParentItem->getSelection(); - - int aRowId = Row(); - int aCurrentId = 0; -#if OCC_VERSION_HEX < 0x070201 - for (aSelection->Init(); aSelection->More(); aSelection->Next(), aCurrentId++) -#else - for (NCollection_Vector::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(); -} - -// ======================================================================= -// function : Reset -// purpose : -// ======================================================================= -void VInspector_ItemSensitiveEntity::Reset() -{ - // an empty method to don't clear the main label, otherwise the model will be empty - TreeModel_ItemBase::Reset(); - myEntity = NULL; -} - -// ======================================================================= -// function : initItem -// purpose : -// ======================================================================= -void VInspector_ItemSensitiveEntity::initItem() const -{ - if (IsInitialized()) - return; - const_cast(this)->Init(); -} - -// ======================================================================= -// function : getEntityOwner -// purpose : -// ======================================================================= -Handle(SelectMgr_EntityOwner) VInspector_ItemSensitiveEntity::getEntityOwner() const -{ - initItem(); - - Handle(SelectMgr_EntityOwner) anOwner; - const Handle(Select3D_SensitiveEntity)& aBase = myEntity->BaseSensitive(); - if (aBase.IsNull()) - return anOwner; - return aBase->OwnerId(); -} diff --git a/tools/VInspector/VInspector_ItemSensitiveEntity.hxx b/tools/VInspector/VInspector_ItemSensitiveEntity.hxx deleted file mode 100644 index 4fbe8045cd..0000000000 --- a/tools/VInspector/VInspector_ItemSensitiveEntity.hxx +++ /dev/null @@ -1,90 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_ItemSensitiveEntity_H -#define VInspector_ItemSensitiveEntity_H - -#include -#include -#include -#include - -class SelectMgr_EntityOwner; -class VInspector_ItemSensitiveEntity; - -typedef QExplicitlySharedDataPointer VInspector_ItemSensitiveEntityPtr; - -//! \class VInspector_ItemSensitiveEntity -//! The item shows information about SelectMgr_EntityOwner. -//! The parent is item selection, children are item entity owners -class VInspector_ItemSensitiveEntity : public VInspector_ItemBase -{ - -public: - - //! Creates an item wrapped by a shared pointer - static VInspector_ItemSensitiveEntityPtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - { return VInspector_ItemSensitiveEntityPtr (new VInspector_ItemSensitiveEntity (theParent, theRow, theColumn)); } - - //! Destructor - virtual ~VInspector_ItemSensitiveEntity() Standard_OVERRIDE {}; - - //! \return the current sensitive entity - Standard_EXPORT Handle(SelectMgr_SensitiveEntity) GetSensitiveEntity() 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; - - //! \return number of children. - virtual int initRowCount() const Standard_OVERRIDE { return !GetSensitiveEntity()->BaseSensitive().IsNull() ? 1 : 0; } - - //! 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; - -protected: - - //! 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; - - //! Returns owner of the current sensitive entity - //! \return owner - Handle(SelectMgr_EntityOwner) getEntityOwner() const; - -private: - - //! Constructor - //! param theParent a parent item - VInspector_ItemSensitiveEntity(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) - : VInspector_ItemBase(theParent, theRow, theColumn) {} - -private: - - Handle(SelectMgr_SensitiveEntity) myEntity; //!< the current entity owner -}; - -#endif diff --git a/tools/VInspector/VInspector_SelectionType.hxx b/tools/VInspector/VInspector_SelectionType.hxx deleted file mode 100644 index 1de71e1957..0000000000 --- a/tools/VInspector/VInspector_SelectionType.hxx +++ /dev/null @@ -1,28 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef VInspector_SelectionType_H -#define VInspector_SelectionType_H - -//! Type of SelectMgr enumeration types -enum VInspector_SelectionType -{ - VInspector_SelectionType_TypeOfUpdate, //!< Values of SelectMgr_TypeOfUpdate - VInspector_SelectionType_StateOfSelection, //!< Values of SelectMgr_StateOfSelection - VInspector_SelectionType_TypeOfBVHUpdate //!< Values of SelectMgr_TypeOfBVHUpdate -}; - -#endif - \ No newline at end of file diff --git a/tools/VInspector/VInspector_ToolActionType.hxx b/tools/VInspector/VInspector_ToolActionType.hxx index 762645463b..fe062f9793 100644 --- a/tools/VInspector/VInspector_ToolActionType.hxx +++ b/tools/VInspector/VInspector_ToolActionType.hxx @@ -20,9 +20,7 @@ enum VInspector_ToolActionType { VInspector_ToolActionType_NoneId, //!< No action activated - VInspector_ToolActionType_UpdateId, //!< Update content of tree view (content of AIS_InteractiveContext) - VInspector_ToolActionType_SelectPresentationsId, //!< Selects presentation in context by selection in tree view - VInspector_ToolActionType_SelectOwnersId //!< Selects owners in context by selection in tree view + VInspector_ToolActionType_UpdateId //!< Update content of tree view (content of AIS_InteractiveContext) }; #endif diff --git a/tools/VInspector/VInspector_ToolBar.cxx b/tools/VInspector/VInspector_ToolBar.cxx index 819a8856c3..193e5dc55c 100644 --- a/tools/VInspector/VInspector_ToolBar.cxx +++ b/tools/VInspector/VInspector_ToolBar.cxx @@ -35,14 +35,6 @@ VInspector_ToolBar::VInspector_ToolBar (QWidget* theParent) myActionsMap[VInspector_ToolActionType_UpdateId]->setText ("Update"); - myActionsMap[VInspector_ToolActionType_SelectPresentationsId] = new QPushButton (theParent); - myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setText ("Select Presentations"); - myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setCheckable (true); - - myActionsMap[VInspector_ToolActionType_SelectOwnersId] = new QPushButton (theParent); - myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setText ("Select Owners"); - myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setCheckable (true); - myMainWindow = new QWidget (theParent); QHBoxLayout* aLay = new QHBoxLayout (myMainWindow); @@ -84,11 +76,6 @@ void VInspector_ToolBar::onActionClicked() break; } - if (anId == VInspector_ToolActionType_SelectPresentationsId && myActionsMap[VInspector_ToolActionType_SelectOwnersId]->isChecked()) - myActionsMap[VInspector_ToolActionType_SelectOwnersId]->setChecked(false); - else if (anId == VInspector_ToolActionType_SelectOwnersId && myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->isChecked()) - myActionsMap[VInspector_ToolActionType_SelectPresentationsId]->setChecked(false); - if (anId != -1) emit actionClicked (anId); } diff --git a/tools/VInspector/VInspector_ToolBar.hxx b/tools/VInspector/VInspector_ToolBar.hxx index 97ddbaeee4..f4c7433aaa 100644 --- a/tools/VInspector/VInspector_ToolBar.hxx +++ b/tools/VInspector/VInspector_ToolBar.hxx @@ -40,7 +40,7 @@ public: Standard_EXPORT VInspector_ToolBar (QWidget* theParent); //! Destructor - virtual ~VInspector_ToolBar() Standard_OVERRIDE {} + virtual ~VInspector_ToolBar() {} //! Returns main control QWidget* GetControl() const { return myMainWindow; } diff --git a/tools/VInspector/VInspector_Tools.cxx b/tools/VInspector/VInspector_Tools.cxx index eeb52fe983..8c33d500de 100644 --- a/tools/VInspector/VInspector_Tools.cxx +++ b/tools/VInspector/VInspector_Tools.cxx @@ -15,24 +15,33 @@ #include +#include +#include + +#include + #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + #include #include #include -#include #include #include #include #include +#include + #include // ======================================================================= @@ -46,30 +55,6 @@ TCollection_AsciiString VInspector_Tools::GetShapeTypeInfo (const TopAbs_ShapeEn return aSStream.str().c_str(); } -// ======================================================================= -// function : GetPointerInfo -// purpose : -// ======================================================================= -TCollection_AsciiString VInspector_Tools::GetPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) -{ - std::ostringstream aPtrStr; - aPtrStr << thePointer.operator->(); - if (!isShortInfo) - return aPtrStr.str().c_str(); - - TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); - for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) - { - if (anInfoPtr.Value(aSymbolId) != '0') - { - anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); - anInfoPtr.Prepend("0x"); - return anInfoPtr; - } - } - return aPtrStr.str().c_str(); -} - // ======================================================================= // function : SelectedOwners // purpose : @@ -100,12 +85,12 @@ int VInspector_Tools::SelectedOwners (const Handle(AIS_InteractiveContext)& theC if (theShapeInfoOnly && BROwnr.IsNull()) continue; - Standard_Transient* anOwnerPtr = anOwner.operator->(); + Standard_Transient* anOwnerPtr = anOwner.get(); if (aSelectedIds.contains ((size_t)anOwnerPtr)) continue; aSelectedIds.append ((size_t)anOwnerPtr); - anObjects.append (VInspector_Tools::GetPointerInfo (anOwnerPtr, true).ToCString()); + anObjects.append (Standard_Dump::GetPointerInfo (anOwnerPtr, true).ToCString()); } return anObjects.size(); } @@ -115,12 +100,11 @@ int VInspector_Tools::SelectedOwners (const Handle(AIS_InteractiveContext)& theC // purpose : // ======================================================================= bool VInspector_Tools::IsOwnerSelected (const Handle(AIS_InteractiveContext)& theContext, - const Handle(SelectMgr_EntityOwner)& theOwner) + const Handle(SelectBasics_EntityOwner)& theOwner) { bool anIsSelected = false; - Handle(SelectMgr_EntityOwner) anOwner = theOwner; for (theContext->InitSelected(); theContext->MoreSelected() && !anIsSelected; theContext->NextSelected()) - anIsSelected = theContext->SelectedOwner() == anOwner; + anIsSelected = theContext->SelectedOwner() == theOwner; return anIsSelected; } @@ -128,10 +112,10 @@ bool VInspector_Tools::IsOwnerSelected (const Handle(AIS_InteractiveContext)& th // function : ContextOwners // purpose : // ======================================================================= -NCollection_List VInspector_Tools::ContextOwners ( +NCollection_List VInspector_Tools::ContextOwners ( const Handle(AIS_InteractiveContext)& theContext) { - NCollection_List aResultOwners; + NCollection_List aResultOwners; if (theContext.IsNull()) return aResultOwners; @@ -143,16 +127,6 @@ NCollection_List VInspector_Tools::ContextOwners 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(); @@ -161,12 +135,11 @@ NCollection_List VInspector_Tools::ContextOwners for (NCollection_Vector::Iterator aSelEntIter (aSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next()) { Handle(SelectMgr_SensitiveEntity) anEntity = aSelEntIter.Value(); -#endif if (anEntity.IsNull()) continue; - const Handle(Select3D_SensitiveEntity)& aBase = anEntity->BaseSensitive(); - Handle(SelectMgr_EntityOwner) anOwner = aBase->OwnerId(); - Standard_Transient* anOwnerPtr = anOwner.operator->(); + const Handle(SelectBasics_SensitiveEntity)& aBase = anEntity->BaseSensitive(); + Handle(SelectBasics_EntityOwner) anOwner = aBase->OwnerId(); + Standard_Transient* anOwnerPtr = anOwner.get(); if (aSelectedIds.contains ((size_t)anOwnerPtr)) continue; aSelectedIds.append ((size_t)anOwnerPtr); @@ -181,32 +154,29 @@ NCollection_List VInspector_Tools::ContextOwners // function : ActiveOwners // purpose : // ======================================================================= -NCollection_List VInspector_Tools::ActiveOwners ( +NCollection_List VInspector_Tools::ActiveOwners ( const Handle(AIS_InteractiveContext)& theContext, - NCollection_List& theEmptySelectableOwners) + NCollection_List& theEmptySelectableOwners) { - NCollection_List aResultOwners; + NCollection_List aResultOwners; // only local context is processed: TODO for global context Handle(AIS_InteractiveContext) aContext = theContext; if (aContext.IsNull()) return aResultOwners; - NCollection_List anActiveOwners; + NCollection_List anActiveOwners; // OCCT BUG:1 - equal pointer owners are appears in the list -#if OCC_VERSION_HEX > 0x060901 aContext->MainSelector()->ActiveOwners (anActiveOwners); -#else - anActiveOwners = aContext->MainSelector()->ActiveOwners(); -#endif QList aSelectedIds; // Remember of selected address in order to avoid duplicates - for (NCollection_List::Iterator anOwnersIt (anActiveOwners); + Handle(SelectMgr_EntityOwner) anOwner; + for (NCollection_List::Iterator anOwnersIt (anActiveOwners); anOwnersIt.More(); anOwnersIt.Next()) { - const Handle(SelectMgr_EntityOwner)& anOwner = anOwnersIt.Value(); + anOwner = anOwnersIt.Value(); if (anOwner.IsNull()) continue; - Standard_Transient* anOwnerPtr = anOwner.operator->(); + Standard_Transient* anOwnerPtr = anOwner.get(); if (aSelectedIds.contains ((size_t)anOwnerPtr)) continue; aSelectedIds.append ((size_t)anOwnerPtr); @@ -225,7 +195,7 @@ NCollection_List VInspector_Tools::ActiveOwners ( // purpose : // ======================================================================= void VInspector_Tools::AddOrRemoveSelectedShapes (const Handle(AIS_InteractiveContext)& theContext, - const NCollection_List& theOwners) + const NCollection_List& theOwners) { // TODO: the next two rows are to be removed later theContext->UnhilightSelected(false); @@ -233,7 +203,7 @@ void VInspector_Tools::AddOrRemoveSelectedShapes (const Handle(AIS_InteractiveCo theContext->UnhilightSelected(Standard_False); - for (NCollection_List::Iterator anOwnersIt(theOwners); + for (NCollection_List::Iterator anOwnersIt(theOwners); anOwnersIt.More(); anOwnersIt.Next()) { Handle(SelectMgr_EntityOwner) anOwner = anOwnersIt.Value(); @@ -267,7 +237,7 @@ QList VInspector_Tools::GetInfo (Handle(AIS_InteractiveObject)& theObj { QList anInfo; anInfo.append (theObject->DynamicType()->Name()); - anInfo.append (VInspector_Tools::GetPointerInfo (theObject, true).ToCString()); + anInfo.append (Standard_Dump::GetPointerInfo (theObject, true).ToCString()); Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theObject); if (aShapeIO.IsNull()) @@ -300,7 +270,7 @@ QList VInspector_Tools::GetHighlightInfo (const Handle(AIS_Interactive Handle(SelectMgr_EntityOwner) anOwner = theContext->DetectedOwner(); if (anOwner.IsNull()) continue; - Standard_Transient* anOwnerPtr = anOwner.operator->(); + Standard_Transient* anOwnerPtr = anOwner.get(); if (aSelectedIds.contains ((size_t)anOwnerPtr)) continue; aSelectedIds.append ((size_t)anOwnerPtr); @@ -314,7 +284,7 @@ QList VInspector_Tools::GetHighlightInfo (const Handle(AIS_Interactive aSelectedPointers.append (anIOInfo[1].toString()); aSelectedTypes.append (anIOInfo[2].toString()); } - aSelectedOwners.append (VInspector_Tools::GetPointerInfo (anOwnerPtr, true).ToCString()); + aSelectedOwners.append (Standard_Dump::GetPointerInfo (anOwnerPtr, true).ToCString()); } aValues.append (aSelectedNames.join (", ")); aValues.append (aSelectedPointers.join (", ")); @@ -344,7 +314,7 @@ QList VInspector_Tools::GetSelectedInfo (const Handle(AIS_InteractiveC Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); if (anOwner.IsNull()) continue; - Standard_Transient* anOwnerPtr = anOwner.operator->(); + Standard_Transient* anOwnerPtr = anOwner.get(); if (aSelectedIds.contains ((size_t)anOwnerPtr)) continue; aSelectedIds.append ((size_t)anOwnerPtr); @@ -359,7 +329,7 @@ QList VInspector_Tools::GetSelectedInfo (const Handle(AIS_InteractiveC aSelectedPointers.append (anIOInfo[1].toString()); aSelectedTypes.append (anIOInfo[2].toString()); } - aSelectedOwners.append (VInspector_Tools::GetPointerInfo (anOwnerPtr, true).ToCString()); + aSelectedOwners.append (Standard_Dump::GetPointerInfo (anOwnerPtr, true).ToCString()); } aValues.append (aSelectedNames.join (", ")); aValues.append (aSelectedPointers.join (", ")); @@ -378,125 +348,39 @@ QString VInspector_Tools::GetSelectedInfoPointers (const Handle(AIS_InteractiveC return aSelectedInfo.size() > 2 ? aSelectedInfo[1].toString() : QString(); } -// ======================================================================= -// function : ToName -// purpose : -// ======================================================================= -TCollection_AsciiString VInspector_Tools::ToName (const VInspector_SelectionType theType, const int theValue) -{ - switch (theType) - { - case VInspector_SelectionType_TypeOfUpdate: - { - switch (theValue) - { - case SelectMgr_TOU_Full: return "Full"; - case SelectMgr_TOU_Partial: return "Partial"; - case SelectMgr_TOU_None: return "None"; - default: break; - } - } - break; - case VInspector_SelectionType_StateOfSelection: - { - switch (theValue) - { - case SelectMgr_SOS_Any: return "Any"; - case SelectMgr_SOS_Unknown: return "Unknown"; - case SelectMgr_SOS_Activated: return "Activated"; - case SelectMgr_SOS_Deactivated: return "Deactivated"; - default: break; - } - } - break; - case VInspector_SelectionType_TypeOfBVHUpdate: - { - switch (theValue) - { - case SelectMgr_TBU_Add: return "Add"; - case SelectMgr_TBU_Remove: return "Remove"; - case SelectMgr_TBU_Renew: return "Renew"; - case SelectMgr_TBU_Invalidate: return "Invalidate"; - case SelectMgr_TBU_None: return "None"; - default: break; - } - } - default: break; - } - return ""; -} - -// ======================================================================= -// function : SelectionModeToName -// purpose : -// ======================================================================= -TCollection_AsciiString VInspector_Tools::SelectionModeToName (int theMode, const Handle(AIS_InteractiveObject)& thePresentation) +namespace { - // types are obtained by comment of SelectMgr_Selection class; - Handle(AIS_Shape) aShapePresentation = Handle(AIS_Shape)::DownCast (thePresentation); - if (!aShapePresentation.IsNull()) - return VInspector_Tools::GetShapeTypeInfo (AIS_Shape::SelectionType (theMode)).ToCString(); - else + static Standard_CString VInspector_Table_PrintDisplayActionType[5] = { - Handle(AIS_Trihedron) aTrihedronPresentation = Handle(AIS_Trihedron)::DownCast (thePresentation); - if (!aTrihedronPresentation.IsNull()) - { - switch (theMode) - { - case 0: return "Trihedron"; - case 1: return "Trihedron Origin"; - case 2: return "Trihedron Axes"; - case 3: return "Trihedron Planes"; - default: break; - } - } - } - return TCollection_AsciiString (theMode); + "None", "Display", "Redisplay", "Erase", "Remove" + }; } -// ======================================================================= -// function : OrientationToName -// purpose : -// ======================================================================= -TCollection_AsciiString VInspector_Tools::OrientationToName (const TopAbs_Orientation& theOrientation) +//======================================================================= +//function : DisplayActionTypeToString +//purpose : +//======================================================================= +Standard_CString VInspector_Tools::DisplayActionTypeToString (View_DisplayActionType theType) { - Standard_SStream aSStream; - TopAbs::Print(theOrientation, aSStream); - return aSStream.str().c_str(); + return VInspector_Table_PrintDisplayActionType[theType]; } -// ======================================================================= -// function : LocationToName -// purpose : -// ======================================================================= -TCollection_AsciiString VInspector_Tools::LocationToName (const TopLoc_Location& theLocation) +//======================================================================= +//function : DisplayActionTypeFromString +//purpose : +//======================================================================= +Standard_Boolean VInspector_Tools::DisplayActionTypeFromString (Standard_CString theTypeString, + View_DisplayActionType& theType) { - gp_Trsf aTrsf = theLocation.Transformation(); - - TCollection_AsciiString aValues; - for (int aRowId = 1; aRowId <= 3; aRowId++) + const TCollection_AsciiString aName (theTypeString); + for (Standard_Integer aTypeIter = 0; aTypeIter <= View_DisplayActionType_RemoveId; ++aTypeIter) { - for (int aColId = 1; aColId <= 4; aColId++) { - aValues += TCollection_AsciiString (aTrsf.Value(aRowId, aColId)); - if (aColId != 4) - aValues += ","; + Standard_CString aTypeName = VInspector_Table_PrintDisplayActionType[aTypeIter]; + if (aName == aTypeName) + { + theType = View_DisplayActionType (aTypeIter); + return Standard_True; } - if (aRowId != 3) - aValues += " "; } - return aValues; -} - -// ======================================================================= -// function : ReadShape -// purpose : -// ======================================================================= -TopoDS_Shape VInspector_Tools::ReadShape (const TCollection_AsciiString& theFileName) -{ - TopoDS_Shape aShape; - - BRep_Builder aBuilder; - BRepTools::Read (aShape, theFileName.ToCString(), aBuilder); - - return aShape; + return Standard_False; } diff --git a/tools/VInspector/VInspector_Tools.hxx b/tools/VInspector/VInspector_Tools.hxx index 5b116b446f..2b65f9d338 100644 --- a/tools/VInspector/VInspector_Tools.hxx +++ b/tools/VInspector/VInspector_Tools.hxx @@ -17,6 +17,12 @@ #define VInspector_Tools_H #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -26,13 +32,21 @@ #include #include -#include +#include + +#include #include #include #include #include +class ViewControl_TableModelValues; + +class Graphic3d_IndexBuffer; +class Graphic3d_Buffer; +class Graphic3d_BoundBuffer; + //! \class VInspector_Tools //! The class that gives auxiliary methods for Visualization elements manipulation class VInspector_Tools @@ -45,13 +59,6 @@ public: //! \return text value Standard_EXPORT static TCollection_AsciiString GetShapeTypeInfo (const TopAbs_ShapeEnum& theType); - //! Convert pointer to string value - //! \param thePointer a pointer - //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped - //! \return the string value - Standard_EXPORT static TCollection_AsciiString GetPointerInfo (const Handle(Standard_Transient)& thePointer, - const bool isShortInfo); - //! Returns number of selected owners for presentation //! \param theContext an interactive context //! \param theObject a presentation @@ -65,27 +72,27 @@ public: //! \param theOwner a selectable owner //! \return boolean value Standard_EXPORT static bool IsOwnerSelected (const Handle(AIS_InteractiveContext)& theContext, - const Handle(SelectMgr_EntityOwner)& theOwner); + const Handle(SelectBasics_EntityOwner)& theOwner); //! Returns all owners present in the context //! \param theContext an interactive context //! \return container of owners - Standard_EXPORT static NCollection_List ContextOwners ( + Standard_EXPORT static NCollection_List ContextOwners ( const Handle(AIS_InteractiveContext)& theContext); //! Returns active owners in main selector of context //! \param theContext an interactive context //! \param theEmptySelectableOwners container of owners with NULL presentation or not displayed presentation //! \return container of owners - Standard_EXPORT static NCollection_List ActiveOwners ( + Standard_EXPORT static NCollection_List ActiveOwners ( const Handle(AIS_InteractiveContext)& theContext, - NCollection_List& theEmptySelectableOwners); + NCollection_List& theEmptySelectableOwners); //! Unhighlight selected, set selected the owners //! \param theContext an interactive context //! \param theOwners a container of owners Standard_EXPORT static void AddOrRemoveSelectedShapes (const Handle(AIS_InteractiveContext)& theContext, - const NCollection_List& theOwners); + const NCollection_List& theOwners); //! Unhighlight selected, set selected presentations //! \param theContext an interactive context @@ -111,32 +118,27 @@ public: //! Returns the first pointer of selection in the context Standard_EXPORT static QString GetSelectedInfoPointers (const Handle(AIS_InteractiveContext)& theContext); - //! Returns string information of call back mode - //! \param theMode type of selection - //! \param theValue a value in selection enumeration - //! \return information text - Standard_EXPORT static TCollection_AsciiString ToName (const VInspector_SelectionType theType, const int theValue); - - //! Returns selection information - //! \param theMode a selection mode - //! \param thePresentation a presentation - //! \return text value - Standard_EXPORT static TCollection_AsciiString SelectionModeToName (int theMode, const Handle(AIS_InteractiveObject)& thePresentation); - - //! Returns text of orientation - //! \param theOrientation an orientation value - //! \return text value - Standard_EXPORT static TCollection_AsciiString OrientationToName (const TopAbs_Orientation& theOrientation); - - //! Returns text of orientation - //! \param theLocation a location value - //! \return text value - Standard_EXPORT static TCollection_AsciiString LocationToName (const TopLoc_Location& theLocation); - - //! Read Shape using BREP reader - //! \param theFileName a file name - //! \return shape or NULL - Standard_EXPORT static TopoDS_Shape ReadShape (const TCollection_AsciiString& theFileName); + //! Returns the string name for a given type. + //! @param theType action type + //! @return string identifier from the display action type + Standard_EXPORT static Standard_CString DisplayActionTypeToString (View_DisplayActionType theType); + + //! Returns the enumeration type from the given string identifier (using case-insensitive comparison). + //! @param theTypeString string identifier + //! @return string identifier from the display action type + static View_DisplayActionType DisplayActionTypeFromString (Standard_CString theTypeString) + { + View_DisplayActionType aType = View_DisplayActionType_NoneId; + DisplayActionTypeFromString (theTypeString, aType); + return aType; + } + + //! Determines the enumeration type from the given string identifier (using case-insensitive comparison). + //! @param theTypeString string identifier + //! @param theType detected action type + //! @return TRUE if string identifier is known + Standard_EXPORT static Standard_Boolean DisplayActionTypeFromString (Standard_CString theTypeString, + View_DisplayActionType& theType); }; #endif diff --git a/tools/VInspector/VInspector_ViewModel.cxx b/tools/VInspector/VInspector_ViewModel.cxx index 207ad48541..2ca792b334 100644 --- a/tools/VInspector/VInspector_ViewModel.cxx +++ b/tools/VInspector/VInspector_ViewModel.cxx @@ -17,20 +17,14 @@ #include #include -#include #include -#include -#include #include #include #include #include -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 @@ -39,42 +33,27 @@ const int COLUMN_SHAPE_TYPE_WIDTH = 75; VInspector_ViewModel::VInspector_ViewModel (QObject* theParent) : 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 ("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 - - SetHeaderItem (20, TreeModel_HeaderSection ("Color", -1)); // ItemPresentableObject +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void VInspector_ViewModel::InitColumns() +{ + TreeModel_ModelBase::InitColumns(); + + SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); + SetHeaderItem (4, TreeModel_HeaderSection ("SelectedOwners", -1)); } // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void VInspector_ViewModel::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr VInspector_ViewModel::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return VInspector_ItemContext::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= @@ -95,29 +74,42 @@ void VInspector_ViewModel::SetContext (const Handle(AIS_InteractiveContext)& the // fill root item by the application for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++) itemDynamicCast(myRootItems[aColId])->SetContext (theContext); - EmitLayoutChanged(); + + UpdateTreeModel(); } // ======================================================================= // function : FindPointers // purpose : // ======================================================================= -QModelIndexList VInspector_ViewModel::FindPointers (const QStringList& thePointers) +void VInspector_ViewModel::FindPointers (const QStringList& thePointers, + const QModelIndex& theParent, + QModelIndexList& theFoundIndices) { - QModelIndexList anIndices; - QModelIndex aParentIndex = index (0, 0); + (void)thePointers; + (void)theParent; + (void)theFoundIndices; + // should be used after Object of items is improved, as it takes a lot of time on BVH item + /* + if (thePointers.isEmpty()) + return; + + QModelIndex aParentIndex = theParent.isValid() ? theParent : index (0, 0); TreeModel_ItemBasePtr aParentItem = TreeModel_ModelBase::GetItemByIndex (aParentIndex); // context item for (int aRowId = 0, aCount = aParentItem->rowCount(); aRowId < aCount; aRowId++) { QModelIndex anIndex = index (aRowId, 0, aParentIndex); TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); - VInspector_ItemPresentableObjectPtr anItemPrs = itemDynamicCast(anItemBase); - if (!anItemPrs) + VInspector_ItemBasePtr aVItem = itemDynamicCast(anItemBase); + if (!aVItem) continue; - if (thePointers.contains (anItemPrs->PointerInfo())) - anIndices.append (anIndex); - } - return anIndices; + const Handle(Standard_Transient)& anObject = aVItem->Object(); + TCollection_AsciiString aPointerInfo = Standard_Dump::GetPointerInfo (anObject); + if (thePointers.contains (aPointerInfo.ToCString())) + theFoundIndices.append (anIndex); + + FindPointers (thePointers, anIndex, theFoundIndices); + }*/ } // ======================================================================= @@ -141,49 +133,6 @@ QModelIndex VInspector_ViewModel::FindIndex (const Handle(AIS_InteractiveObject) return QModelIndex(); } -// ======================================================================= -// function : GetSelectedOwners -// purpose : -// ======================================================================= -void VInspector_ViewModel::GetSelectedOwners (QItemSelectionModel* theSelectionModel, - NCollection_List& theOwners) -{ - if (!theSelectionModel) - return; - QList anItems; - - QModelIndexList anIndices = theSelectionModel->selectedIndexes(); - for (QModelIndexList::const_iterator anIndicesIt = anIndices.begin(); anIndicesIt != anIndices.end(); anIndicesIt++) - { - TreeModel_ItemBasePtr anItem = TreeModel_ModelBase::GetItemByIndex (*anIndicesIt); - if (!anItem || anItems.contains (anItem)) - continue; - anItems.append (anItem); - } - - QList aSelectedIds; // Remember of selected address in order to avoid duplicates - for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); anItemIt++) - { - TreeModel_ItemBasePtr anItem = *anItemIt; - Handle(SelectMgr_EntityOwner) anEntityOwner; - if (VInspector_ItemEntityOwnerPtr anOwnerItem = itemDynamicCast(anItem)) - { - anEntityOwner = anOwnerItem->EntityOwner(); - } - else if (VInspector_ItemSensitiveEntityPtr aSensItem = itemDynamicCast(anItem)) - { - anEntityOwner = aSensItem->GetSensitiveEntity()->BaseSensitive()->OwnerId(); - } - if (anEntityOwner.IsNull()) - continue; - if (aSelectedIds.contains ((size_t)anEntityOwner.operator->())) - continue; - aSelectedIds.append ((size_t)anEntityOwner.operator->()); - if (!anEntityOwner.IsNull()) - theOwners.Append (anEntityOwner); - } -} - // ======================================================================= // function : UpdateTreeModel // purpose : diff --git a/tools/VInspector/VInspector_ViewModel.hxx b/tools/VInspector/VInspector_ViewModel.hxx index 839e550057..906f9f60f7 100644 --- a/tools/VInspector/VInspector_ViewModel.hxx +++ b/tools/VInspector/VInspector_ViewModel.hxx @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -47,7 +47,10 @@ public: Standard_EXPORT VInspector_ViewModel (QObject* theParent); //! Destructor - virtual ~VInspector_ViewModel() Standard_OVERRIDE {}; + virtual ~VInspector_ViewModel() {} + + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; //! Initialize the model by the given context //! \param theContext viewer context @@ -59,38 +62,25 @@ public: //! Returns tree view indices for the given pointers of presentable object //! \param thePointers a list of presentation pointers - //! \return container of indices - Standard_EXPORT QModelIndexList FindPointers (const QStringList& thePointers); + //! \param theParent an index of the parent item + //! \param [out] container of indices + Standard_EXPORT void FindPointers (const QStringList& thePointers, + const QModelIndex& theParent, + QModelIndexList& theFoundIndices); //! Returns tree model index of the presentation item in the tree view. //! \param thePresentation a presentation //! \return model index if the value is found or Null model index Standard_EXPORT QModelIndex FindIndex (const Handle(AIS_InteractiveObject)& thePresentation) const; - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const Standard_OVERRIDE - { return myRootItems[theColumn]; } - - //! 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& 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: + Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; - QMap myRootItems; //!< container of root items, for each column own root item }; #endif diff --git a/tools/VInspector/VInspector_ViewModelHistory.cxx b/tools/VInspector/VInspector_ViewModelHistory.cxx index de42b99fd7..980dc1e865 100644 --- a/tools/VInspector/VInspector_ViewModelHistory.cxx +++ b/tools/VInspector/VInspector_ViewModelHistory.cxx @@ -42,32 +42,40 @@ const int HISTORY_AIS_NAME_COLUMN_WIDTH = 140; // purpose : // ======================================================================= VInspector_ViewModelHistory::VInspector_ViewModelHistory (QObject* theParent, const int theHistoryTypesMaxAmount) -: TreeModel_ModelBase (theParent) +: TreeModel_ModelBase (theParent), myHistoryTypesMaxAmount (theHistoryTypesMaxAmount) { +} + +// ======================================================================= +// function : InitColumns +// purpose : +// ======================================================================= +void VInspector_ViewModelHistory::InitColumns() +{ + TreeModel_ModelBase::InitColumns(); + 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)); + SetHeaderItem (1, TreeModel_HeaderSection ("Visibility", COLUMN_SIZE_WIDTH)); // visualization item + SetHeaderItem (2, TreeModel_HeaderSection ("Size", COLUMN_SIZE_WIDTH)); + SetHeaderItem (3, TreeModel_HeaderSection ("Pointer", COLUMN_POINTER_WIDTH)); + SetHeaderItem (4, TreeModel_HeaderSection ("Shape type", COLUMN_SHAPE_TYPE_WIDTH)); + SetHeaderItem (5, TreeModel_HeaderSection ("AIS Name", COLUMN_AIS_NAME_WIDTH)); + SetHeaderItem (6, TreeModel_HeaderSection ("Selected/Highlighted", -1)); for (int aColumnId = 0, aNbColumns = columnCount(); aColumnId < aNbColumns; aColumnId++) { VInspector_ItemHistoryRootPtr aRootItem = itemDynamicCast (myRootItems[aColumnId]); - aRootItem->SetHistoryTypesMaxAmount (theHistoryTypesMaxAmount); + aRootItem->SetHistoryTypesMaxAmount (myHistoryTypesMaxAmount); } } - // ======================================================================= // function : createRootItem // purpose : // ======================================================================= -void VInspector_ViewModelHistory::createRootItem (const int theColumnId) +TreeModel_ItemBasePtr VInspector_ViewModelHistory::createRootItem (const int theColumnId) { - myRootItems.insert (theColumnId, VInspector_ItemHistoryRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId)); - if (theColumnId == 0) - m_pRootItem = myRootItems[0]; + return VInspector_ItemHistoryRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId); } // ======================================================================= diff --git a/tools/VInspector/VInspector_ViewModelHistory.hxx b/tools/VInspector/VInspector_ViewModelHistory.hxx index d4215c3475..304023477e 100644 --- a/tools/VInspector/VInspector_ViewModelHistory.hxx +++ b/tools/VInspector/VInspector_ViewModelHistory.hxx @@ -41,7 +41,10 @@ public: Standard_EXPORT VInspector_ViewModelHistory (QObject* theParent, const int theHistoryTypesMaxAmount = 50); //! Destructor - virtual ~VInspector_ViewModelHistory() Standard_OVERRIDE {}; + virtual ~VInspector_ViewModelHistory() {} + + //! Creates model columns and root items. + Standard_EXPORT virtual void InitColumns() Standard_OVERRIDE; //! Append new element under the root item Standard_EXPORT void AddElement (const VInspector_CallBackMode& theMode, const QList& theInfo); @@ -51,20 +54,14 @@ public: //! \param container of strings Standard_EXPORT QStringList GetSelectedPointers (const QModelIndex& theIndex); - //! Returns root item by column - //! \param theColumn an index of the column - //! \return root item instance - virtual TreeModel_ItemBasePtr RootItem(const int theColumn) const Standard_OVERRIDE { return myRootItems[theColumn]; } - protected: //! Creates root item //! \param theColumnId index of a column - virtual void createRootItem (const int theColumnId) Standard_OVERRIDE; + Standard_EXPORT virtual TreeModel_ItemBasePtr createRootItem (const int theColumnId) Standard_OVERRIDE; private: - - QMap myRootItems; //!< container of root items, for each column own root item + int myHistoryTypesMaxAmount; //!< maximum types in history }; #endif diff --git a/tools/VInspector/VInspector_Window.cxx b/tools/VInspector/VInspector_Window.cxx index e102fbb709..22ed9e50f6 100644 --- a/tools/VInspector/VInspector_Window.cxx +++ b/tools/VInspector/VInspector_Window.cxx @@ -16,29 +16,37 @@ #include #include +#include + +#include #include #include +#include #include #include +#include #include +#include -#include #include #include #include #include #include -#include -#include +#include #include #include #include #include +#include #include +#include +#include +#include #include #include @@ -56,6 +64,9 @@ #include #include +const int VINSPECTOR_DEFAULT_PROPERTY_VIEW_WIDTH = 300; +const int VINSPECTOR_DEFAULT_PROPERTY_VIEW_HEIGHT = 1000; + const int VINSPECTOR_DEFAULT_WIDTH = 1250; const int VINSPECTOR_DEFAULT_HEIGHT = 800; @@ -78,6 +89,8 @@ const int VINSPECTOR_DEFAULT_VIEW_POSITION_Y = 60; // TINSPECTOR_DEFAULT_POSITIO VInspector_Window::VInspector_Window() : myParent (0), myExportToShapeViewDialog (0), myViewWindow (0) { + myDisplayer = new View_Displayer(); + myMainWindow = new QMainWindow (0); QWidget* aCentralWidget = new QWidget (myMainWindow); @@ -97,6 +110,7 @@ VInspector_Window::VInspector_Window() myTreeView->header()->setStretchLastSection (true); myTreeView->setContextMenuPolicy(Qt::CustomContextMenu); VInspector_ViewModel* aTreeModel = new VInspector_ViewModel (myTreeView); + aTreeModel->InitColumns(); myTreeView->setModel (aTreeModel); // hide Visibility column TreeModel_HeaderSection anItem = aTreeModel->GetHeaderItem ((int)TreeModel_ColumnType_Visibility); @@ -110,12 +124,22 @@ VInspector_Window::VInspector_Window() 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&))); + this, SLOT (onTreeViewSelectionChanged (const QItemSelection&, const QItemSelection&))); aParentLay->addWidget(myTreeView, 1, 0); aParentLay->setRowStretch (1, 1); myMainWindow->setCentralWidget (aCentralWidget); + // property view + myPropertyView = new ViewControl_PropertyView (myMainWindow, + QSize(VINSPECTOR_DEFAULT_PROPERTY_VIEW_WIDTH, VINSPECTOR_DEFAULT_PROPERTY_VIEW_HEIGHT)); + myPropertyPanelWidget = new QDockWidget (tr ("PropertyPanel"), myMainWindow); + myPropertyPanelWidget->setObjectName (myPropertyPanelWidget->windowTitle()); + myPropertyPanelWidget->setTitleBarWidget (new QWidget(myMainWindow)); + myPropertyPanelWidget->setWidget (myPropertyView->GetControl()); + myMainWindow->addDockWidget (Qt::RightDockWidgetArea, myPropertyPanelWidget); + connect (myPropertyPanelWidget->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT (onPropertyPanelShown (bool))); + myHistoryView = new ViewControl_TreeView (myMainWindow); myHistoryView->setSelectionBehavior (QAbstractItemView::SelectRows); ((ViewControl_TreeView*)myHistoryView)->SetPredefinedSize (QSize (VINSPECTOR_DEFAULT_HISTORY_VIEW_WIDTH, @@ -126,6 +150,7 @@ VInspector_Window::VInspector_Window() myHistoryView->setSelectionMode (QAbstractItemView::ExtendedSelection); VInspector_ViewModelHistory* aHistoryModel = new VInspector_ViewModelHistory (myHistoryView); + aHistoryModel->InitColumns(); myHistoryView->setModel (aHistoryModel); QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aHistoryModel); @@ -134,8 +159,8 @@ VInspector_Window::VInspector_Window() this, SLOT (onHistoryViewSelectionChanged (const QItemSelection&, const QItemSelection&))); anItem = aHistoryModel->GetHeaderItem (0); - TreeModel_Tools::UseVisibilityColumn (myHistoryView, false); // hide Visibility column + TreeModel_Tools::UseVisibilityColumn (myHistoryView, false); anItem = aHistoryModel->GetHeaderItem ((int)TreeModel_ColumnType_Visibility); anItem.SetIsHidden (true); aHistoryModel->SetHeaderItem ((int)TreeModel_ColumnType_Visibility, anItem); @@ -203,9 +228,29 @@ void VInspector_Window::GetPreferences (TInspectorAPI_PreferencesDataMap& theIte } anItems.clear(); - TreeModel_Tools::SaveState (myHistoryView, anItems, "history_view_"); + View_PreviewParameters::SaveState (displayer()->DisplayPreview()->GetPreviewParameters(), anItems, "preview_parameters_"); for (QMap::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 (myTreeView, anItems); + for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) + { + theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); + } + + anItems.clear(); + ViewControl_PropertyView::SaveState (myPropertyView, anItems, "property_view_parameters_"); + for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) + theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); + + if (myViewWindow) + { + anItems.clear(); + View_Window::SaveState(myViewWindow, anItems); + for (QMap::const_iterator anItemsIt = anItems.begin(); anItemsIt != anItems.end(); anItemsIt++) + theItem.Bind (anItemsIt.key().toStdString().c_str(), anItemsIt.value().toStdString().c_str()); + } } // ======================================================================= @@ -223,13 +268,23 @@ void VInspector_Window::SetPreferences (const TInspectorAPI_PreferencesDataMap& 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())) + TCollection_AsciiString anItemKey = anItemIt.Key(); + TCollection_AsciiString anItemValue = anItemIt.Value(); + if (anItemKey.IsEqual ("geometry")) + myMainWindow->restoreState (TreeModel_Tools::ToByteArray (anItemValue.ToCString())); + else if (TreeModel_Tools::RestoreState (myTreeView, anItemKey.ToCString(), anItemValue.ToCString())) continue; - else if (TreeModel_Tools::RestoreState (myHistoryView, anItemIt.Key().ToCString(), anItemIt.Value().ToCString(), + else if (TreeModel_Tools::RestoreState (myHistoryView, anItemKey.ToCString(), anItemValue.ToCString(), "history_view_")) continue; + else if (View_PreviewParameters::RestoreState (displayer()->DisplayPreview()->GetPreviewParameters(), anItemKey.ToCString(), + anItemValue.ToCString(), "preview_parameters_")) + continue; + else if (ViewControl_PropertyView::RestoreState (myPropertyView, anItemKey.ToCString(), + anItemValue.ToCString(), "property_view_parameters_")) + continue; + else if (myViewWindow && View_Window::RestoreState(myViewWindow, anItemIt.Key().ToCString(), anItemIt.Value().ToCString())) + continue; } } @@ -278,6 +333,73 @@ void VInspector_Window::UpdateContent() myTreeView->scrollTo (aPresentationIndex); } } + + if (!myCallBack.IsNull()) + { + VInspector_ViewModelHistory* aHistoryModel = dynamic_cast + (myHistoryView->model()); + aHistoryModel->Reset(); + aHistoryModel->EmitLayoutChanged(); + } +} + +// ======================================================================= +// function : SelectedPresentations +// purpose : +// ======================================================================= +NCollection_List VInspector_Window::SelectedPresentations (QItemSelectionModel* theModel) +{ + NCollection_List aSelectedPresentations; + + QList anItems = TreeModel_ModelBase::SelectedItems (theModel->selectedIndexes()); + + QList aSelectedIds; // Remember of selected address in order to avoid duplicates + NCollection_List anItemPresentations; + for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt) + { + TreeModel_ItemBasePtr anItem = *anItemIt; + VInspector_ItemBasePtr aVItem = itemDynamicCast(anItem); + if (!aVItem) + continue; + + anItemPresentations.Clear(); + aVItem->Presentations (anItemPresentations); + + for (NCollection_List::Iterator anIt (anItemPresentations); anIt.More(); anIt.Next()) + { + Handle(AIS_InteractiveObject) aPresentation = Handle(AIS_InteractiveObject)::DownCast (anIt.Value()); + if (aSelectedIds.contains ((size_t)aPresentation.get())) + continue; + aSelectedIds.append ((size_t)aPresentation.get()); + if (!aPresentation.IsNull()) + aSelectedPresentations.Append (aPresentation); + } + } + return aSelectedPresentations; +} + +// ======================================================================= +// function : SelectedShapes +// purpose : +// ======================================================================= +void VInspector_Window::SelectedShapes (NCollection_List& theSelPresentations) +{ + QModelIndexList theIndices = myTreeView->selectionModel()->selectedIndexes(); + + QList anItems = TreeModel_ModelBase::SelectedItems (theIndices); + for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt) + { + TreeModel_ItemBasePtr anItem = *anItemIt; + VInspector_ItemBasePtr aVItem = itemDynamicCast(anItem); + if (!aVItem /*|| aVItem->Row() == 0*/) + continue; + + TopoDS_Shape aShape = aVItem->GetPresentationShape(); + if (aShape.IsNull()) + continue; + + theSelPresentations.Append (new Convert_TransientShape (aShape)); + } } // ======================================================================= @@ -286,8 +408,13 @@ void VInspector_Window::UpdateContent() // ======================================================================= bool VInspector_Window::Init (const NCollection_List& theParameters) { + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); + if (!aViewModel) + return Standard_False; + Handle(AIS_InteractiveContext) aContext; Handle(VInspector_CallBack) aCallBack; + Standard_Boolean isModelUpdated = Standard_False; for (NCollection_List::Iterator aParamsIt (theParameters); aParamsIt.More(); aParamsIt.Next()) { @@ -298,13 +425,10 @@ bool VInspector_Window::Init (const NCollection_List if (aCallBack.IsNull()) aCallBack = Handle(VInspector_CallBack)::DownCast (anObject); } - if (aContext.IsNull()) - return false; - VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); - if (aViewModel && aViewModel->GetContext() == aContext) - UpdateTreeModel(); + if (aViewModel->GetContext() != aContext) + SetContext(aContext); else - SetContext (aContext); + isModelUpdated = Standard_True; if (!aCallBack.IsNull() && aCallBack != myCallBack) { @@ -314,6 +438,10 @@ bool VInspector_Window::Init (const NCollection_List myCallBack->SetContext(aContext); myCallBack->SetHistoryModel(aHistoryModel); } + + if (isModelUpdated) + UpdateTreeModel(); + return true; } @@ -323,12 +451,18 @@ bool VInspector_Window::Init (const NCollection_List // ======================================================================= void VInspector_Window::SetContext (const Handle(AIS_InteractiveContext)& theContext) { + if (theContext.IsNull()) + return; + VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); aViewModel->SetContext (theContext); myTreeView->setExpanded (aViewModel->index (0, 0), true); if (!myCallBack.IsNull()) myCallBack->SetContext (theContext); + + if (myDisplayer) + myDisplayer->SetContext (theContext); } // ======================================================================= @@ -350,13 +484,13 @@ bool VInspector_Window::OpenFile(const TCollection_AsciiString& theFileName) isModelUpdated = true; } - TopoDS_Shape aShape = VInspector_Tools::ReadShape (theFileName); + TopoDS_Shape aShape = Convert_Tools::ReadShape (theFileName); if (aShape.IsNull()) return isModelUpdated; Handle(AIS_Shape) aPresentation = new AIS_Shape (aShape); - aContext->Display (aPresentation, false); - aContext->Load (aPresentation, -1/*selection mode*/); + View_Displayer* aDisplayer = myViewWindow->Displayer(); + aDisplayer->DisplayPresentation (aPresentation); aContext->UpdateCurrentViewer(); UpdateTreeModel(); @@ -372,8 +506,34 @@ void VInspector_Window::onTreeViewContextMenuRequested(const QPoint& thePosition { QMenu* aMenu = new QMenu (GetMainWindow()); 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)); + aMenu->addSeparator(); + + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (myTreeView->selectionModel()->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (anItemBase) + { + if (itemDynamicCast (anItemBase)) + { + aMenu->addAction (ViewControl_Tools::CreateAction (tr ("Export to MessageView"), SLOT (onExportToMessageView()), GetMainWindow(), this)); + aMenu->addSeparator(); + } + } + + aMenu->addSeparator(); + for (int aTypeId = (int)View_DisplayActionType_DisplayId; aTypeId <= (int)View_DisplayActionType_RemoveId; aTypeId++) + { + aMenu->addAction (ViewControl_Tools::CreateAction (VInspector_Tools::DisplayActionTypeToString ((View_DisplayActionType) aTypeId), + SLOT (onDisplayActionTypeClicked()), GetMainWindow(), this)); + } + aMenu->addSeparator(); + + 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)); + + aMenu->addSeparator(); + aMenu->addAction (ViewControl_Tools::CreateAction ("Test AddChild", SLOT (OnTestAddChild()), GetMainWindow(), this)); + QPoint aPoint = myTreeView->mapToGlobal (thePosition); aMenu->exec(aPoint); } @@ -395,46 +555,55 @@ void VInspector_Window::onToolBarActionClicked (const int theActionId) UpdateTreeModel(); break; } - case VInspector_ToolActionType_SelectPresentationsId: - { - bool isChecked = myToolBar->GetToolButton((VInspector_ToolActionType)theActionId)->isChecked(); - NCollection_List aPresentationsForViewer; - if (isChecked) - aPresentationsForViewer = VInspector_ItemPresentableObject::GetSelectedPresentations(myTreeView->selectionModel()); - Handle(AIS_InteractiveContext) aContext = aViewModel->GetContext(); - VInspector_Tools::AddOrRemovePresentations(aContext, aPresentationsForViewer); - UpdateTreeModel(); - break; - } - case VInspector_ToolActionType_SelectOwnersId: - { - NCollection_List anOwnersForViewer; - if (myToolBar->GetToolButton((VInspector_ToolActionType)theActionId)->isChecked()) - VInspector_ViewModel::GetSelectedOwners(myTreeView->selectionModel(), anOwnersForViewer); - VInspector_Tools::AddOrRemoveSelectedShapes(aViewModel->GetContext(), anOwnersForViewer); - UpdateTreeModel(); - break; - } default: break; } } // ======================================================================= -// function : onSelectionChanged +// function : onPropertyPanelShown // purpose : // ======================================================================= -void VInspector_Window::onSelectionChanged (const QItemSelection&, - const QItemSelection&) +void VInspector_Window::onPropertyPanelShown (bool isToggled) { - QApplication::setOverrideCursor (Qt::WaitCursor); + if (!isToggled) + return; - if (myToolBar->GetToolButton(VInspector_ToolActionType_SelectPresentationsId)->isChecked()) - onToolBarActionClicked(VInspector_ToolActionType_SelectPresentationsId); - else if (myToolBar->GetToolButton(VInspector_ToolActionType_SelectOwnersId)->isChecked()) - onToolBarActionClicked(VInspector_ToolActionType_SelectOwnersId); + myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel())); +} - QApplication::restoreOverrideCursor(); +// ======================================================================= +// function : onTreeViewSelectionChanged +// purpose : +// ======================================================================= +void VInspector_Window::onTreeViewSelectionChanged (const QItemSelection&, + const QItemSelection&) +{ + if (myPropertyPanelWidget->toggleViewAction()->isChecked()) + myPropertyView->Init (ViewControl_Tools::CreateTableModelValues (myTreeView->selectionModel())); + + NCollection_List aSelPresentations; + + QModelIndexList aSelectedIndices = myTreeView->selectionModel()->selectedIndexes(); + for (QModelIndexList::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++) + { + QModelIndex anIndex = *aSelIt; + if (anIndex.column() != 0) + continue; + + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + continue; + + const Handle(TreeModel_ItemProperties)& anItemProperties = anItemBase->Properties(); + if (anItemProperties) + { + anItemProperties->Presentations (aSelPresentations); + } + } + + SelectedShapes (aSelPresentations); + displayer()->DisplayPreview()->UpdatePreview (View_DisplayActionType_DisplayId, aSelPresentations, myViewWindow->ViewWidget()->DisplayMode()); } // ======================================================================= @@ -453,20 +622,7 @@ void VInspector_Window::onHistoryViewSelectionChanged (const QItemSelection& the QModelIndexList aSelectedIndices = theSelected.indexes(); QStringList aPointers = aHistoryModel->GetSelectedPointers(aSelectedIndices.first()); - - VInspector_ViewModel* aTreeModel = dynamic_cast (myTreeView->model()); - if (!aTreeModel) - return; - - QModelIndexList anIndices = aTreeModel->FindPointers (aPointers); - QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); - aSelectionModel->clear(); - for (int anIndicesId = 0, aSize = anIndices.size(); anIndicesId < aSize; anIndicesId++) - { - QModelIndex anIndex = anIndices[anIndicesId]; - myTreeView->setExpanded (aTreeModel->parent (anIndex), true); - aSelectionModel->select (anIndex, QItemSelectionModel::Select); - } + selectTreeViewItems (aPointers); } // ======================================================================= @@ -475,10 +631,8 @@ void VInspector_Window::onHistoryViewSelectionChanged (const QItemSelection& the // ======================================================================= void VInspector_Window::onExportToShapeView() { - NCollection_List aSelectedPresentations = - VInspector_ItemPresentableObject::GetSelectedPresentations(myTreeView->selectionModel()); - if (aSelectedPresentations.Extent() <= 0) - return; + NCollection_List aSelectedShapes; + SelectedShapes (aSelectedShapes); TCollection_AsciiString aPluginName ("TKShapeView"); NCollection_List aParameters; @@ -490,24 +644,46 @@ void VInspector_Window::onExportToShapeView() anItemNames = myParameters->GetSelectedNames (aPluginName); QStringList anExportedPointers; - for (NCollection_List::Iterator anIOIt (aSelectedPresentations); anIOIt.More(); anIOIt.Next()) + if (aSelectedShapes.Extent() > 0) { - Handle(AIS_Shape) aShapePresentation = Handle(AIS_Shape)::DownCast (anIOIt.Value()); - if (aShapePresentation.IsNull()) - continue; + for (NCollection_List::Iterator aShapeIt (aSelectedShapes); aShapeIt.More(); aShapeIt.Next()) + { + Handle(Convert_TransientShape) aShapePtr = Handle(Convert_TransientShape)::DownCast (aShapeIt.Value()); + if (aShapePtr.IsNull()) + continue; - const TopoDS_Shape& aShape = aShapePresentation->Shape(); - if (aShape.IsNull()) + const TopoDS_Shape& aShape = aShapePtr->Shape(); + if (aShape.IsNull()) + continue; + aParameters.Append (aShape.TShape()); + anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString(aShape)); + anExportedPointers.append (Standard_Dump::GetPointerInfo (aShape.TShape(), true).ToCString()); + } + } + + // search for objects to be exported + QList anItems = TreeModel_ModelBase::SelectedItems (myTreeView->selectionModel()->selectedIndexes()); + for (QList::const_iterator anItemIt = anItems.begin(); anItemIt != anItems.end(); ++anItemIt) + { + TreeModel_ItemBasePtr anItem = *anItemIt; + VInspector_ItemBasePtr aVItem = itemDynamicCast(anItem); + if (!aVItem) + continue; + + const Handle(Standard_Transient)& anObject = aVItem->Object(); + if (anObject.IsNull()) continue; - aParameters.Append (aShape.TShape()); - anItemNames.Append (TInspectorAPI_PluginParameters::ParametersToString(aShape)); - anExportedPointers.append (VInspector_Tools::GetPointerInfo (aShape.TShape(), true).ToCString()); + + aParameters.Append (anObject); + anItemNames.Append (anObject->DynamicType()->Name()); + anExportedPointers.append (Standard_Dump::GetPointerInfo (anObject, true).ToCString()); } - if (anExportedPointers.empty()) + + if (anExportedPointers.isEmpty()) return; TCollection_AsciiString aPluginShortName = aPluginName.SubString (3, aPluginName.Length()); - QString aMessage = QString ("TShape %1 is sent to %2.") + QString aMessage = QString ("Objects %1 are sent to %2.") .arg (anExportedPointers.join(", ")) .arg (aPluginShortName.ToCString()); QString aQuestion = QString ("Would you like to activate %1 immediately?\n") @@ -523,21 +699,82 @@ void VInspector_Window::onExportToShapeView() } // ======================================================================= -// function : onShow +// function : onDisplayActionTypeClicked // purpose : // ======================================================================= -void VInspector_Window::onShow() +void VInspector_Window::onDisplayActionTypeClicked() { - displaySelectedPresentations (true); + QAction* anAction = (QAction*)sender(); + + displaySelectedPresentations (VInspector_Tools::DisplayActionTypeFromString (anAction->text().toStdString().c_str())); } // ======================================================================= -// function : onHide +// function : onExpand // purpose : // ======================================================================= -void VInspector_Window::onHide() +void VInspector_Window::onExpand() { - displaySelectedPresentations (false); + QApplication::setOverrideCursor (Qt::WaitCursor); + + QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); + QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes(); + for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) + { + int aLevels = 2; + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); + } + QApplication::restoreOverrideCursor(); +} + +// ======================================================================= +// function : onExpandAll +// purpose : +// ======================================================================= +void VInspector_Window::onExpandAll() +{ + QApplication::setOverrideCursor (Qt::WaitCursor); + + QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); + QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes(); + for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) + { + int aLevels = -1; + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], true, aLevels); + } + QApplication::restoreOverrideCursor(); +} + +// ======================================================================= +// function : onCollapseAll +// purpose : +// ======================================================================= +void VInspector_Window::onCollapseAll() +{ + QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); + QModelIndexList aSelectedIndices = aSelectionModel->selectedIndexes(); + for (int aSelectedId = 0, aSize = aSelectedIndices.size(); aSelectedId < aSize; aSelectedId++) + { + int aLevels = -1; + TreeModel_Tools::SetExpanded (myTreeView, aSelectedIndices[aSelectedId], false, aLevels); + } +} + +// ======================================================================= +// function : UpdateTreeModel +// purpose : +// ======================================================================= +void VInspector_Window::OnTestAddChild() +{ + Handle(AIS_Shape) aPresentation = new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt())); + + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt (10., 10., 10.)))); + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt(20., 10., 10.)))); + aPresentation->AddChild (new AIS_Shape (BRepBuilderAPI_MakeVertex (gp_Pnt(30., 10., 10.)))); + + displayer()->DisplayPresentation (aPresentation); + + UpdateTreeModel(); } // ======================================================================= @@ -555,7 +792,8 @@ void VInspector_Window::UpdateTreeModel() // function : displaySelectedPresentations // purpose : // ======================================================================= -void VInspector_Window::displaySelectedPresentations(const bool theToDisplay) + +void VInspector_Window::displaySelectedPresentations (const View_DisplayActionType theType) { VInspector_ViewModel* aViewModel = dynamic_cast (myTreeView->model()); if (!aViewModel) @@ -565,30 +803,85 @@ void VInspector_Window::displaySelectedPresentations(const bool theToDisplay) if (aContext.IsNull()) return; - NCollection_List aSelectedPresentations = - VInspector_ItemPresentableObject::GetSelectedPresentations(myTreeView->selectionModel()); - if (aSelectedPresentations.Extent() <= 0) + QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); + if (!aSelectionModel) + return; + + NCollection_List aSelectedPresentations = SelectedPresentations (aSelectionModel); + // the order of objects returned by AIS_InteractiveContext is changed because the processed object is moved from + // Erased to Displayed container or back + aSelectionModel->clear(); + + + if (aSelectedPresentations.Extent() == 0) return; for (NCollection_List::Iterator anIOIt(aSelectedPresentations); anIOIt.More(); anIOIt.Next()) { Handle(AIS_InteractiveObject) aPresentation = anIOIt.Value(); - if (theToDisplay) + switch (theType) { - aContext->Display(aPresentation, false); - aContext->Load(aPresentation, -1); + case View_DisplayActionType_DisplayId: + { + aContext->Display(aPresentation, false); + aContext->Load(aPresentation, -1); + } + break; + + case View_DisplayActionType_RedisplayId: aContext->Redisplay (aPresentation, false); break; + case View_DisplayActionType_EraseId: aContext->Erase (aPresentation, false); break; + case View_DisplayActionType_RemoveId: aContext->Remove (aPresentation, false); break; + default: break; } - else - aContext->Erase(aPresentation, false); } aContext->UpdateCurrentViewer(); - // the order of objects returned by AIS_InteractiveContext is changed because the processed object is moved from - // Erased to Displayed container or back + UpdateTreeModel(); +} + +// ======================================================================= +// function : highlightTreeViewItems +// purpose : +// ======================================================================= +void VInspector_Window::highlightTreeViewItems (const QStringList& thePointers) +{ + VInspector_ViewModel* aTreeModel = dynamic_cast (myTreeView->model()); + if (!aTreeModel) + return; + + QModelIndexList anIndices; + aTreeModel->FindPointers (thePointers, QModelIndex(), anIndices); + for (int anIndicesId = 0, aSize = anIndices.size(); anIndicesId < aSize; anIndicesId++) + { + QModelIndex anIndex = anIndices[anIndicesId]; + TreeModel_Tools::SetExpandedTo (myTreeView, anIndex); + } + aTreeModel->SetHighlighted (anIndices); + + if (!anIndices.isEmpty()) + myTreeView->scrollTo (anIndices.last()); +} + +// ======================================================================= +// function : selectTreeViewItems +// purpose : +// ======================================================================= +void VInspector_Window::selectTreeViewItems (const QStringList& thePointers) +{ + VInspector_ViewModel* aTreeModel = dynamic_cast (myTreeView->model()); + if (!aTreeModel) + return; + + QModelIndexList anIndices; + aTreeModel->FindPointers (thePointers, QModelIndex(), anIndices); QItemSelectionModel* aSelectionModel = myTreeView->selectionModel(); aSelectionModel->clear(); - - UpdateTreeModel(); + for (int anIndicesId = 0, aSize = anIndices.size(); anIndicesId < aSize; anIndicesId++) + { + QModelIndex anIndex = anIndices[anIndicesId]; + TreeModel_Tools::SetExpandedTo (myTreeView, anIndex); + aSelectionModel->select (anIndex, QItemSelectionModel::Select); + } } // ======================================================================= @@ -597,10 +890,25 @@ void VInspector_Window::displaySelectedPresentations(const bool theToDisplay) // ======================================================================= Handle(AIS_InteractiveContext) VInspector_Window::createView() { - myViewWindow = new View_Window (0); - myViewWindow->GetView()->SetPredefinedSize (VINSPECTOR_DEFAULT_VIEW_WIDTH, VINSPECTOR_DEFAULT_VIEW_HEIGHT); + // create two view windows + Handle(AIS_InteractiveContext) aContext = View_Viewer::CreateStandardViewer(); + + myViewWindow = new View_Window (0, aContext, false /*for opening several BREP files*/, true); + myViewWindow->ViewWidget()->SetPredefinedSize (VINSPECTOR_DEFAULT_VIEW_WIDTH, VINSPECTOR_DEFAULT_VIEW_HEIGHT); myViewWindow->move (VINSPECTOR_DEFAULT_VIEW_POSITION_X, VINSPECTOR_DEFAULT_VIEW_POSITION_Y); myViewWindow->show(); - return myViewWindow->GetView()->GetViewer()->GetContext(); + return aContext; +} + +// ======================================================================= +// function : displayer +// purpose : +// ======================================================================= +View_Displayer* VInspector_Window::displayer() +{ + if (myViewWindow) + return myViewWindow->Displayer(); + + return myDisplayer; } diff --git a/tools/VInspector/VInspector_Window.hxx b/tools/VInspector/VInspector_Window.hxx index 73783f39b0..3eedc14685 100644 --- a/tools/VInspector/VInspector_Window.hxx +++ b/tools/VInspector/VInspector_Window.hxx @@ -18,11 +18,12 @@ #include #include -#include +#include #include #include #include +#include #include #include @@ -31,13 +32,16 @@ #include class ViewControl_MessageDialog; +class ViewControl_PropertyView; class VInspector_ToolBar; + +class View_Displayer; class View_Window; class QAbstractItemModel; class QAction; -class QMainWindow; +class QDockWidget; class QTreeView; class QWidget; @@ -53,7 +57,7 @@ public: Standard_EXPORT VInspector_Window(); //! Destructor - virtual ~VInspector_Window() Standard_OVERRIDE {} + virtual ~VInspector_Window() {} //! Provides the container with a parent where this container should be inserted. //! If Qt implementation, it should be QWidget with QLayout set inside @@ -82,6 +86,15 @@ public: //! Returns main control QWidget* GetMainWindow() const { return myMainWindow; } + //! Returns presentations of selected items in tree model + //! \param theModel selection model + //! \return container of presentations + NCollection_List SelectedPresentations (QItemSelectionModel* theModel); + + //! Returns selected shapes + //! \param [out] container of shapes + void SelectedShapes (NCollection_List& theSelPresentations); + private: //! Fills controls of the plugin by parameters: @@ -103,6 +116,10 @@ private slots: //! \param theActionId an action identifier in tool bar void onToolBarActionClicked (const int theActionId); + //! Display content of selected tree view item if isToggled is true + //! \param isToggled true if the property dock widget is shown + void onPropertyPanelShown (bool isToggled); + //! Synchronization selection between history and tree view. Selection by history view //! \param theSelected a selected items //! \param theDeselected a deselected items @@ -113,16 +130,25 @@ private slots: //! check box is checked //! \param theSelected a selected items //! \param theDeselected a deselected items - void onSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + void onTreeViewSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); //! Exports the first selected shape into ShapeViewer plugin. void onExportToShapeView(); - //! Shows selected presentation if it is not shown yet - void onShow(); + //! Apply activated display action + void onDisplayActionTypeClicked(); + + //! Expand two next levels for all selected item + void onExpand(); + + //! Expand all levels for all selected items + void onExpandAll(); + + //! Collapse all levels for all selected items + void onCollapseAll(); - //! Erase selected presentation if it is shown - void onHide(); + //! Creates a tree of inherited presentable objects + void OnTestAddChild(); private: @@ -135,8 +161,20 @@ private: //! 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 - void displaySelectedPresentations (const bool theToDisplay); + //! \param theType display action type + void displaySelectedPresentations (const View_DisplayActionType theType); + + //! Set items of the pointers highlighted in tree view + //! \param theType display action type + void highlightTreeViewItems (const QStringList& thePointers); + + //! Set items of the pointers selected in tree view + //! \param theType display action type + void selectTreeViewItems (const QStringList& thePointers); + + //! Returns displayer where the presentations/preview should be shown/erased + //! If default view is created, it returns displayer of this view + Standard_EXPORT View_Displayer* displayer(); //! Creates an istance of 3D view to initialize context. //! \return a context of created view. @@ -148,6 +186,10 @@ private: QMainWindow* myMainWindow; //!< main control VInspector_ToolBar* myToolBar; //!< tool bar actions + + QDockWidget* myPropertyPanelWidget; //!< property pane dockable widget + ViewControl_PropertyView* myPropertyView; //!< property control to display model item values if exist + QTreeView* myTreeView; //!< tree view of AIS content QTreeView* myHistoryView; //!< history of AIS context calls Handle(VInspector_CallBack) myCallBack; //!< AIS context call back, if set @@ -156,6 +198,8 @@ private: 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_Displayer* myDisplayer; //!< class to display presentations/preview if myMainWindow is not used }; #endif diff --git a/tools/View/FILES b/tools/View/FILES index f0c48897a4..0048d3b829 100644 --- a/tools/View/FILES +++ b/tools/View/FILES @@ -1,14 +1,17 @@ View.qrc View_ContextType.hxx +View_DisplayActionType.hxx View_Displayer.cxx View_Displayer.hxx +View_DisplayPreview.cxx +View_DisplayPreview.hxx View_PresentationType.hxx +View_PreviewParameters.cxx +View_PreviewParameters.hxx 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 diff --git a/tools/View/View.qrc b/tools/View/View.qrc index 6be49efee2..89d2f9a795 100644 --- a/tools/View/View.qrc +++ b/tools/View/View.qrc @@ -4,6 +4,7 @@ icons/cursor_zoom.png icons/keep_view_off.png icons/keep_view_on.png + icons/trihedron.png icons/view_clear.png icons/view_dm_shading.png icons/view_dm_wireframe.png diff --git a/tools/View/View_DisplayActionType.hxx b/tools/View/View_DisplayActionType.hxx new file mode 100644 index 0000000000..bc0126e692 --- /dev/null +++ b/tools/View/View_DisplayActionType.hxx @@ -0,0 +1,29 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_DisplayActionType_H +#define View_DisplayActionType_H + +//! \enum View_DisplayActionType +enum View_DisplayActionType +{ + View_DisplayActionType_NoneId, //!< No action activated + View_DisplayActionType_DisplayId, //!< Display action + View_DisplayActionType_RedisplayId, //!< Redisplay action + View_DisplayActionType_EraseId, //!< Erase action + View_DisplayActionType_RemoveId //!< Remove action +}; + +#endif diff --git a/tools/View/View_DisplayPreview.cxx b/tools/View/View_DisplayPreview.cxx new file mode 100644 index 0000000000..7e6c55123b --- /dev/null +++ b/tools/View/View_DisplayPreview.cxx @@ -0,0 +1,167 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +static void enableGlobalClipping (const Handle(AIS_InteractiveObject)& theObject, const bool theIsEnable) +{ + if (theIsEnable) + { + theObject->SetClipPlanes (Handle(Graphic3d_SequenceOfHClipPlane)()); + } + else + { + Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = new Graphic3d_SequenceOfHClipPlane(); + aPlanes->SetOverrideGlobal (Standard_True); + theObject->SetClipPlanes (aPlanes); + } +} + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +View_DisplayPreview::View_DisplayPreview() +{ + myPreviewParameters = new View_PreviewParameters(); +} + +// ======================================================================= +// function : SetContext +// purpose : +// ======================================================================= +void View_DisplayPreview::SetContext (const Handle(AIS_InteractiveContext)& theContext) +{ + if (myContext == theContext) + return; + + // remove all preview presentations from the previous context, display it in the new + + myContext = theContext; + if (!theContext.IsNull()) + myPreviewParameters->GetDrawer()->Link (theContext->DefaultDrawer()); +} + +// ======================================================================= +// function : UpdatePreview +// purpose : +// ======================================================================= +void View_DisplayPreview::UpdatePreview (const View_DisplayActionType, + const NCollection_List& thePresentations, + int theDisplayMode) +{ + if (myContext.IsNull()) + return; + + // clear previous previews + for (NCollection_List::Iterator anIterator (myPreviewReadyPresentations); anIterator.More(); anIterator.Next()) + { + if (!anIterator.Value()->GetContext().IsNull()) + anIterator.Value()->GetContext()->Remove (anIterator.Value(), Standard_True); + } + myPreviewReadyPresentations.Clear(); + + if (thePresentations.IsEmpty()) + { + if (!myPreviewPresentation.IsNull() && !myPreviewPresentation->GetContext().IsNull()) + myPreviewPresentation->GetContext()->Remove (myPreviewPresentation, Standard_True); + myPreviewPresentation = NULL; + + return; + } + + // display parameter previews + BRep_Builder aBuilder; + TopoDS_Compound aCompound; + aBuilder.MakeCompound (aCompound); + for (NCollection_List::Iterator anIterator (thePresentations); anIterator.More(); anIterator.Next()) + { + if (Handle(Convert_TransientShape) aShapePtr = Handle(Convert_TransientShape)::DownCast (anIterator.Value())) + { + aBuilder.Add (aCompound, aShapePtr->Shape()); + } + Handle(AIS_InteractiveObject) aPrs = Handle(AIS_InteractiveObject)::DownCast (anIterator.Value()); + if (!aPrs.IsNull() && aPrs->GetContext().IsNull()/*is not displayed in another context*/) + { + myContext->Display (aPrs, theDisplayMode, -1/*does not participate in selection*/, Standard_True); + enableGlobalClipping(aPrs, false); + myPreviewReadyPresentations.Append (aPrs); + } + } + + if (myPreviewPresentation.IsNull()) + { + myPreviewPresentation = new AIS_Shape (aCompound); + Quantity_Color aColor(Quantity_NOC_TOMATO); + myPreviewPresentation->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0)); + myPreviewPresentation->SetAttributes (myPreviewParameters->GetDrawer()); + + myContext->Display (myPreviewPresentation, theDisplayMode, -1/*does not participate in selection*/, Standard_True); + enableGlobalClipping(myPreviewPresentation, false); + } + else + { + Handle(AIS_Shape)::DownCast (myPreviewPresentation)->Set (aCompound); + if (!myPreviewPresentation->GetContext().IsNull()) + { + myPreviewPresentation->GetContext()->Redisplay (myPreviewPresentation, Standard_True); + } + } +} + +// ======================================================================= +// function : SetDisplayMode +// purpose : +// ======================================================================= +void View_DisplayPreview::SetDisplayMode (const int theDisplayMode, const bool theToUpdateViewer) +{ + if (myContext.IsNull()) + return; + + if (!myPreviewPresentation.IsNull()) + { + if (myContext == myPreviewPresentation->GetContext()) + myContext->SetDisplayMode (myPreviewPresentation, theDisplayMode, Standard_False); + } + + for (NCollection_List::Iterator aPreviewIt (myPreviewReadyPresentations); aPreviewIt.More(); aPreviewIt.Next()) + { + if (myContext == aPreviewIt.Value()->GetContext()) + myContext->SetDisplayMode (aPreviewIt.Value(), theDisplayMode, Standard_False); + } + + if (theToUpdateViewer) + myContext->UpdateCurrentViewer(); +} diff --git a/tools/View/View_DisplayPreview.hxx b/tools/View/View_DisplayPreview.hxx new file mode 100644 index 0000000000..530bfea248 --- /dev/null +++ b/tools/View/View_DisplayPreview.hxx @@ -0,0 +1,80 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_DisplayPreview_H +#define View_DisplayPreview_H + +#include + +#include +#include +#include +#include + +class AIS_InteractiveObject; +class View_PreviewParameters; + +//! \class View_DisplayPreview +//! \brief It is responsible for communication with AIS Interactive Context to: +//! - display/erase presentations; +//! - change display mode of visualized presentations (Shaded or WireFrame mode) +//! +//! It contains containers of visualized presentations to obtain presentations relating only to this displayer. +//! Displayer is connected to AIS Interactive Context +class View_DisplayPreview +{ +public: + + //! Constructor + Standard_EXPORT View_DisplayPreview(); + + //! Destructor + virtual ~View_DisplayPreview() {} + + //! Stores the current context where the presentations will be displayed/erased. + //! Erases previuously displayd presentations if there were some displayed + //! \param theContext a context instance + Standard_EXPORT void SetContext (const Handle(AIS_InteractiveContext)& theContext); + + //! Returns preview parameters + View_PreviewParameters* GetPreviewParameters() const { return myPreviewParameters; } + + //! Updates visibility of the presentations for the display type + Standard_EXPORT void UpdatePreview (const View_DisplayActionType theType, + const NCollection_List& thePresentations, + int theDisplayMode); + + //! Sets display mode for all displayed presentations + Standard_EXPORT void SetDisplayMode (const int theDisplayMode, + const bool theToUpdateViewer = true); + + //! Returns true if preview presentation is shown + Standard_Boolean HasPreview() const { return !myPreviewPresentation.IsNull(); } + +private: + + //! Returns the current context + const Handle(AIS_InteractiveContext)& GetContext() const { return myContext; } + +private: + + Handle(AIS_InteractiveContext) myContext; //!< context, where the displayer works + + View_PreviewParameters* myPreviewParameters; //!< drawer of preview presentation + Handle(AIS_InteractiveObject) myPreviewPresentation; //!< presentation of preview for a selected object + NCollection_List myPreviewReadyPresentations; //!< presentation of preview for a selected object +}; + +#endif diff --git a/tools/View/View_Displayer.cxx b/tools/View/View_Displayer.cxx index 50d41a989c..9d36606c96 100644 --- a/tools/View/View_Displayer.cxx +++ b/tools/View/View_Displayer.cxx @@ -20,9 +20,12 @@ #include #include #include +#include #include #include #include + +#include #include #include @@ -33,6 +36,7 @@ View_Displayer::View_Displayer() : myIsKeepPresentations (false), myFitAllActive (false), myDisplayMode (-1) { + myDisplayPreview = new View_DisplayPreview(); } // ======================================================================= @@ -53,6 +57,7 @@ void View_Displayer::SetContext (const Handle(AIS_InteractiveContext)& theContex aPresentationsIt.More(); aPresentationsIt.Next()) DisplayPresentation (aPresentationsIt.Value(), aType, false); } + myDisplayPreview->SetContext (theContext); UpdateViewer(); } @@ -74,6 +79,8 @@ void View_Displayer::SetDisplayMode (const int theDisplayMode, for (AIS_ListIteratorOfListOfInteractive aDisplayedIt (aDisplayed); aDisplayedIt.More(); aDisplayedIt.Next()) GetContext()->SetDisplayMode (aDisplayedIt.Value(), theDisplayMode, Standard_False); + myDisplayPreview->SetDisplayMode (theDisplayMode, Standard_False); + if (theToUpdateViewer) UpdateViewer(); } @@ -209,6 +216,22 @@ void View_Displayer::ErasePresentation (const Handle(Standard_Transient)& thePre UpdateViewer(); } +// ======================================================================= +// function : DisplayDefaultTrihedron +// purpose : +// ======================================================================= +void View_Displayer::DisplayDefaultTrihedron (const Standard_Boolean toDisplay, const bool theToUpdateViewer) +{ + const Handle(AIS_Trihedron)& aTrihedron = defaultTrihedron (toDisplay); + if (aTrihedron.IsNull()) + return; + + if (toDisplay) + GetContext()->Display (aTrihedron, theToUpdateViewer); + else + GetContext()->Erase (aTrihedron, theToUpdateViewer); +} + // ======================================================================= // function : SetVisible // purpose : @@ -240,6 +263,18 @@ bool View_Displayer::IsVisible (const TopoDS_Shape& theShape, const View_Present return !aPresentation.IsNull(); } +// ======================================================================= +// function : UpdatePreview +// purpose : +// ======================================================================= +void View_Displayer::UpdatePreview (const View_DisplayActionType theType, + const NCollection_List& thePresentations) +{ + myDisplayPreview->UpdatePreview (theType, thePresentations, myDisplayMode); + if (!myIsKeepPresentations || myFitAllActive) + fitAllView(); +} + // ======================================================================= // function : UpdateViewer // purpose : @@ -321,11 +356,7 @@ Handle(AIS_InteractiveObject) View_Displayer::FindPresentation (const TopoDS_Sha // ======================================================================= 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; + return new AIS_Shape (theShape); } // ======================================================================= @@ -340,4 +371,18 @@ void View_Displayer::fitAllView() aView->FitAll(); aView->Redraw(); } -} \ No newline at end of file +} + +// ======================================================================= +// function : defaultTrihedron +// purpose : +// ======================================================================= +const Handle(AIS_Trihedron)& View_Displayer::defaultTrihedron (const bool toCreate) +{ + if (myDefaultTrihedron.IsNull() && toCreate) + { + myDefaultTrihedron = new AIS_Trihedron (new Geom_Axis2Placement (gp::XOY())); + myDefaultTrihedron->SetSize (1); + } + return myDefaultTrihedron; +} diff --git a/tools/View/View_Displayer.hxx b/tools/View/View_Displayer.hxx index 8e7bc4ccf7..da1f029a46 100644 --- a/tools/View/View_Displayer.hxx +++ b/tools/View/View_Displayer.hxx @@ -23,9 +23,13 @@ #include #include #include + #include +#include +class AIS_Trihedron; class V3d_View; +class View_DisplayPreview; //! \class View_Displayer //! \brief It is responsible for communication with AIS Interactive Context to: @@ -44,6 +48,9 @@ public: //! Destructor virtual ~View_Displayer() {} + //! Returns preview display instance + View_DisplayPreview* DisplayPreview() const { return myDisplayPreview; } + //! Stores the current context where the presentations will be displayed/erased. //! Erases previuously displayd presentations if there were some displayed //! \param theContext a context instance @@ -54,10 +61,16 @@ public: //! \param theToKeepPresentation boolean state void KeepPresentations (const bool theToKeepPresentations) { myIsKeepPresentations = theToKeepPresentations; } + //! Returns true if fit Fit All should be peformed automatically by each Display + bool IsFitAllActive() const { return myFitAllActive; } + //! Stores flag whether the FitAll shoud be done automatically for each display //! \param theFitAllActive boolean value void SetFitAllActive (const bool theFitAllActive) { myFitAllActive = theFitAllActive; } + //! Returns current display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded + int DisplayMode() const { return myDisplayMode; } + //! Stores display mode and changes display mode of displayed presentations //! \param theDisplayMode a mode: 0 - AIS_WireFrame, 1 - AIS_Shaded //! \param theType presentation type @@ -95,7 +108,7 @@ public: Standard_EXPORT void ErasePresentations (const View_PresentationType theType = View_PresentationType_Main, const bool theToUpdateViewer = true); - //! Erase presentation from viewer + //! Erases 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 @@ -103,6 +116,11 @@ public: const View_PresentationType theType = View_PresentationType_Main, const bool theToUpdateViewer = true); + //! Displays presentation of default trihedron, create it by the first call + //! \param toDisplay flag to display presentation if true, or erase it + //! \param isToUpdateView boolean state if viewer should be updated + Standard_EXPORT void DisplayDefaultTrihedron (const Standard_Boolean toDisplay, const bool theToUpdateViewer); + //! Sets shape visible/invisible //! \theShape shape instance //! \theState visibility state @@ -114,6 +132,10 @@ public: Standard_EXPORT bool IsVisible (const TopoDS_Shape& theShape, const View_PresentationType theType = View_PresentationType_Main) const; + //! Updates visibility of the presentations for the display type + Standard_EXPORT void UpdatePreview (const View_DisplayActionType theType, + const NCollection_List& thePresentations); + //! Calls UpdateCurrentViewer of context Standard_EXPORT void UpdateViewer(); @@ -152,12 +174,20 @@ private: //! Returns 3d view Handle(V3d_View) GetView() const; - //! Fit all view + //! Fits all view void fitAllView(); + //! Returns default trihedron, create it if flag allows + //! \param toCreate boolean state if trihedron should be created if it is NULL + const Handle(AIS_Trihedron)& defaultTrihedron (const bool toCreate); + private: + View_DisplayPreview* myDisplayPreview; //!< class for preview display + Handle(AIS_InteractiveContext) myContext; //!< context, where the displayer works + Handle(AIS_Trihedron) myDefaultTrihedron; //!< NULL presentation until the first display + NCollection_DataMap> myDisplayed; //!< visualized presentations NCollection_DataMap myColorAttributes; //!< color properties of presentations diff --git a/tools/View/View_PreviewParameters.cxx b/tools/View/View_PreviewParameters.cxx new file mode 100644 index 0000000000..8cc48d06b1 --- /dev/null +++ b/tools/View/View_PreviewParameters.cxx @@ -0,0 +1,46 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 + +#include +#include +#include + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +View_PreviewParameters::View_PreviewParameters() +{ + myDrawer = new Prs3d_Drawer(); + + Quantity_Color aColor(Quantity_NOC_TOMATO); + + // point parameters + myDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_O_PLUS, aColor, 3.0)); + + // shading parameters + Graphic3d_MaterialAspect aShadingMaterial; + aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + + myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); + myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); + myDrawer->ShadingAspect()->SetColor (aColor); + myDrawer->ShadingAspect()->SetMaterial (aShadingMaterial); + + // common parameters + myDrawer->SetZLayer (Graphic3d_ZLayerId_Topmost); +} diff --git a/tools/View/View_PreviewParameters.hxx b/tools/View/View_PreviewParameters.hxx new file mode 100644 index 0000000000..700ecc2332 --- /dev/null +++ b/tools/View/View_PreviewParameters.hxx @@ -0,0 +1,71 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_PreviewParameters_H +#define View_PreviewParameters_H + +#include +#include + +#include + +#include +#include +#include +#include + +//! \class View_PreviewParameters +//! Container of View tool bar actions +class View_PreviewParameters +{ +public: + + //! Constructor + Standard_EXPORT View_PreviewParameters (); + + //! Destructor + virtual ~View_PreviewParameters() {} + + //! Returns main control + const Handle(Prs3d_Drawer)& GetDrawer() const { return myDrawer; } + + //! Saves state of preview parameters in a container in form: key, value. It saves: + //! - visibility of columns, + //! - columns width + //! \param theTreeView a view instance + //! \param theItems [out] properties + //! \param thePrefix peference item prefix + static void SaveState (View_PreviewParameters* theParameters, + QMap& theItems, + const QString& thePrefix = QString()) + { (void)theParameters; (void)theItems; (void)thePrefix; } + + //! Restores state of preview parameters 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 applied to the tree view + static bool RestoreState (View_PreviewParameters* theParameters, + const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()) + { (void)theParameters; (void)theKey; (void)theValue; (void)thePrefix; return false; } + +private: + + Handle(Prs3d_Drawer) myDrawer; //!< attributes for preview presentation +}; + +#endif diff --git a/tools/View/View_ToolActionType.hxx b/tools/View/View_ToolActionType.hxx index d5308a6290..a518d2ba54 100644 --- a/tools/View/View_ToolActionType.hxx +++ b/tools/View/View_ToolActionType.hxx @@ -21,7 +21,8 @@ enum View_ToolActionType { View_ToolActionType_KeepViewId, //!< Do not clear previously shown presentations View_ToolActionType_KeepViewOffId, //!< Do show only for new displayed presentation - View_ToolActionType_ClearViewId //!< Erase all displayed presentations + View_ToolActionType_ClearViewId, //!< Erase all displayed presentations + View_ToolActionType_Trihedron //!< Display/Erase trihedron presentation }; #endif diff --git a/tools/View/View_ToolBar.cxx b/tools/View/View_ToolBar.cxx index 1ebff8d129..7887ebbed6 100644 --- a/tools/View/View_ToolBar.cxx +++ b/tools/View/View_ToolBar.cxx @@ -32,7 +32,7 @@ const int DEFAULT_SPACING = 3; // purpose : // ======================================================================= View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView) -: QObject (theParent) +: QObject (theParent), myDefaultContextType (-1) { myMainWindow = new QWidget (theParent); @@ -63,6 +63,12 @@ View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView) myViewContexts[View_ContextType_Own] = Handle(AIS_InteractiveContext)(); myViewContexts[View_ContextType_External] = Handle(AIS_InteractiveContext)(); + myActionsMap[View_ToolActionType_Trihedron] = new QToolButton (theParent); + myActionsMap[View_ToolActionType_Trihedron]->setIcon (QIcon (":/icons/trihedron.png")); + myActionsMap[View_ToolActionType_Trihedron]->setToolTip (tr ("Trihedron display")); + myActionsMap[View_ToolActionType_Trihedron]->setCheckable (true); + myActionsMap[View_ToolActionType_Trihedron]->setChecked (false); + if (isUseKeepView) { myActionsMap[View_ToolActionType_KeepViewId] = new QToolButton (theParent); @@ -80,12 +86,12 @@ View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView) 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")); - myActionsMap[View_ToolActionType_ClearViewId]->setToolTip (tr ("Remove all visualized presentations from view context")); + 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")); + myActionsMap[View_ToolActionType_ClearViewId]->setToolTip (tr ("Remove all visualized presentations from view context")); + } for (QMap::ConstIterator anActionsIt = myActionsMap.begin(), anActionsLast = myActionsMap.end(); anActionsIt != anActionsLast; anActionsIt++) @@ -97,26 +103,6 @@ View_ToolBar::View_ToolBar (QWidget* theParent, const bool isUseKeepView) aLay->addStretch (1); } -TCollection_AsciiString getPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo) -{ - std::ostringstream aPtrStr; - aPtrStr << thePointer.operator->(); - if (!isShortInfo) - return aPtrStr.str().c_str(); - - TCollection_AsciiString anInfoPtr (aPtrStr.str().c_str()); - for (int aSymbolId = 1; aSymbolId < anInfoPtr.Length(); aSymbolId++) - { - if (anInfoPtr.Value(aSymbolId) != '0') - { - anInfoPtr = anInfoPtr.SubString(aSymbolId, anInfoPtr.Length()); - anInfoPtr.Prepend("0x"); - return anInfoPtr; - } - } - return aPtrStr.str().c_str(); -} - // ======================================================================= // function : SetContext // purpose : @@ -128,28 +114,45 @@ void View_ToolBar::SetContext (View_ContextType theType, const Handle(AIS_Intera QString aViewContextName = myViewContextNames[theType]; if (!theContext.IsNull()) aViewContextName = QString ("%1 : [%2]").arg (myViewContextNames[theType]) - .arg (getPointerInfo (theContext, true).ToCString()); + .arg (Standard_Dump::GetPointerInfo (theContext, true).ToCString()); // there are only "Own" and "None" items if (!theContext.IsNull() && theType == View_ContextType_External && myViewSelector->count() == 2) myViewSelector->insertItem (View_ContextType_External, aViewContextName); else myViewSelector->setItemText (theType, aViewContextName); + + if (myDefaultContextType >= 0 && myViewSelector->count() > myDefaultContextType) + { + // using default type during the first setting the external context + myViewSelector->setCurrentIndex (myDefaultContextType); + myDefaultContextType = -1; + } } // ======================================================================= -// function : getCurrentContextType +// function : CurrentContextType // purpose : // ======================================================================= -View_ContextType View_ToolBar::GetCurrentContextType() const +View_ContextType View_ToolBar::CurrentContextType() const { return (View_ContextType)myViewSelector->currentIndex(); } // ======================================================================= -// function : GetCurrentContext +// function : SetCurrentContext +// purpose : +// ======================================================================= +void View_ToolBar::SetCurrentContextType (View_ContextType theType) +{ + myViewSelector->setCurrentIndex ((int)theType); + emit contextChanged(); +} + +// ======================================================================= +// function : CurrentContext // purpose : // ======================================================================= -Handle(AIS_InteractiveContext) View_ToolBar::GetCurrentContext() const +Handle(AIS_InteractiveContext) View_ToolBar::CurrentContext() const { View_ContextType aCurrentType = (View_ContextType)myViewSelector->currentIndex(); return myViewContexts[aCurrentType]; @@ -165,6 +168,35 @@ bool View_ToolBar::IsActionChecked (const int theActionId) const return myActionsMap.contains (anActionId) ? myActionsMap[anActionId]->isChecked() : false; } +// ======================================================================= +// function : SaveState +// purpose : +// ======================================================================= +void View_ToolBar::SaveState (View_ToolBar* theToolBar, + QMap& theItems, + const QString& thePrefix) +{ + theItems[thePrefix + "context_type"] = QString::number (theToolBar->CurrentContextType()); +} + +// ======================================================================= +// function : RestoreState +// purpose : +// ======================================================================= +bool View_ToolBar::RestoreState (View_ToolBar* theToolBar, + const QString& theKey, const QString& theValue, + const QString& thePrefix) +{ + if (theKey == thePrefix + "context_type") + { + theToolBar->SetDefaultContextType ((View_ContextType)theValue.toInt()); + } + else + return false; + + return true; +} + // ======================================================================= // function : onActionClicked // purpose : diff --git a/tools/View/View_ToolBar.hxx b/tools/View/View_ToolBar.hxx index dca417ba05..0a6fac1869 100644 --- a/tools/View/View_ToolBar.hxx +++ b/tools/View/View_ToolBar.hxx @@ -47,25 +47,50 @@ public: Standard_EXPORT View_ToolBar (QWidget* theParent, const bool isUseKeepView = true); //! Destructor - virtual ~View_ToolBar() Standard_OVERRIDE {} + virtual ~View_ToolBar() {} //! \returns parent widget of actions QWidget* GetControl() const { return myMainWindow; } - //! Append context for the given type + //! Appends context for the given type //! \param theType a context type //! \param theContext a context Standard_EXPORT void SetContext (View_ContextType theType, const Handle(AIS_InteractiveContext)& theContext); //! \returns type of active item of context selector - Standard_EXPORT View_ContextType GetCurrentContextType() const; + Standard_EXPORT View_ContextType CurrentContextType() const; + + //! Sets current context type + //! \param theType a context type + Standard_EXPORT void SetCurrentContextType (View_ContextType theType); + + //! Sets default context type + //! \param theType a context type + void SetDefaultContextType (const View_ContextType theType) { myDefaultContextType = (int)theType; } //! \returns an active context of context selector - Standard_EXPORT Handle(AIS_InteractiveContext) GetCurrentContext() const; + Standard_EXPORT Handle(AIS_InteractiveContext) CurrentContext() const; //! \returns whether the action is checked(toggled). Acceptable only if the action is checkable. Standard_EXPORT bool IsActionChecked (const int theActionId) const; + //! Saves state of tool bar actions + //! \param theToolBar a view instance + //! \param theItems [out] properties + //! \param thePrefix peference item prefix + Standard_EXPORT static void SaveState (View_ToolBar* theToolBar, + QMap& theItems, + const QString& thePrefix = QString()); + //! Restores state of tool bar actions + //! \param theToolBar a view instance + //! \param theKey property key + //! \param theValue property value + //! \param thePrefix peference item prefix + //! \return boolean value whether the property is applied to the tree view + Standard_EXPORT static bool RestoreState (View_ToolBar* theToolBar, + const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()); + signals: //! Signal about click on action of View_ToolActionType enumeration @@ -83,6 +108,7 @@ private: QWidget* myMainWindow; //!< tool bar parent widget QComboBox* myViewSelector; //!< container of possible contexts + int myDefaultContextType; //!< type of context read from preferences QMap myActionsMap; //!< tool actions QMap myViewContexts; //!< contexts diff --git a/tools/View/View_Tools.cxx b/tools/View/View_Tools.cxx deleted file mode 100644 index 1699446f00..0000000000 --- a/tools/View/View_Tools.cxx +++ /dev/null @@ -1,76 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -// ======================================================================= -// 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& 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; -} diff --git a/tools/View/View_Tools.hxx b/tools/View/View_Tools.hxx deleted file mode 100644 index 2c105f7ed6..0000000000 --- a/tools/View/View_Tools.hxx +++ /dev/null @@ -1,65 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef View_Tools_H -#define View_Tools_H - -#include -#include - -#include -#include -#include -#include - -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& 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 diff --git a/tools/View/View_Viewer.cxx b/tools/View/View_Viewer.cxx index 1b2ed6c105..f2d8dac73c 100644 --- a/tools/View/View_Viewer.cxx +++ b/tools/View/View_Viewer.cxx @@ -17,7 +17,6 @@ #include #include -#include // ======================================================================= // function : CreateView @@ -41,26 +40,31 @@ void View_Viewer::SetWindow(const Handle(Aspect_Window)& theWindow) } // ======================================================================= -// function : InitStandardViewer +// function : InitViewer // purpose : // ======================================================================= -void View_Viewer::InitStandardViewer() +void View_Viewer::InitViewer (const Handle(AIS_InteractiveContext)& theContext) +{ + myContext = theContext; + myViewer = myContext->CurrentViewer(); +} + +// ======================================================================= +// function : CreateStandardViewer +// purpose : +// ======================================================================= +Handle(AIS_InteractiveContext) View_Viewer::CreateStandardViewer() { Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection(); static Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection); -#if OCC_VERSION_HEX > 0x060901 - myViewer = new V3d_Viewer (aGraphicDriver); -#else - TCollection_AsciiString a3DName ("Visu3D"); - myViewer = new V3d_Viewer (aGraphicDriver, a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Quantity_NOC_GRAY30, - V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, Standard_True, Standard_False); -#endif + Handle(V3d_Viewer) aViewer = new V3d_Viewer (aGraphicDriver); + aViewer->SetDefaultLights(); + aViewer->SetLightOn(); + aViewer->SetDefaultBackgroundColor (Quantity_NOC_GRAY30); - myViewer->SetDefaultLights(); - myViewer->SetLightOn(); - myViewer->SetDefaultBackgroundColor (Quantity_NOC_GRAY30); + Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext (aViewer); + aContext->UpdateCurrentViewer(); - myContext = new AIS_InteractiveContext (myViewer); - myContext->UpdateCurrentViewer(); + return aContext; } diff --git a/tools/View/View_Viewer.hxx b/tools/View/View_Viewer.hxx index b05550f76a..9d88efa841 100644 --- a/tools/View/View_Viewer.hxx +++ b/tools/View/View_Viewer.hxx @@ -39,7 +39,7 @@ public: static Quantity_Color DefaultColor() { return Quantity_Color(Quantity_NOC_BLACK); } //! Returns the view default colors - static Quantity_Color DisabledColor() { return Quantity_Color(195 / 255., 195 / 255., 195 / 255., Quantity_TOC_RGB); } + static Quantity_Color DisabledColor() { return Quantity_Color(195 / 255., 195 / 255., 195 / 255., Quantity_TOC_sRGB); } //! Creates V3d view Standard_EXPORT void CreateView(); @@ -50,7 +50,11 @@ public: //! Creates OCC components on the window //! \param theWindowHandle an id of the application window - Standard_EXPORT void InitStandardViewer(); + Standard_EXPORT void InitViewer (const Handle(AIS_InteractiveContext)& theContext); + + //! Creates OCC components on the window + //! \param theWindowHandle an id of the application window + Standard_EXPORT static Handle(AIS_InteractiveContext) CreateStandardViewer(); //! Returns an OCC viewer const Handle(V3d_Viewer)& GetViewer() { return myViewer; } diff --git a/tools/View/View_Widget.cxx b/tools/View/View_Widget.cxx index 33230ef59d..878b19f708 100644 --- a/tools/View/View_Widget.cxx +++ b/tools/View/View_Widget.cxx @@ -19,10 +19,8 @@ #include -#include #include #include -#include #include #include @@ -63,16 +61,21 @@ // function : Constructor // purpose : // ======================================================================= -View_Widget::View_Widget (QWidget* theParent, const bool isFitAllActive) +View_Widget::View_Widget (QWidget* theParent, + const Handle(AIS_InteractiveContext)& theContext, + 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), 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); + if (!theContext.IsNull()) + myViewer->InitViewer (theContext); + else + { + myViewer->InitViewer (myViewer->CreateStandardViewer()); + } setAttribute (Qt::WA_PaintOnScreen); setAttribute (Qt::WA_NoSystemBackground); @@ -108,10 +111,6 @@ void View_Widget::Init() #ifdef _WIN32 Aspect_Handle aWindowHandle = (Aspect_Handle)winId(); Handle(Aspect_Window) aWnd = new WNT_Window (aWindowHandle); -#if OCC_VERSION_HEX <= 0x060901 - myViewer->GetView()->SetZClippingDepth (0.5); - myViewer->GetView()->SetZClippingWidth (0.5); -#endif #elif defined (__APPLE__) && !defined (MACOSX_USE_GLX) NSView* aViewHandle = (NSView*)winId(); Handle(Aspect_Window) aWnd = new Cocoa_Window (aViewHandle); @@ -130,14 +129,23 @@ void View_Widget::Init() } // ======================================================================= -// function : GetDisplayMode +// function : DisplayMode // purpose : // ======================================================================= -int View_Widget::GetDisplayMode() const +int View_Widget::DisplayMode() const { return myViewActions[View_ViewActionType_DisplayModeId]->isChecked() ? AIS_Shaded : AIS_WireFrame; } +// ======================================================================= +// function : SetDisplayMode +// purpose : +// ======================================================================= +void View_Widget::SetDisplayMode (const int theMode) +{ + myViewActions[View_ViewActionType_DisplayModeId]->setChecked ( theMode ? AIS_Shaded : AIS_WireFrame); +} + // ======================================================================= // function : paintEvent // purpose : @@ -197,7 +205,41 @@ void View_Widget::SetEnabledView (const bool theIsEnabled) myViewer->GetView()->SetBackgroundColor (theIsEnabled ? View_Viewer::DefaultColor() : View_Viewer::DisabledColor()); for (int anActionId = View_ViewActionType_FitAreaId; anActionId <= View_ViewActionType_DisplayModeId; anActionId++) - GetViewAction ((View_ViewActionType)anActionId)->setEnabled (theIsEnabled); + ViewAction ((View_ViewActionType)anActionId)->setEnabled (theIsEnabled); +} + +// ======================================================================= +// function : SaveState +// purpose : +// ======================================================================= +void View_Widget::SaveState (View_Widget* theWidget, + QMap& theItems, + const QString& thePrefix) +{ + theItems[thePrefix + "fitall"] = theWidget->ViewAction (View_ViewActionType_FitAllId)->isChecked(); + theItems[thePrefix + "dispmode"] = QString::number (theWidget->DisplayMode()); +} + +// ======================================================================= +// function : RestoreState +// purpose : +// ======================================================================= +bool View_Widget::RestoreState (View_Widget* theWidget, + const QString& theKey, const QString& theValue, + const QString& thePrefix) +{ + if (theKey == thePrefix + "fitall") + { + theWidget->SetActionChecked (View_ViewActionType_FitAllId, theValue.toInt() > 0); + } + else if (theKey == thePrefix + "dispmode") + { + theWidget->SetDisplayMode (theValue.toInt()); + } + else + return false; + + return true; } // ======================================================================= @@ -268,10 +310,10 @@ void View_Widget::initViewActions() if (!myViewActions.empty()) return; - myFitAllAction = new View_ToolButton (this); //!< action for automatic fit all + 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)); + myFitAllAction->setDefaultAction (ViewAction (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); @@ -420,6 +462,7 @@ void View_Widget::processLeftButtonDown (const int theFlags, const QPoint thePoi } } activateCursor (myCurrentMode); + emit leftButtonDown(thePoint.x(), thePoint.y()); } // ======================================================================= @@ -513,8 +556,8 @@ void View_Widget::processLeftButtonUp (const int theFlags, const QPoint thePoint myDragMultiButtonDownX = 0; myDragMultiButtonDownY = 0; - activateCursor (myCurrentMode); emit selectionChanged(); + emit leftButtonUp(thePoint.x(), thePoint.y()); } // ======================================================================= @@ -608,6 +651,7 @@ void View_Widget::processMouseMove (const int theFlags, const QPoint thePoint) else processMoveEvent (thePoint.x(), thePoint.y()); } + emit moveTo (thePoint.x(), thePoint.y()); } // ======================================================================= diff --git a/tools/View/View_Widget.hxx b/tools/View/View_Widget.hxx index 5e6ad9bacb..3fd7fdb069 100644 --- a/tools/View/View_Widget.hxx +++ b/tools/View/View_Widget.hxx @@ -66,15 +66,17 @@ protected: //! Enumeration defines drag mode enum View_DragMode { - View_DragMode_ButtonDown, // theState == -1 button down - View_DragMode_ButtonMove, // theState == 0 move - View_DragMode_ButtonUp // theState == 1 button up + View_DragMode_ButtonDown, //!< theState == -1 button down + View_DragMode_ButtonMove, //!< theState == 0 move + View_DragMode_ButtonUp //< theState == 1 button up }; public: //! Constructor - Standard_EXPORT View_Widget (QWidget* theParent, const bool isFitAllActive); + Standard_EXPORT View_Widget (QWidget* theParent, + const Handle(AIS_InteractiveContext)& theContext, + const bool isFitAllActive); //! Destructor virtual ~View_Widget() {} @@ -90,41 +92,83 @@ public: //! Returns an action for the given action type //! \param theActionId an action index - QAction* GetViewAction (const View_ViewActionType theActionId) const { return myViewActions[theActionId]; }; + QAction* ViewAction (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; + Standard_EXPORT int DisplayMode() const; - //! Enable/disable view and tool bar actions depending on the parameter + //! Sets display mode: 0 - AIS_WireFrame, 1 - AIS_Shaded + Standard_EXPORT void SetDisplayMode (const int theMode); + + //! Sets enable/disable view and tool bar actions depending on the parameter //! \param theIsEnabled boolean value Standard_EXPORT void SetEnabledView (const bool theIsEnabled); - //!< widget for fit all, processed double click to perform action automatically + //! Returns true if action is checked. It processes fit all action only. + //! \param theIsEnabled boolean value + bool IsActionChecked (const View_ViewActionType theActionId) + { return theActionId == View_ViewActionType_FitAllId && myFitAllAction->isChecked(); } + + //! Sets checked fit all action. Double click on fit all action set the action checked automatically //! \param theIsEnabled boolean value - bool IsActionChecked (const View_ViewActionType theActionId) { if (theActionId == View_ViewActionType_FitAllId) return myFitAllAction->isChecked(); } + void SetActionChecked (const View_ViewActionType theActionId, const bool isChecked) + { if (theActionId == View_ViewActionType_FitAllId) myFitAllAction->setChecked(isChecked); } - //!< Setx initial camera position + //! Sets 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. + //! Returns paint engine for the OpenGL viewer. Avoid default execution of Qt Widget. virtual QPaintEngine* paintEngine() const Standard_OVERRIDE { return 0; } - //! Recommended size for view. If default size exists, it returns the default size + //! Return the recommended size for view. If default size exists, it returns the default size Standard_EXPORT virtual QSize sizeHint() const Standard_OVERRIDE; + //! Saves state of widget actions + //! \param theParameters a view instance + //! \param theItems [out] properties + //! \param thePrefix peference item prefix + Standard_EXPORT static void SaveState (View_Widget* theWidget, + QMap& theItems, + const QString& thePrefix = QString()); + + //! Restores state of widget actions + //! \param theParameters a view instance + //! \param theKey property key + //! \param theValue property value + //! \param thePrefix peference item prefix + //! \return boolean value whether the property is applied to the tree view + Standard_EXPORT static bool RestoreState (View_Widget* theWidget, + const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()); + signals: //! Sends a signal about selection change if the left mouse button is pressed and current action does not process it void selectionChanged(); + //! Sends a signal about moving to the point in the view + //! \param theX X mouse position in pixels + //! \param theY Y mouse position in pixels + void moveTo (const int theX, const int theY); + + //! Sends a signal about up the left mouse button down + //! \param theX X mouse position in pixels + //! \param theY Y mouse position in pixels + void leftButtonDown (const int theX, const int theY); + + //! Sends a signal about up the left mouse button up + //! \param theX X mouse position in pixels + //! \param theY Y mouse position in pixels + void leftButtonUp (const int theX, const int theY); + //! Sends a signal about display mode change void displayModeClicked(); @@ -163,11 +207,11 @@ public slots: protected: - //! Avoid Qt standard execution of this method, redraw V3d view + //! Avoids Qt standard execution of this method, redraw V3d view //! \param an event virtual void paintEvent (QPaintEvent* theEvent) Standard_OVERRIDE; - //! Avoid Qt standard execution of this method, do mustBeResized for V3d view, Init view if it is the first call + //! Avoids Qt standard execution of this method, do mustBeResized for V3d view, Init view if it is the first call //! \param an event virtual void resizeEvent (QResizeEvent* theEvent) Standard_OVERRIDE; diff --git a/tools/View/View_Window.cxx b/tools/View/View_Window.cxx index 98edc7485c..f47cbeb9c2 100644 --- a/tools/View/View_Window.cxx +++ b/tools/View/View_Window.cxx @@ -19,11 +19,10 @@ #include -#include - #include +#include +#include #include -#include #include #include @@ -43,14 +42,16 @@ const int DEFAULT_SPACING = 3; // function : Constructor // purpose : // ======================================================================= -View_Window::View_Window (QWidget* theParent, const bool isUseKeepView, const bool isFitAllActive) +View_Window::View_Window (QWidget* theParent, + const Handle(AIS_InteractiveContext)& theContext, + 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, isFitAllActive); + myView = new View_Widget (this, theContext, isFitAllActive); myViewToolBar = new View_ToolBar (this, isUseKeepView); aViewLayout->addWidget (myViewToolBar->GetControl(), 0, 0, 1, 2); connect (myViewToolBar, SIGNAL (contextChanged()), this, SLOT (onViewSelectorActivated())); @@ -69,7 +70,7 @@ View_Window::View_Window (QWidget* theParent, const bool isUseKeepView, const bo 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)); + myActionsToolBar->addAction (myView->ViewAction ((View_ViewActionType)anActionId)); aViewLayout->addWidget (myActionsToolBar, 1, 0); aViewLayout->addWidget (myView, 1, 1); @@ -92,7 +93,76 @@ View_Window::View_Window (QWidget* theParent, const bool isUseKeepView, const bo // ======================================================================= void View_Window::SetContext (View_ContextType /*theType*/, const Handle(AIS_InteractiveContext)& theContext) { - GetViewToolBar()->SetContext (View_ContextType_External, theContext); + ViewToolBar()->SetContext (View_ContextType_External, theContext); +} + +// ======================================================================= +// function : SaveState +// purpose : +// ======================================================================= +void View_Window::SaveState (View_Window* theView, QMap& theItems, + const QString& thePrefix) +{ + QStringList aCameraDirection; + Standard_Real aVX, aVY, aVZ; + Handle(V3d_View) aView = theView->ViewWidget()->GetViewer()->GetView(); + if (aView.IsNull()) + return; + + aView->Proj (aVX, aVY, aVZ); + aCameraDirection << QString::number (aVX) << QString::number (aVY) << QString::number (aVZ); + + theItems[thePrefix + "view_camera_direction"] = aCameraDirection.join (","); + + View_PreviewParameters::SaveState (theView->Displayer()->DisplayPreview()->GetPreviewParameters(), theItems, "preview_parameters_"); + View_ToolBar::SaveState (theView->ViewToolBar(), theItems, "view_toolbar_"); + View_Widget::SaveState (theView->ViewWidget(), theItems, "view_widget_"); +} + +// ======================================================================= +// function : RestoreState +// purpose : +// ======================================================================= +bool View_Window::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->ViewWidget()->SetInitProj (aVX, aVY, aVZ); + } + return true; + } + else if (View_PreviewParameters::RestoreState (theView->Displayer()->DisplayPreview()->GetPreviewParameters(), + theKey, theValue, "preview_parameters_")) + { + return true; + } + else if (View_ToolBar::RestoreState (theView->ViewToolBar(), theKey, theValue, "view_toolbar_")) + { + return true; + } + else if (View_Widget::RestoreState (theView->ViewWidget(), theKey, theValue, "view_widget_")) + { + // display mode is restored + View_Displayer* aDisplayer = theView->Displayer(); + if (theView->ViewWidget()->DisplayMode() != aDisplayer->DisplayMode()) + aDisplayer->SetDisplayMode (theView->ViewWidget()->DisplayMode()); + + bool toFitAll = theView->ViewWidget()->IsActionChecked (View_ViewActionType_FitAllId); + if (toFitAll != aDisplayer->IsFitAllActive()) + aDisplayer->SetFitAllActive (toFitAll); + + return true; + } + + return false; } // ======================================================================= @@ -101,12 +171,12 @@ void View_Window::SetContext (View_ContextType /*theType*/, const Handle(AIS_Int // ======================================================================= void View_Window::onViewSelectorActivated() { - View_ContextType aType = myViewToolBar->GetCurrentContextType(); + View_ContextType aType = myViewToolBar->CurrentContextType(); bool isViewEnabled = aType == View_ContextType_Own; myView->SetEnabledView (isViewEnabled); - Handle(AIS_InteractiveContext) aContext = myViewToolBar->GetCurrentContext(); + Handle(AIS_InteractiveContext) aContext = myViewToolBar->CurrentContext(); myDisplayer->EraseAllPresentations (true); emit eraseAllPerformed(); @@ -121,6 +191,11 @@ void View_Window::onToolBarActionClicked (const int theActionId) { switch (theActionId) { + case View_ToolActionType_Trihedron: + { + myDisplayer->DisplayDefaultTrihedron (myViewToolBar->IsActionChecked (theActionId), Standard_True); + break; + } case View_ToolActionType_KeepViewId: { myDisplayer->KeepPresentations (myViewToolBar->IsActionChecked (theActionId)); @@ -158,23 +233,22 @@ void View_Window::onCheckedStateChanged (int theActionId, bool theState) // ======================================================================= void View_Window::onViewContextMenuRequested (const QPoint& thePosition) { -#if TINSPECTORAPI_VERSION_HEX > 0x070200 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)); + + QAction* anAction = new QAction (V3d::TypeOfOrientationToString (anOrientationType), this); + QObject::connect (anAction, SIGNAL (triggered (bool)), this, SLOT (onSetOrientation())); + + anOrientationSubMenu->addAction (anAction); } aMenu->addMenu (anOrientationSubMenu); QPoint aPoint = myView->mapToGlobal (thePosition); aMenu->exec (aPoint); -#else - (void)thePosition; -#endif } // ======================================================================= @@ -183,7 +257,6 @@ void View_Window::onViewContextMenuRequested (const QPoint& thePosition) // ======================================================================= void View_Window::onSetOrientation() { -#if TINSPECTORAPI_VERSION_HEX > 0x070200 QAction* anAction = (QAction*)(sender()); TCollection_AsciiString anOrientationStr (anAction->text().toStdString().c_str()); @@ -199,7 +272,6 @@ void View_Window::onSetOrientation() aView->SetProj (anOrientationType); aView->FitAll(); aView->Redraw(); -#endif } // ======================================================================= @@ -208,7 +280,7 @@ void View_Window::onSetOrientation() // ======================================================================= void View_Window::onDisplayModeChanged() { - int aDisplayMode = myView->GetDisplayMode(); + int aDisplayMode = myView->DisplayMode(); for (NCollection_DataMap >::Iterator anIterator(myDisplayer->GetDisplayed()); anIterator.More(); anIterator.Next()) myDisplayer->SetDisplayMode (aDisplayMode, anIterator.Key(), false); diff --git a/tools/View/View_Window.hxx b/tools/View/View_Window.hxx index 91eb8018c1..b270f816d3 100644 --- a/tools/View/View_Window.hxx +++ b/tools/View/View_Window.hxx @@ -40,28 +40,48 @@ class View_Window : public QWidget public: //! Constructor - Standard_EXPORT View_Window (QWidget* theParent, const bool isUseKeepView = true, const bool isFitAllActive = true); + Standard_EXPORT View_Window (QWidget* theParent, + const Handle(AIS_InteractiveContext)& theContext = Handle(AIS_InteractiveContext)(), + const bool isUseKeepView = true, const bool isFitAllActive = true); //! Destructor virtual ~View_Window() {} //! Returns view displayer - View_Displayer* GetDisplayer() const { return myDisplayer; } + View_Displayer* Displayer() const { return myDisplayer; } //! Returns view widget - View_Widget* GetView() const { return myView; } + View_Widget* ViewWidget() const { return myView; } //! Returns actions tool bar - QToolBar* GetActionsToolBar() const { return myActionsToolBar; } + QToolBar* ActionsToolBar() const { return myActionsToolBar; } //! Returns window tool bar - View_ToolBar* GetViewToolBar() const { return myViewToolBar; } + View_ToolBar* ViewToolBar() const { return myViewToolBar; } //! Sets a new context for context type //! \param theType a type of context, will be selected in the tool bar combo box //! \param theContext an AIS context Standard_EXPORT void SetContext (View_ContextType theType, const Handle(AIS_InteractiveContext)& theContext); + //! Saves state of view window in a container in form: key, value. It saves: + //! - visibility 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& theItems, + const QString& thePrefix = QString()); + + //! Restores state of view window 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 applied to the tree view + Standard_EXPORT static bool RestoreState (View_Window* theView, const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()); + signals: //! Signals about calling erasing all presentations in context void eraseAllPerformed(); diff --git a/tools/View/icons/trihedron.png b/tools/View/icons/trihedron.png new file mode 100644 index 0000000000..bc5894dc38 Binary files /dev/null and b/tools/View/icons/trihedron.png differ diff --git a/tools/ViewControl/FILES b/tools/ViewControl/FILES index 432c6f8adf..9fda7a71be 100644 --- a/tools/ViewControl/FILES +++ b/tools/ViewControl/FILES @@ -1,5 +1,14 @@ +ViewControl_EditType.hxx ViewControl_MessageDialog.cxx ViewControl_MessageDialog.hxx +ViewControl_PropertyView.cxx +ViewControl_PropertyView.hxx +ViewControl_Table.cxx +ViewControl_Table.hxx +ViewControl_TableModel.cxx +ViewControl_TableModel.hxx +ViewControl_TableModelValues.cxx +ViewControl_TableModelValues.hxx ViewControl_Tools.cxx ViewControl_Tools.hxx -ViewControl_TreeView.hxx \ No newline at end of file +ViewControl_TreeView.hxx diff --git a/tools/ViewControl/ViewControl_EditType.hxx b/tools/ViewControl/ViewControl_EditType.hxx new file mode 100644 index 0000000000..7d12ae0115 --- /dev/null +++ b/tools/ViewControl/ViewControl_EditType.hxx @@ -0,0 +1,30 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_EditType_H +#define ViewControl_EditType_H + +//! Type of context used in a tool library +enum ViewControl_EditType +{ + ViewControl_EditType_None, //!< View widget is null + ViewControl_EditType_Bool, //!< check box widget + ViewControl_EditType_Double, //!< line edit widget used double validator + ViewControl_EditType_Line, //!< line edit widget + ViewControl_EditType_Spin, //!< spin box widget + ViewControl_EditType_DoAction //!< control to perform the row action +}; + +#endif diff --git a/tools/ViewControl/ViewControl_MessageDialog.hxx b/tools/ViewControl/ViewControl_MessageDialog.hxx index 8c1e16eca0..e8ae197a17 100644 --- a/tools/ViewControl/ViewControl_MessageDialog.hxx +++ b/tools/ViewControl/ViewControl_MessageDialog.hxx @@ -66,20 +66,20 @@ private slots: void onCancelClicked(); private: - //! Change state of the dialog to message tool tip. Only information control will be shown in the dialog + //! Changes 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 + 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 + 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 + QLabel* myInformationLabel; //!< message control + QCheckBox* myDoNotShowCheckBox; //!< choice whether the dialog will be shown again + QPushButton* myOkButton; //!< accept button + QPushButton* myCancelButton; //!< reject button }; diff --git a/tools/ViewControl/ViewControl_PropertyView.cxx b/tools/ViewControl/ViewControl_PropertyView.cxx new file mode 100644 index 0000000000..215d44c953 --- /dev/null +++ b/tools/ViewControl/ViewControl_PropertyView.cxx @@ -0,0 +1,208 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//! Class that uses parameter size as recommended size for the widget. +//! If the control is placed in a dock widget of the main window, it will not be resized on free size by resizing the main window. +class ViewControl_PredefinedSizeWidget : public QWidget +{ +public: + //! Constructor + ViewControl_PredefinedSizeWidget (QWidget* theParent, const QSize& theSize) : QWidget (theParent) { SetPredefinedSize (theSize); } + + //! Destructor + virtual ~ViewControl_PredefinedSizeWidget() {} + + //! 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 : QWidget::sizeHint(); } + +private: + QSize myDefaultSize; //!< default size, empty size if it should not be used +}; + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +ViewControl_PropertyView::ViewControl_PropertyView (QWidget* theParent, const QSize& thePredefinedSize) +: QObject (theParent), myOwnSelectionChangeBlocked (false) +{ + myMainWidget = new ViewControl_PredefinedSizeWidget (theParent, QSize (1, 100)); + if (!thePredefinedSize.isEmpty()) + ((ViewControl_PredefinedSizeWidget*)myMainWidget)->SetPredefinedSize (thePredefinedSize); + + QVBoxLayout* aLayout = new QVBoxLayout (myMainWidget); + aLayout->setContentsMargins (0, 0, 0, 0); + + QScrollArea* anArea = new QScrollArea (myMainWidget); + + myAttributesStack = new QStackedWidget (myMainWidget); + anArea->setWidget (myAttributesStack); + anArea->setWidgetResizable( true ); + aLayout->addWidget (anArea); + + myEmptyWidget = new QWidget (myAttributesStack); + myAttributesStack->addWidget (myEmptyWidget); + + myTableWidget = new QWidget (myAttributesStack); + myTableWidgetLayout = new QVBoxLayout (myTableWidget); + myTableWidgetLayout->setContentsMargins (0, 0, 0, 0); + myAttributesStack->addWidget (myTableWidget); + + myAttributesStack->setCurrentWidget (myEmptyWidget); + + // create table + ViewControl_Table* aTable = new ViewControl_Table (myMainWidget); + ViewControl_TableModel* aModel = new ViewControl_TableModel(aTable->TableView()); + aTable->SetModel (aModel); + + connect (aTable->TableView()->selectionModel(), + SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), + this, SLOT(onTableSelectionChanged (const QItemSelection&, const QItemSelection&))); + + connect (aModel, SIGNAL (dataChanged(const QModelIndex&, const QModelIndex&, const QVector&)), + this, SIGNAL (propertyViewDataChanged())); + + myTableWidgetLayout->addWidget (aTable->GetControl()); + myTable = aTable; +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void ViewControl_PropertyView::Init (ViewControl_TableModelValues* theTableValues) +{ + ViewControl_Table* aTable = Table(); + if (theTableValues) + { + aTable->Init (theTableValues); + ViewControl_Tools::SetDefaultHeaderSections (aTable->TableView(), Qt::Horizontal); + } + aTable->SetActive (theTableValues != 0); + + if (theTableValues) + myAttributesStack->setCurrentWidget (myTableWidget); + else + myAttributesStack->setCurrentWidget (myEmptyWidget); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void ViewControl_PropertyView::Init (QWidget*) +{ +} + +// ======================================================================= +// function : ClearActiveTablesSelection +// purpose : +// ======================================================================= +void ViewControl_PropertyView::ClearActiveTablesSelection() +{ + bool aWasBlocked = myOwnSelectionChangeBlocked; + myOwnSelectionChangeBlocked = true; + + QList aTables; + ViewControl_Table* aTable = Table(); + if (aTable->IsActive()) + aTable->TableView()->selectionModel()->clearSelection(); + + myOwnSelectionChangeBlocked = aWasBlocked; +} + +// ======================================================================= +// function : Clear +// purpose : +// ======================================================================= +void ViewControl_PropertyView::Clear() +{ + ViewControl_Table* aTable = Table(); + if (aTable->IsActive()) + { + ViewControl_TableModel* aModel = dynamic_cast (aTable->TableView()->model()); + aModel->SetModelValues (0); + + aTable->SetActive (true); + } + myAttributesStack->setCurrentWidget (myEmptyWidget); +} + +// ======================================================================= +// function : SaveState +// purpose : +// ======================================================================= +void ViewControl_PropertyView::SaveState (ViewControl_PropertyView* thePropertyView, + QMap& theItems, + const QString& thePrefix) +{ + ViewControl_Table* aTable = thePropertyView->Table(); + int aColumnWidth = aTable->TableView()->columnWidth (0); + theItems[thePrefix + "column_width_0"] = QString::number (aColumnWidth); +} + +// ======================================================================= +// function : RestoreState +// purpose : +// ======================================================================= +bool ViewControl_PropertyView::RestoreState (ViewControl_PropertyView* thePropertyView, + const QString& theKey, + const QString& theValue, + const QString& thePrefix) +{ + if (theKey == thePrefix + "column_width_0") + { + bool isOk; + int aWidth = theValue.toInt (&isOk); + if (isOk) + thePropertyView->Table()->TableView()->horizontalHeader()->setDefaultSectionSize (aWidth); + } + else + return false; + return true; +} + +// ======================================================================= +// function : onTableSelectionChanged +// purpose : +// ======================================================================= +void ViewControl_PropertyView::onTableSelectionChanged (const QItemSelection&, const QItemSelection&) +{ + if (myOwnSelectionChangeBlocked) + return; + + emit propertyViewSelectionChanged(); +} diff --git a/tools/ViewControl/ViewControl_PropertyView.hxx b/tools/ViewControl/ViewControl_PropertyView.hxx new file mode 100644 index 0000000000..f424245ad3 --- /dev/null +++ b/tools/ViewControl/ViewControl_PropertyView.hxx @@ -0,0 +1,116 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_PropertyView_H +#define TreeModel_PropertyView_H + +#include +#include + +#include + +#include +#include +#include +#include + +class QAbstractTableModel; +class QStackedWidget; +class QWidget; +class QVBoxLayout; + +class ViewControl_TableModelValues; + +//! \class ViewControl_PropertyView +//! \brief View widget where several tables are visualized in vertical layout. +class ViewControl_PropertyView : public QObject +{ + Q_OBJECT +public: + + //! Constructor + Standard_EXPORT ViewControl_PropertyView (QWidget* theParent, const QSize& thePredefinedSize = QSize()); + + //! Destructor + virtual ~ViewControl_PropertyView() {} + + //! Fills the view content with values. Number of visible tables is size of container, + //! Each element of container is values of the corresponded table + //! \param theTableValues values + Standard_EXPORT void Init (ViewControl_TableModelValues* theTableValues); + + //! Fills the view content with the parameter custom widget. + //! \param theWidget control + Standard_EXPORT void Init (QWidget* theWidget); + + //! Clears layout of the view and tables models. + Standard_EXPORT void Clear(); + + //! \return the text edit control + QWidget* GetControl() const { return myMainWidget; } + + //! Returns container an active table or NULL + ViewControl_Table* Table() { return myTable; } + + //! Clears selection in active tables + Standard_EXPORT void ClearActiveTablesSelection(); + + //! Saves state of property view in a container in form: key, value. It saves: + //! - visibility of columns, + //! - columns width + //! \param theTreeView a view instance + //! \param theItems [out] properties + //! \param thePrefix peference item prefix + Standard_EXPORT static void SaveState (ViewControl_PropertyView* theParameters, + QMap& theItems, + const QString& thePrefix = QString()); + + //! Restores state of property 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 applied to the tree view + Standard_EXPORT static bool RestoreState (ViewControl_PropertyView* theParameters, + const QString& theKey, const QString& theValue, + const QString& thePrefix = QString()); + +signals: + //! Signal about selection change in property view table + void propertyViewSelectionChanged(); + + //! Signal about data change in property view table + void propertyViewDataChanged(); + +protected slots: + //! Emits signal about selection is changed + //! \param theSelected container of selected table cells + //! \param theDeselected container of selected table cells + void onTableSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + +private: + bool myOwnSelectionChangeBlocked; //!< blocking emit of selection changed signal + + QWidget* myMainWidget; //!< parent of all controls + + QStackedWidget* myAttributesStack; //!< container of already created panes + QWidget* myEmptyWidget; //!< an empty widget when nothing is selected in tree view + + QWidget* myTableWidget; //!< widget of tables in vertical layout + QVBoxLayout* myTableWidgetLayout; //!< main view layout where tables or custom widgets are presented + ViewControl_Table* myTable; //!< table view, shown only first tables filled in Init method + QWidget* myCustomWidget; //!< custom view widget +}; +#endif diff --git a/tools/ViewControl/ViewControl_Table.cxx b/tools/ViewControl/ViewControl_Table.cxx new file mode 100644 index 0000000000..76269f21b0 --- /dev/null +++ b/tools/ViewControl/ViewControl_Table.cxx @@ -0,0 +1,165 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +ViewControl_Table::ViewControl_Table (QWidget* theParent) +: QObject (theParent), myIsUseProperty (false) +{ + myMainWidget = new QWidget (theParent); + QGridLayout* aLayout = new QGridLayout (myMainWidget); + aLayout->setContentsMargins (0, 0, 0, 0); + + myTableView = new QTableView (myMainWidget); + myTableView->setVerticalScrollMode (QAbstractItemView::ScrollPerPixel); + + QHeaderView* aVHeader = myTableView->verticalHeader(); + int aDefCellSize = aVHeader->minimumSectionSize(); + aVHeader->setDefaultSectionSize (aDefCellSize); + + connect (myTableView->horizontalHeader(), SIGNAL (sectionResized (int, int, int)), + this, SLOT(onHeaderResized (int, int, int))); + + aLayout->addWidget (myTableView); +} + +// ======================================================================= +// function : SetModel +// purpose : +// ======================================================================= +void ViewControl_Table::SetModel (QAbstractTableModel* theModel) +{ + myTableView->setModel (theModel); + + myTableView->setSelectionMode(QAbstractItemView::ExtendedSelection); + QItemSelectionModel* aSelectionModel = new QItemSelectionModel(theModel); + myTableView->setSelectionModel (aSelectionModel); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void ViewControl_Table::Init (ViewControl_TableModelValues* theModelValues) +{ + myTableView->selectionModel()->clearSelection(); + + ViewControl_TableModel* aModel = dynamic_cast (myTableView->model()); + aModel->SetModelValues (theModelValues); + + myTableView->horizontalHeader()->setVisible (theModelValues->IsHeaderVisible (Qt::Horizontal)); + + myTableView->verticalHeader()->setVisible (theModelValues->IsHeaderVisible (Qt::Vertical)); + int aSectionSize; + if (theModelValues->DefaultSectionSize (Qt::Vertical, aSectionSize) ) + { + myTableView->verticalHeader()->setDefaultSectionSize (aSectionSize); + } + else + myTableView->verticalHeader()->setDefaultSectionSize (myTableView->verticalHeader()->minimumSectionSize()); + + aModel->EmitLayoutChanged(); +} + +// ======================================================================= +// function : SelectedIndices +// purpose : +// ======================================================================= +void ViewControl_Table::SelectedIndices (QMap>& theSelectedIndices) const +{ + QModelIndexList aSelected = myTableView->selectionModel()->selectedIndexes(); + + int aRow, aColumn; + for (QModelIndexList::const_iterator anIt = aSelected.begin(); anIt != aSelected.end(); anIt++) + { + QModelIndex anIndex = *anIt; + aRow = anIndex.row(); + aColumn = anIndex.column(); + if (!theSelectedIndices.contains (aRow)) + theSelectedIndices.insert (aRow, QList()); + theSelectedIndices[aRow].append (aColumn); + } +} + +// ======================================================================= +// function : SeparatorData +// purpose : +// ======================================================================= +QString ViewControl_Table::SeparatorData() +{ + return ViewControl_Tools::TableSeparator(); +} + +// ======================================================================= +// function : SelectedPointers +// purpose : +// ======================================================================= +void ViewControl_Table::SelectedPointers (QStringList& thePointers) const +{ + QMap> aSelectedIndices; + SelectedIndices (aSelectedIndices); + + ViewControl_TableModel* aTableModel = dynamic_cast(TableView()->model()); + ViewControl_TableModelValues* aTableValues = aTableModel->ModelValues(); + + for (QMap>::const_iterator aSelIt = aSelectedIndices.begin(); aSelIt != aSelectedIndices.end(); aSelIt++) + { + int aRowId = aSelIt.key(); + QList aColIds = aSelIt.value(); + for (int aColId = 0; aColId < aColIds.size(); aColId++) + { + int aSelectedColId = aColIds[aColId]; + if (aSelectedColId != 1) + continue; + + QString aData = aTableValues->Data (aRowId, aSelectedColId, Qt::DisplayRole).toString(); + if (aData.contains (Standard_Dump::GetPointerPrefix().ToCString())) + thePointers.append (aData); + } + } +} + +// ======================================================================= +// function : onHeaderResized +// purpose : +// ======================================================================= +void ViewControl_Table::onHeaderResized (int theSectionId, int, int) +{ + if (theSectionId != 0) + return; + + myTableView->horizontalHeader()->setDefaultSectionSize (myTableView->columnWidth (theSectionId)); +} diff --git a/tools/ViewControl/ViewControl_Table.hxx b/tools/ViewControl/ViewControl_Table.hxx new file mode 100644 index 0000000000..47e81fc7d9 --- /dev/null +++ b/tools/ViewControl/ViewControl_Table.hxx @@ -0,0 +1,95 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_Table_H +#define ViewControl_Table_H + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +class ViewControl_TableModelValues; + +class QAbstractTableModel; +class QContextMenuEvent; +class QWidget; + +//! \class ViewControl_Table +//! \brief View to display table values with possibility to change table columns +//! if the table has 1D dimension and Horizontal orientation +class ViewControl_Table : public QObject +{ + Q_OBJECT +public: + + //! Constructor + Standard_EXPORT ViewControl_Table (QWidget* theParent); + + //! Destructor + virtual ~ViewControl_Table() {} + + //! Sets model into table view, init selection model by the given model, connect to selection change + //! \param theModel table values model + void SetModel (QAbstractTableModel* theModel); + + //! Fills table view and table size control by the model + //! \param theModel values model + Standard_EXPORT void Init (ViewControl_TableModelValues* theModelValues); + + //! true if the table is used in property view and visible + bool IsActive() const { return myIsActive; } + + //! Sets the table active and show the table + //! \param theState boolean value + void SetActive (const bool theState) { myIsActive = theState; TableView()->setVisible (theState); } + + //! \return the text edit control + QWidget* GetControl() const { return myMainWidget; } + + //! \return the table view + QTableView* TableView() const { return myTableView; } + + //! Retuns model indices of the selected cells in table view + //! \param theSelectedIndices [out] a container of indices: row to list of columns + Standard_EXPORT void SelectedIndices (QMap>& aSelectedIndices) const; + + //! Returns pointers from selected cells + Standard_EXPORT void SelectedPointers (QStringList& thePointers) const; + + //! Returns text of separation row in table + //! \return string value + Standard_EXPORT static QString SeparatorData(); + +protected slots: + void onHeaderResized (int theSectionId, int, int); + +private: + bool myIsActive; //!< true if the table is used in property view and visible + + QWidget* myMainWidget; //!< parent of all controls + bool myIsUseProperty; //!< boolean value whether the property control should be shown/hidden + QTableView* myTableView; //!< table view +}; +#endif diff --git a/tools/ViewControl/ViewControl_TableModel.cxx b/tools/ViewControl/ViewControl_TableModel.cxx new file mode 100644 index 0000000000..fe6363f9fc --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModel.cxx @@ -0,0 +1,82 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 + +// ======================================================================= +// function : SetModelValues +// purpose : +// ======================================================================= +void ViewControl_TableModel::SetModelValues (ViewControl_TableModelValues* theModelValues) +{ + if (myModelValues) + delete myModelValues; + + myModelValues = theModelValues; +} + +// ======================================================================= +// function : columnCount +// purpose : +// ======================================================================= +int ViewControl_TableModel::columnCount(const QModelIndex& theParent) const +{ + if (!myModelValues) + return 0; + + return myModelValues->ColumnCount (theParent); +} + +// ======================================================================= +// function : rowCount +// purpose : +// ======================================================================= +int ViewControl_TableModel::rowCount(const QModelIndex& theParent ) const +{ + if (!myModelValues) + return 0; + + return myModelValues->RowCount (theParent); +} + +// ======================================================================= +// function : data +// purpose : +// ======================================================================= +QVariant ViewControl_TableModel::data (const QModelIndex& theIndex, int theRole) const +{ + if (!myModelValues) + return QVariant(); + + int aRow = theIndex.row(), aColumn = theIndex.column(); + return myModelValues->Data (aRow, aColumn, theRole); +} + +// ======================================================================= +// function : setData +// purpose : +// ======================================================================= +bool ViewControl_TableModel::setData (const QModelIndex& theIndex, const QVariant& theValue, int theRole) +{ + if (!myModelValues) + return false; + + int aRow = theIndex.row(), aColumn = theIndex.column(); + bool aResult = myModelValues->SetData (aRow, aColumn, theValue, theRole); + + emit dataChanged (theIndex, theIndex); + + return aResult; +} diff --git a/tools/ViewControl/ViewControl_TableModel.hxx b/tools/ViewControl/ViewControl_TableModel.hxx new file mode 100644 index 0000000000..79714282bb --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModel.hxx @@ -0,0 +1,100 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_TableModel_H +#define ViewControl_TableModel_H + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +//! \class ViewControl_TableModel +//! \brief This is an extension of table model to visualize a container of values +//! It is possible to: +//! - set orientation to interpretate the values. +//! - set table view header values. +//! Items of the view are enabled and selectable. +class ViewControl_TableModel : public QAbstractTableModel +{ +public: + + //! Constructor + ViewControl_TableModel (QObject* theParent = 0) : myModelValues (0) { (void)theParent; } + + //! Destructor + virtual ~ViewControl_TableModel() {} + + //! Returns instance of interface for access totable values + //! \return interface or NULL + ViewControl_TableModelValues* ModelValues() const { return myModelValues; } + + //! Sets interface to table values + //! \theModelValues instance of values + Standard_EXPORT void SetModelValues (ViewControl_TableModelValues* theModelValues); + + //! Emits the layoutChanged signal from outside of this class + void EmitLayoutChanged() { emit layoutChanged(); } + + //! Returns number of columns, depending on orientation: myColumnCount or size of values container + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE; + + //! Returns number of rows, depending on orientation: myColumnCount or size of values container + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE; + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! Sets the new value of passed role to tree cell. + //! \param[in] index refers to item in tree. + //! \param[in] value the new value. + //! \param[in] role the role of value. + Standard_EXPORT virtual bool setData (const QModelIndex& theIndex, const QVariant& theValue, int theRole) Standard_OVERRIDE; + + //! Returns content of the model index for the given role, it is obtainer from internal container of header values + //! It returns value only for DisplayRole. + //! \param theSection an index of value in the container + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + virtual QVariant headerData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const Standard_OVERRIDE + { return myModelValues ? myModelValues->HeaderData (theSection, theOrientation, theRole) : QVariant(); } + + //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable + //! \param theIndex a model index + //! \return flags + Qt::ItemFlags flags (const QModelIndex& theIndex) const + { return myModelValues ? myModelValues->Flags (theIndex) : Qt::NoItemFlags; } + +private: + ViewControl_TableModelValues* myModelValues; //!< interface to table values +}; + +#endif diff --git a/tools/ViewControl/ViewControl_TableModelValues.cxx b/tools/ViewControl/ViewControl_TableModelValues.cxx new file mode 100644 index 0000000000..80a70e3a22 --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModelValues.cxx @@ -0,0 +1,143 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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 + +#include +#include +#include +#include + +// ======================================================================= +// function : ColumnCount +// purpose : +// ======================================================================= + +int ViewControl_TableModelValues::ColumnCount (const QModelIndex&) const +{ + if (!Properties().IsNull()) + return Properties()->ColumnCount(); + + return 0; +} + + +// ======================================================================= +// function : RowCount +// purpose : +// ======================================================================= + +int ViewControl_TableModelValues::RowCount (const QModelIndex&) const +{ + return !Properties().IsNull() ? Properties()->RowCount() : 0; +} + +// ======================================================================= +// function : Data +// purpose : +// ======================================================================= + +QVariant ViewControl_TableModelValues::Data (const int theRow, const int theColumn, int theRole) const +{ + if (!Properties().IsNull()) + { + QVariant aValue = Properties()->Data (theRow, theColumn, theRole); + if (aValue.isValid()) + return aValue; + } + + if (theRole == Qt::TextAlignmentRole) // for multi-lines text, align it to the top + return Qt::AlignTop; + + if ((theRole == Qt::FontRole || theRole == Qt::ForegroundRole) && isItalicHeader (theRow, theColumn)) + { + if (theRole == Qt::FontRole) + { + QFont aFont = qApp->font(); + aFont.setItalic (true); + return aFont; + } + else + return QColor (Qt::darkGray).darker (150); + } + return QVariant(); +} + +// ======================================================================= +// function : SetData +// purpose : +// ======================================================================= + +bool ViewControl_TableModelValues::SetData (const int theRow, const int theColumn, const QVariant& theValue, int) +{ + if (!Properties().IsNull()) + return Properties()->SetData (theRow, theColumn, theValue); + + return false; +} + +// ======================================================================= +// function : HeaderData +// purpose : +// ======================================================================= + +QVariant ViewControl_TableModelValues::HeaderData (int theSection, Qt::Orientation theOrientation, int theRole) const +{ + if (theRole == Qt::DisplayRole) + return myHeaderValues.contains (theOrientation) ? myHeaderValues[theOrientation][theSection].GetName() + : QString::number (theSection + 1); + else if (theRole == Qt::ForegroundRole) + return QColor (Qt::darkGray); + + return QVariant(); +} + +// ======================================================================= +// function : EditType +// purpose : +// ======================================================================= +ViewControl_EditType ViewControl_TableModelValues::EditType (const int theRow, const int theColumn) const +{ + if (!Properties().IsNull()) + { + return Properties()->EditType (theRow, theColumn); + } + return ViewControl_EditType_None; +} + +// ======================================================================= +// function : isItalicHeader +// purpose : +// ======================================================================= +Qt::ItemFlags ViewControl_TableModelValues::Flags (const QModelIndex& theIndex) const +{ + if (!Properties().IsNull()) + { + return Properties()->TableFlags (theIndex.row(), theIndex.column()); + } + return theIndex.isValid() ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags; +} + +// ======================================================================= +// function : isItalicHeader +// purpose : +// ======================================================================= +bool ViewControl_TableModelValues::isItalicHeader (const int theRow, const int theColumn) const +{ + Qt::Orientation anOrientation = myOrientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical; + int aCell = anOrientation == Qt::Horizontal ? theColumn : theRow; + + return HeaderItem (anOrientation, aCell).IsItalic(); +} diff --git a/tools/ViewControl/ViewControl_TableModelValues.hxx b/tools/ViewControl/ViewControl_TableModelValues.hxx new file mode 100644 index 0000000000..058d008e95 --- /dev/null +++ b/tools/ViewControl/ViewControl_TableModelValues.hxx @@ -0,0 +1,161 @@ +// Created on: 2020-01-25 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2020 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_TableModelValues_H +#define ViewControl_TableModelValues_H + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +//! \class ViewControl_TableModelValues +//! \brief This is an interace for ViewControl_TableModel to give real values of the model +//! It should be filled or redefined. +class ViewControl_TableModelValues +{ +public: + + //! Constructor + ViewControl_TableModelValues (const Qt::Orientation& theOrientation = Qt::Vertical) { SetOrientation (theOrientation); } + + //! Destructor + virtual ~ViewControl_TableModelValues() {} + + //! Returns item table properties builder + Handle(TreeModel_ItemProperties) Properties() const { return myProperties; } + + //! Sets item table properties builder + void SetProperties (const Handle(TreeModel_ItemProperties)& theProperties) { myProperties = theProperties; } + + //! Sets direction of the values applying, whether it should be placed by rows or by columns + //! \param theOrientation if horizontal, the values are applied by rows, otherwise by columns + void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; } + + //! Fills the model header values for orientation. + //! \param theValues a container of header text values + //! \param theOrientation an orientation of header + void SetHeaderValues (const QList& theValues, const Qt::Orientation theOrientation) + { myHeaderValues.insert (theOrientation, theValues); } + + //! Returns whether the column is hidden by default + //! \param theColumnId a column index + //! \return header section values container + TreeModel_HeaderSection HeaderItem (const Qt::Orientation theOrientation, const int theColumnId) const + { return myHeaderValues.contains(theOrientation) ? myHeaderValues[theOrientation][theColumnId] : TreeModel_HeaderSection(); } + + //! Stores information about table view header visibility + //! \param theOrientation an orientation of header + //! \param theVisibility if true, header is visible + void SetHeaderVisible (const Qt::Orientation theOrientation, const bool theVisibility) + { myVisibleHeader.insert (theOrientation, theVisibility); } + + //! Stores information about table view header visibility + //! \param theOrientation an orientation of header + //! \param theVisibility if true, header is visible + bool IsHeaderVisible (const Qt::Orientation theOrientation) const + { return myVisibleHeader.contains(theOrientation) ? myVisibleHeader[theOrientation] : true; } + + //! Get default section size if defined + //! \param theOrientation an orientation of header + //! \param theVisibility if true, header is visible + bool DefaultSectionSize (const Qt::Orientation theOrientation, int& theSectionSize) + { + theSectionSize = myDefaultSectionSize.contains (theOrientation) ? myDefaultSectionSize[theOrientation] : -1; + return myDefaultSectionSize.contains (theOrientation); + } + + //! Set default section size if defined + //! \param theOrientation an orientation of header + //! \param theVisibility if true, header is visible + void SetDefaultSectionSize (const Qt::Orientation theOrientation, const int& theSectionSize) + { myDefaultSectionSize.insert(theOrientation, theSectionSize); } + + //! Returns number of columns, size of header values + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int ColumnCount (const QModelIndex& theParent = QModelIndex()) const; + + //! Returns number of rows, depending on orientation: myColumnCount or size of values container + //! \param theParent an index of the parent item + //! \return an integer value + Standard_EXPORT virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const; + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const; + + //! Sets content of the model index for the given role, it is applied to internal container of values + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param theRole a view role + //! \return true if the value is changed + Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue, + int theRole = Qt::DisplayRole); + + //! Returns content of the model index for the given role, it is obtainer from internal container of header values + //! It returns value only for DisplayRole. + //! \param theSection an index of value in the container + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + Standard_EXPORT virtual QVariant HeaderData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const; + + //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable + //! \param theIndex a model index + //! \return flags + Standard_EXPORT virtual Qt::ItemFlags Flags (const QModelIndex& theIndex) const; + + //! Returns type of edit control for the model index. By default, it is an empty control + //! \param theRow a model index row + //! \param theColumn a model index column + //! \return edit type + Standard_EXPORT virtual ViewControl_EditType EditType (const int theRow, const int theColumn) const; + + //! Returns default color for editable cell + //! \return color value + static QColor EditCellColor() { return QColor (Qt::darkBlue); } + +protected: + //! Returns true if the header item is italic of the parameter index + //! \param theRow a model index row + //! \param theColumn a model index column + //! \param boolean value + bool isItalicHeader (const int theRow, const int theColumn) const; + +protected: + + Qt::Orientation myOrientation; //!< orientation how the values should fill the current table view + QMap > myHeaderValues; //!< table header values + QMap myVisibleHeader; //!< table header visibility + QMap myDefaultSectionSize; //!< table section default size + + Handle(TreeModel_ItemProperties) myProperties; //!< item properties +}; + +#endif diff --git a/tools/ViewControl/ViewControl_Tools.cxx b/tools/ViewControl/ViewControl_Tools.cxx index 99d3e441ef..1ad884d5d4 100644 --- a/tools/ViewControl/ViewControl_Tools.cxx +++ b/tools/ViewControl/ViewControl_Tools.cxx @@ -15,10 +15,15 @@ #include +#include +#include + #include #include +#include #include #include +#include #include #include @@ -43,3 +48,61 @@ void ViewControl_Tools::SetWhiteBackground (QWidget* theControl) aPalette.setColor (QPalette::All, QPalette::Foreground, Qt::white); theControl->setPalette (aPalette); } + +// ======================================================================= +// function : SetDefaultHeaderSections +// purpose : +// ======================================================================= +void ViewControl_Tools::SetDefaultHeaderSections(QTableView* theTableView, const Qt::Orientation theOrientation) +{ + ViewControl_TableModel * aTableModel = dynamic_cast (theTableView->model()); + ViewControl_TableModelValues* aModelValues = aTableModel->ModelValues(); + if (!aModelValues) + return; + + int aSectionSize; + if (aModelValues->DefaultSectionSize (Qt::Horizontal, aSectionSize) ) + theTableView->horizontalHeader()->setDefaultSectionSize (aSectionSize); + else { + bool isStretchLastSection = true; + for (int aColumnId = 0, aNbColumns = aTableModel->columnCount(); aColumnId < aNbColumns; aColumnId++) + { + TreeModel_HeaderSection aSection = aModelValues->HeaderItem (theOrientation, aColumnId); + if (aSection.IsEmpty()) + continue; + + int aColumnWidth = aSection.GetWidth(); + if (aColumnWidth > 0) + { + theTableView->setColumnWidth (aColumnId, aColumnWidth); + if (aColumnId == aNbColumns - 1) + isStretchLastSection = false; + } + theTableView->setColumnHidden (aColumnId, aSection.IsHidden()); + } + if (isStretchLastSection != theTableView->horizontalHeader()->stretchLastSection()) + theTableView->horizontalHeader()->setStretchLastSection (isStretchLastSection); + } +} + +// ======================================================================= +// function : CreateTableModelValues +// purpose : +// ======================================================================= +ViewControl_TableModelValues* ViewControl_Tools::CreateTableModelValues (QItemSelectionModel* theSelectionModel) +{ + ViewControl_TableModelValues* aTableValues = 0; + + QModelIndex anIndex = TreeModel_ModelBase::SingleSelected (theSelectionModel->selectedIndexes(), 0); + TreeModel_ItemBasePtr anItemBase = TreeModel_ModelBase::GetItemByIndex (anIndex); + if (!anItemBase) + return aTableValues; + + const Handle(TreeModel_ItemProperties)& anItemProperties = anItemBase->Properties(); + if (anItemProperties.IsNull()) + return aTableValues; + + aTableValues = new ViewControl_TableModelValues(); + aTableValues->SetProperties (anItemProperties); + return aTableValues; +} diff --git a/tools/ViewControl/ViewControl_Tools.hxx b/tools/ViewControl/ViewControl_Tools.hxx index 7dd4bd4b39..39994b6cbe 100644 --- a/tools/ViewControl/ViewControl_Tools.hxx +++ b/tools/ViewControl/ViewControl_Tools.hxx @@ -18,13 +18,18 @@ #include #include +#include #include #include #include +class ViewControl_TableModelValues; + class QAction; +class QItemSelectionModel; class QObject; +class QTableView; class QWidget; //! \class ViewControl_Tools @@ -32,6 +37,9 @@ class QWidget; class ViewControl_Tools { public: + //! Returns text of separation row in table + //! \return string value + static QString TableSeparator() { return "---------------------------"; } //! Creates an action with the given text connected to the slot //! \param theText an action text value @@ -46,6 +54,15 @@ public: //! \param theControl a widget to be modified Standard_EXPORT static void SetWhiteBackground (QWidget* theControl); + //! Fills tree view by default sections parameters obtained in view's table model + //! \param theTableView table view instance + //! \param theOrientation header orientation + Standard_EXPORT static void SetDefaultHeaderSections (QTableView* theTableView, const Qt::Orientation theOrientation); + + //! Create table of values on the current selection + //! It is created if the selection contains only one item and it has a property item + Standard_EXPORT static ViewControl_TableModelValues* CreateTableModelValues (QItemSelectionModel* theSelectionModel); + }; #endif diff --git a/tools/ViewControl/ViewControl_TreeView.hxx b/tools/ViewControl/ViewControl_TreeView.hxx index 20db18fa5a..046ea406d1 100644 --- a/tools/ViewControl/ViewControl_TreeView.hxx +++ b/tools/ViewControl/ViewControl_TreeView.hxx @@ -45,7 +45,7 @@ public: 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 + QSize myDefaultSize; //!< default size, empty size if it should not be used }; #endif