Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / DriverUNV / UNV2411_Structure.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <fstream>      
23 #include <stdio.h>      
24
25 #include "UNV2411_Structure.hxx"
26 #include "UNV_Utilities.hxx"
27
28 using namespace std;
29 using namespace UNV;
30 using namespace UNV2411;
31
32 #ifdef _DEBUG_
33 static int MYDEBUG = 1;
34 #else
35 static int MYDEBUG = 0;
36 #endif
37
38 static string _label_dataset = "2411";
39
40 UNV2411::TRecord::TRecord():
41   exp_coord_sys_num(0),
42   disp_coord_sys_num(0),
43   color(0)
44 {}
45
46 void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
47 {
48   if(!in_stream.good())
49     EXCEPTION(runtime_error,"ERROR: Input file not good.");
50
51   /*
52    * adjust the \p istream to our
53    * position
54    */
55   if(!beginning_of_dataset(in_stream,_label_dataset))
56     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
57
58   /**
59    * always 3 coordinates in the UNV file, no matter
60    * which dimensionality libMesh is in
61    */
62   TNodeLab aLabel;
63   std::string num_buf;
64   for(; !in_stream.eof();){
65     in_stream >> aLabel ;
66     if(aLabel == -1){
67       // end of dataset is reached
68       break;
69     }
70
71     TRecord aRec;
72     in_stream>>aRec.exp_coord_sys_num;
73     in_stream>>aRec.disp_coord_sys_num;
74     in_stream>>aRec.color;
75
76     /*
77      * take care of the
78      * floating-point data
79      */
80     for(int d = 0; d < 3; d++){
81       in_stream>>num_buf;
82       aRec.coord[d] = D_to_e(num_buf);
83     }
84
85     theDataSet.insert(TDataSet::value_type(aLabel,aRec));
86   }
87 }
88
89
90 void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
91 {
92   if(!out_stream.good())
93     EXCEPTION(runtime_error,"ERROR: Output file not good.");
94   
95   /*
96    * Write beginning of dataset
97    */
98   out_stream<<"    -1\n";
99   out_stream<<"  "<<_label_dataset<<"\n";
100
101   TDataSet::const_iterator anIter = theDataSet.begin();
102   for(; anIter != theDataSet.end(); anIter++){
103     const TNodeLab& aLabel = anIter->first;
104     const TRecord& aRec = anIter->second;
105     char buf[78];
106     sprintf(buf, "%10d%10d%10d%10d\n", 
107             aLabel,
108             aRec.exp_coord_sys_num,
109             aRec.disp_coord_sys_num,
110             aRec.color);
111     out_stream<<buf;
112
113     // the coordinates
114     sprintf(buf, "%25.16E%25.16E%25.16E\n", 
115             aRec.coord[0],
116             aRec.coord[1],
117             aRec.coord[2]);
118     out_stream<<buf;
119   }
120   
121   
122   /*
123    * Write end of dataset
124    */
125   out_stream<<"    -1\n";
126 }