Salome HOME
untabify
[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 static string _label_dataset = "2411";
33
34 UNV2411::TRecord::TRecord():
35   exp_coord_sys_num(0),
36   disp_coord_sys_num(0),
37   color(11)//(0) -  0019936: EDF 794 SMESH : Export UNV : Node color and group id
38 {}
39
40 void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
41 {
42   if(!in_stream.good())
43     EXCEPTION(runtime_error,"ERROR: Input file not good.");
44
45   /*
46    * adjust the \p istream to our
47    * position
48    */
49   if(!beginning_of_dataset(in_stream,_label_dataset))
50     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
51
52   /**
53    * always 3 coordinates in the UNV file, no matter
54    * which dimensionality libMesh is in
55    */
56   TNodeLab aLabel;
57   std::string num_buf;
58   for(; !in_stream.eof();){
59     in_stream >> aLabel ;
60     if(aLabel == -1){
61       // end of dataset is reached
62       break;
63     }
64
65     TRecord aRec;
66     in_stream>>aRec.exp_coord_sys_num;
67     in_stream>>aRec.disp_coord_sys_num;
68     in_stream>>aRec.color;
69
70     /*
71      * take care of the
72      * floating-point data
73      */
74     for(int d = 0; d < 3; d++){
75       in_stream>>num_buf;
76       aRec.coord[d] = D_to_e(num_buf);
77     }
78
79     theDataSet.insert(TDataSet::value_type(aLabel,aRec));
80   }
81 }
82
83
84 void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
85 {
86   if(!out_stream.good())
87     EXCEPTION(runtime_error,"ERROR: Output file not good.");
88   
89   /*
90    * Write beginning of dataset
91    */
92   out_stream<<"    -1\n";
93   out_stream<<"  "<<_label_dataset<<"\n";
94
95   TDataSet::const_iterator anIter = theDataSet.begin();
96   for(; anIter != theDataSet.end(); anIter++){
97     const TNodeLab& aLabel = anIter->first;
98     const TRecord& aRec = anIter->second;
99     char buf[78];
100     sprintf(buf, "%10d%10d%10d%10d\n", 
101             aLabel,
102             aRec.exp_coord_sys_num,
103             aRec.disp_coord_sys_num,
104             aRec.color);
105     out_stream<<buf;
106
107     // the coordinates
108     sprintf(buf, "%25.16E%25.16E%25.16E\n", 
109             aRec.coord[0],
110             aRec.coord[1],
111             aRec.coord[2]);
112     out_stream<<buf;
113   }
114   
115   
116   /*
117    * Write end of dataset
118    */
119   out_stream<<"    -1\n";
120 }