1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0029743: Samples - Inspector tool - crash by selecting TNaming_UsedShapes tree item

- TNaming_UsedShapes is corrected to do not call methods of empty TopoDS_Shape
- TNaming_NamedShape is corrected to have not NULL TNaming_RefShape even if TopoDS_Shape is NULL(TNaming_Builder::Delete).
- DFBrowserPane presentation tree item for this is corrected in the same way and obsolete methods of processing SortedReferences are removed.
This commit is contained in:
nds 2018-05-08 17:55:09 +03:00 committed by abv
parent b2300241d1
commit 26b004e9e8
5 changed files with 37 additions and 76 deletions

View File

@ -722,6 +722,7 @@ void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
TNaming_Node* pdn = new TNaming_Node(pos,pns);
myAtt->Add(pdn);
UpdateFirstUseOrNextSameShape (pos,pdn);
UpdateFirstUseOrNextSameShape (pns,pdn);
}
//=======================================================================

View File

@ -159,7 +159,14 @@ Standard_OStream& TNaming_UsedShapes::Dump(Standard_OStream& anOS) const
anOS<<"The content of UsedShapes attribute:"<<endl;
TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape itr(myMap);
for (; itr.More(); itr.Next()) {
anOS<<" ";
if (itr.Key().IsNull())
{
anOS << "Empty Shape at label =";
itr.Value()->Label().EntryDump(anOS);
anOS << endl;
continue;
}
anOS << " ";
TopAbs::Print(itr.Key().ShapeType(),anOS);
anOS<<" ";
itr.Value()->Label().EntryDump(anOS);

6
tests/tools/dfbrowser/A7 Normal file
View File

@ -0,0 +1,6 @@
puts "========"
puts "0029743: Samples - Inspector tool - crash by selecting TNaming_UsedShapes tree item"
puts "========"
pload INSPECTOR
tinspector -plugins dfbrowser -open [locate_data_file bug29743.cbf] -select 0 TNaming_UsedShapes

View File

@ -71,66 +71,29 @@ void DFBrowserPane_TNamingUsedShapes::GetValues (const Handle(TDF_Attribute)& th
return;
std::list<TCollection_AsciiString> aReferences;
if (myAttributeRefs.Find (anAttribute, aReferences))
TNaming_DataMapOfShapePtrRefShape& aMap = anAttribute->Map();
for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (aMap); aRefIt.More(); aRefIt.Next())
{
QMap<TCollection_AsciiString, QList<QVariant> > anEntryValues;
QList<QVariant> aValues;
TNaming_DataMapOfShapePtrRefShape& aMap = anAttribute->Map();
for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (aMap); aRefIt.More(); aRefIt.Next())
TopoDS_Shape aShape = aRefIt.Key();
TNaming_PtrRefShape aPtrRefShape = aRefIt.Value();
if (!aShape.IsNull())
{
TCollection_AsciiString anEntry = DFBrowserPane_Tools::GetEntry (aRefIt.Value()->Label());
aValues.clear();
TopoDS_Shape aShape = aRefIt.Key();
aValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::ToName (DB_SHAPE_TYPE, aShape.ShapeType()).ToCString()
: "EMPTY SHAPE");
aValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString() : "");
const TopoDS_Shape aValueShape = aRefIt.Value()->Shape();
aValues.append (!aValueShape.IsNull() ?
DFBrowserPane_Tools::GetPointerInfo (aValueShape.TShape()->This()).ToCString() : "");
anEntryValues[anEntry] = aValues;
theValues.append(DFBrowserPane_Tools::ToName(DB_SHAPE_TYPE, aShape.ShapeType()).ToCString());
theValues.append(DFBrowserPane_Tools::GetPointerInfo(aShape.TShape()->This()).ToCString());
}
else
theValues << "EMPTY SHAPE" << "";
for (std::list<TCollection_AsciiString>::const_iterator aRefIt = aReferences.begin(); aRefIt != aReferences.end(); aRefIt++)
if (aPtrRefShape && aPtrRefShape->FirstUse())
{
aValues = anEntryValues[*aRefIt];
theValues << aValues[0] << aValues[1] << QString ((*aRefIt).ToCString()) << aValues[2];
theValues.append(DFBrowserPane_Tools::GetEntry(aPtrRefShape->Label()).ToCString());
const TopoDS_Shape& aValueShape = aPtrRefShape->Shape();
theValues.append(!aValueShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo(aValueShape.TShape()->This()).ToCString() : "");
}
else
theValues << "" << "";
}
else
{
TNaming_DataMapOfShapePtrRefShape& aMap = anAttribute->Map();
for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (aMap); aRefIt.More(); aRefIt.Next())
{
TopoDS_Shape aShape = aRefIt.Key();
theValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::ToName (DB_SHAPE_TYPE, aShape.ShapeType()).ToCString()
: "EMPTY SHAPE");
theValues.append (!aShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aShape.TShape()->This()).ToCString() : "");
theValues.append (DFBrowserPane_Tools::GetEntry (aRefIt.Value()->Label()).ToCString());
const TopoDS_Shape aValueShape = aRefIt.Value()->Shape();
theValues.append (!aValueShape.IsNull() ? DFBrowserPane_Tools::GetPointerInfo (aValueShape.TShape()->This()).ToCString() : "");
}
}
}
// =======================================================================
// function : GetAttributeInfo
// purpose :
// =======================================================================
QVariant DFBrowserPane_TNamingUsedShapes::GetAttributeInfo (const Handle(TDF_Attribute)& theAttribute, int theRole,
int theColumnId)
{
if (theColumnId != 0)
return DFBrowserPane_AttributePane::GetAttributeInfo (theAttribute, theRole, theColumnId);
switch (theRole)
{
case Qt::ForegroundRole: return QColor (myAttributeRefs.IsEmpty() ? Qt::gray : Qt::black);
case Qt::ToolTipRole:
return QVariant (myAttributeRefs.IsEmpty() ? QString (QObject::tr ("Content is not sorted yet")) : "");
default:
break;
}
return DFBrowserPane_AttributePane::GetAttributeInfo (theAttribute, theRole, theColumnId);
}
// =======================================================================
@ -165,8 +128,12 @@ void DFBrowserPane_TNamingUsedShapes::GetAttributeReferences (const Handle(TDF_A
for (TNaming_DataMapIteratorOfDataMapOfShapePtrRefShape aRefIt (anAttribute->Map()); aRefIt.More(); aRefIt.Next())
{
if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aRefIt.Value()->Label()).ToCString()))
theRefAttributes.Append (aRefIt.Value()->NamedShape());
TNaming_PtrRefShape aPtrRefShape = aRefIt.Value();
if (!aPtrRefShape || !aPtrRefShape->FirstUse())
continue;
if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aPtrRefShape->Label()).ToCString()))
theRefAttributes.Append (aPtrRefShape->NamedShape());
}
}

