FeatureImportStep.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <fcntl.h>
00027 # include <TopTools_HSequenceOfShape.hxx>
00028 # include <STEPControl_Writer.hxx>
00029 # include <STEPControl_Reader.hxx>
00030 # include <TopoDS_Shape.hxx>
00031 # include <TFunction_Logbook.hxx>
00032 #endif
00033
00034 #include <Base/Console.h>
00035 #include <Base/Sequencer.h>
00036 #include "FeatureImportStep.h"
00037
00038
00039 using namespace Import;
00040
00041 void FeatureImportStep::InitLabel(const TDF_Label &rcLabel)
00042 {
00043 addProperty("String","FileName");
00044
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054 Standard_Integer FeatureImportStep::Execute(void)
00055 {
00056 Base::Console().Log("FeaturePartImportStep::Execute()\n");
00057
00058
00059
00060
00061
00062
00063
00064
00065 try{
00066
00067 STEPControl_Reader aReader;
00068 TopoDS_Shape aShape;
00069
00070 std::string FileName = getPropertyString("FileName");
00071
00072 if( FileName == "")
00073 return 1;
00074
00075 int i=_open(FileName.c_str(),O_RDONLY);
00076 if( i != -1)
00077 {
00078 _close(i);
00079 }else{
00080 setError("File not readable");
00081 return 1;
00082 }
00083
00084
00085 Base::Sequencer().start("Load IGES", 1);
00086 Base::Sequencer().next();
00087
00088 Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = new TopTools_HSequenceOfShape;
00089 if (aReader.ReadFile((const Standard_CString)FileName.c_str()) != IFSelect_RetDone)
00090 {
00091 setError("File not readable");
00092 return 1;
00093 }
00094
00095
00096 Standard_Integer nbr = aReader.NbRootsForTransfer();
00097
00098 for ( Standard_Integer n = 1; n<= nbr; n++)
00099 {
00100 printf("STEP: Transfering Root %d\n",n);
00101 aReader.TransferRoot(n);
00102
00103 Standard_Integer nbs = aReader.NbShapes();
00104 if (nbs == 0) {
00105 aHSequenceOfShape.Nullify();
00106 return 1;
00107 } else {
00108 for (Standard_Integer i =1; i<=nbs; i++)
00109 {
00110 printf("STEP: Transfering Shape %d\n",n);
00111 aShape=aReader.Shape(i);
00112 aHSequenceOfShape->Append(aShape);
00113 }
00114 }
00115 }
00116
00117 setShape(aShape);
00118 Base::Sequencer().stop();
00119 }
00120 catch(...){
00121 Base::Sequencer().halt();
00122 Base::Console().Error("FeaturePartImportStep::Execute() failed!");
00123 return 1;
00124 }
00125
00126 return 0;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141