static void StlAPI_WriteBinary(const void* filepath) { if (!BmkBRep::inputShape.IsNull()) { StlAPI_Writer writer; writer.ASCIIMode() = Standard_False; const char* cfilepath = static_cast<const char*>(filepath); #if OCC_VERSION_HEX >= 0x060900 const StlAPI_ErrorStatus err = writer.Write(BmkBRep::inputShape, cfilepath); if (err != StlAPI_StatusOK) std::cerr << "StlAPI_Writer::Write() error: " << err << std::endl; #else writer.Write(BmkBRep::inputShape, cfilepath); #endif } }
int OCCTools::writeSTL(const char *filename, std::vector<OCCBase *> shapes) { try { BRep_Builder B; TopoDS_Compound shape; B.MakeCompound(shape); for (unsigned i = 0; i < shapes.size(); i++) { B.Add(shape, shapes[i]->getShape()); } StlAPI_Writer writer; writer.Write(shape, filename); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); //printf("ERROR: %s\n", e->GetMessageString()); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to write STL file"); } return 0; } return 1; }
Standard_Boolean GeomImportExport::SaveSTL(const QString& aFileName, const TopoDS_Shape& aHSequenceOfShape) { Standard_Boolean ReturnValue = Standard_True; StlAPI_Writer myStlWriter; myStlWriter.Write(aHSequenceOfShape, aFileName.toAscii().data()); return ReturnValue; }
int main(void) { TopoDS_Shape topoDSShape; IGESControl_Reader igesReader; IFSelect_ReturnStatus returnStatus = igesReader.ReadFile("./TestFiles/circuit-board-pcb-mock-example.snapshot.4/Buoy_Circuitbuoy.igs"); switch(returnStatus){ case IFSelect_RetDone: std::cout << "File read successful" << std::endl; break; default: std::cout << "File read not succesful!" << std::endl; exit(-1); } Standard_Boolean failsonly = Standard_False; IFSelect_PrintCount mode; igesReader.PrintCheckLoad(failsonly,mode); std::cout << "Mode: " << mode << std::endl; Standard_Integer ic = Interface_Static::IVal("read.iges.bspline.continuity"); std::cout << "ic: " << ic << std::endl; //All Entities: Handle_TColStd_HSequenceOfTransient list = igesReader.GiveList(); //All faces: //Handle_TColStd_HSequenceOfTransient list = igesReader.GiveList("iges-faces"); //Translate all entitites in one operation // for (Standard_Integer i = 1; i <= 425; i ++) { // Handle(Standard_Transient) ent = list.; // Standard_Boolean OK = reader.TransferEntity (ent); // } Standard_Integer nbtrans = igesReader.TransferList(list); std::cout << "Number of translations: " << nbtrans << std::endl; Standard_Integer nbs = igesReader.NbShapes(); std::cout << "Number of shapes: " << nbs << std::endl; TopoDS_Shape shape; // for(Standard_Integer i = 1; i <= nbs; i++){ // std::cout << "i: " << i << " ... "; // shape = igesReader.Shape(i); // std::cout << "successful!" << std::endl; // } TopoDS_Shape shape2 = igesReader.OneShape(); StlAPI_Writer stlWriter; stlWriter.Write(shape2, "./circuitBuoy.stl"); return EXIT_SUCCESS; }
int step2stl(char *in, char *out) { // Read from STEP STEPControl_Reader reader; IFSelect_ReturnStatus stat = reader.ReadFile(in); Standard_Integer NbRoots = reader.NbRootsForTransfer(); Standard_Integer NbTrans = reader.TransferRoots(); TopoDS_Shape Original_Solid = reader.OneShape(); // Write to STL StlAPI_Writer stlWriter = StlAPI_Writer(); // stlWriter.SetCoefficient(0.0001); stlWriter.ASCIIMode() = Standard_False; stlWriter.Write( Original_Solid, out); return 1; }
STLEXPORT_EXPORT int Export(const TopoDS_Shape& theShape, const TCollection_AsciiString& theFileName, const TCollection_AsciiString& theFormatName) { MESSAGE("Export STL into file " << theFileName.ToCString()); try { StlAPI_Writer aWriter; bool aIsASCIIMode; aIsASCIIMode = (theFormatName.IsEqual("STL_ASCII")) ? true : false; aWriter.ASCIIMode() = aIsASCIIMode; aWriter.Write(theShape, theFileName.ToCString()) ; return 1; } catch(Standard_Failure) { //THROW_SALOME_CORBA_EXCEPTION("Exception catched in STLExport", SALOME::BAD_PARAM); } return 0; }
/*! \brief Write a topologic shape to a file (binary STL format) * \param shape Topologic shape to write * \param fileName Path to the file to write */ void IO::writeBinaryStlFile(const TopoDS_Shape& shape, const QString& fileName) { StlAPI_Writer writer; writer.ASCIIMode() = Standard_False; writer.Write(shape, fileName.toAscii().data()); }