TopologyPy.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *
00004  *                                                                         *
00005  *   This file is part of the FreeCAD CAx development system.              *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU Library General Public License (LGPL)   *
00009  *   as published by the Free Software Foundation; either version 2 of     *
00010  *   the License, or (at your option) any later version.                   *
00011  *   for detail see the LICENCE text file.                                 *
00012  *                                                                         *
00013  *   FreeCAD is distributed in the hope that it will be useful,            *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU Library General Public License for more details.                  *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU Library General Public     *
00019  *   License along with FreeCAD; if not, write to the Free Software        *
00020  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00021  *   USA                                                                   *
00022  *                                                                         *
00023  *   Juergen Riegel 2002                                                   *
00024  ***************************************************************************/
00025 
00026 
00027 #include "PreCompiled.h"
00028 #if 0
00029 #ifndef _PreComp_
00030 # include <assert.h>
00031 # include <sstream>
00032 # include <BRepTools.hxx>
00033 # include <BRep_Builder.hxx>
00034 # include <BRepCheck_Analyzer.hxx>
00035 # include <BRepCheck_Result.hxx>
00036 # include <BRepCheck_ListIteratorOfListOfStatus.hxx>
00037 # include <IGESControl_Controller.hxx>
00038 # include <IGESControl_Writer.hxx>
00039 # include <IGESControl_Reader.hxx>
00040 # include <STEPControl_Writer.hxx>
00041 # include <STEPControl_Reader.hxx>
00042 # include <StlAPI_Writer.hxx>
00043 # include <Interface_Static.hxx>
00044 # include <TopoDS_Iterator.hxx>
00045 #endif
00046 
00047 #include <Base/Exception.h>
00048 #include <Base/FileInfo.h>
00049 #include <Base/Console.h>
00050 #include <Base/Sequencer.h>
00051 #include "TopologyPy.h"
00052 
00053 # include <BRepOffsetAPI_MakeOffsetShape.hxx>
00054 # include <BRepAlgoAPI_Cut.hxx>
00055 #include <BRepAlgoAPI_Section.hxx>
00056 # include <GeomAPI_IntSS.hxx>
00057 
00058 using Base::Console;
00059 
00060 using namespace Part;
00061 
00062 
00063 //===========================================================================
00064 // TopoShapePyOld - Warpper for the TopoDS classes
00065 //===========================================================================
00066 
00067 //--------------------------------------------------------------------------
00068 // Type structure
00069 //--------------------------------------------------------------------------
00070 
00071 PyTypeObject TopoShapePyOld::Type = {
00072         PyObject_HEAD_INIT(&PyType_Type)
00073         0,                                              /*ob_size*/
00074         "Part.Shape",                           /*tp_name*/
00075         sizeof(TopoShapePyOld), /*tp_basicsize*/
00076         0,                                              /*tp_itemsize*/
00077         /* methods */
00078         PyDestructor,                   /*tp_dealloc*/
00079         0,                                              /*tp_print*/
00080         __getattr,                              /*tp_getattr*/
00081         __setattr,                              /*tp_setattr*/
00082         0,                                              /*tp_compare*/
00083         __repr,                                 /*tp_repr*/
00084         0,                                              /*tp_as_number*/
00085         0,                                              /*tp_as_sequence*/
00086         0,                                              /*tp_as_mapping*/
00087         0,                                              /*tp_hash*/
00088         0,                                              /*tp_call */
00089   0,                                                /*tp_str  */
00090   0,                                                /*tp_getattro*/
00091   0,                                                /*tp_setattro*/
00092   /* --- Functions to access object as input/output buffer ---------*/
00093   0,                                                /* tp_as_buffer */
00094   /* --- Flags to define presence of optional/expanded features */
00095   Py_TPFLAGS_HAVE_CLASS,                            /*tp_flags */
00096   "About shape",                               /*tp_doc */
00097   0,                                                /*tp_traverse */
00098   0,                                                /*tp_clear */
00099   0,                                                /*tp_richcompare */
00100   0,                                                /*tp_weaklistoffset */
00101   0,                                                /*tp_iter */
00102   0,                                                /*tp_iternext */
00103   TopoShapePyOld::Methods,                             /*tp_methods */
00104   0,                                                /*tp_members */
00105   0,                                                /*tp_getset */
00106   &Base::PyObjectBase::Type,                        /*tp_base */
00107   0,                                                /*tp_dict */
00108   0,                                                /*tp_descr_get */
00109   0,                                                /*tp_descr_set */
00110   0,                                                /*tp_dictoffset */
00111   PyInit,                                           /*tp_init */
00112   0,                                                /*tp_alloc */
00113   PyMake,                                           /*tp_new */
00114   0,                                                /*tp_free   Low-level free-memory routine */
00115   0,                                                /*tp_is_gc  For PyObject_IS_GC */
00116   0,                                                /*tp_bases */
00117   0,                                                /*tp_mro    method resolution order */
00118   0,                                                /*tp_cache */
00119   0,                                                /*tp_subclasses */
00120   0                                                 /*tp_weaklist */
00121 };
00122 
00123 //--------------------------------------------------------------------------
00124 // Methods structure
00125 //--------------------------------------------------------------------------
00126 PyMethodDef TopoShapePyOld::Methods[] = {
00127   {"hasChild",         (PyCFunction) shasChild,         Py_NEWARGS},
00128   {"isNull",           (PyCFunction) sisNull,           Py_NEWARGS},
00129   {"isValid",          (PyCFunction) sisValid,          Py_NEWARGS},
00130   {"analyze",          (PyCFunction) sanalyze,          Py_NEWARGS},
00131   {"importIGES",       (PyCFunction) simportIGES,       Py_NEWARGS},
00132   {"exportIGES",       (PyCFunction) sexportIGES,       Py_NEWARGS},
00133   {"importSTEP",       (PyCFunction) simportSTEP,       Py_NEWARGS},
00134   {"exportSTEP",       (PyCFunction) sexportSTEP,       Py_NEWARGS},
00135   {"importBREP",       (PyCFunction) simportBREP,       Py_NEWARGS},
00136   {"exportBREP",       (PyCFunction) sexportBREP,       Py_NEWARGS},
00137   {"exportSTL",        (PyCFunction) sexportSTL,        Py_NEWARGS},
00138 
00139   {NULL, NULL}          /* Sentinel */
00140 };
00141 
00142 PyObject *TopoShapePyOld::PyMake(PyTypeObject  *ignored, PyObject *args, PyObject *kwds)  // Python wrapper
00143 {
00144   return new TopoShapePyOld();
00145 }
00146 
00147 int TopoShapePyOld::PyInit(PyObject* self, PyObject* args, PyObject*)
00148 {
00149   PyObject *pcObj=0;
00150   if (!PyArg_ParseTuple(args, "|O!", &(TopoShapePyOld::Type), &pcObj))     // convert args: Python->C 
00151     return -1;                             // NULL triggers exception 
00152 
00153   if ( pcObj )
00154   {
00155     TopoShapePyOld* pcShape = (TopoShapePyOld*)pcObj;
00156     ((TopoShapePyOld*)self)->_cTopoShape = pcShape->_cTopoShape;
00157   }
00158 
00159   return 0;
00160 }
00161 
00162 //--------------------------------------------------------------------------
00163 // Parents structure
00164 //--------------------------------------------------------------------------
00165 PyParentObject TopoShapePyOld::Parents[] = {&Base::PyObjectBase::Type,&TopoShapePyOld::Type, NULL};     
00166 
00167 //--------------------------------------------------------------------------
00168 // constructor
00169 //--------------------------------------------------------------------------
00170 TopoShapePyOld::TopoShapePyOld(PyTypeObject *T)
00171 : Base::PyObjectBase(0,T)
00172 {
00173   Base::Console().Log("Create TopoShape: %p \n",this);
00174 }
00175 
00176 TopoShapePyOld::TopoShapePyOld(const TopoDS_Shape &cShape, PyTypeObject *T) 
00177  : PyObjectBase( 0,T), _cTopoShape(cShape)
00178 {
00179         Console().Log("Create TopoShape %p\n",this);
00180 }
00181 
00182 //--------------------------------------------------------------------------
00183 //  TopoShapePyOld destructor 
00184 //--------------------------------------------------------------------------
00185 TopoShapePyOld::~TopoShapePyOld()                                               // Everything handled in parent
00186 {
00187         Console().Log("Destroy TopoShape %p\n",this);
00188 } 
00189 
00190 //--------------------------------------------------------------------------
00191 // TopoShapePyOld Attributes
00192 //--------------------------------------------------------------------------
00193 PyObject *TopoShapePyOld::_getattr(char *attr)                          // __getattr__ function: note only need to handle new state
00194 { 
00195         try{
00196                 // Access the number of attributes at this label
00197                 if (Base::streq(attr, "AttributeCount"))
00198                 {
00199                         return Py_BuildValue("i", 1); 
00200                 }else
00201                         _getattr_up(PyObjectBase);                                              // send to parent
00202         }catch(...){
00203                 Console().Log("Exception in TopoShapePyOld::_getattr()\n");
00204                 return 0;
00205         }
00206 } 
00207 
00208 int TopoShapePyOld::_setattr(char *attr, PyObject *value)       // __setattr__ function: note only need to handle new state
00209 { 
00210         if (Base::streq(attr, "Real"))                                          // settable new state
00211                 ; 
00212         else  
00213                 return PyObjectBase::_setattr(attr, value);     // send up to parent
00214         return 0;
00215 } 
00216 
00217 //--------------------------------------------------------------------------
00218 // PartFeaturePy representation
00219 //--------------------------------------------------------------------------
00220 PyObject *TopoShapePyOld::_repr(void)
00221 {
00222   std::stringstream a;
00223   a << "TopoShape: [ ";
00224   a << "]" << std::endl;
00225         return Py_BuildValue("s", a.str().c_str());
00226 }
00227 
00228 
00229 //--------------------------------------------------------------------------
00230 // Python wrappers
00231 //--------------------------------------------------------------------------
00232 
00233 PyObject *TopoShapePyOld::hasChild(PyObject *args)
00234 { 
00235   if (!PyArg_ParseTuple(args, "" ))   
00236     return NULL;                      
00237         Py_Return; 
00238 }
00239 
00240 PyObject *TopoShapePyOld::isNull(PyObject *args)
00241 { 
00242   if (!PyArg_ParseTuple(args, "" ))   
00243     return NULL;
00244 
00245   return Py_BuildValue("O", (_cTopoShape.IsNull() ? Py_True : Py_False));
00246 }
00247 
00248 PyObject *TopoShapePyOld::isValid(PyObject *args)
00249 { 
00250   if (!PyArg_ParseTuple(args, "" ))   
00251     return NULL;
00252   if ( !_cTopoShape.IsNull() )
00253   {
00254     BRepCheck_Analyzer aChecker(_cTopoShape);
00255     return Py_BuildValue("O", (aChecker.IsValid() ? Py_True : Py_False));
00256   }
00257 
00258   return Py_BuildValue("O", Py_False); 
00259 }
00260 
00261 PyObject *TopoShapePyOld::analyze(PyObject *args)
00262 { 
00263   if (!PyArg_ParseTuple(args, "" ))   
00264     return NULL;
00265   if ( !_cTopoShape.IsNull() )
00266   {
00267     BRepCheck_Analyzer aChecker(_cTopoShape);
00268     if (!aChecker.IsValid())
00269     {
00270       TopoDS_Iterator it(_cTopoShape);
00271       for (;it.More(); it.Next())
00272       {
00273         if (!aChecker.IsValid(it.Value()))
00274         {
00275           const Handle_BRepCheck_Result& result = aChecker.Result(it.Value());
00276           const BRepCheck_ListOfStatus& status = result->StatusOnShape(it.Value());
00277 
00278           BRepCheck_ListIteratorOfListOfStatus it(status);
00279           while ( it.More() )
00280           {
00281             BRepCheck_Status& val = it.Value();
00282             switch (val)
00283             {
00284             case BRepCheck_NoError:
00285               PyErr_SetString(PyExc_StandardError, "No error");
00286               break;
00287             case BRepCheck_InvalidPointOnCurve:
00288               PyErr_SetString(PyExc_StandardError, "Invalid point on curve");
00289               break;
00290             case BRepCheck_InvalidPointOnCurveOnSurface:
00291               PyErr_SetString(PyExc_StandardError, "Invalid point on curve on surface");
00292               break;
00293             case BRepCheck_InvalidPointOnSurface:
00294               PyErr_SetString(PyExc_StandardError, "Invalid point on surface");
00295               break;
00296             case BRepCheck_No3DCurve:
00297               PyErr_SetString(PyExc_StandardError, "No 3D curve");
00298               break;
00299             case BRepCheck_Multiple3DCurve:
00300               PyErr_SetString(PyExc_StandardError, "Multiple 3D curve");
00301               break;
00302             case BRepCheck_Invalid3DCurve:
00303               PyErr_SetString(PyExc_StandardError, "Invalid 3D curve");
00304               break;
00305             case BRepCheck_NoCurveOnSurface:
00306               PyErr_SetString(PyExc_StandardError, "No curve on surface");
00307               break;
00308             case BRepCheck_InvalidCurveOnSurface:
00309               PyErr_SetString(PyExc_StandardError, "Invalid curve on surface");
00310               break;
00311             case BRepCheck_InvalidCurveOnClosedSurface:
00312               PyErr_SetString(PyExc_StandardError, "Invalid curve on closed surface");
00313               break;
00314             case BRepCheck_InvalidSameRangeFlag:
00315               PyErr_SetString(PyExc_StandardError, "Invalid same-range flag");
00316               break;
00317             case BRepCheck_InvalidSameParameterFlag:
00318               PyErr_SetString(PyExc_StandardError, "Invalid same-parameter flag");
00319               break;
00320             case BRepCheck_InvalidDegeneratedFlag:
00321               PyErr_SetString(PyExc_StandardError, "Invalid degenerated flag");
00322               break;
00323             case BRepCheck_FreeEdge:
00324               PyErr_SetString(PyExc_StandardError, "Free edge");
00325               break;
00326             case BRepCheck_InvalidMultiConnexity:
00327               PyErr_SetString(PyExc_StandardError, "Invalid multi-connexity");
00328               break;
00329             case BRepCheck_InvalidRange:
00330               PyErr_SetString(PyExc_StandardError, "Invalid range");
00331               break;
00332             case BRepCheck_EmptyWire:
00333               PyErr_SetString(PyExc_StandardError, "Empty wire");
00334               break;
00335             case BRepCheck_RedundantEdge:
00336               PyErr_SetString(PyExc_StandardError, "Redundant edge");
00337               break;
00338             case BRepCheck_SelfIntersectingWire:
00339               PyErr_SetString(PyExc_StandardError, "Self-intersecting wire");
00340               break;
00341             case BRepCheck_NoSurface:
00342               PyErr_SetString(PyExc_StandardError, "No surface");
00343               break;
00344             case BRepCheck_InvalidWire:
00345               PyErr_SetString(PyExc_StandardError, "Invalid wires");
00346               break;
00347             case BRepCheck_RedundantWire:
00348               PyErr_SetString(PyExc_StandardError, "Redundant wires");
00349               break;
00350             case BRepCheck_IntersectingWires:
00351               PyErr_SetString(PyExc_StandardError, "Intersecting wires");
00352               break;
00353             case BRepCheck_InvalidImbricationOfWires:
00354               PyErr_SetString(PyExc_StandardError, "Invalid imbrication of wires");
00355               break;
00356             case BRepCheck_EmptyShell:
00357               PyErr_SetString(PyExc_StandardError, "Empty shell");
00358               break;
00359             case BRepCheck_RedundantFace:
00360               PyErr_SetString(PyExc_StandardError, "Redundant face");
00361               break;
00362             case BRepCheck_UnorientableShape:
00363               PyErr_SetString(PyExc_StandardError, "Unorientable shape");
00364               break;
00365             case BRepCheck_NotClosed:
00366               PyErr_SetString(PyExc_StandardError, "Not closed");
00367               break;
00368             case BRepCheck_NotConnected:
00369               PyErr_SetString(PyExc_StandardError, "Not connected");
00370               break;
00371             case BRepCheck_SubshapeNotInShape:
00372               PyErr_SetString(PyExc_StandardError, "Sub-shape not in shape");
00373               break;
00374             case BRepCheck_BadOrientation:
00375               PyErr_SetString(PyExc_StandardError, "Bad orientation");
00376               break;
00377             case BRepCheck_BadOrientationOfSubshape:
00378               PyErr_SetString(PyExc_StandardError, "Bad orientation of sub-shape");
00379               break;
00380             case BRepCheck_InvalidToleranceValue:
00381               PyErr_SetString(PyExc_StandardError, "Invalid tolerance value");
00382               break;
00383             case BRepCheck_CheckFail:
00384               PyErr_SetString(PyExc_StandardError, "Check failed");
00385               break;
00386             }
00387 
00388             if (PyErr_Occurred())
00389               PyErr_Print();
00390             it.Next();
00391           }
00392         }
00393       }
00394     }
00395   }
00396 
00397   Py_Return; 
00398 }
00399 
00400 #if 0 // need a define for version of OCC
00401 //#include <Message_ProgressIndicator.hxx>
00402 //#include <Message_ProgressScale.hxx>
00403 #include <MoniTool_ProgressIndicator.hxx>
00404 #include <MoniTool_ProgressScale.hxx>
00405 #include <Transfer_FinderProcess.hxx>
00406 #include <Handle_TCollection_HAsciiString.hxx>
00407 #include <TCollection_HAsciiString.hxx>
00408 #include <Transfer_TransientProcess.hxx>
00409 #include <IGESData_IGESEntity.hxx>
00410 #include <Handle_XSControl_TransferReader.hxx>
00411 #include <XSControl_TransferReader.hxx>
00412 #include <XSControl_WorkSession.hxx>
00413 #include <Interface_InterfaceModel.hxx>
00414 
00415 class ProgressIndicator : public MoniTool_ProgressIndicator
00416 //class ProgressIndicator : public Message_ProgressIndicator
00417 {
00418 public:
00419   ProgressIndicator() {}
00420   virtual ~ProgressIndicator() 
00421   {
00422     Base::Sequencer().stop();
00423   }
00424   
00425   virtual  void Reset()
00426   {
00427   }
00428   virtual  Standard_Boolean UserBreak()
00429   {
00430     return Base::Sequencer().wasCanceled();
00431   }
00432   virtual  Standard_Boolean Show(const Standard_Boolean force = Standard_True)
00433   {
00434     Standard_Real min, max, step; Standard_Boolean isInf;
00435     GetScale(min, max, step, isInf);
00436     Standard_Real val = GetValue();
00437     Standard_Integer scopes = GetNbScopes();
00438 
00439     const MoniTool_ProgressScale& scale = GetScope(scopes);
00440     Handle_TCollection_HAsciiString name = scale.GetName();
00441 
00442     if ( val < 2.0 )
00443       Base::Sequencer().start(name->ToCString(), (unsigned long)max);
00444     else
00445       Base::Sequencer().next();
00446 
00447     return false;
00448   }
00449 };
00450 #endif
00451 
00452 PyObject *TopoShapePyOld::importIGES(PyObject *args)
00453 {
00454   char* filename;
00455   if (!PyArg_ParseTuple(args, "s", &filename ))   
00456     return NULL;
00457 
00458   PY_TRY {
00459  
00460     // checking for the file
00461     Base::FileInfo File(filename);
00462     if(!File.isReadable()) {
00463       PyErr_SetString(PyExc_Exception,"File to read does not exist or is not readable");
00464       return NULL;
00465     }
00466 
00467     // read iges file
00468     IGESControl_Reader aReader;
00469 
00470     if (aReader.ReadFile((const Standard_CString)filename) != IFSelect_RetDone) {
00471       PyErr_SetString(PyExc_Exception,"Reading IGES failed");
00472       return NULL;
00473     }
00474 
00475 #if 0
00476     // get all root shapes 
00477     Handle(TColStd_HSequenceOfTransient) aList=aReader.GiveList("xst-transferrable-roots");
00478     for (Standard_Integer j=1; j<=aList->Length(); j++) {
00479       Handle(IGESData_IGESEntity) igesEntity=Handle(IGESData_IGESEntity)::DownCast(aList->Value(j));
00480       // get names 
00481       Handle_TCollection_HAsciiString name = igesEntity->NameValue();
00482       if ( !name.IsNull() ) {
00483         const char* cname = name->ToCString();
00484       }
00485       if (igesEntity->HasShortLabel()) {
00486         name = igesEntity->ShortLabel();
00487         if ( !name.IsNull() ) {
00488           const char* cname = name->ToCString();
00489         }
00490       }
00491       const char* type = igesEntity->DynamicType()->Name();
00492     }
00493  
00494     //Standard_Integer val = Interface_Static::IVal("read.iges.bspline.continuity");
00495     //Interface_Static::SetIVal("read.iges.bspline.continuity", 2);
00496     //Standard_Integer ic = Interface_Static::IVal("read.precision.mode");
00497     //Standard_Real rp = Interface_Static::RVal("read.precision.val");
00498     
00499     //Handle(TColStd_HSequenceOfTransient) aList; 
00500     //aList = aReader.GiveList ("iges-type(114)");
00501     //int ct = aList->Length();
00502     //Reader.TransferList(aList);
00503     //ct = aReader.NbShapes();
00504 #endif
00505 
00506     // one shape that contains all subshapes
00507     aReader.TransferRoots();
00508     //ct = aReader.NbShapes();
00509     
00510     _cTopoShape = aReader.OneShape();
00511   } PY_CATCH;
00512 
00513   Py_Return; 
00514 }
00515 
00516 PyObject *TopoShapePyOld::exportIGES(PyObject *args)
00517 {
00518   char* filename;
00519   if (!PyArg_ParseTuple(args, "s", &filename ))   
00520     return NULL;
00521 
00522   PY_TRY {
00523 
00524 #if 0
00525     // An OCC example
00526     IGESControl_Controller::Init();
00527           IGESControl_Writer writer( Interface_Static::CVal( "XSTEP.iges.unit" ),
00528                                Interface_Static::IVal( "XSTEP.iges.writebrep.mode" ) );
00529                 writer.AddShape ( _cTopoShape );
00530           writer.ComputeModel();
00531           writer.Write( (const Standard_CString)filename );
00532 #endif
00533 
00534     // write iges file
00535     IGESControl_Controller::Init();
00536     IGESControl_Writer aWriter;
00537 
00538 #if 0
00539     Handle(Transfer_FinderProcess) proc = aWriter.TransferProcess();
00540     Handle(MoniTool_ProgressIndicator) prog = new ProgressIndicator();
00541     proc->SetProgress(prog);
00542 
00543     Standard_CString byvalue = Interface_Static::CVal("write.iges.header.author");
00544     Interface_Static::SetCVal ("write.iges.header.author", "FreeCAD");
00545     //Interface_Static::SetCVal ("write.iges.header.company", "FreeCAD");
00546 #endif
00547 
00548     aWriter.AddShape(_cTopoShape);
00549 #if 0
00550     aWriter.ComputeModel();
00551 #endif
00552 
00553     if (aWriter.Write((const Standard_CString)filename) != IFSelect_RetDone) {
00554       PyErr_SetString(PyExc_Exception,"Writing IGES failed");
00555       return NULL;
00556     }
00557 
00558   } PY_CATCH;
00559 
00560   Py_Return; 
00561 }
00562 
00563 PyObject *TopoShapePyOld::importSTEP(PyObject *args)
00564 {
00565   char* filename;
00566   if (!PyArg_ParseTuple(args, "s", &filename ))   
00567     return NULL;
00568 
00569   PY_TRY {
00570     // checking for the file
00571     Base::FileInfo File(filename);
00572     if(!File.isReadable()) {
00573       PyErr_SetString(PyExc_Exception,"File to read does not exist or is not readable");
00574       return NULL;
00575     }
00576 
00577     // read step file
00578     STEPControl_Reader aReader;
00579     if (aReader.ReadFile((const Standard_CString)filename) != IFSelect_RetDone) {
00580       PyErr_SetString(PyExc_Exception,"Reading STEP failed");
00581       return NULL;
00582     }
00583 
00584 #if 0 // Some interesting stuff
00585     Handle(TColStd_HSequenceOfTransient) aList=aReader.GiveList("xst-transferrable-roots");
00586     for (Standard_Integer j=1; j<=aList->Length(); j++) {
00587       Handle(IGESData_IGESEntity) igesEntity=Handle(IGESData_IGESEntity)::DownCast(aList->Value(j));
00588       // get names 
00589       Handle_TCollection_HAsciiString name = igesEntity->NameValue();
00590       if ( !name.IsNull() ) {
00591         const char* cname = name->ToCString();
00592       }
00593       if (igesEntity->HasShortLabel()) {
00594         name = igesEntity->ShortLabel();
00595         if ( !name.IsNull() ) {
00596           const char* cname = name->ToCString();
00597         }
00598       }
00599       const char* type = igesEntity->DynamicType()->Name();
00600     }
00601 #endif
00602 
00603     aReader.TransferRoots();
00604     _cTopoShape = aReader.OneShape();
00605 
00606 #if 0 // Some interesting stuff
00607           Handle_XSControl_WorkSession ws = aReader.WS();
00608           //SetModel( reader.StepModel() );
00609           Handle_XSControl_TransferReader tr = ws->TransferReader();
00610           Handle_Standard_Transient ent = tr->EntityFromShapeResult(_cTopoShape, 3);
00611           if ( ! ent.IsNull() ) {
00612                   //printf( "Name of STEP-Model: %s\n", ws->Model()->StringLabel(ent)->String() );
00613           }
00614           TopTools_IndexedMapOfShape smap;
00615           TopExp::MapShapes( _cTopoShape, smap);
00616           for ( Standard_Integer k = 1; k <= smap.Extent(); k++ ) {
00617                   const TopoDS_Shape& tsh = smap(k);
00618                   Handle_Standard_Transient ent = tr->EntityFromShapeResult(tsh, 3);
00619                   if ( ! ent.IsNull() ) {
00620                           //printf( "Part %s ", ws->Model()->StringLabel(ent)->String() );
00621                           //printf( "is a %s\n", ws->Model()->TypeName(ent) );
00622         //MoniTool_DataMapOfShapeTransient map;
00623                           //map.Bind(tsh, ws->Model()->StringLabel(ent)->ShallowCopy() );
00624                   }
00625           }
00626 #endif
00627 
00628   } PY_CATCH;
00629 
00630   Py_Return; 
00631 }
00632 
00633 PyObject *TopoShapePyOld::exportSTEP(PyObject *args)
00634 {
00635   char* filename;
00636   if (!PyArg_ParseTuple(args, "s", &filename))
00637     return NULL;
00638 
00639   PY_TRY {
00640 
00641     // write step file
00642     STEPControl_Writer aWriter;
00643 
00644     //FIXME: Does not work this way!!!
00645     if (aWriter.Transfer(_cTopoShape, STEPControl_AsIs)) {
00646       PyErr_SetString(PyExc_Exception,"Transferring STEP failed");
00647       return NULL;
00648     }
00649 
00650     if (aWriter.Write((const Standard_CString)filename) != IFSelect_RetDone) {
00651       PyErr_SetString(PyExc_Exception,"Writing STEP failed");
00652       return NULL;
00653     }
00654         
00655   } PY_CATCH;
00656 
00657   Py_Return; 
00658 }
00659 
00660 PyObject *TopoShapePyOld::importBREP(PyObject *args)
00661 {
00662   char* filename;
00663   if (!PyArg_ParseTuple(args, "s", &filename ))   
00664     return NULL;
00665 
00666   PY_TRY {
00667     // checking for the file
00668     Base::FileInfo File(filename);
00669     if(!File.isReadable()) {
00670       PyErr_SetString(PyExc_Exception,"File to read does not exist or is not readable");
00671       return NULL;
00672     }
00673     
00674     // read brep file
00675     BRep_Builder aBuilder;
00676     if (!BRepTools::Read(_cTopoShape,(const Standard_CString)filename,aBuilder)) {
00677       PyErr_SetString(PyExc_Exception,"Reading BREP failed");
00678       return NULL;
00679     }
00680   } PY_CATCH;
00681 
00682   Py_Return; 
00683 }
00684 
00685 PyObject *TopoShapePyOld::exportBREP(PyObject *args)
00686 {
00687   char* filename;
00688   if (!PyArg_ParseTuple(args, "s", &filename ))
00689     return NULL;
00690 
00691   PY_TRY {
00692     // read brep file
00693     if (!BRepTools::Write(_cTopoShape,(const Standard_CString)filename)) {
00694       PyErr_SetString(PyExc_Exception,"Writing BREP failed");
00695       return NULL;
00696     }
00697   } PY_CATCH;
00698 
00699   Py_Return; 
00700 }
00701 
00702 PyObject *TopoShapePyOld::exportSTL(PyObject *args)
00703 {
00704   char* filename;
00705   if (!PyArg_ParseTuple(args, "s", &filename ))
00706     return NULL;
00707 
00708   PY_TRY {
00709     // write STL file
00710         StlAPI_Writer writer;
00711           writer.Write( _cTopoShape, (const Standard_CString)filename );
00712   } PY_CATCH;
00713 
00714   Py_Return; 
00715 }
00716 
00717 #endif

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