View File

@ -18,7 +18,6 @@
#include <inspector/DFBrowserPane_AttributePane.hxx>
#include <NCollection_DataMap.hxx>
#include <Standard.hxx>
#include <TCollection_AsciiString.hxx>
@ -36,14 +35,6 @@ public:
//! Destructor
virtual ~DFBrowserPane_TNamingUsedShapes() {}
//! Sets cache of sorted references. If it exists, table view values are obtained not from the attibute
//! \param theAttributeRefs container of references
void SetSortedReferences (NCollection_DataMap<Handle(TDF_Attribute), std::list<TCollection_AsciiString> >& theAttributeRefs)
{ myAttributeRefs = theAttributeRefs; }
//! Clears cache container of sorted references
void ClearSortedReferences() { myAttributeRefs.Clear(); }
//! Returns values to fill the table view model
//! \param theAttribute a current attribute
//! \param theValues a container of values
@ -56,14 +47,6 @@ public:
Standard_EXPORT virtual void GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
QList<QVariant>& theValues) Standard_OVERRIDE;
//! Returns information for the given attribute
//! \param theAttribute a current attribute
//! \param theRole a role of information, used by tree model (e.g. DisplayRole, icon, background and so on)
//! \param theColumnId a tree model column
//! \return value, interpreted by tree model depending on the role
Standard_EXPORT virtual QVariant GetAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
int theRole, int theColumnId) Standard_OVERRIDE;
//! Returns container of Attribute references to the attribute
//! \param theAttribute a current attribute
//! \param theRefAttributes a container of attribute references, to be selected in tree view
@ -77,9 +60,6 @@ protected:
//! \return container of widths
Standard_EXPORT virtual QMap<int, int> getTableColumnWidths() const;
private:
NCollection_DataMap<Handle(TDF_Attribute), std::list<TCollection_AsciiString> > myAttributeRefs;
};
#endif