diff --git a/codes/cgns/src/CgnsCoor.cpp b/codes/cgns/src/CgnsCoor.cpp index 6b6cfdab..46900727 100644 --- a/codes/cgns/src/CgnsCoor.cpp +++ b/codes/cgns/src/CgnsCoor.cpp @@ -345,8 +345,8 @@ void CgnsCoor::SetDimensionStr() irmax[ 2 ] = isize[ j ++ ]; } // cell size - cellSize[ 0 ] = isize[ j ++ ]; - cellSize[ 1 ] = isize[ j ++ ]; + this->cellSize[ 0 ] = isize[ j ++ ]; + this->cellSize[ 1 ] = isize[ j ++ ]; if ( this->cgnsZone->cgnsBase->celldim == THREE_D ) { cellSize[ 2 ] = isize[ j ++ ]; diff --git a/tools/codes/cgns/CgnsBase.cpp b/tools/codes/cgns/CgnsBase.cpp index b9727a3a..b2fed801 100644 --- a/tools/codes/cgns/CgnsBase.cpp +++ b/tools/codes/cgns/CgnsBase.cpp @@ -77,7 +77,6 @@ void BBase::ReadFile(const std::string &fileName) { //namespace fs = std::filesystem; //std::cout << "Current path is " << fs::current_path() << '\n'; - int openStatus = cg_open( fileName.c_str(), CG_MODE_READ, & this->fileId ); std::string stars( "**************************************************************" ); std::cout << stars << "\n"; @@ -157,9 +156,12 @@ void Base::ReadBaseUnits( int fileId, int baseId ) { DataClass_t dclass; cg_goto(fileId, 1, "end"); - cg_dataclass_read(&dclass); + int ierr = cg_dataclass_read(&dclass); - std::cout << "dclass = " << dclass << " dclass name = " << DataClassName[dclass] << "\n"; + if ( ierr == CG_OK ) + { + std::cout << "dclass = " << dclass << " dclass name = " << DataClassName[ dclass ] << "\n"; + } CGNS_ENUMT(MassUnits_t) mass; CGNS_ENUMT(LengthUnits_t) length; @@ -176,30 +178,41 @@ void Base::ReadBaseUnits( int fileId, int baseId ) CGNS_ENUMT(TemperatureUnits_t) ix; CGNS_ENUMT(AngleUnits_t) ia; - cg_units_read(&im,&il,&it,&ix,&ia); + ierr = cg_units_read(&im,&il,&it,&ix,&ia); - std::printf("\nUnits=\n %s\n %s\n %s\n %s\n %s\n", - MassUnitsName[im],LengthUnitsName[il],TimeUnitsName[it], - TemperatureUnitsName[ix],AngleUnitsName[ia]); + if ( ierr == CG_OK ) + { + std::printf( "\nUnits=\n %s\n %s\n %s\n %s\n %s\n", + MassUnitsName[ im ], LengthUnitsName[ il ], TimeUnitsName[ it ], + TemperatureUnitsName[ ix ], AngleUnitsName[ ia ] ); + } int nunits = -1; - cg_nunits(&nunits); - - std::cout << " CGNS nunits = " << nunits << "\n"; + ierr = cg_nunits(&nunits); + if ( ierr == CG_OK ) + { + std::cout << " CGNS nunits = " << nunits << "\n"; + } - cg_unitsfull_read(&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity); - std::cout << "mass = " << mass << " MassUnitsName[mass] = " << MassUnitsName[mass]<<"\n"; - std::cout << "length = " << length << " LengthUnitsName[length] = " << LengthUnitsName[length]<<"\n"; - std::cout << "time = " << time << " TimeUnitsName[time] = " << TimeUnitsName[time]<<"\n"; - std::cout << "temp = " << temp << " TemperatureUnitsName[temp] = " << TemperatureUnitsName[temp]<<"\n"; - std::cout << "angle = " << angle<< " AngleUnitsName[angle] = " << AngleUnitsName[angle]<<"\n"; - std::cout << "current = " << current<< " ElectricCurrentUnitsName[current] = " << ElectricCurrentUnitsName[current]<<"\n"; - std::cout << "amount = " << amount<< " SubstanceAmountUnitsName[amount] = " << SubstanceAmountUnitsName[amount]<<"\n"; - std::cout << "intensity = " << intensity << " LuminousIntensityUnitsName[intensity] = " << LuminousIntensityUnitsName[intensity]<<"\n"; + ierr = cg_unitsfull_read(&mass, &length, &time, &temp, &angle, ¤t, &amount, &intensity); + if ( ierr == CG_OK ) + { + std::cout << "mass = " << mass << " MassUnitsName[mass] = " << MassUnitsName[ mass ] << "\n"; + std::cout << "length = " << length << " LengthUnitsName[length] = " << LengthUnitsName[ length ] << "\n"; + std::cout << "time = " << time << " TimeUnitsName[time] = " << TimeUnitsName[ time ] << "\n"; + std::cout << "temp = " << temp << " TemperatureUnitsName[temp] = " << TemperatureUnitsName[ temp ] << "\n"; + std::cout << "angle = " << angle << " AngleUnitsName[angle] = " << AngleUnitsName[ angle ] << "\n"; + std::cout << "current = " << current << " ElectricCurrentUnitsName[current] = " << ElectricCurrentUnitsName[ current ] << "\n"; + std::cout << "amount = " << amount << " SubstanceAmountUnitsName[amount] = " << SubstanceAmountUnitsName[ amount ] << "\n"; + std::cout << "intensity = " << intensity << " LuminousIntensityUnitsName[intensity] = " << LuminousIntensityUnitsName[ intensity ] << "\n"; + } int nexps = -1; - cg_nexponents (&nexps); - std::cout << "nexps = " << nexps << "\n"; + ierr = cg_nexponents (&nexps); + if ( ierr == CG_OK ) + { + std::cout << "nexps = " << nexps << "\n"; + } } void Base::ReadBase( int fileId, int baseId ) @@ -323,7 +336,7 @@ void Zone::DumpZone() } std::cout << "total faces of zone : " << this->nFaces << "\n"; std::cout << "total number face nodes of zone : " << this->totalNumFaceNodes << "\n"; - this->DrawZone(); + //this->DrawZone(); } void Zone::DrawZone() @@ -497,6 +510,47 @@ void Zone::SetDimensions() this->nNodes = this->irmax[ 0 ]; this->nCells = this->cellSize[ 0 ]; } + else + { + // lower range index + this->irmin[ 0 ] = 1; + this->irmin[ 1 ] = 1; + this->irmin[ 2 ] = 1; + + // upper range index of vertices + this->irmax[ 0 ] = 1; + this->irmax[ 1 ] = 1; + this->irmax[ 2 ] = 1; + + this->cellSize[ 0 ] = 1; + this->cellSize[ 1 ] = 1; + this->cellSize[ 2 ] = 1; + + // upper range index of vertices + // vertex size + int j = 0; + this->irmax[ 0 ] = this->isize[ j ++ ]; + this->irmax[ 1 ] = this->isize[ j ++ ]; + + int celldim = THREE_D; + if ( celldim == THREE_D ) + { + this->irmax[ 2 ] = this->isize[ j ++ ]; + } + // cell size + this->cellSize[ 0 ] = this->isize[ j ++ ]; + this->cellSize[ 1 ] = this->isize[ j ++ ]; + if ( celldim == THREE_D ) + { + cellSize[ 2 ] = this->isize[ j ++ ]; + } + std::cout << " The Dimension Of Grid is : \n"; + std::cout << " I Direction " << std::setw( 10 ) << irmin[ 0 ] << std::setw( 10 ) << irmax[ 0 ] << "\n"; + std::cout << " J Direction " << std::setw( 10 ) << irmin[ 1 ] << std::setw( 10 ) << irmax[ 1 ] << "\n"; + std::cout << " K Direction " << std::setw( 10 ) << irmin[ 2 ] << std::setw( 10 ) << irmax[ 2 ] << "\n"; + this->nNodes = irmax[ 0 ] * irmax[ 1 ] * irmax[ 2 ]; + this->nCells = cellSize[ 0 ] * cellSize[ 1 ] * cellSize[ 2 ]; + } std::cout << " numberOfNodes = " << this->nNodes << " numberOfCells = " << this->nCells << "\n"; } @@ -651,12 +705,12 @@ void Coor::DumpCoor() Field::Field() { - this->data = 0; + //this->data = 0; } Field::~Field() { - this->DeAllocateData(); + //this->DeAllocateData(); } void Field::ReadField( int fileId, int baseId, int zoneId, int solutionId, int fieldId, Zone * zone ) @@ -679,7 +733,7 @@ void Field::ReadField( int fileId, int baseId, int zoneId, int solutionId, int f this->AllocateData( zone->nNodes ); std::cout << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl; - int ierr = cg_field_read( fileId, baseId, zoneId, solutionId, this->fieldName, this->dataType, zone->irmin, zone->irmax, this->data); + int ierr = cg_field_read( fileId, baseId, zoneId, solutionId, this->fieldName, this->dataType, zone->irmin, zone->irmax, this->data.data()); if ( ierr == CG_OK ) { std::cout << "cg_field_read ierr = " << ierr << "\n"; @@ -737,28 +791,38 @@ void Field::AllocateData( int nNodes ) this->nNodes = nNodes; if ( this->dataType == RealSingle ) { - this->data = new float [ nNodes ]; + //this->data = new float [ nNodes ]; + this->data.resize(nNodes * sizeof(float) ); } - else + else if ( this->dataType == RealDouble ) { - this->data = new double [ nNodes ]; + //this->data = new double [ nNodes ]; + this->data.resize(nNodes * sizeof(double) ); } -} - -void Field::DeAllocateData() -{ - if ( this->dataType == RealSingle ) + else if ( this->dataType == ComplexSingle ) { - float * f_data = static_cast< float * >( this->data ); - delete [] f_data; + this->data.resize(nNodes * 2 * sizeof(float) ); } - else + else if ( this->dataType == ComplexDouble ) { - double * d_data = static_cast< double * >( this->data ); - delete [] d_data; + this->data.resize(nNodes * 2 * sizeof(double) ); } } +void Field::DeAllocateData() +{ + //if ( this->dataType == RealSingle ) + //{ + // float * f_data = static_cast< float * >( this->data ); + // delete [] f_data; + //} + //else + //{ + // double * d_data = static_cast< double * >( this->data ); + // delete [] d_data; + //} +} + Solution::Solution() { ; diff --git a/tools/codes/cgns/CgnsBase.h b/tools/codes/cgns/CgnsBase.h index b503ac2c..a19ef459 100644 --- a/tools/codes/cgns/CgnsBase.h +++ b/tools/codes/cgns/CgnsBase.h @@ -139,7 +139,8 @@ class Field char33 fieldName; int fieldId = -1; double doubleFieldId = -1; - void * data; + //void * data; + std::vector data; cgsize_t nNodes; DataClass_t dataclass; int dimflag=-1; //0: nondimensional 1: dimensional diff --git a/tools/codes/cgnspanel.cpp b/tools/codes/cgnspanel.cpp index eb6beb7e..b24ea6f8 100644 --- a/tools/codes/cgnspanel.cpp +++ b/tools/codes/cgnspanel.cpp @@ -1,4 +1,5 @@ #include "cgnspanel.h" +#include "cgnsview.h" #include #include #include @@ -110,3 +111,23 @@ void CgnsPanel::resizeEvent(QResizeEvent *event) this->nodeDataGroupBox->resize(event->size().width(),event->size().height()-this->h1-this->h2-this->h3); } + +void CgnsPanel::Display(const QString &text) +{ + this->nodeDataTextEdit->setPlainText(text); +} + +void CgnsPanel::DisplayNode(CgnsNode *node) +{ + this->parentNodeLineEdit->setText(QString::fromStdString(node->parent_name)); + this->nodeNameLineEdit->setText(QString::fromStdString(node->name)); + this->nodeLabelLineEdit->setText(QString::fromStdString(node->label)); + this->dataTypeLineEdit->setText(QString::fromStdString(node->data_type)); + this->dimLineEdit->setText(QString::fromStdString(node->dimstr)); + this->bytesLineEdit->setText(QString::number(node->data_size)); + this->nodeDataTextEdit->setPlainText(QString::fromStdString(node->valuestr)); + + this->linkFileLineEdit->setText(QString::fromStdString(node->link_file)); + this->linkNodeLineEdit->setText(QString::fromStdString(node->link_node)); + +} diff --git a/tools/codes/cgnspanel.h b/tools/codes/cgnspanel.h index 0e2de550..c2db7ae4 100644 --- a/tools/codes/cgnspanel.h +++ b/tools/codes/cgnspanel.h @@ -8,6 +8,8 @@ class QGridLayout; class QLabel; class QLineEdit; +class CgnsNode; + class CgnsPanel : public QWidget { Q_OBJECT @@ -17,6 +19,9 @@ class CgnsPanel : public QWidget void resizeEvent(QResizeEvent *event) override; signals: +public: + void Display(const QString &text); + void DisplayNode(CgnsNode *node); private: QGroupBox *nodeDescGroupBox; QGroupBox *linkDescGroupBox; diff --git a/tools/codes/cgnsview.cpp b/tools/codes/cgnsview.cpp index 02a89ce0..38c07985 100644 --- a/tools/codes/cgnsview.cpp +++ b/tools/codes/cgnsview.cpp @@ -1,4 +1,5 @@ #include "cgnsview.h" +#include "cgnspanel.h" #include #include #include @@ -8,7 +9,208 @@ #include "cgnslib.h" #include "CgnsBase.h" #include "CgnsBc.h" +#include "cgns_io.h" #include +#include +#include + +static int cgioNum = 0; +static double RootID = 0.0; +std::map nodeMap; +std::map cgnsNodeMap; + +#define I4 int +#define U4 unsigned int +#define I8 cglong_t +#define U8 cgulong_t +#define R4 float +#define R8 double +#define X4 float +#define X8 double +#define C1 char +#define B1 unsigned char + +enum DataTags { + MTdata = 0, + I4data, + I8data, + U4data, + U8data, + R4data, + R8data, + X4data, + X8data, + C1data, + B1data, + LKdata +}; + +static struct DataType { + const char *name; + int type; + int bytes; + int size; +} DataList[] = { + {"MT", MTdata, 0, 0}, + {"I4", I4data, 4, sizeof(I4)}, + {"I8", I8data, 8, sizeof(I8)}, + {"U4", U4data, 4, sizeof(U4)}, + {"U8", U8data, 8, sizeof(U8)}, + {"R4", R4data, 4, sizeof(R4)}, + {"R8", R8data, 8, sizeof(R8)}, + {"X4", X4data, 8, sizeof(X4)*2}, + {"X8", X8data, 16, sizeof(X8)*2}, + {"C1", C1data, 1, 1}, + {"B1", B1data, 1, 1}, + {"LK", LKdata, 0, 0} +}; + +cgsize_t numberOfElements(int cgio_num, double nodeid) +{ + int n, ndim; + cgsize_t dims[CGIO_MAX_DIMENSIONS]; + + if ( cgio_get_dimensions (cgioNum, nodeid, &ndim, dims) ) { + std::cout << "cgio_get_dimensions error\n"; + return -1; + } + + if ( ndim == 0 ) + { + return 0; + } + + cgsize_t np = 1; + + for (int n = 0; n < ndim; n++) + { + np *= dims[n]; + } + return np; +} + +template +void nestedFormatString( std::vector &values, int ndim, cgsize_t * dims, int nElements, int depth, std::vector &indices, int &icount, std::string & valuestr ) +{ + if ( nElements > 200 ) return; + + if ( depth == ndim ) + { + const T *x = (T *)values.data(); + + double number = x[icount++]; + + //valuestr += std::to_string(x[icount++]); + valuestr += std::format("{:g}", number); + valuestr += " "; + return; + } + + cgsize_t N = dims[ depth ]; + for ( int i = 0; i < N; ++i ) + { + indices.push_back(i); + nestedFormatString( values, ndim, dims, nElements, depth + 1, indices, icount, valuestr ); + indices.pop_back(); + if( i == ( N - 1 ) && depth == ( ndim - 1 ) ) + { + valuestr += "\n"; + } + } +} + +template +void nestedFormatStringComplex( std::vector &values, int ndim, cgsize_t * dims, int nElements, int depth, std::vector &indices, int &icount, std::string & valuestr ) +{ + if ( nElements > 200 ) return; + + if ( depth == ndim ) + { + T *x = (T *)values.data(); + + valuestr += "{"; + valuestr += std::to_string(x[icount++]); + valuestr += ","; + valuestr += std::to_string(x[icount++]); + valuestr += "} "; + + return; + } + + cgsize_t N = dims[ depth ]; + for ( int i = 0; i < N; ++i ) + { + indices.push_back(i); + nestedFormatStringComplex( values, ndim, dims, nElements, depth + 1, indices, icount, valuestr ); + indices.pop_back(); + if( i == ( N - 1 ) && depth == ( ndim - 1 ) ) + { + valuestr += "\n"; + } + } +} + + +void printNestedFormatValues( const char *data_type, std::vector &values, int ndim, cgsize_t * dims, int nElements, std::string & valuestr ) +{ + int icount = 0; + std::vector indices = {}; + int depth = 0; + + qDebug() << "printValues data_type = " << data_type; + if ( std::strncmp(data_type,"C1",2) == 0 || + std::strncmp(data_type,"B1",2) == 0 ) + { + qDebug() << "std::strncmp(data_type,\"C1\",2) data_type = " << data_type; + valuestr += values.data(); + qDebug() << "valuestr=" << valuestr; + } + else if ( std::strncmp(data_type,"I4",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"I8",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"U4",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"U8",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"R4",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"R8",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"X4",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } + else if ( std::strncmp(data_type,"X8",2) == 0 ) + { + nestedFormatString( values, ndim, dims, nElements, depth, indices, icount, valuestr ); + } +} + +void printItem(QStandardItem* item, int depth = 0) +{ + if (!item) return; // 如果 item 为空,返回 + + // 打印当前项的文本 + qDebug().nospace() << QString("%1%2").arg(QString(" ").repeated(depth)).arg(item->text()); + + // 遍历子项 + for (int i = 0; i < item->rowCount(); ++i) { + printItem(item->child(i), depth + 1); // 递归调用 + } +} CgnsView::CgnsView(QWidget *parent) : QWidget{parent} @@ -23,7 +225,6 @@ CgnsView::CgnsView(QWidget *parent) void CgnsView::resizeEvent(QResizeEvent *event) { this->treeView->resize(event->size()); - } void CgnsView::SetUpHeader() @@ -37,57 +238,294 @@ void CgnsView::SetUpHeader() itemModel->setHorizontalHeaderLabels(labels); } -void printItem(QStandardItem* item, int depth = 0) +void CgnsView::SetUpCgnsInfo() { - if (!item) return; // 如果 item 为空,返回 + this->SetUpHeader(); - // 打印当前项的文本 - qDebug().nospace() << QString("%1%2").arg(QString(" ").repeated(depth)).arg(item->text()); + QString fileName = "D:/work/cgns_work/cgnsgrid_example/yf17_hdf5.cgns"; + //QString fileName = "D:/work/cgns_work/ModernCGNS/codes/UserGuideCode/read_complex/complex_data.cgns"; + //QString fileName = "D:/work/cgns_work/ModernCGNS/codes/UserGuideCode/cg_link_write/grid/links.cgns"; - // 遍历子项 - for (int i = 0; i < item->rowCount(); ++i) { - printItem(item->child(i), depth + 1); // 递归调用 - } + ::ReadCgnsFile( fileName.toLatin1().data() ); + + //this->AddCgnsToQStandardItem( ::GetBBase() ); + this->ReadCgnsToQStandardItem( fileName ); } -void CgnsView::SetUpCgnsInfo() +void CgnsView::ReadCgnsChild(int cgio_num, double pid, QStandardItem *pItem ) { - this->SetUpHeader(); + QIcon folderIcon(":/folder.png"); + QIcon fileIcon(":/file.jpg"); + QIcon forwardIcon(":/forward.png"); - QStandardItemModel *itemModel = static_cast(this->treeView->model()); + char parent_name[33]; + cgio_get_name(cgio_num, pid, parent_name); + qDebug() << "parent_name = " << parent_name; - qDebug() << " dataTypeName 1= " << DataTypeName[ RealDouble ]; - qDebug() << " dataTypeName 2= " << DataTypeName[ ComplexSingle ]; + char parent_label[33]; + cgio_get_label (cgio_num, pid, parent_label); + qDebug() << "parent_label = " << parent_label; - QString fileName = "D:/work/cgns_work/cgnsgrid_example/yf17_hdf5.cgns"; + int num_children=-1; + cgio_number_children (cgio_num, pid, &num_children); + qDebug() << "num_children = " << num_children; + if ( num_children <= 0 ) return; - // QStandardItem *rootItem = new QStandardItem( "/" ); - // itemModel->appendRow(rootItem); + double childID = -1; + char childName[33]; + for ( int n = 1; n <= num_children; n++ ) + { + int cnt=-1; + cgio_children_ids(cgio_num, pid, n, 1, &cnt, &childID); + qDebug() << " n= " << n << " cnt = " << cnt; + qDebug("childID = %30.22e", childID); + cgio_get_name(cgio_num, childID, childName); + qDebug() << "parent_name = " << parent_name; + qDebug() << "childName = " << childName; + char pid_name[33]; + cgio_get_name(cgio_num, pid, pid_name); + qDebug() << "pid_name = " << pid_name; + + double node_id=-1; + cgio_get_node_id (cgio_num, pid, childName, &node_id); + qDebug("pid = %30.22e", pid); + qDebug("node_id = %30.22e", node_id); + qDebug("node_id = %f", node_id); + qDebug("childID = %e", childID); + + int link_len = -1; + cgio_is_link (cgio_num, node_id, &link_len); + qDebug() << "link_len = " << link_len; + + std::string link_file; + std::string link_node; + + if ( link_len > 0 ) + { + int file_len = -1; + int name_len = -1; + cgio_link_size (cgio_num, node_id, &file_len, &name_len); + qDebug() << "file_len = " << file_len << " name_len = " << name_len; + std::vector filename_vchar(file_len); + std::vector name_in_file_vchar(name_len); + //cgio_get_link (cgio_num, node_id, filename, name_in_file); + cgio_get_link (cgio_num, node_id, filename_vchar.data(), name_in_file_vchar.data()); + link_file = filename_vchar.data(); + link_node = name_in_file_vchar.data(); + + qDebug() << "link_file = " << link_file << " link_node = " << link_node; + } - QModelIndex rootIndex = this->treeView->rootIndex(); - qDebug() << "rootIndex = " << rootIndex; + char label[CGIO_MAX_LABEL_LENGTH+1]; + cgio_get_label (cgio_num, node_id, label); + qDebug() << "label = " << label; + + char data_type[CGIO_MAX_DATATYPE_LENGTH+1]; + cgio_get_data_type (cgio_num, node_id, data_type); + qDebug() << "data_type = " << data_type; + + cglong_t data_size; + cgio_get_data_size(cgio_num, node_id, &data_size); + qDebug() << "data_size = " << data_size; + + int ndim; + cgsize_t dims[CGIO_MAX_DIMENSIONS]; + cgio_get_dimensions (cgio_num, node_id, &ndim, dims); + qDebug() << "ndim = " << ndim; + std::string dimstr; + + qDebug() << "dims = "; + for( int i = 0; i < ndim; ++ i ) + { + qDebug() << dims[i]; + dimstr += std::to_string(dims[i]); + if ( i != ndim-1 ) + { + dimstr += " "; + } + } + qDebug() << ""; + + cgsize_t np = numberOfElements(cgio_num, node_id); + qDebug() << "numberOfElements = " << np; + + std::vector values(data_size+1); + cgio_read_all_data_type (cgio_num, node_id, data_type, values.data()); + + std::string valuestr; + + printNestedFormatValues( data_type, values, ndim, dims, np, valuestr ); + + int nchild =-1; + cgio_number_children (cgio_num, childID, &nchild); + + QStandardItem *childItem = new QStandardItem(childName); + pItem->appendRow(childItem); + + CgnsNode * node = new CgnsNode(); + node->parent_name = parent_name; + node->name = childName; + node->label = label; + node->item = childItem; + node->data_type = data_type; + node->dimstr = dimstr; + node->data_size = data_size; + node->valuestr = valuestr; + node->link_file = link_file; + node->link_node = link_node; + + nodeMap.insert(std::make_pair(childID, node)); + std::map::iterator iter; + iter = nodeMap.find( childID ); + qDebug() << "iter->second->name = " << iter->second->name; + qDebug() << "iter->second->parent_name = " << iter->second->parent_name; + qDebug() << "iter->second->label = " << iter->second->label; + + cgnsNodeMap.insert(std::make_pair(childItem, node)); + std::map::iterator cgnsIter; + cgnsIter = cgnsNodeMap.find( childItem ); + qDebug() << "cgnsIter->second->name = " << cgnsIter->second->name; + qDebug() << "cgnsIter->second->parent_name = " << iter->second->parent_name; + qDebug() << "cgnsIter->second->label = " << cgnsIter->second->label; + qDebug() << "cgnsIter->second->data_type = " << cgnsIter->second->data_type; + + if( nchild <= 0 ) + { + childItem->setIcon(fileIcon); + } + else + { + childItem->setIcon(folderIcon); + if( link_len > 0 ) + { + childItem->setIcon(forwardIcon); + } + ReadCgnsChild( cgio_num, childID, childItem ); + } + } +} + +void CgnsView::ReadCgnsToQStandardItem(const QString &fileName) +{ + int cgio_num = -1; + cgio_open_file (fileName.toLatin1().data(), CG_MODE_READ, CGIO_FILE_HDF5, &cgio_num); + ::cgioNum = cgio_num; + qDebug() << "cgio_num = " << cgio_num; + double root_id=-1; + cgio_get_root_id(cgio_num,&root_id); + qDebug() << "root_id = " << root_id; + qDebug("root_id = %30.22e", root_id); + + char root_name[33]; + cgio_get_name(cgio_num, root_id, root_name); + qDebug() << "root_name = " << root_name; + + char root_label[33]; + cgio_get_label (cgio_num, root_id, root_label); + qDebug() << "root_label = " << root_label; + + int link_len = -1; + cgio_is_link (cgio_num, root_id, &link_len); + qDebug() << "link_len = " << link_len; + + std::string link_file; + std::string link_node; + + if ( link_len > 0 ) + { + int file_len = -1; + int name_len = -1; + cgio_link_size (cgio_num, root_id, &file_len, &name_len); + qDebug() << "file_len = " << file_len << " name_len = " << name_len; + std::vector filename_vchar(file_len); + std::vector name_in_file_vchar(name_len); + cgio_get_link (cgio_num, root_id, filename_vchar.data(), name_in_file_vchar.data()); + link_file = filename_vchar.data(); + link_node = name_in_file_vchar.data(); + + qDebug() << "link_file = " << link_file << " link_node = " << link_node; + } + + + char data_type[CGIO_MAX_DATATYPE_LENGTH+1]; + cgio_get_data_type (cgio_num, root_id, data_type); + qDebug() << "data_type = " << data_type; + + cglong_t data_size; + cgio_get_data_size(cgio_num, root_id, &data_size); + qDebug() << "data_size = " << data_size; - int count = itemModel->rowCount(); - qDebug() << "rowCount=" << count; + int ndim; + cgsize_t dims[CGIO_MAX_DIMENSIONS]; + cgio_get_dimensions (cgio_num, root_id, &ndim, dims); + qDebug() << "ndim = " << ndim; + std::string dimstr; - // 打印每个项的信息 - for (int i = 0; i < itemModel->rowCount(); ++i) + qDebug() << "dims = "; + for( int i = 0; i < ndim; ++ i ) { - printItem(itemModel->item(i)); + qDebug() << dims[i]; + dimstr += std::to_string(dims[i]); + if ( i != ndim-1 ) + { + dimstr += " "; + } } + qDebug() << ""; - int row = rootIndex.row(); - int col = rootIndex.column(); - qDebug() <<"rootIndex row=" << row << "column=" << col; + cgsize_t np = numberOfElements(cgio_num, root_id); + qDebug() << "numberOfElements = " << np; - QString text = rootIndex.data(Qt::DisplayRole).toString(); - qDebug() << "rootIndex text = " << text; + std::vector values(data_size+1); + cgio_read_all_data_type (cgio_num, root_id, data_type, values.data()); + std::string valuestr; - this->treeView->expandAll(); + printNestedFormatValues( data_type, values, ndim, dims, np, valuestr ); - ::ReadCgnsFile( fileName.toLatin1().data() ); + char version[33]; + sprintf (version, "%g", CGNS_DOTVERS); + qDebug() << "version = " << version; - this->AddCgnsToQStandardItem( ::GetBBase() ); + char lib_version[CGIO_MAX_VERSION_LENGTH+1]; + cgio_library_version (cgio_num, lib_version); + qDebug() << "lib_version = " << lib_version; + + QIcon folderIcon(":/folder.png"); + QIcon fileIcon(":/file.jpg"); + + QStandardItemModel *itemModel = static_cast(this->treeView->model()); + QStandardItem *rootItem = new QStandardItem( "/" ); + itemModel->appendRow(rootItem); + rootItem->setIcon(folderIcon); + + CgnsNode * node = new CgnsNode(); + node->parent_name = ""; + node->name = "/"; + node->label = root_label; + node->item = rootItem; + node->data_type = data_type; + node->dimstr = dimstr; + node->data_size = data_size; + node->valuestr = valuestr; + node->link_file = link_file; + node->link_node = link_node; + + nodeMap.insert(std::make_pair(root_id, node)); + std::map::iterator iter; + iter = nodeMap.find( root_id ); + qDebug() << "iter->second->name = " << iter->second->name; + qDebug() << "iter->second->parent_name = " << iter->second->parent_name; + qDebug() << "iter->second->label = " << iter->second->label; + + cgnsNodeMap.insert(std::make_pair(rootItem, node)); + std::map::iterator cgnsIter; + cgnsIter = cgnsNodeMap.find( rootItem ); + qDebug() << "cgnsIter->second->name = " << cgnsIter->second->name; + qDebug() << "cgnsIter->second->parent_name = " << cgnsIter->second->parent_name; + qDebug() << "cgnsIter->second->label = " << cgnsIter->second->label; + qDebug() << "cgnsIter->second->data_type = " << cgnsIter->second->data_type; + + ReadCgnsChild(cgio_num,root_id,rootItem); } void CgnsView::AddCgnsToQStandardItem(BBase *bbase) @@ -130,7 +568,7 @@ void CgnsView::AddCgnsToQStandardItem(BBase *bbase) rootItem->setIcon(folderIcon); QStandardItem *libraryVersionItem = new QStandardItem("CGNSLibraryVersion"); - itemModel->appendRow(libraryVersionItem); + rootItem->appendRow(libraryVersionItem); libraryVersionItem->setIcon(fileIcon); this->treeView->expandRecursively(rootItem->index()); @@ -143,7 +581,7 @@ void CgnsView::AddCgnsToQStandardItem(BBase *bbase) Base * base = bbase->bases[ iBase ]; qDebug() << "base->name=" << base->name; QStandardItem *baseItem = new QStandardItem( base->name ); - itemModel->appendRow(baseItem); + rootItem->appendRow(baseItem); baseItem->setIcon(folderIcon); this->AddZoneItem(base, baseItem); @@ -302,17 +740,32 @@ void CgnsView::AddZoneBcs(Zone * zone, QStandardItem *zoneItem) QStandardItem *bcItem = new QStandardItem( boco->name.c_str() ); zoneBcItem->appendRow(bcItem); bcItem->setIcon(folderIcon); + qDebug() << "bcItem->index()=" << bcItem->index(); + qDebug() << "bcItem=" << bcItem; + qDebug() << "bcItem->model()->itemFromIndex(bcItem->index())=" << bcItem->model()->itemFromIndex(bcItem->index()); + qDebug() << "bcItem->index().internalPointer()=" << bcItem->index().internalPointer(); + qDebug() << "bcItem->model()=" << bcItem->model(); + qDebug() << "bcItem->parent()=" << bcItem->parent(); + qDebug() << "zoneBcItem=" << zoneBcItem; QStandardItem *pointRangeItem = new QStandardItem( "PointRange" ); bcItem->appendRow(pointRangeItem); pointRangeItem->setIcon(fileIcon); + qDebug() << "pointRangeItem->index()=" << pointRangeItem->index(); + qDebug() << "pointRangeItem=" << pointRangeItem; + QStandardItem *gridLocationItem = new QStandardItem( "GridLocation" ); bcItem->appendRow(gridLocationItem); gridLocationItem->setIcon(fileIcon); } } +void CgnsView::SetCgnsPanel(CgnsPanel * cgnsPanel) +{ + this->cgnsPanel = cgnsPanel; +} + void CgnsView::onTreeItemClicked(const QModelIndex &index) { qDebug() <<"CgnsView::on_treeView_clicked" << "index=" << index; @@ -321,7 +774,23 @@ void CgnsView::onTreeItemClicked(const QModelIndex &index) qDebug() <<"item row=" << row << "column=" << col; QString text = index.data(Qt::DisplayRole).toString(); + //this->cgnsPanel->Display(text); qDebug() << "text = " << text; + QStandardItemModel * itemModel = static_cast( this->treeView->model() ); + QStandardItem * item = itemModel->itemFromIndex( index ); + + std::map::iterator cgnsIter; + cgnsIter = cgnsNodeMap.find( item ); + qDebug() << "cgnsIter->second->name = " << cgnsIter->second->name; + qDebug() << "cgnsIter->second->parent_name = " << cgnsIter->second->parent_name; + qDebug() << "cgnsIter->second->label = " << cgnsIter->second->label; + + this->cgnsPanel->DisplayNode( cgnsIter->second ); + + + // this->cgnsPanel->Display(node); + //DisplayNode(CgnsNode *node) + } diff --git a/tools/codes/cgnsview.h b/tools/codes/cgnsview.h index 56bd5e6d..24f0ecc5 100644 --- a/tools/codes/cgnsview.h +++ b/tools/codes/cgnsview.h @@ -1,11 +1,36 @@ #pragma once #include +#include "cgnslib.h" + class QTreeView; class QStandardItem; class BBase; class Base; class Zone; +class CgnsPanel; + +class CgnsNode +{ +public: + CgnsNode(){}; + ~CgnsNode(){}; +public: + double id; + double pid; + std::string name; + std::string label; + std::string parent_name; + std::string data_type; + QStandardItem * item; + std::string dimstr; + cgsize_t np; + cglong_t data_size; + std::string valuestr; + std::string link_file; + std::string link_node; +}; + class CgnsView : public QWidget { @@ -17,6 +42,8 @@ class CgnsView : public QWidget private: void SetUpCgnsInfo(); void SetUpHeader(); + void ReadCgnsToQStandardItem(const QString &fileName); + void ReadCgnsChild(int cgio_num, double pid, QStandardItem *pItem ); private: void onTreeItemClicked(const QModelIndex &index); private: @@ -25,8 +52,11 @@ class CgnsView : public QWidget void AddZoneSections(Zone * zone, QStandardItem *zoneItem); void AddZoneBcs(Zone * zone, QStandardItem *zoneItem); void AddZoneFlowSolution(Zone * zone, QStandardItem *zoneItem); +public: + void SetCgnsPanel(CgnsPanel * cgnsPanel); signals: private: + CgnsPanel * cgnsPanel = nullptr; QTreeView * treeView = nullptr; int fileId = -1; int baseId = -1; diff --git a/tools/codes/leftpanel.cpp b/tools/codes/leftpanel.cpp index 4cb7ac1e..43a0caa4 100644 --- a/tools/codes/leftpanel.cpp +++ b/tools/codes/leftpanel.cpp @@ -15,11 +15,11 @@ LeftPanel::LeftPanel(QWidget *parent) this->stack = new QStackedWidget(this); //this->stack->setStyleSheet("background-color: rgb(243,243,243);"); - QList ws = ::GetWidgetListL(); + QList wp = ::GetWidgetPairList(); - for( int i = 0; i < ws.count(); ++ i ) + for( int i = 0; i < wp.count(); ++ i ) { - this->stack->addWidget( ws[i] ); + this->stack->addWidget( wp[i]->GetLeft() ); } qDebug() << "this->stack->count()="<< this->stack->count(); diff --git a/tools/codes/panel.cpp b/tools/codes/panel.cpp index 04b230db..5e036d65 100644 --- a/tools/codes/panel.cpp +++ b/tools/codes/panel.cpp @@ -14,66 +14,116 @@ #include #include -QList widgetsL; -QList widgetsR; +QList widgetPairList; +bool initWidgetPairListFlag = false; +void InitWidgetPairList() +{ + if ( initWidgetPairListFlag ) return; + initWidgetPairListFlag = true; + widgetPairList.append( new ExplorePair() ); + widgetPairList.append( new ProjectPair() ); + widgetPairList.append( new CgnsPair() ); +} + +QList &GetWidgetPairList() +{ + InitWidgetPairList(); -bool initWidgetListFlagL = false; -void InitWidgetListL(); -bool initWidgetListFlagR = false; -void InitWidgetListR(); + return widgetPairList; +} -QList &GetWidgetListL() +WidgetPair::WidgetPair() { - if( !initWidgetListFlagL ) - { - InitWidgetListL(); - } - return widgetsL; } -void InitWidgetListL() +WidgetPair::~WidgetPair() { - if ( initWidgetListFlagL ) return; - initWidgetListFlagL = true; - widgetsL.append( new Explorer() ); - widgetsL.append( new QPushButton("Project") ); - widgetsL.append( new CgnsView() ); } -QList &GetWidgetListR() +QWidget *WidgetPair::GetLeft() { - if( !initWidgetListFlagR ) - { - InitWidgetListR(); - } - return widgetsR; + return nullptr; } -void InitWidgetListR() +QWidget *WidgetPair::GetRight() { - if ( initWidgetListFlagR ) return; - initWidgetListFlagR = true; + return nullptr; +} - QSplitter *splitterV = new QSplitter(Qt::Vertical); +ExplorePair::ExplorePair() +{ + this->explorer = new Explorer(); + this->splitterV = new QSplitter(Qt::Vertical); QTextEdit* pRightTopEdt = new QTextEdit(); pRightTopEdt->setText(QObject::tr("Right Top Window")); - splitterV->addWidget(pRightTopEdt); - splitterV->addWidget( new Terminal() ); + this->splitterV->addWidget(pRightTopEdt); + this->splitterV->addWidget( new Terminal() ); + +} + +ExplorePair::~ExplorePair() +{ + delete this->explorer; + delete this->splitterV; +} + +QWidget *ExplorePair::GetLeft() +{ + return this->explorer; +} + +QWidget *ExplorePair::GetRight() +{ + return this->splitterV; +} + +ProjectPair::ProjectPair() +{ + this->leftButton = new QPushButton("Project"); + this->rightButton = new QPushButton("btn2"); + +} + +ProjectPair::~ProjectPair() +{ + delete this->leftButton; + delete this->rightButton; +} - widgetsR.append( splitterV ); - widgetsR.append( new QPushButton("btn2") ); - widgetsR.append( new CgnsPanel() ); +QWidget *ProjectPair::GetLeft() +{ + return this->leftButton; +} + +QWidget *ProjectPair::GetRight() +{ + return this->rightButton; } -// class tmpInitWidgets -// { -// public: -// tmpInitWidgets() -// { -// ::InitWidgetList(); -// } -// }; + +CgnsPair::CgnsPair() +{ + this->cgnsView = new CgnsView(); + this->cgnsPanel = new CgnsPanel(); + this->cgnsView->SetCgnsPanel(this->cgnsPanel); +} + +CgnsPair::~CgnsPair() +{ + delete this->cgnsView; + delete this->cgnsPanel; +} + +QWidget *CgnsPair::GetLeft() +{ + return this->cgnsView; +} + +QWidget *CgnsPair::GetRight() +{ + return this->cgnsPanel; +} // tmpInitWidgets _tmpInitWidgets; @@ -199,3 +249,4 @@ void Panel::onGridToolButtonClicked() this->leftPanel->stack->setCurrentIndex(2); this->rightPanel->stack->setCurrentIndex(2); } + diff --git a/tools/codes/panel.h b/tools/codes/panel.h index 97aba12c..d8881a4b 100644 --- a/tools/codes/panel.h +++ b/tools/codes/panel.h @@ -9,8 +9,64 @@ class RightPanel; class QVBoxLayout; class QSpacerItem; -QList &GetWidgetListL(); -QList &GetWidgetListR(); +class WidgetPair; +QList &GetWidgetPairList(); + +class WidgetPair +{ +public: + WidgetPair(); + ~WidgetPair(); +public: + virtual QWidget *GetLeft(); + virtual QWidget *GetRight(); +}; + +class Explorer; + +class ExplorePair : public WidgetPair +{ +public: + ExplorePair(); + ~ExplorePair(); +public: + QWidget *GetLeft(); + QWidget *GetRight(); +public: + QSplitter *splitterV = nullptr; + Explorer *explorer = nullptr; +}; + +class QPushButton; + +class ProjectPair : public WidgetPair +{ +public: + ProjectPair(); + ~ProjectPair(); +public: + QWidget *GetLeft(); + QWidget *GetRight(); +public: + QPushButton *leftButton = nullptr; + QPushButton *rightButton = nullptr; +}; + +class CgnsView; +class CgnsPanel; +class CgnsPair : public WidgetPair +{ +public: + CgnsPair(); + ~CgnsPair(); +public: + QWidget *GetLeft(); + QWidget *GetRight(); +public: + CgnsView *cgnsView = nullptr; + CgnsPanel *cgnsPanel = nullptr; +}; + class Panel : public QWidget { diff --git a/tools/codes/rightpanel.cpp b/tools/codes/rightpanel.cpp index caf5ce7f..289fed17 100644 --- a/tools/codes/rightpanel.cpp +++ b/tools/codes/rightpanel.cpp @@ -15,13 +15,14 @@ RightPanel::RightPanel(QWidget *parent) this->stack = new QStackedWidget(this); - QList ws = ::GetWidgetListR(); + QList wp = ::GetWidgetPairList(); - for( int i = 0; i < ws.count(); ++ i ) + for( int i = 0; i < wp.count(); ++ i ) { - this->stack->addWidget( ws[i] ); + this->stack->addWidget( wp[i]->GetRight() ); } + qDebug() << "this->stack->count()="<< this->stack->count(); } diff --git a/tools/images/forward.png b/tools/images/forward.png new file mode 100644 index 00000000..d14c087b Binary files /dev/null and b/tools/images/forward.png differ diff --git a/tools/images/res.qrc b/tools/images/res.qrc index d05ec65a..f34d6f3d 100644 --- a/tools/images/res.qrc +++ b/tools/images/res.qrc @@ -12,5 +12,6 @@ minus1.png plus.png minus2.png + forward.png