Back to index

salome-smesh  6.5.0
UNV2411_Structure.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <fstream>      
00024 #include <stdio.h>      
00025 
00026 #include "UNV2411_Structure.hxx"
00027 #include "UNV_Utilities.hxx"
00028 
00029 using namespace std;
00030 using namespace UNV;
00031 using namespace UNV2411;
00032 
00033 static string _label_dataset = "2411";
00034 
00035 UNV2411::TRecord::TRecord():
00036   exp_coord_sys_num(1),
00037   disp_coord_sys_num(1),
00038   color(11)//(0) -  0019936: EDF 794 SMESH : Export UNV : Node color and group id
00039 {}
00040 
00041 void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
00042 {
00043   if(!in_stream.good())
00044     EXCEPTION(runtime_error,"ERROR: Input file not good.");
00045 
00046   /*
00047    * adjust the \p istream to our
00048    * position
00049    */
00050   if(!beginning_of_dataset(in_stream,_label_dataset))
00051     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
00052 
00057   std::string num_buf;
00058   while ( !in_stream.eof() )
00059   {
00060     TRecord aRec;
00061     in_stream >> aRec.label ;
00062     if ( aRec.label == -1 ) {
00063       // end of dataset is reached
00064       break;
00065     }
00066 
00067     in_stream>>aRec.exp_coord_sys_num;
00068     in_stream>>aRec.disp_coord_sys_num;
00069     in_stream>>aRec.color;
00070 
00071     /*
00072      * take care of the
00073      * floating-point data
00074      */
00075     for(int d = 0; d < 3; d++){
00076       in_stream>>num_buf;
00077       aRec.coord[d] = D_to_e(num_buf);
00078     }
00079 
00080     theDataSet.push_back(aRec);
00081   }
00082 }
00083 
00084 
00085 void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
00086 {
00087   if(!out_stream.good())
00088     EXCEPTION(runtime_error,"ERROR: Output file not good.");
00089   
00090   /*
00091    * Write beginning of dataset
00092    */
00093   out_stream<<"    -1\n";
00094   out_stream<<"  "<<_label_dataset<<"\n";
00095 
00096   TDataSet::const_iterator anIter = theDataSet.begin();
00097   for(; anIter != theDataSet.end(); anIter++)
00098   {
00099     const TRecord& aRec = *anIter;
00100     char buf[78];
00101     sprintf(buf, "%10d%10d%10d%10d\n", 
00102             aRec.label,
00103             aRec.exp_coord_sys_num,
00104             aRec.disp_coord_sys_num,
00105             aRec.color);
00106     out_stream<<buf;
00107 
00108     // the coordinates
00109     sprintf(buf, "%25.16E%25.16E%25.16E\n", 
00110             aRec.coord[0],
00111             aRec.coord[1],
00112             aRec.coord[2]);
00113     out_stream<<buf;
00114   }
00115   
00116   
00117   /*
00118    * Write end of dataset
00119    */
00120   out_stream<<"    -1\n";
00121 }