bool saveInIGES(TopoDS_Shape &shape, char const *filename) { if(!IGESControl_Controller::Init()) { return false; }; IGESControl_Writer writer; writer.AddShape(shape); return writer.Write(filename); }
void Werkstuck::IGESExportieren() { IGESControl_Controller::Init(); IGESControl_Writer *schreiber = new IGESControl_Writer( Interface_Static::CVal( "XSTEP.iges.unit" ), Interface_Static::IVal( "XSTEP.iges.writebrep.mode" ) ); //Interface_Static::SetIVal("write.iges.brep.mode",1); bool res1 = schreiber->AddShape(WS); QString str = QFileDialog::getSaveFileName(); if (str.isEmpty()) return; schreiber->ComputeModel(); bool res2 = schreiber->Write(str.toStdString().c_str()); if (res1&&res2) showMessage(tr("Экспорт в IGES успешно!")); delete schreiber; }
Standard_Boolean GeomImportExport::SaveIGES(const QString& aFileName, const TopoDS_Shape& aShape) { IGESControl_Controller::Init(); IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"), Interface_Static::IVal("XSTEP.iges.writebrep.mode")); ICW.AddShape (aShape); ICW.ComputeModel(); Standard_Boolean result = ICW.Write(aFileName.toAscii().data() ); return result; }
/** * @briefAdds a shape to the IGES file. All faces are named according to their face * traits. If there are no faces, the wires are named according to the shape name. * * The level parameter defines the iges layer/level, which is another way of grouping faces. */ void CTiglExportIges::AddToIges(PNamedShape shape, IGESControl_Writer& writer, int level) const { if (!shape) { return; } std::string shapeName = shape->Name(); std::string shapeShortName = shape->ShortName(); Handle(Transfer_FinderProcess) FP = writer.TransferProcess(); TopTools_IndexedMapOfShape faceMap; TopExp::MapShapes(shape->Shape(), TopAbs_FACE, faceMap); // any faces? if (faceMap.Extent() > 0) { int ret = writer.AddShape(shape->Shape()); if (ret > IFSelect_RetDone) { throw CTiglError("Error: Export to IGES file failed in CTiglExportStep. Could not translate shape " + shapeName + " to iges entity,", TIGL_ERROR); } WriteIgesNames(FP, shape, level); } else { // no faces, export edges as wires Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape(); TopExp_Explorer myEdgeExplorer (shape->Shape(), TopAbs_EDGE); while (myEdgeExplorer.More()) { Edges->Append(TopoDS::Edge(myEdgeExplorer.Current())); myEdgeExplorer.Next(); } ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges, 1e-7, false, Edges); for (int iwire = 1; iwire <= Edges->Length(); ++iwire) { int ret = writer.AddShape(Edges->Value(iwire)); if (ret > IFSelect_RetDone) { throw CTiglError("Error: Export to IGES file failed in CTiglExportIges. Could not translate shape " + shapeName + " to iges entity,", TIGL_ERROR); } PNamedShape theWire(new CNamedShape(Edges->Value(iwire),shapeName.c_str())); theWire->SetShortName(shapeShortName.c_str()); WriteIGESShapeNames(FP, theWire, level); WriteIgesWireName(FP, theWire); } } }
bool CShape::ExportSolidsFile(const std::list<HeeksObj*>& objects, const wxChar* filepath, std::map<int, CShapeData> *index_map) { // returns true, if suffix handled wxString wf(filepath); wf.LowerCase(); if(wf.EndsWith(_T(".stp")) || wf.EndsWith(_T(".step"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); STEPControl_Writer writer; // add all the solids int i = 1; for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++) { HeeksObj* object = *It; WriteShapeOrGroup(writer, object, index_map, i); } writer.Write(aFileName); setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".igs")) || wf.EndsWith(_T(".iges"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); IGESControl_Controller::Init(); IGESControl_Writer writer; // add all the solids for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++) { HeeksObj* object = *It; if(CShape::IsTypeAShape(object->GetType())){ writer.AddShape(((CShape*)object)->Shape()); } else if(object->GetType() == WireType){ writer.AddShape(((CWire*)object)->Shape()); } } writer.Write(aFileName); setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".brep"))) { #ifdef __WXMSW__ ofstream ofs(filepath); #else ofstream ofs(Ttc(filepath)); #endif for(std::list<HeeksObj*>::const_iterator It = objects.begin(); It != objects.end(); It++) { HeeksObj* object = *It; if(CShape::IsTypeAShape(object->GetType())){ BRepTools::Write(((CShape*)object)->Shape(), ofs); } } } return false; }
int EG_saveModel(const egObject *model, const char *name) { int i, len, outLevel; egadsModel *mshape; FILE *fp; if (model == NULL) return EGADS_NULLOBJ; if (model->magicnumber != MAGIC) return EGADS_NOTOBJ; if (model->oclass != MODEL) return EGADS_NOTMODEL; outLevel = EG_outLevel(model); if (name == NULL) { if (outLevel > 0) printf(" EGADS Warning: NULL Filename (EG_saveModel)!\n"); return EGADS_NONAME; } /* does file exist? */ fp = fopen(name, "r"); if (fp != NULL) { if (outLevel > 0) printf(" EGADS Warning: File %s Exists (EG_saveModel)!\n", name); fclose(fp); return EGADS_NOTFOUND; } /* find extension */ len = strlen(name); for (i = len-1; i > 0; i--) if (name[i] == '.') break; if (i == 0) { if (outLevel > 0) printf(" EGADS Warning: No Extension in %s (EG_saveModel)!\n", name); return EGADS_NODATA; } mshape = (egadsModel *) model->blind; if ((strcasecmp(&name[i],".step") == 0) || (strcasecmp(&name[i],".stp") == 0)) { /* STEP files */ STEPControl_Writer aWriter; TopExp_Explorer Exp; const STEPControl_StepModelType aVal = STEPControl_AsIs; for (Exp.Init(mshape->shape, TopAbs_WIRE, TopAbs_FACE); Exp.More(); Exp.Next()) aWriter.Transfer(Exp.Current(), aVal); for (Exp.Init(mshape->shape, TopAbs_FACE, TopAbs_SHELL); Exp.More(); Exp.Next()) aWriter.Transfer(Exp.Current(), aVal); for (Exp.Init(mshape->shape, TopAbs_SHELL, TopAbs_SOLID); Exp.More(); Exp.Next()) aWriter.Transfer(Exp.Current(), aVal); for (Exp.Init(mshape->shape, TopAbs_SOLID); Exp.More(); Exp.Next()) aWriter.Transfer(Exp.Current(), aVal); if (!aWriter.Write(name)) { printf(" EGADS Warning: STEP Write Error (EG_saveModel)!\n"); return EGADS_WRITERR; } } else if ((strcasecmp(&name[i],".iges") == 0) || (strcasecmp(&name[i],".igs") == 0)) { /* IGES files */ try { IGESControl_Controller::Init(); IGESControl_Writer iWrite; TopExp_Explorer Exp; for (Exp.Init(mshape->shape, TopAbs_WIRE, TopAbs_FACE); Exp.More(); Exp.Next()) iWrite.AddShape(Exp.Current()); for (Exp.Init(mshape->shape, TopAbs_FACE, TopAbs_SHELL); Exp.More(); Exp.Next()) iWrite.AddShape(Exp.Current()); for (Exp.Init(mshape->shape, TopAbs_SHELL, TopAbs_SOLID); Exp.More(); Exp.Next()) iWrite.AddShape(Exp.Current()); for (Exp.Init(mshape->shape, TopAbs_SOLID); Exp.More(); Exp.Next()) iWrite.AddShape(Exp.Current()); iWrite.ComputeModel(); if (!iWrite.Write(name)) { printf(" EGADS Warning: IGES Write Error (EG_saveModel)!\n"); return EGADS_WRITERR; } } catch (...) { printf(" EGADS Warning: Internal IGES Write Error (EG_saveModel)!\n"); return EGADS_WRITERR; } } else if ((strcasecmp(&name[i],".brep") == 0) || (strcasecmp(&name[i],".egads") == 0)) { /* Native OCC file or our filetype */ if (!BRepTools::Write(mshape->shape, name)) { printf(" EGADS Warning: OCC Write Error (EG_saveModel)!\n"); return EGADS_WRITERR; } if (strcasecmp(&name[i],".brep") == 0) return EGADS_SUCCESS; /* append the attributes -- output in the read order */ FILE *fp = fopen(name, "a"); if (fp == NULL) { printf(" EGADS Warning: EGADS Open Error (EG_saveModel)!\n"); return EGADS_WRITERR; } fprintf(fp, "\n##EGADS HEADER FILE-REV 1 ##\n"); /* write model attributes */ EG_writeAttrs(model, fp); TopExp_Explorer Exp; for (Exp.Init(mshape->shape, TopAbs_WIRE, TopAbs_FACE); Exp.More(); Exp.Next()) { TopoDS_Shape shape = Exp.Current(); for (i = 0; i < mshape->nbody; i++) { egObject *obj = mshape->bodies[i]; egadsBody *pbody = (egadsBody *) obj->blind; if (shape.IsSame(pbody->shape)) { EG_writeAttrs(obj, fp); break; } } } for (Exp.Init(mshape->shape, TopAbs_FACE, TopAbs_SHELL); Exp.More(); Exp.Next()) { TopoDS_Shape shape = Exp.Current(); for (i = 0; i < mshape->nbody; i++) { egObject *obj = mshape->bodies[i]; egadsBody *pbody = (egadsBody *) obj->blind; if (shape.IsSame(pbody->shape)) { EG_writeAttrs(obj, fp); break; } } } for (Exp.Init(mshape->shape, TopAbs_SHELL, TopAbs_SOLID); Exp.More(); Exp.Next()) { TopoDS_Shape shape = Exp.Current(); for (i = 0; i < mshape->nbody; i++) { egObject *obj = mshape->bodies[i]; egadsBody *pbody = (egadsBody *) obj->blind; if (shape.IsSame(pbody->shape)) { EG_writeAttrs(obj, fp); break; } } } for (Exp.Init(mshape->shape, TopAbs_SOLID); Exp.More(); Exp.Next()) { TopoDS_Shape shape = Exp.Current(); for (i = 0; i < mshape->nbody; i++) { egObject *obj = mshape->bodies[i]; egadsBody *pbody = (egadsBody *) obj->blind; if (shape.IsSame(pbody->shape)) { EG_writeAttrs(obj, fp); break; } } } fclose(fp); } else { if (outLevel > 0) printf(" EGADS Warning: Extension in %s Not Supported (EG_saveModel)!\n", name); return EGADS_NODATA; } return EGADS_SUCCESS; }