0030268: Inspectors - improvements in VInspector plugin
[occt.git] / tools / DFBrowserPaneXDE / DFBrowserPaneXDE_XCAFDocShapeMapTool.cxx
CommitLineData
14bbbdcb 1// Created on: 2017-06-16
2// Created by: Natalia ERMOLAEVA
3// Copyright (c) 2017 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
0cb512c0 16#include <inspector/DFBrowserPaneXDE_XCAFDocShapeMapTool.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19#include <inspector/DFBrowserPane_HelperExport.hxx>
20#include <inspector/DFBrowserPane_ItemDelegateButton.hxx>
21#include <inspector/DFBrowserPane_TableView.hxx>
22#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 23
24#include <AIS_Shape.hxx>
25#include <BRepTools.hxx>
26#include <BRep_Builder.hxx>
27#include <TopoDS_Shape.hxx>
28#include <TopoDS_Compound.hxx>
29#include <XCAFDoc_ShapeMapTool.hxx>
30
130eb114 31#include <Standard_WarningsDisable.hxx>
14bbbdcb 32#include <QEvent>
33#include <QFileDialog>
34#include <QGridLayout>
35#include <QHeaderView>
36#include <QIcon>
37#include <QMap>
38#include <QPainter>
39#include <QStyledItemDelegate>
40#include <QTableView>
41#include <QVariant>
42#include <QWidget>
130eb114 43#include <Standard_WarningsRestore.hxx>
14bbbdcb 44
45const int COLUMN_EXPORT_WIDTH = 20;
46const int COLUMN_TYPE_WIDTH = 70;
47const int COLUMN_POINTER_WIDTH = 110;
48
49// =======================================================================
50// function : Constructor
51// purpose :
52// =======================================================================
53DFBrowserPaneXDE_XCAFDocShapeMapTool::DFBrowserPaneXDE_XCAFDocShapeMapTool()
54: DFBrowserPane_AttributePane(), myHelperExport (0)
55{
56 QList<QVariant> aHeaderValues;
57 aHeaderValues << "TShape"<< "Type" << "";
58
59 getPaneModel()->SetHeaderValues (aHeaderValues, Qt::Horizontal);
60 getPaneModel()->SetColumnCount (aHeaderValues.count());
d2c90917 61 getPaneModel()->SetItalicColumns (QList<int>());
14bbbdcb 62}
63
64// =======================================================================
65// function : CreateWidget
66// purpose :
67// =======================================================================
68QWidget* DFBrowserPaneXDE_XCAFDocShapeMapTool::CreateWidget (QWidget* theParent)
69{
70 QWidget* aMainWidget = new QWidget (theParent);
71 aMainWidget->setVisible (false);
72
73 myTableView = new DFBrowserPane_TableView (aMainWidget);
74 myTableView->SetModel (myPaneModel);
75 QTableView* aTableView = myTableView->GetTableView();
76 aTableView->setSelectionModel (mySelectionModels.front());
77 aTableView->horizontalHeader()->setStretchLastSection (false);
78
79 aTableView->setColumnWidth (0, COLUMN_POINTER_WIDTH);
80 aTableView->setColumnWidth (1, COLUMN_TYPE_WIDTH);
81 aTableView->setColumnWidth (2, COLUMN_EXPORT_WIDTH);
82 aTableView->verticalHeader()->setVisible (true);
83 DFBrowserPane_ItemDelegateButton* anItemDelegate = new DFBrowserPane_ItemDelegateButton (aTableView,
84 ":/icons/export_shape.png");
85 QObject::connect (anItemDelegate, SIGNAL (buttonPressed (const QModelIndex&)),
86 &myHelperExport, SLOT (OnButtonPressed (const QModelIndex&)));
87 aTableView->setItemDelegateForColumn (2, anItemDelegate);
88
89 QGridLayout* aLay = new QGridLayout (aMainWidget);
90 aLay->setContentsMargins (0, 0, 0, 0);
91 aLay->addWidget (myTableView, 0, 0);
92
93 return aMainWidget;
94}
95
96// =======================================================================
97// function : Init
98// purpose :
99// =======================================================================
100void DFBrowserPaneXDE_XCAFDocShapeMapTool::Init (const Handle(TDF_Attribute)& theAttribute)
101{
102 DFBrowserPane_AttributePaneAPI::Init (theAttribute);
103}
104
105// =======================================================================
106// function : GetValues
107// purpose :
108// =======================================================================
109void DFBrowserPaneXDE_XCAFDocShapeMapTool::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
110{
111 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
112
113 const TopTools_IndexedMapOfShape& aShapeMap = anAttr->GetMap();
114 for (int aShapeValueId = 1, aNbShapes = aShapeMap.Extent(); aShapeValueId <= aNbShapes; aShapeValueId++)
115 {
116 const TopoDS_Shape& aShape = aShapeMap(aShapeValueId);
117
118 if (!aShape.IsNull())
7e1c1e48 119 theValues << Standard_Dump::GetPointerInfo (aShape.TShape()->This()).ToCString()
14bbbdcb 120 << DFBrowserPane_Tools::ShapeTypeInfo (aShape)
121 << "";
122 else
123 theValues << "" << "" << "";
124 }
125}
126
127// =======================================================================
128// function : GetShortAttributeInfo
129// purpose :
130// =======================================================================
131void DFBrowserPaneXDE_XCAFDocShapeMapTool::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
132 QList<QVariant>& theValues)
133{
134 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
135 theValues.append (QString ("[%1]").arg (anAttr->GetMap().Extent()));
136}
137
138// =======================================================================
139// function : GetPresentation
140// purpose :
141// =======================================================================
142Handle(Standard_Transient) DFBrowserPaneXDE_XCAFDocShapeMapTool::GetPresentation (const Handle(TDF_Attribute)& theAttribute)
143{
144 Handle(AIS_InteractiveObject) aPresentation;
145
146 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
147 if (anAttr.IsNull())
148 return aPresentation;
149
150 BRep_Builder aBuilder;
151 TopoDS_Compound aComp;
152 aBuilder.MakeCompound (aComp);
153
154 const TopTools_IndexedMapOfShape& aShapeMap = anAttr->GetMap();
155 for (int aShapeValueId = 1, aNbShapes = aShapeMap.Extent(); aShapeValueId <= aNbShapes; aShapeValueId++)
156 {
157 const TopoDS_Shape& aShape = aShapeMap(aShapeValueId);
158 if (!aShape.IsNull())
159 aBuilder.Add (aComp, aShape);
160 }
161 aPresentation = new AIS_Shape (aComp);
162 return aPresentation;
163}