1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0029674: Improvements in Inspector tool

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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