+ code clean-up
This commit is contained in:
parent
f47cc169ae
commit
5033983c64
|
@ -304,106 +304,3 @@ PyObject* initModule()
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Import
|
} // namespace Import
|
||||||
|
|
||||||
/* module functions */
|
|
||||||
|
|
||||||
static PyObject * exporter(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject* object;
|
|
||||||
char* Name;
|
|
||||||
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
|
|
||||||
return NULL;
|
|
||||||
std::string Utf8Name = std::string(Name);
|
|
||||||
PyMem_Free(Name);
|
|
||||||
std::string name8bit = Part::encodeFilename(Utf8Name);
|
|
||||||
|
|
||||||
PY_TRY {
|
|
||||||
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
|
|
||||||
Handle(TDocStd_Document) hDoc;
|
|
||||||
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
|
|
||||||
Import::ExportOCAF ocaf(hDoc);
|
|
||||||
|
|
||||||
Py::Sequence list(object);
|
|
||||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
|
||||||
PyObject* item = (*it).ptr();
|
|
||||||
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
|
|
||||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
|
|
||||||
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
|
||||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
|
||||||
std::vector<App::Color> colors;
|
|
||||||
ocaf.saveShape(part, colors);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (PyTuple_Check(item) && PyTuple_Size(item) == 2) {
|
|
||||||
Py::Tuple tuple(*it);
|
|
||||||
Py::Object item0 = tuple.getItem(0);
|
|
||||||
Py::Object item1 = tuple.getItem(1);
|
|
||||||
if (PyObject_TypeCheck(item0.ptr(), &(App::DocumentObjectPy::Type))) {
|
|
||||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item0.ptr())->getDocumentObjectPtr();
|
|
||||||
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
|
|
||||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
|
||||||
App::PropertyColorList colors;
|
|
||||||
colors.setPyObject(item1.ptr());
|
|
||||||
ocaf.saveShape(part, colors.getValues());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Base::FileInfo file(Utf8Name.c_str());
|
|
||||||
if (file.hasExtension("stp") || file.hasExtension("step")) {
|
|
||||||
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
|
|
||||||
STEPCAFControl_Writer writer;
|
|
||||||
writer.Transfer(hDoc, STEPControl_AsIs);
|
|
||||||
|
|
||||||
// edit STEP header
|
|
||||||
#if OCC_VERSION_HEX >= 0x060500
|
|
||||||
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
|
|
||||||
#else
|
|
||||||
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
|
|
||||||
#endif
|
|
||||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
|
||||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("STEP");
|
|
||||||
|
|
||||||
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)Utf8Name.c_str()));
|
|
||||||
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
|
|
||||||
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
|
|
||||||
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::GetApplication().getExecutableName()));
|
|
||||||
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
|
|
||||||
IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str());
|
|
||||||
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
|
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
|
|
||||||
IGESControl_Controller::Init();
|
|
||||||
IGESCAFControl_Writer writer;
|
|
||||||
IGESData_GlobalSection header = writer.Model()->GlobalSection();
|
|
||||||
header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author")));
|
|
||||||
header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company")));
|
|
||||||
header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product")));
|
|
||||||
writer.Model()->SetGlobalSection(header);
|
|
||||||
writer.Transfer(hDoc);
|
|
||||||
Standard_Boolean ret = writer.Write(name8bit.c_str());
|
|
||||||
if (!ret) {
|
|
||||||
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Standard_Failure) {
|
|
||||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
|
||||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
PY_CATCH
|
|
||||||
|
|
||||||
Py_Return;
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,10 +34,6 @@ namespace MeshPart {
|
||||||
extern PyObject* initModule();
|
extern PyObject* initModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(module_MeshPart_doc,
|
|
||||||
"This module is the MeshPart module.");
|
|
||||||
|
|
||||||
|
|
||||||
/* Python entry */
|
/* Python entry */
|
||||||
PyMODINIT_FUNC initMeshPart()
|
PyMODINIT_FUNC initMeshPart()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user