From 1b141b0cb9e62ce46359c06d2f4edd75ec283dd3 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 23 Jan 2012 08:00:05 +0000 Subject: [PATCH] 0021198: EDF 1548 GEOM: Writing of coordinates system into exported UNV files --- src/DriverUNV/Makefile.am | 4 + src/DriverUNV/UNV164_Structure.cxx | 83 +++++++++++++++ src/DriverUNV/UNV164_Structure.hxx | 94 +++++++++++++++++ src/DriverUNV/UNV2420_Structure.cxx | 152 ++++++++++++++++++++++++++++ src/DriverUNV/UNV2420_Structure.hxx | 119 ++++++++++++++++++++++ 5 files changed, 452 insertions(+) create mode 100644 src/DriverUNV/UNV164_Structure.cxx create mode 100644 src/DriverUNV/UNV164_Structure.hxx create mode 100644 src/DriverUNV/UNV2420_Structure.cxx create mode 100644 src/DriverUNV/UNV2420_Structure.hxx diff --git a/src/DriverUNV/Makefile.am b/src/DriverUNV/Makefile.am index 89ac29deb..58c0aaf57 100644 --- a/src/DriverUNV/Makefile.am +++ b/src/DriverUNV/Makefile.am @@ -34,9 +34,11 @@ salomeinclude_HEADERS = \ # not-exported (internal) files EXTRA_DIST += \ + UNV164_Structure.hxx \ UNV2411_Structure.hxx \ UNV2412_Structure.hxx \ UNV2417_Structure.hxx \ + UNV2420_Structure.hxx \ UNV_Utilities.hxx # Libraries targets @@ -45,8 +47,10 @@ dist_libMeshDriverUNV_la_SOURCES = \ DriverUNV_R_SMDS_Mesh.cxx \ DriverUNV_W_SMDS_Mesh.cxx \ UNV_Utilities.cxx \ + UNV164_Structure.cxx \ UNV2411_Structure.cxx \ UNV2412_Structure.cxx \ + UNV2420_Structure.cxx \ UNV2417_Structure.cxx # Executables targets diff --git a/src/DriverUNV/UNV164_Structure.cxx b/src/DriverUNV/UNV164_Structure.cxx new file mode 100644 index 000000000..8ade4ded9 --- /dev/null +++ b/src/DriverUNV/UNV164_Structure.cxx @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "UNV164_Structure.hxx" +#include "UNV_Utilities.hxx" + +#include +#include +#include + +using namespace std; +using namespace UNV; +using namespace UNV164; + +static string _label_dataset = "164"; + +void UNV164::Read(std::ifstream& in_stream, TRecord& theUnitsRecord ) +{ + if(!in_stream.good()) + EXCEPTION(runtime_error,"ERROR: Input file not good."); + + if(!beginning_of_dataset(in_stream,_label_dataset)) + return; + + string num_buf; + char line[theMaxLineLen]; + + in_stream >> theUnitsRecord.units_code; + in_stream.readsome( line, 20 ); + theUnitsRecord.units_description = line; + in_stream >> theUnitsRecord.temp_mode; + + for ( int i = 0; i < 4; i++ ) + { + in_stream >> num_buf; + theUnitsRecord.factors[i] = D_to_e(num_buf); + } +} + +void UNV164::Write(std::ofstream& out_stream) +{ + if(!out_stream.good()) + EXCEPTION(runtime_error,"ERROR: Output file not good."); + + out_stream<<" -1" << endl; + out_stream<<" "<<_label_dataset << endl; + + out_stream<<" 1 SI: Meter (newton) 2" << endl; + out_stream<<" 1.0000000000000000E+0 1.0000000000000000E+0 1.0000000000000000E+0" << endl; + out_stream<<" 2.7314999999999998E+2" << endl; + + out_stream<<" -1" << endl; +} + +UNV164::TRecord::TRecord() +{ + units_code = 1; + units_description = "SI: Meter (newton)"; + temp_mode = 2; + factors[0] = 1.0; + factors[1] = 1.0; + factors[2] = 1.0; + factors[3] = 273.15; +} diff --git a/src/DriverUNV/UNV164_Structure.hxx b/src/DriverUNV/UNV164_Structure.hxx new file mode 100644 index 000000000..908239419 --- /dev/null +++ b/src/DriverUNV/UNV164_Structure.hxx @@ -0,0 +1,94 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef UNV164_Structure_HeaderFile +#define UNV164_Structure_HeaderFile + +// Universal Dataset Number: 164 +// Name: Units +// Status: Current +// Owner: General +// Revision Date: 19-AUG-1987 +// ----------------------------------------------------------------------- + +// Record 1: FORMAT(I10,20A1,I10) +// Field 1 -- units code +// = 1 - SI: Meter (newton) +// = 2 - BG: Foot (pound f) +// = 3 - MG: Meter (kilogram f) +// = 4 - BA: Foot (poundal) +// = 5 - MM: mm (milli newton) +// = 6 - CM: cm (centi newton) +// = 7 - IN: Inch (pound f) +// = 8 - GM: mm (kilogram f) +// = 9 - US: USER_DEFINED +// = 10- MN: mm (newton) +// Field 2 -- units description (used for +// documentation only) +// Field 3 -- temperature mode +// = 1 - absolute +// = 2 - relative +// Record 2: FORMAT(3D25.17) +// Unit factors for converting universal file units to SI. +// To convert from universal file units to SI divide by +// the appropriate factor listed below. +// Field 1 -- length +// Field 2 -- force +// Field 3 -- temperature +// Field 4 -- temperature offset + +// Example: + +// -1 +// 164 +// 2Foot (pound f) 2 +// 3.28083989501312334D+00 2.24808943099710480D-01 1.79999999999999999D+00 +// 4.59670000000000002D+02 +// -1 + +#include "SMESH_DriverUNV.hxx" + +#include + +namespace UNV164 +{ + enum { LENGTH_FACTOR, FORCE_FACTOR, TEMP_FACTOR, TEMP_OFFSET }; + + struct MESHDRIVERUNV_EXPORT TRecord + { + int units_code; + std::string units_description; + int temp_mode; + double factors[4]; + TRecord(); + }; + + MESHDRIVERUNV_EXPORT void + Read(std::ifstream& in_stream, TRecord& theUnitsRecord); + + MESHDRIVERUNV_EXPORT void + Write(std::ofstream& out_stream ); + +}; + + +#endif diff --git a/src/DriverUNV/UNV2420_Structure.cxx b/src/DriverUNV/UNV2420_Structure.cxx new file mode 100644 index 000000000..76db6bc0d --- /dev/null +++ b/src/DriverUNV/UNV2420_Structure.cxx @@ -0,0 +1,152 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "UNV2420_Structure.hxx" +#include "UNV_Utilities.hxx" + +#include +#include +#include + +using namespace std; +using namespace UNV; +using namespace UNV2420; + +static string _label_dataset = "2420"; + +void UNV2420::Read(std::ifstream& in_stream, + std::string& part_name, // can re-store a mesh name + 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)) + return; + + string num_buf; + int part_uid; + + in_stream >> part_uid; // Record 1 + part_name = read_line( in_stream ); // Record 2 + + while ( !in_stream.eof() ) + { + TRecord aRec; + + // Record 3 + in_stream >> aRec.coord_sys_label; + if ( aRec.coord_sys_label == -1 ) // end of dataset is reached + break; + in_stream >> aRec.coord_sys_type; + in_stream >> aRec.coord_sys_color; + + aRec.coord_sys_name = read_line( in_stream ); // Record 4 + + // Records 5-8: rows of Transformation Matrix + for ( int row = 0; row < 4; ++row ) + for ( int i = 0; i < 3; i++ ) + { + in_stream >> num_buf; + aRec.matrix[row][i] = D_to_e(num_buf); + } + // Store a CS data only if it requires conversion into the global Cartesian CS + if ( aRec.coord_sys_type != 0 || !aRec.isIdentityMatrix() ) // 0 - Cartesian CS + theDataSet.push_back( aRec ); + } +} + + +void UNV2420::Write(std::ofstream& out_stream, + const std::string& part_name) +// const TDataSet& theDataSet) +{ + if(!out_stream.good()) + EXCEPTION(runtime_error,"ERROR: Output file not good."); + + out_stream<<" -1" << endl; + out_stream<<" "<<_label_dataset << endl; + + out_stream<<" 1" << endl; // R1: Part UID + if ( part_name.empty() ) + out_stream<<"SMESH_Mesh" << endl; // R2: Part Name + else + out_stream<< part_name << endl; + out_stream<<" 1 0 0" << endl; // R3: Label, Type, Color + + out_stream<<"Global Cartesian Coordinate System" << endl; // R4: Name + out_stream<<" 1.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0" << endl; + out_stream<<" 0.0000000000000000E+0 1.0000000000000000E+0 0.0000000000000000E+0" << endl; + out_stream<<" 0.0000000000000000E+0 0.0000000000000000E+0 1.0000000000000000E+0" << endl; + out_stream<<" 0.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0" << endl; + + out_stream<<" -1" << endl; +} + + +bool UNV2420::TRecord::isIdentityMatrix() const +{ + bool isIdentity = true; + for ( int row = 0; row < 4 && isIdentity; ++row ) + for ( int i = 0; i < 3; i++ ) + { + if ( matrix[row][i] != ( row==i ? 1. : 0. )) + { + isIdentity = false; + break; + } + } + return isIdentity; +} + +void UNV2420::TRecord::ApplyMatrix( double* c ) const +{ + const double x = matrix[0][0] * c[0] + matrix[0][1] * c[1] + matrix[0][2] * c[2]; + const double y = matrix[1][0] * c[0] + matrix[1][1] * c[1] + matrix[1][2] * c[2]; + const double z = matrix[2][0] * c[0] + matrix[2][1] * c[1] + matrix[2][2] * c[2]; + c[0] = x + matrix[3][0]; + c[1] = y + matrix[3][1]; + c[2] = z + matrix[3][2]; +} + +void UNV2420::TRecord::FromCylindricalCS( double* coords ) +{ + const double x = coords[0] * cos( coords[1] ); + const double y = coords[0] * sin( coords[1] ); + coords[0] = x; + coords[1] = y; +} + +void UNV2420::TRecord::FromSphericalCS ( double* coords ) +{ + const double sin2 = sin( coords[2] ); + const double x = coords[0] * cos( coords[1] ) * sin2; + const double y = coords[0] * sin( coords[1] ) * sin2; + const double z = coords[0] * cos( coords[2] ); + coords[0] = x; + coords[1] = y; + coords[2] = z; +} diff --git a/src/DriverUNV/UNV2420_Structure.hxx b/src/DriverUNV/UNV2420_Structure.hxx new file mode 100644 index 000000000..896b35047 --- /dev/null +++ b/src/DriverUNV/UNV2420_Structure.hxx @@ -0,0 +1,119 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef UNV2420_Structure_HeaderFile +#define UNV2420_Structure_HeaderFile + +// Name: Coordinate Systems +// ----------------------------------------------------------------------- + +// Record 1: FORMAT (1I10) +// Field 1 -- Part UID + +// Record 2: FORMAT (40A2) +// Field 1 -- Part Name + +// Record 3: FORMAT (3I10) +// Field 1 -- Coordinate System Label +// Field 2 -- Coordinate System Type +// = 0, Cartesian +// = 1, Cylindrical +// = 2, Spherical +// Field 3 -- Coordinate System Color + +// Record 4: FORMAT (40A2) +// Field 1 -- Coordinate System Name + +// Record 5: FORMAT (1P3D25.16) +// Field 1-3 -- Transformation Matrix Row 1 + +// Record 6: FORMAT (1P3D25.16) +// Field 1-3 -- Transformation Matrix Row 2 + +// Record 7: FORMAT (1P3D25.16) +// Field 1-3 -- Transformation Matrix Row 3 + +// Record 8: FORMAT (1P3D25.16) +// Field 1-3 -- Transformation Matrix Row 4 + +// Records 3 thru 8 are repeated for each Coordinate System in the Part. + +// Example: +// -1 +// 2420 +// 100 +// Untitled +// 6 1 15 +// FEMAP Global Cylindrical (6) +// 1.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0 +// 0.0000000000000000E+0 1.0000000000000000E+0 0.0000000000000000E+0 +// 0.0000000000000000E+0 0.0000000000000000E+0 1.0000000000000000E+0 +// 0.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0 +// 7 2 15 +// Coordinate System 4 +// 1.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0 +// 0.0000000000000000E+0 1.0000000000000000E+0 0.0000000000000000E+0 +// 0.0000000000000000E+0 0.0000000000000000E+0 1.0000000000000000E+0 +// 0.0000000000000000E+0 0.0000000000000000E+0 0.0000000000000000E+0 +// -1 + +#include "SMESH_DriverUNV.hxx" + +#include +#include + +namespace UNV2420 +{ + enum { Cartesian=0, Cylindrical, Spherical }; + + typedef int TCSLabel; // type of coord system label + + struct MESHDRIVERUNV_EXPORT TRecord + { + TCSLabel coord_sys_label; + int coord_sys_type; // { Cartesian=0, Cylindrical, Spherical } + int coord_sys_color; + std::string coord_sys_name; + double matrix[4][3]; + + bool isIdentityMatrix() const; + void ApplyMatrix ( double* coords ) const; + static void FromCylindricalCS( double* coords ); + static void FromSphericalCS ( double* coords ); + }; + + typedef std::vector TDataSet; + + MESHDRIVERUNV_EXPORT void + Read(std::ifstream& in_stream, + std::string& part_name, // can re-store a mesh name + TDataSet& theDataSet); + + MESHDRIVERUNV_EXPORT void + Write(std::ofstream& out_stream, + const std::string& part_name); // can store a mesh name + // const TDataSet& theDataSet); + +}; + + +#endif -- 2.30.2