-//=======================================================================
-static bool writeGHS3DPRLFiles (const TCollection_AsciiString & GHS3DPRL_In,
- SMESHDS_Mesh * theMesh,
- map <int,int> & theSmdsToGHS3DPRLIdMap,
- map <int,const SMDS_MeshNode*> & theGHS3DPRLIdToNodeMap)
-{
- bool Ok;
- int ifam=0;
- TCollection_AsciiString namefile(GHS3DPRL_In);
- namefile+=".points";
- removeFile(namefile);
- ofstream theFile;
- theFile.open(namefile.ToCString(),ios::out);
-#ifdef WIN32
- Ok = theFile.is_open();
-#else
- Ok=theFile.rdbuf()->is_open();
-#endif
- if (!Ok)
- {
- INFOS("Can't write into "<<namefile.ToCString());
- return false;
- }
- cout<<endl<<"writeGHS3DPRLFiles version 2.1 "<<endl;
- cout<<endl<<"Creating GHS3DPRL processed mesh file : "<<namefile<<endl;
-
- int nbVertices=theMesh->NbNodes();
- int nbFaces=theMesh->NbFaces(); //triangles or quadrangles
- const char* space=" ";
- //const int dummyint=1; //nrs,nsd,refnum=1 (for wrap)
-
- // Writing SMESH points into GHS3DPRL File.points
- theFile<<nbVertices<<endl;
-
- int aSmdsNodeID=1;
- const SMDS_MeshNode* node_2;
- SMDS_NodeIteratorPtr itOnNode=theMesh->nodesIterator();
- //int ifam=100;//test famille
- theFile.precision(15); theFile.setf(ios::scientific,ios::floatfield);
- //cout<<"set precision 15 on float\n";
- while (itOnNode->more())
- {
- node_2 = itOnNode->next();
- theSmdsToGHS3DPRLIdMap.insert(map <int,int>::value_type(node_2->GetID(),aSmdsNodeID));
- theGHS3DPRLIdToNodeMap.insert(map <int,const SMDS_MeshNode*>::value_type(aSmdsNodeID,node_2));
- theFile<<node_2->X()<<space<<node_2->Y()<<space<<node_2->Z()<<space<<ifam<<endl;
- aSmdsNodeID++;
- //if (aSmdsNodeID==11) ifam++;
- }
- //no specified points;
- theFile.close();
-
- namefile=GHS3DPRL_In+".faces";
- removeFile(namefile);
- theFile.open(namefile.ToCString(),ios::out);
-#ifdef WIN32
- Ok=theFile.is_open();
-#else
- Ok=theFile.rdbuf()->is_open();
-#endif
- if (!Ok)
- {
- INFOS("Can't write into "<<namefile.ToCString());
- return false;
- }
- cout<<endl<<"Creating GHS3DPRL processed mesh file : "<<namefile<<endl;
-
- // Writing SMESH faces into GHS3DPRL File.faces
- theFile<<nbFaces<<" 0"<<endl; //NB_ELEMS DUMMY_INT
- //" 0" is a reserved parameter
-
- const SMDS_MeshElement* aFace;
- map<int,int>::const_iterator itOnSmdsNode;
- SMDS_ElemIteratorPtr itOnFaceNode;
- SMDS_FaceIteratorPtr itOnSmdsFace = theMesh->facesIterator();
- long nbNoTriangles=0;
- int ifaces=0;
- //ifam=300;
- while (itOnSmdsFace->more())
- {
- aFace=itOnSmdsFace->next();
- itOnFaceNode=aFace->nodesIterator();
- const int nbNodes=aFace->NbNodes();
- if (nbNodes!=3) nbNoTriangles++;
- ifaces++;
- theFile<<nbNodes<<space; // NB_NODES
- while (itOnFaceNode->more())
- {
- aSmdsNodeID=itOnFaceNode->next()->GetID();
- itOnSmdsNode=theSmdsToGHS3DPRLIdMap.find(aSmdsNodeID);
- ASSERT(itOnSmdsNode!=theSmdsToGHS3DPRLIdMap.end());
- theFile<<space<<(*itOnSmdsNode).second; //NODE_1 NODE_2 ...
- }
- //(NB_NODES+1) times: DUMMY_INT
- //if (ifaces==11) ifam++;
- theFile<<space<<ifam;
- for ( int i=1; i<=nbNodes; i++) theFile<<space<<200+i;
- theFile<<endl;
- }
- theFile.close();
-
- cout<<"Processed mesh files created, they contains :\n";
- cout<<" "<<nbVertices<<" vertices\n";
- if (nbNoTriangles==0)
- cout<<" "<<nbFaces<<" faces\n\n";
- else
- cout<<" "<<nbFaces<<" faces with "<<nbNoTriangles<<"faces no triangles\n\n";
- return true;
-}
-
-//=======================================================================
-// static bool getInt( int & theValue, char * & theLine )
-// {
-// char *ptr;
-// theValue = strtol( theLine, &ptr, 10 );
-// if ( ptr == theLine ||
-// // there must not be neither '.' nor ',' nor 'E' ...
-// (*ptr != ' ' && *ptr != '\n' && *ptr != '\0'))
-// return false;
-
-// DUMP( " " << theValue );
-// theLine = ptr;
-// return true;
-// }
-
-//=======================================================================
-// static bool getDouble( double & theValue, char * & theLine )
-// {
-// char *ptr;
-// theValue = strtod( theLine, &ptr );
-// if ( ptr == theLine )
-// return false;
-
-// DUMP( " " << theValue );
-// theLine = ptr;
-// return true;
-// }
-
-//=======================================================================
-
-#define GHS3DPRLPlugin_BUFLENGTH 256
-#define GHS3DPRLPlugin_ReadLine(aPtr,aBuf,aFile,aLineNb) \
-{ aPtr = fgets( aBuf, GHS3DPRLPlugin_BUFLENGTH - 2, aFile ); aLineNb++; DUMP(endl); }
-
-//=======================================================================
-// static bool readResult(FILE * theFile,
-// SMESHDS_Mesh * theMesh,
-// const TopoDS_Shape & theShape,
-// map <int,const SMDS_MeshNode*> & theGHS3DPRLIdToNodeMap,
-// const TCollection_AsciiString & GHS3DPRL_Out,
-// int & nodeRefNumber)
-// {
-// // ---------------------------------
-// // Read generated elements and nodes
-// // ---------------------------------
-
-// cout << "Reading GHS3DPRL output file : " << GHS3DPRL_Out << endl;
-// cout << endl;
-
-// char aBuffer[ GHS3DPRLPlugin_BUFLENGTH ];
-// char * aPtr;
-// int aLineNb = 0;
-// int shapeID = theMesh->ShapeToIndex( theShape );
-
-// int line = 1, EndOfFile = 0, nbElem = 0, nField = 10, nbRef = 0, aGHS3DPRLNodeID = 0;
-// const char * theField;
-
-// vector<const char*> tabField = vector<const char*>(nField);
-// vector<int> tabRef = vector<int>(nField);
-
-// tabField[0] = "MeshVersionFormatted"; tabRef[0] = 0;
-// tabField[1] = "Dimension"; tabRef[1] = 0;
-// tabField[2] = "Vertices"; tabRef[2] = 3;
-// tabField[3] = "Edges"; tabRef[3] = 2;
-// tabField[4] = "Triangles"; tabRef[4] = 3;
-// tabField[5] = "Quadrilaterals"; tabRef[5] = 4;
-// tabField[6] = "Hexahedra"; tabRef[6] = 8;
-// tabField[7] = "Corners"; tabRef[7] = 1;
-// tabField[8] = "Ridges"; tabRef[0] = 1;
-// tabField[9] = "End"; tabRef[0] = 0;
-
-// nodeRefNumber += theMesh->NbNodes();
-
-// SMDS_NodeIteratorPtr itOnGHS3DPRLInputNode = theMesh->nodesIterator();
-// while ( itOnGHS3DPRLInputNode->more() )
-// theMesh->RemoveNode( itOnGHS3DPRLInputNode->next() );
-
-// while ( EndOfFile == 0 ) {
-// GHS3DPRLPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
-// for ( int iField = 0; iField < nField; iField++ ) {
-// stringstream theMessage;
-// theField = tabField[iField];
-// if ( strncmp(aPtr, theField, strlen(theField)) == 0 ) {
-// if ( strcmp(theField, "End") == 0 ) {
-// EndOfFile = 1;
-// theMessage << "End of GHS3DPRL output file has been reached";
-// }
-// else {
-// GHS3DPRLPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
-// line++;
-// getInt( nbElem, aPtr );
-
-// if ( strcmp(theField, "MeshVersionFormatted") == 0 )
-// theMessage << "GHS3DPRL mesh descriptor : " << theField << " " << nbElem;
-// else if ( strcmp(theField, "Dimension") == 0 )
-// theMessage << "GHS3DPRL mesh of " << nbElem << "D dimension";
-// else if ( strcmp(theField, "Vertices") == 0 ||
-// strcmp(theField, "Edges") == 0 ||
-// strcmp(theField, "Quadrilaterals") == 0 ||
-// strcmp(theField, "Hexahedra") == 0 ) {
-// nbRef = tabRef[iField];
-// GHS3DPRLPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb ); // read blank line
-
-// if ( strcmp(theField, "Vertices") == 0 ) {
-// int aGHS3DPRLID;
-// vector<double> coord = vector<double>(nbRef);
-// SMDS_MeshNode * aGHS3DPRLNode;
-
-// for ( int iElem = 0; iElem < nbElem; iElem++ ) {
-// aGHS3DPRLID = iElem + 1 + nodeRefNumber;
-// GHS3DPRLPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb ); // read file lines
-// for ( int iCoord = 0; iCoord < 3; iCoord++ )
-// getDouble ( coord[ iCoord ], aPtr );
-// aGHS3DPRLNode = theMesh->AddNode(coord[0], coord[1], coord[2]);
-// theMesh->SetNodeInVolume( aGHS3DPRLNode, shapeID );
-// theGHS3DPRLIdToNodeMap[ aGHS3DPRLID ] = aGHS3DPRLNode;
-// }
-// }
-// else {
-// vector<const SMDS_MeshNode*> node = vector<const SMDS_MeshNode*>(nbRef);
-// SMDS_MeshElement* aGHS3DPRLElement;
-// map <int,const SMDS_MeshNode*>::iterator itOnGHS3DPRLNode;
-
-// for ( int iElem = 0; iElem < nbElem; iElem++ ) {
-// GHS3DPRLPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb ); // read file lines
-// for ( int iRef = 0; iRef < nbRef; iRef++ ) {
-// getInt ( aGHS3DPRLNodeID, aPtr ); // read nbRef aGHS3DPRLNodeID
-// aGHS3DPRLNodeID += nodeRefNumber;
-// itOnGHS3DPRLNode = theGHS3DPRLIdToNodeMap.find( aGHS3DPRLNodeID );
-// node[ iRef ] = itOnGHS3DPRLNode->second;
-// }
-
-// if ( strcmp(theField, "Edges") == 0 ) // create an element
-// aGHS3DPRLElement = theMesh->AddEdge( node[0], node[1] );
-// else if ( strcmp(theField, "Quadrilaterals") == 0 )
-// aGHS3DPRLElement = theMesh->AddFace( node[0], node[1], node[2], node[3] );
-// else if ( strcmp(theField, "Hexahedra") == 0 )
-// aGHS3DPRLElement = theMesh->AddVolume( node[0], node[1], node[2], node[3], node[4], node[5], node[6], node[7] );
-
-// theMesh->SetMeshElementOnShape( aGHS3DPRLElement, shapeID );
-// }
-// }
-// theMessage << nbElem << " " << theField << " created";
-// }
-// }
-// if ( theMessage.str().size() != 0 ) {
-// cout << theMessage.str() << endl;
-// break;
-// }
-// }
-// }
-// }
-// cout << endl;
-// return true;
-// }
-