FeatureImportStep.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 bool FeaturePartImportStep::MustExecute(void)
00049 {
00050         Base::Console().Log("PartBoxFeature::MustExecute()\n");
00051         return false;
00052 }
00053 */
00054 Standard_Integer FeatureImportStep::Execute(void)
00055 {
00056         Base::Console().Log("FeaturePartImportStep::Execute()\n");
00057 
00058 /*  cout << GetFloatProperty("x") << endl;
00059   cout << GetFloatProperty("y") << endl;
00060   cout << GetFloatProperty("z") << endl;
00061   cout << GetFloatProperty("l") << endl;
00062   cout << GetFloatProperty("h") << endl;
00063   cout << GetFloatProperty("w") << endl;*/
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     // just do show the wait cursor when the Gui is up
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     // Root transfers
00096     Standard_Integer nbr = aReader.NbRootsForTransfer();
00097     //aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
00098     for ( Standard_Integer n = 1; n<= nbr; n++)
00099     {
00100       printf("STEP: Transfering Root %d\n",n);
00101       aReader.TransferRoot(n);
00102       // Collecting resulting entities
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 void FeatureImportStep::Validate(void)
00131 {
00132         Base::Console().Log("FeaturePartImportStep::Validate()\n");
00133  
00134   // We validate the object label ( Label() ), all the arguments and the results of the object:
00135   log.SetValid(Label(), Standard_True);
00136 
00137 
00138 }
00139 */
00140 
00141 

Generated on Wed Nov 23 19:00:11 2011 for FreeCAD by  doxygen 1.6.1