1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <inspector/DFBrowserPaneXDE_XCAFDocShapeMapTool.hxx>
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>
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>
31 #include <Standard_WarningsDisable.hxx>
33 #include <QFileDialog>
34 #include <QGridLayout>
35 #include <QHeaderView>
39 #include <QStyledItemDelegate>
43 #include <Standard_WarningsRestore.hxx>
45 const int COLUMN_EXPORT_WIDTH = 20;
46 const int COLUMN_TYPE_WIDTH = 70;
47 const int COLUMN_POINTER_WIDTH = 110;
49 // =======================================================================
50 // function : Constructor
52 // =======================================================================
53 DFBrowserPaneXDE_XCAFDocShapeMapTool::DFBrowserPaneXDE_XCAFDocShapeMapTool()
54 : DFBrowserPane_AttributePane(), myHelperExport (0)
56 QList<QVariant> aHeaderValues;
57 aHeaderValues << "TShape"<< "Type" << "";
59 getPaneModel()->SetHeaderValues (aHeaderValues, Qt::Horizontal);
60 getPaneModel()->SetColumnCount (aHeaderValues.count());
61 getPaneModel()->SetItalicColumns (QList<int>());
64 // =======================================================================
65 // function : CreateWidget
67 // =======================================================================
68 QWidget* DFBrowserPaneXDE_XCAFDocShapeMapTool::CreateWidget (QWidget* theParent)
70 QWidget* aMainWidget = new QWidget (theParent);
71 aMainWidget->setVisible (false);
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);
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);
89 QGridLayout* aLay = new QGridLayout (aMainWidget);
90 aLay->setContentsMargins (0, 0, 0, 0);
91 aLay->addWidget (myTableView, 0, 0);
96 // =======================================================================
99 // =======================================================================
100 void DFBrowserPaneXDE_XCAFDocShapeMapTool::Init (const Handle(TDF_Attribute)& theAttribute)
102 DFBrowserPane_AttributePaneAPI::Init (theAttribute);
105 // =======================================================================
106 // function : GetValues
108 // =======================================================================
109 void DFBrowserPaneXDE_XCAFDocShapeMapTool::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
111 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
113 const TopTools_IndexedMapOfShape& aShapeMap = anAttr->GetMap();
114 for (int aShapeValueId = 1, aNbShapes = aShapeMap.Extent(); aShapeValueId <= aNbShapes; aShapeValueId++)
116 const TopoDS_Shape& aShape = aShapeMap(aShapeValueId);
118 if (!aShape.IsNull())
119 theValues << DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString()
120 << DFBrowserPane_Tools::ShapeTypeInfo (aShape)
123 theValues << "" << "" << "";
127 // =======================================================================
128 // function : GetShortAttributeInfo
130 // =======================================================================
131 void DFBrowserPaneXDE_XCAFDocShapeMapTool::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
132 QList<QVariant>& theValues)
134 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
135 theValues.append (QString ("[%1]").arg (anAttr->GetMap().Extent()));
138 // =======================================================================
139 // function : GetPresentation
141 // =======================================================================
142 Handle(Standard_Transient) DFBrowserPaneXDE_XCAFDocShapeMapTool::GetPresentation (const Handle(TDF_Attribute)& theAttribute)
144 Handle(AIS_InteractiveObject) aPresentation;
146 Handle(XCAFDoc_ShapeMapTool) anAttr = Handle(XCAFDoc_ShapeMapTool)::DownCast (theAttribute);
148 return aPresentation;
150 BRep_Builder aBuilder;
151 TopoDS_Compound aComp;
152 aBuilder.MakeCompound (aComp);
154 const TopTools_IndexedMapOfShape& aShapeMap = anAttr->GetMap();
155 for (int aShapeValueId = 1, aNbShapes = aShapeMap.Extent(); aShapeValueId <= aNbShapes; aShapeValueId++)
157 const TopoDS_Shape& aShape = aShapeMap(aShapeValueId);
158 if (!aShape.IsNull())
159 aBuilder.Add (aComp, aShape);
161 aPresentation = new AIS_Shape (aComp);
162 return aPresentation;