smesh/src/DriverUNV/UNV2411_Structure.cxx

122 lines
3.1 KiB
C++
Raw Normal View History

2013-04-01 19:05:47 +06:00
// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
#include <fstream>
#include <stdio.h>
2004-12-01 15:48:31 +05:00
#include "UNV2411_Structure.hxx"
#include "UNV_Utilities.hxx"
using namespace std;
using namespace UNV;
using namespace UNV2411;
static string _label_dataset = "2411";
UNV2411::TRecord::TRecord():
2012-08-09 16:03:55 +06:00
exp_coord_sys_num(1),
disp_coord_sys_num(1),
color(11)//(0) - 0019936: EDF 794 SMESH : Export UNV : Node color and group id
2004-12-01 15:48:31 +05:00
{}
void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
{
if(!in_stream.good())
EXCEPTION(runtime_error,"ERROR: Input file not good.");
/*
* adjust the \p istream to our
* position
*/
if(!beginning_of_dataset(in_stream,_label_dataset))
EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
/**
* always 3 coordinates in the UNV file, no matter
* which dimensionality libMesh is in
*/
std::string num_buf;
2012-08-09 16:03:55 +06:00
while ( !in_stream.eof() )
{
TRecord aRec;
in_stream >> aRec.label ;
if ( aRec.label == -1 ) {
2004-12-01 15:48:31 +05:00
// end of dataset is reached
break;
}
in_stream>>aRec.exp_coord_sys_num;
in_stream>>aRec.disp_coord_sys_num;
in_stream>>aRec.color;
/*
* take care of the
* floating-point data
*/
for(int d = 0; d < 3; d++){
in_stream>>num_buf;
aRec.coord[d] = D_to_e(num_buf);
}
2012-08-09 16:03:55 +06:00
theDataSet.push_back(aRec);
2004-12-01 15:48:31 +05:00
}
}
void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
{
if(!out_stream.good())
EXCEPTION(runtime_error,"ERROR: Output file not good.");
/*
* Write beginning of dataset
*/
out_stream<<" -1\n";
out_stream<<" "<<_label_dataset<<"\n";
TDataSet::const_iterator anIter = theDataSet.begin();
2012-08-09 16:03:55 +06:00
for(; anIter != theDataSet.end(); anIter++)
{
const TRecord& aRec = *anIter;
2004-12-01 15:48:31 +05:00
char buf[78];
sprintf(buf, "%10d%10d%10d%10d\n",
2012-08-09 16:03:55 +06:00
aRec.label,
aRec.exp_coord_sys_num,
aRec.disp_coord_sys_num,
aRec.color);
2004-12-01 15:48:31 +05:00
out_stream<<buf;
// the coordinates
sprintf(buf, "%25.16E%25.16E%25.16E\n",
2012-08-09 16:03:55 +06:00
aRec.coord[0],
aRec.coord[1],
aRec.coord[2]);
2004-12-01 15:48:31 +05:00
out_stream<<buf;
}
/*
* Write end of dataset
*/
out_stream<<" -1\n";
}