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/DFBrowserPane_TNamingUsedShapes.hxx>
18 #include <AIS_Shape.hxx>
19 #include <BRep_Builder.hxx>
21 #include <inspector/DFBrowserPane_AttributePaneModel.hxx>
22 #include <inspector/DFBrowserPane_AttributePaneSelector.hxx>
23 #include <inspector/DFBrowserPane_TableView.hxx>
24 #include <inspector/DFBrowserPane_Tools.hxx>
26 #include <TDF_Label.hxx>
28 #include <TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <TNaming_PtrRefShape.hxx>
31 #include <TNaming_RefShape.hxx>
32 #include <TNaming_UsedShapes.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_Shape.hxx>
37 #include <Standard_WarningsDisable.hxx>
38 #include <QItemSelectionModel>
42 #include <Standard_WarningsRestore.hxx>
44 const int COLUMN_TYPE_WIDTH = 70;
45 const int COLUMN_POINTER_WIDTH = 90;
46 const int COLUMN_REFERENCE_WIDTH = 90;
48 // =======================================================================
49 // function : Constructor
51 // =======================================================================
52 DFBrowserPane_TNamingUsedShapes::DFBrowserPane_TNamingUsedShapes()
53 : DFBrowserPane_AttributePane()
55 getPaneModel()->SetColumnCount (4);
56 getPaneModel()->SetItalicColumns (QList<int>());
58 QList<QVariant> aValues;
59 aValues << "ShapeType" << "TShape" << "Label" << "RefShape";
60 getPaneModel()->SetHeaderValues (aValues, Qt::Horizontal);
63 // =======================================================================
64 // function : GetValues
66 // =======================================================================
67 void DFBrowserPane_TNamingUsedShapes::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
69 Handle(TNaming_UsedShapes) anAttribute = Handle(TNaming_UsedShapes)::DownCast (theAttribute);
70 if (anAttribute.IsNull())
73 std::list<TCollection_AsciiString> aReferences;
74 TNaming_DataMapOfShapePtrRefShape& aMap = anAttribute->Map();
75 for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (aMap); aRefIt.More(); aRefIt.Next())
77 TopoDS_Shape aShape = aRefIt.Key();
78 TNaming_PtrRefShape aPtrRefShape = aRefIt.Value();
82 theValues.append(DFBrowserPane_Tools::ToName(DB_SHAPE_TYPE, aShape.ShapeType()).ToCString());
83 theValues.append(DFBrowserPane_Tools::GetPointerInfo(aShape.TShape()->This()).ToCString());
86 theValues << "EMPTY SHAPE" << "";
88 if (aPtrRefShape && aPtrRefShape->FirstUse())
90 theValues.append(DFBrowserPane_Tools::GetEntry(aPtrRefShape->Label()).ToCString());
91 const TopoDS_Shape& aValueShape = aPtrRefShape->Shape();
92 theValues.append(!aValueShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo(aValueShape.TShape()->This()).ToCString() : "");
95 theValues << "" << "";
99 // =======================================================================
100 // function : GetShortAttributeInfo
102 // =======================================================================
103 void DFBrowserPane_TNamingUsedShapes::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
104 QList<QVariant>& theValues)
106 Handle(TNaming_UsedShapes) anAttribute = Handle(TNaming_UsedShapes)::DownCast (theAttribute);
107 if (anAttribute.IsNull())
110 theValues.append (QString ("%1").arg (anAttribute->Map().Extent()));
113 // =======================================================================
114 // function : GetAttributeReferences
116 // =======================================================================
117 void DFBrowserPane_TNamingUsedShapes::GetAttributeReferences (const Handle(TDF_Attribute)& theAttribute,
118 NCollection_List<Handle(TDF_Attribute)>& theRefAttributes,
119 Handle(Standard_Transient)& /*theRefPresentation*/)
121 Handle(TNaming_UsedShapes) anAttribute = Handle(TNaming_UsedShapes)::DownCast (theAttribute);
122 if (anAttribute.IsNull())
125 QStringList aSelectedEntries = DFBrowserPane_TableView::GetSelectedColumnValues (getTableView()->GetTableView(), 2);
126 if (aSelectedEntries.isEmpty())
129 for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (anAttribute->Map()); aRefIt.More(); aRefIt.Next())
131 TNaming_PtrRefShape aPtrRefShape = aRefIt.Value();
132 if (!aPtrRefShape || !aPtrRefShape->FirstUse())
135 if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aPtrRefShape->Label()).ToCString()))
136 theRefAttributes.Append (aPtrRefShape->NamedShape());
140 // =======================================================================
141 // function : getTableColumnWidths
143 // =======================================================================
144 QMap<int, int> DFBrowserPane_TNamingUsedShapes::getTableColumnWidths() const
146 QMap<int, int> aValues;
147 aValues[0] = COLUMN_TYPE_WIDTH; // "ShapeType"
148 aValues[1] = COLUMN_POINTER_WIDTH; // "Key_TShape"
149 aValues[2] = COLUMN_REFERENCE_WIDTH; // "Label Entry"