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_TNamingNaming.hxx>
18 #include <AIS_Shape.hxx>
19 #include <BRep_Builder.hxx>
21 #include <inspector/DFBrowserPane_AttributePaneModel.hxx>
22 #include <inspector/DFBrowserPane_TableView.hxx>
23 #include <inspector/DFBrowserPane_Tools.hxx>
25 #include <TDF_Label.hxx>
26 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
27 #include <TNaming_Name.hxx>
28 #include <TNaming_Naming.hxx>
29 #include <TNaming_NamedShape.hxx>
31 #include <TopoDS_Compound.hxx>
33 #include <QGridLayout>
34 #include <QHeaderView>
39 // =======================================================================
40 // function : Constructor
42 // =======================================================================
43 DFBrowserPane_TNamingNaming::DFBrowserPane_TNamingNaming()
44 : DFBrowserPane_AttributePane(), myNamingView (0)
46 myNamingModel = new DFBrowserPane_AttributePaneModel();
47 myNamingModel->SetColumnCount (2);
50 // =======================================================================
51 // function : CreateWidget
53 // =======================================================================
54 QWidget* DFBrowserPane_TNamingNaming::CreateWidget (QWidget* theParent)
56 QWidget* aMainWidget = new QWidget (theParent);
58 myNamingView = new DFBrowserPane_TableView (aMainWidget);
59 myNamingView->GetTableView()->verticalHeader()->setVisible (false);
60 myNamingView->GetTableView()->horizontalHeader()->setVisible (false);
61 myNamingView->SetModel (myNamingModel);
63 myTableView = new DFBrowserPane_TableView (aMainWidget);
64 myTableView->SetModel (getPaneModel());
65 myTableView->GetTableView()->setSelectionModel (mySelectionModels.front());
67 QGridLayout* aLay = new QGridLayout (aMainWidget);
68 aLay->setContentsMargins (0, 0, 0, 0);
69 aLay->addWidget (myNamingView);
70 aLay->addWidget (myTableView);
71 aLay->setRowStretch (1, 1);
76 // =======================================================================
79 // =======================================================================
80 void DFBrowserPane_TNamingNaming::Init (const Handle(TDF_Attribute)& theAttribute)
82 QList<QVariant> aValues;
83 GetValues (theAttribute, aValues);
85 QList<QVariant> aNamingValues;
86 for (int anValueId = 0; anValueId < 14; anValueId++)
87 aNamingValues.append (aValues[anValueId]);
88 myNamingModel->Init (aNamingValues);
90 myNamingView->GetTableView()->resizeColumnToContents (0);
92 QList<QVariant> aNamedShapesValues;
93 for (int anValueId = 14, aCount = aValues.size(); anValueId < aCount; anValueId++)
94 aNamedShapesValues.append (aValues[anValueId]);
96 getPaneModel()->Init (aNamedShapesValues);
98 myTableView->GetTableView()->resizeColumnToContents (0);
101 // =======================================================================
102 // function : GetValues
104 // =======================================================================
105 void DFBrowserPane_TNamingNaming::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
107 Handle(TNaming_Naming) anAttribute = Handle(TNaming_Naming)::DownCast (theAttribute);
108 if (anAttribute.IsNull())
111 TNaming_Name aNamingName = anAttribute->GetName();
114 theValues.append ("Type");
115 theValues.append (DFBrowserPane_Tools::ToName (DB_NAMING_TYPE, aNamingName.Type()).ToCString());
116 theValues.append ("ShapeType");
117 theValues.append (DFBrowserPane_Tools::ToName (DB_SHAPE_TYPE, aNamingName.ShapeType()).ToCString());
118 Handle(TNaming_NamedShape) aStopShape = aNamingName.StopNamedShape();
119 theValues.append ("StopNamedShape");
120 theValues.append (!aStopShape.IsNull() ? DFBrowserPane_Tools::GetEntry (aStopShape->Label()).ToCString() : "");
121 theValues.append ("Index");
122 theValues.append (QString::number (aNamingName.Index()));
123 TopoDS_Shape aShape = aNamingName.Shape();
124 theValues.append ("Shape(TShape)");
125 theValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString() : "");
126 TDF_Label aContextLabel = aNamingName.ContextLabel();
127 theValues.append ("ContextLabel");
128 theValues.append (!aContextLabel.IsNull() ? DFBrowserPane_Tools::GetEntry (aContextLabel).ToCString() : "");
129 theValues.append ("Orientation");
130 theValues.append (DFBrowserPane_Tools::ToName (DB_ORIENTATION_TYPE, aNamingName.Orientation()).ToCString());
132 // values from 14 till count of arguments
134 for (TNaming_ListIteratorOfListOfNamedShape anArgIt(aNamingName.Arguments()); anArgIt.More(); anArgIt.Next(), anArgIndex++)
136 theValues << "Argument";
137 theValues.append (DFBrowserPane_Tools::GetEntry (anArgIt.Value()->Label()).ToCString());
141 // =======================================================================
142 // function : GetPresentation
144 // =======================================================================
145 Handle(Standard_Transient) DFBrowserPane_TNamingNaming::GetPresentation (const Handle (TDF_Attribute)& theAttribute)
147 Handle(Standard_Transient) aPresentation;
148 Handle(TNaming_Naming) anAttribute = Handle(TNaming_Naming)::DownCast (theAttribute);
149 if (anAttribute.IsNull())
150 return aPresentation;
152 DFBrowserPane_TableView* aTableView = getTableView();
153 if (!aTableView) // the pane is not visualized yet
154 return aPresentation;
156 QStringList aSelectedEntries = DFBrowserPane_TableView::GetSelectedColumnValues (aTableView->GetTableView(), 1);
157 TNaming_Name aNamingName = anAttribute->GetName();
159 BRep_Builder aBuilder;
160 TopoDS_Compound aComp;
161 aBuilder.MakeCompound (aComp);
162 bool aHasShapes = false;
163 for (TNaming_ListIteratorOfListOfNamedShape aNamingIt(aNamingName.Arguments()); aNamingIt.More(); aNamingIt.Next())
165 Handle(TNaming_NamedShape) aShapeAttr = aNamingIt.Value();
166 if (aShapeAttr.IsNull())
168 TDF_Label aLabel = aShapeAttr->Label();
169 if (!aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aLabel).ToCString()))
171 aBuilder.Add (aComp, aShapeAttr->Get());
174 TopoDS_Shape aShape = aComp;
175 if (!aShape.IsNull() && aHasShapes)
176 aPresentation = new AIS_Shape (aShape);
178 return aPresentation;
181 // =======================================================================
182 // function : GetReferences
184 // =======================================================================
185 void DFBrowserPane_TNamingNaming::GetReferences (const Handle(TDF_Attribute)& theAttribute,
186 NCollection_List<TDF_Label>& theRefLabels,
187 Handle(Standard_Transient)&)
189 Handle(TNaming_Naming) anAttribute = Handle(TNaming_Naming)::DownCast (theAttribute);
190 if (anAttribute.IsNull())
193 QStringList aSelectedEntries = DFBrowserPane_TableView::GetSelectedColumnValues (getTableView()->GetTableView(), 1);
194 for (TNaming_ListIteratorOfListOfNamedShape aNamingIt(anAttribute->GetName().Arguments()); aNamingIt.More(); aNamingIt.Next())
196 Handle(TNaming_NamedShape) aShapeAttr = aNamingIt.Value();
197 if (aShapeAttr.IsNull())
199 TDF_Label aLabel = aShapeAttr->Label();
200 if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aLabel).ToCString()))
201 theRefLabels.Append (aLabel);