Import: Extend OCAF browser

This commit is contained in:
wmayer
2023-10-03 15:23:25 +02:00
committed by wwmayer
parent b42b2c85b4
commit 3fb37a6075
2 changed files with 177 additions and 63 deletions

View File

@@ -37,7 +37,7 @@
#include <TDataStd.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_TreeNode.hxx>
#include <TDataStd_Real.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_ChildIDIterator.hxx>
@@ -45,10 +45,11 @@
#include <TDF_Label.hxx>
#include <TDF_ListIteratorOfIDList.hxx>
#include <TDF_TagSource.hxx>
#include <TDF_Tool.hxx>
#include <TDocStd_Document.hxx>
#include <TDocStd_Owner.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_UsedShapes.hxx>
#include <XCAFDoc.hxx>
#include <XCAFDoc_Color.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <XCAFDoc_LayerTool.hxx>
@@ -62,7 +63,7 @@
using namespace ImportGui;
OCAFBrowser::OCAFBrowser(Handle(TDocStd_Document) hDoc)
OCAFBrowser::OCAFBrowser(const Handle(TDocStd_Document) & hDoc)
: pDoc(hDoc)
{
myGroupIcon = QApplication::style()->standardIcon(QStyle::SP_DirIcon);
@@ -81,13 +82,15 @@ OCAFBrowser::OCAFBrowser(Handle(TDocStd_Document) hDoc)
myList.Append(XCAFDoc_Location::GetID());
}
std::string OCAFBrowser::toString(const TCollection_ExtendedString& extstr) const
std::string OCAFBrowser::toString(const TCollection_ExtendedString& extstr)
{
// NOLINTBEGIN
char* str = new char[extstr.LengthOfCString() + 1];
extstr.ToUTF8CString(str);
std::string text(str);
delete[] str;
return text;
// NOLINTEND
}
void OCAFBrowser::load(QTreeWidget* theTree)
@@ -102,14 +105,14 @@ void OCAFBrowser::load(QTreeWidget* theTree)
load(pDoc->GetData()->Root(), root, QString::fromLatin1("0"));
}
void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QString& s)
void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QString& str)
{
label.Dump(std::cout);
Handle(TDataStd_Name) name;
if (label.FindAttribute(TDataStd_Name::GetID(), name)) {
QString text =
QString::fromLatin1("%1 %2").arg(s, QString::fromUtf8(toString(name->Get()).c_str()));
QString::fromLatin1("%1 %2").arg(str, QString::fromUtf8(toString(name->Get()).c_str()));
item->setText(0, text);
}
@@ -120,6 +123,7 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
localList.Append(itr.Value()->ID());
}
// Hint: In OCC 7.7 use XCAFDoc::AttributeInfo
for (TDF_ListIteratorOfIDList it(localList); it.More(); it.Next()) {
Handle(TDF_Attribute) attr;
if (label.FindAttribute(it.Value(), attr)) {
@@ -132,6 +136,13 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
str << " = " << toString(Handle(TDataStd_Name)::DownCast(attr)->Get()).c_str();
child->setText(0, text);
}
else if (it.Value() == TNaming_UsedShapes::GetID()) {
QString text;
QTextStream str(&text);
str << attr->DynamicType()->Name();
str << " = " << Handle(TNaming_UsedShapes)::DownCast(attr)->Map().Size();
child->setText(0, text);
}
else if (it.Value() == TDF_TagSource::GetID()) {
QString text;
QTextStream str(&text);
@@ -146,44 +157,41 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
str << " = " << Handle(TDataStd_Integer)::DownCast(attr)->Get();
child->setText(0, text);
}
else if (it.Value() == TNaming_NamedShape::GetID()) {
TopoDS_Shape shape = Handle(TNaming_NamedShape)::DownCast(attr)->Get();
else if (it.Value() == TDataStd_Real::GetID()) {
QString text;
QTextStream str(&text);
str << attr->DynamicType()->Name() << " = ";
if (!shape.IsNull()) {
switch (shape.ShapeType()) {
case TopAbs_COMPOUND:
str << "COMPOUND PRIMITIVE";
break;
case TopAbs_COMPSOLID:
str << "COMPSOLID PRIMITIVE";
break;
case TopAbs_SOLID:
str << "SOLID PRIMITIVE";
break;
case TopAbs_SHELL:
str << "SHELL PRIMITIVE";
break;
case TopAbs_FACE:
str << "FACE PRIMITIVE";
break;
case TopAbs_WIRE:
str << "WIRE PRIMITIVE";
break;
case TopAbs_EDGE:
str << "EDGE PRIMITIVE";
break;
case TopAbs_VERTEX:
str << "VERTEX PRIMITIVE";
break;
case TopAbs_SHAPE:
str << "SHAPE PRIMITIVE";
break;
}
}
str << attr->DynamicType()->Name();
str << " = " << Handle(TDataStd_Real)::DownCast(attr)->Get();
child->setText(0, text);
}
else if (it.Value() == XCAFDoc_Color::GetID()) {
Quantity_ColorRGBA rgba = Handle(XCAFDoc_Color)::DownCast(attr)->GetColorRGBA();
Quantity_Color rgb = rgba.GetRGB();
QString tuple = QString::fromLatin1("(%1, %2, %3, %4)")
.arg(rgb.Red())
.arg(rgb.Green())
.arg(rgb.Blue())
.arg(rgba.Alpha());
QString text;
QTextStream str(&text);
str << attr->DynamicType()->Name();
str << " = " << Quantity_Color::StringName(rgb.Name()) << " " << tuple;
child->setText(0, text);
}
else if (it.Value() == XCAFDoc_ShapeMapTool::GetID()) {
QString text;
QTextStream str(&text);
str << attr->DynamicType()->Name();
str << " = " << Handle(XCAFDoc_ShapeMapTool)::DownCast(attr)->GetMap().Size();
child->setText(0, text);
}
else if (it.Value() == TNaming_NamedShape::GetID()) {
child->setText(0, toText(Handle(TNaming_NamedShape)::DownCast(attr)));
}
else if (!Handle(TDataStd_TreeNode)::DownCast(attr).IsNull()) {
Handle(TDataStd_TreeNode) aTreeNode = Handle(TDataStd_TreeNode)::DownCast(attr);
child->setText(0, toText(aTreeNode));
}
else {
child->setText(0, QLatin1String(attr->DynamicType()->Name()));
}
@@ -191,9 +199,9 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
}
int i = 1;
for (TDF_ChildIterator it(label); it.More(); it.Next(), i++) {
QString text = QString::fromLatin1("%1:%2").arg(s).arg(i);
int index = 1;
for (TDF_ChildIterator it(label); it.More(); it.Next(), index++) {
QString text = QString::fromLatin1("%1:%2").arg(str).arg(index);
QTreeWidgetItem* child = new QTreeWidgetItem();
child->setText(0, text);
child->setIcon(0, myGroupIcon);
@@ -202,30 +210,132 @@ void OCAFBrowser::load(const TDF_Label& label, QTreeWidgetItem* item, const QStr
}
}
void OCAFBrowser::showDialog(const QString& title, Handle(TDocStd_Document) hDoc)
QString OCAFBrowser::toText(const Handle(TNaming_NamedShape) & namedShape)
{
static QPointer<QDialog> dlg = nullptr;
if (!dlg) {
dlg = new QDialog(Gui::getMainWindow());
QTreeWidget* tree = new QTreeWidget();
tree->setHeaderLabel(QString::fromLatin1("OCAF Browser"));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(tree);
dlg->setLayout(layout);
QDialogButtonBox* btn = new QDialogButtonBox(dlg);
btn->setStandardButtons(QDialogButtonBox::Close);
QObject::connect(btn, &QDialogButtonBox::rejected, dlg, &QDialog::reject);
QHBoxLayout* boxlayout = new QHBoxLayout;
boxlayout->addWidget(btn);
layout->addLayout(boxlayout);
TopoDS_Shape shape = namedShape->Get();
QString text;
QTextStream str(&text);
str << namedShape->DynamicType()->Name() << " = ";
if (!shape.IsNull()) {
switch (shape.ShapeType()) {
case TopAbs_COMPOUND:
str << "COMPOUND PRIMITIVE";
break;
case TopAbs_COMPSOLID:
str << "COMPSOLID PRIMITIVE";
break;
case TopAbs_SOLID:
str << "SOLID PRIMITIVE";
break;
case TopAbs_SHELL:
str << "SHELL PRIMITIVE";
break;
case TopAbs_FACE:
str << "FACE PRIMITIVE";
break;
case TopAbs_WIRE:
str << "WIRE PRIMITIVE";
break;
case TopAbs_EDGE:
str << "EDGE PRIMITIVE";
break;
case TopAbs_VERTEX:
str << "VERTEX PRIMITIVE";
break;
case TopAbs_SHAPE:
str << "SHAPE PRIMITIVE";
break;
}
}
return text;
}
QString OCAFBrowser::toText(const Handle(TDataStd_TreeNode) & treeNode)
{
Standard_CString type = "";
if (treeNode->ID() == XCAFDoc::ShapeRefGUID()) {
type = "Shape Instance Link";
}
else if (treeNode->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorGen)) {
type = "Generic Color Link";
}
else if (treeNode->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorSurf)) {
type = "Surface Color Link";
}
else if (treeNode->ID() == XCAFDoc::ColorRefGUID(XCAFDoc_ColorCurv)) {
type = "Curve Color Link";
}
else if (treeNode->ID() == XCAFDoc::DimTolRefGUID()) {
type = "DGT Link";
}
else if (treeNode->ID() == XCAFDoc::DatumRefGUID()) {
type = "Datum Link";
}
else if (treeNode->ID() == XCAFDoc::MaterialRefGUID()) {
type = "Material Link";
}
QString prefix = QString::fromLatin1(type);
QString display;
if (treeNode->HasFather()) {
TDF_Label aLabel = treeNode->Father()->Label();
TCollection_AsciiString entry;
TDF_Tool::Entry(aLabel, entry);
QString suffix = QString::fromLatin1(entry.ToCString());
display = QString::fromLatin1("%1 ==> %2").arg(prefix, suffix);
}
else {
Handle(TDataStd_TreeNode) aFirstChild = treeNode->First();
QStringList aRefs;
while (!aFirstChild.IsNull()) {
TDF_Label aLabel = aFirstChild->Label();
TCollection_AsciiString entry;
TDF_Tool::Entry(aLabel, entry);
QString suffix = QString::fromLatin1(entry.ToCString());
aRefs.append(suffix);
aFirstChild = aFirstChild->Next();
}
display = QString::fromLatin1("%1 <== %2").arg(prefix, aRefs.join(QChar::fromLatin1(',')));
}
QString text;
QTextStream str(&text);
str << treeNode->DynamicType()->Name();
if (!display.isEmpty()) {
str << " = " << display;
}
return text;
}
void OCAFBrowser::showDialog(const QString& title, const Handle(TDocStd_Document) & hDoc)
{
// NOLINTBEGIN
QDialog* dlg = new QDialog(Gui::getMainWindow());
QTreeWidget* tree = new QTreeWidget();
tree->setHeaderLabel(QString::fromLatin1("OCAF Browser"));
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(tree);
dlg->setLayout(layout);
QDialogButtonBox* btn = new QDialogButtonBox(dlg);
btn->setStandardButtons(QDialogButtonBox::Close);
QObject::connect(btn, &QDialogButtonBox::rejected, dlg, &QDialog::reject);
QHBoxLayout* boxlayout = new QHBoxLayout;
boxlayout->addWidget(btn);
layout->addLayout(boxlayout);
dlg->setWindowTitle(title);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
OCAFBrowser browse(hDoc);
browse.load(dlg->findChild<QTreeWidget*>());
tree->expandAll();
dlg->resize(400, 600);
// NOLINTEND
}

View File

@@ -27,7 +27,9 @@
#include <QIcon>
#include <TCollection_ExtendedString.hxx>
#include <TDF_IDList.hxx>
#include <TDataStd_TreeNode.hxx>
#include <TDocStd_Document.hxx>
#include <TNaming_NamedShape.hxx>
#include <string>
class QString;
@@ -39,14 +41,16 @@ namespace ImportGui
class OCAFBrowser
{
public:
explicit OCAFBrowser(Handle(TDocStd_Document) hDoc);
explicit OCAFBrowser(const Handle(TDocStd_Document) & hDoc);
void load(QTreeWidget*);
static void showDialog(const QString& title, Handle(TDocStd_Document) hDoc);
static void showDialog(const QString& title, const Handle(TDocStd_Document) & hDoc);
private:
void load(const TDF_Label& label, QTreeWidgetItem* item, const QString&);
std::string toString(const TCollection_ExtendedString& extstr) const;
static std::string toString(const TCollection_ExtendedString& extstr);
static QString toText(const Handle(TDataStd_TreeNode) & treeNode);
static QString toText(const Handle(TNaming_NamedShape) & namedShape);
private:
QIcon myGroupIcon;