geom/src/IGESImport/IGESImport.cxx

161 lines
5.1 KiB
C++
Raw Normal View History

2010-04-21 14:08:27 +06:00
// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
2005-12-05 21:23:52 +05:00
//
2009-02-13 17:16:39 +05:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2005-12-05 21:23:52 +05:00
//
2009-02-13 17:16:39 +05: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.
//
// 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
2005-12-05 21:23:52 +05:00
//
2010-04-21 14:08:27 +06:00
2009-12-25 16:28:58 +05:00
// File: IGESImport.cxx
// Created: Wed May 19 14:36:35 2004
// Author: Pavel TELKOV
// <ptv@mutex.nnov.opencascade.com>
2009-02-13 17:16:39 +05:00
//
2004-12-01 15:39:14 +05:00
#include "utilities.h"
2009-12-08 17:05:55 +05:00
#include <Basics_Utils.hxx>
2004-12-01 15:39:14 +05:00
#include <IFSelect_ReturnStatus.hxx>
#include <IGESControl_Reader.hxx>
2009-06-03 13:39:16 +06:00
#include <IGESData_IGESModel.hxx>
2004-12-01 15:39:14 +05:00
2009-06-03 13:39:16 +06:00
#include <TCollection_HAsciiString.hxx>
2004-12-01 15:39:14 +05:00
#include <TopoDS_Shape.hxx>
2009-06-03 13:39:16 +06:00
#include <TDF_Label.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <Interface_Static.hxx>
2004-12-01 15:39:14 +05:00
2005-08-11 10:43:57 +06:00
#ifdef WNT
#if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS
#if defined WIN32
#define IGESIMPORT_EXPORT __declspec( dllexport )
#else
#define IGESIMPORT_EXPORT
#endif
#else
#if defined WIN32
#define IGESIMPORT_EXPORT __declspec( dllimport )
#else
#define IGESIMPORT_EXPORT
#endif
#endif
2005-08-11 10:43:57 +06:00
#else
#define IGESIMPORT_EXPORT
2005-08-11 10:43:57 +06:00
#endif
2004-12-01 15:39:14 +05:00
//=============================================================================
/*!
*
*/
//=============================================================================
extern "C"
{
IGESIMPORT_EXPORT
2004-12-01 15:39:14 +05:00
TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
2009-06-03 13:39:16 +06:00
const TCollection_AsciiString& theFormatName,
TCollection_AsciiString& theError,
2009-12-25 16:28:58 +05:00
const TDF_Label&)
2004-12-01 15:39:14 +05:00
{
2009-12-08 17:05:55 +05:00
// Set "C" numeric locale to save numbers correctly
Kernel_Utils::Localizer loc;
2004-12-01 15:39:14 +05:00
IGESControl_Reader aReader;
TopoDS_Shape aResShape;
Interface_Static::SetCVal("xstep.cascade.unit","M");
2004-12-01 15:39:14 +05:00
try {
IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
if (status == IFSelect_RetDone) {
2009-06-03 13:39:16 +06:00
2009-12-25 16:28:58 +05:00
if( theFormatName == "IGES_UNIT" ) {
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
gp_Pnt P(1.0,0.0,0.0);
if(!aModel.IsNull()) {
Handle(TCollection_HAsciiString) aUnitName =
aModel->GlobalSection().UnitName();
//cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
//cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
if( aUnitName->String()=="MM" ) {
P = gp_Pnt(0.001,0.0,0.0);
}
else if( aUnitName->String()=="CM" ) {
P = gp_Pnt(0.01,0.0,0.0);
}
}
BRep_Builder B;
TopoDS_Vertex V;
B.MakeVertex(V,P,1.e-7);
aResShape = V;
return aResShape;
}
if( theFormatName == "IGES_SCALE" ) {
//cout<<"need re-scale a model"<<endl;
// set UnitFlag to 'meter'
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
if(!aModel.IsNull()) {
IGESData_GlobalSection aGS = aModel->GlobalSection();
aGS.SetUnitFlag(6);
aModel->SetGlobalSection(aGS);
}
}
2009-06-03 13:39:16 +06:00
2004-12-01 15:39:14 +05:00
MESSAGE("ImportIGES : all Geometry Transfer");
//OCC 5.1.2 porting
// aReader.Clear();
// aReader.TransferRoots(false);
aReader.ClearShapes();
aReader.TransferRoots();
MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes());
aResShape = aReader.OneShape();
} else {
// switch (status) {
// case IFSelect_RetVoid:
// theError = "Nothing created or No data to process";
// break;
// case IFSelect_RetError:
// theError = "Error in command or input data";
// break;
// case IFSelect_RetFail:
// theError = "Execution was run, but has failed";
// break;
// case IFSelect_RetStop:
// theError = "Execution has been stopped. Quite possible, an exception was raised";
// break;
// default:
// break;
// }
theError = "Wrong format of the imported file. Can't import file.";
2009-12-25 16:28:58 +05:00
aResShape.Nullify();
2004-12-01 15:39:14 +05:00
}
}
catch(Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
theError = aFail->GetMessageString();
aResShape.Nullify();
}
return aResShape;
}
}