Merge remote-tracking branch 'origin/master' into remove_redundant_definition

This commit is contained in:
liukaiwen
2023-10-02 01:42:37 +08:00
898 changed files with 77546 additions and 60716 deletions

View File

@@ -30,17 +30,8 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wextra-semi"
#endif
#include <APIHeaderSection_MakeHeader.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <IGESCAFControl_Writer.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESData_GlobalSection.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESToBRep_Actor.hxx>
#include <Interface_Static.hxx>
#include <OSD_Exception.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <STEPCAFControl_Writer.hxx>
#include <Standard_Version.hxx>
#include <TColStd_IndexedDataMapOfStringString.hxx>
#include <TDocStd_Document.hxx>
@@ -74,7 +65,11 @@
#include "ImportOCAF2.h"
#include "ReaderGltf.h"
#include "ReaderIges.h"
#include "ReaderStep.h"
#include "WriterGltf.h"
#include "WriterIges.h"
#include "WriterStep.h"
namespace Import
{
@@ -177,25 +172,8 @@ private:
if (file.hasExtension({"stp", "step"})) {
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str()))
!= IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
Import::ReaderStep reader(file);
reader.read(hDoc);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
@@ -206,40 +184,9 @@ private:
}
}
else if (file.hasExtension({"igs", "iges"})) {
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("IGES");
try {
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(
hGrp->GetBool("SkipBlankEntities", true) ? Standard_True : Standard_False);
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str()))
!= IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read IGES file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
// http://opencascade.blogspot.de/2009/03/unnoticeable-memory-leaks-part-2.html
Handle(IGESToBRep_Actor)::DownCast(aReader.WS()->TransferReader()->Actor())
->SetModel(new IGESData_IGESModel);
Import::ReaderIges reader(file);
reader.read(hDoc);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
@@ -332,7 +279,6 @@ private:
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
Py::Sequence list(object);
@@ -389,56 +335,15 @@ private:
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension({"stp", "step"})) {
STEPCAFControl_Writer writer;
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
writer.Transfer(hDoc, STEPControl_AsIs);
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("STEP");
// Don't set name because STEP doesn't support UTF-8
// https://forum.freecad.org/viewtopic.php?f=8&t=52967
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::Application::getExecutableName().c_str()));
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());
throw Py::Exception();
}
Import::WriterStep writer(file);
writer.write(hDoc);
}
else if (file.hasExtension({"igs", "iges"})) {
IGESControl_Controller::Init();
IGESCAFControl_Writer writer;
IGESData_GlobalSection header = writer.Model()->GlobalSection();
header.SetAuthorName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor()));
header.SetCompanyName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany()));
header.SetSendName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct()));
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());
throw Py::Exception();
}
Import::WriterIges writer(file);
writer.write(hDoc);
}
else if (file.hasExtension({"glb", "gltf"})) {
Import::WriterGltf writer(name8bit, file);
Import::WriterGltf writer(file);
writer.write(hDoc);
}

View File

@@ -30,6 +30,10 @@ SET(Import_SRCS
#ImportOCAFAssembly.h
ReaderGltf.cpp
ReaderGltf.h
ReaderIges.cpp
ReaderIges.h
ReaderStep.cpp
ReaderStep.h
StepShapePy.xml
StepShape.h
StepShape.cpp
@@ -38,6 +42,10 @@ SET(Import_SRCS
PreCompiled.h
WriterGltf.cpp
WriterGltf.h
WriterIges.cpp
WriterIges.h
WriterStep.cpp
WriterStep.h
dxf/ImpExpDxf.cpp
dxf/ImpExpDxf.h
dxf/dxf.cpp

View File

@@ -24,7 +24,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <sstream>
#include <Standard_Version.hxx>
#include <TDF_Label.hxx>
#include <TDF_TagSource.hxx>
@@ -60,9 +59,7 @@ void ReaderGltf::read(Handle(TDocStd_Document) hDoc) // NOLINT
TCollection_AsciiString filename(file.filePath().c_str());
Standard_Boolean ret = aReader.Perform(filename, Message_ProgressRange());
if (!ret) {
std::stringstream str;
str << "Cannot read from file '"
<< "" << file.filePath() << "'";
throw Base::FileException("Cannot read from file: ", file);
}
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(hDoc->Main());
@@ -77,6 +74,7 @@ void ReaderGltf::read(Handle(TDocStd_Document) hDoc) // NOLINT
}
#else
(void)hDoc;
throw Base::RuntimeError("gITF support requires OCCT 7.5.0 or later");
#endif
}

View File

@@ -0,0 +1,85 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <IGESControl_Controller.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <IGESData_GlobalSection.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESToBRep_Actor.hxx>
#include <Standard_Version.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
#endif
#include "ReaderIges.h"
#include <Base/Exception.h>
#include <App/Application.h>
#include <Mod/Part/App/encodeFilename.h>
#include <Mod/Part/App/ProgressIndicator.h>
using namespace Import;
ReaderIges::ReaderIges(const Base::FileInfo& file) // NOLINT
: file {file}
{}
void ReaderIges::read(Handle(TDocStd_Document) hDoc) // NOLINT
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("IGES");
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(hGrp->GetBool("SkipBlankEntities", true));
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
throw Base::FileException("Cannot read IGES file", file);
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
// http://opencascade.blogspot.de/2009/03/unnoticeable-memory-leaks-part-2.html
Handle(IGESToBRep_Actor)::DownCast(aReader.WS()->TransferReader()->Actor())
->SetModel(new IGESData_IGESModel);
}

View File

@@ -0,0 +1,47 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef IMPORT_READER_IGES_H
#define IMPORT_READER_IGES_H
#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <TDocStd_Document.hxx>
namespace Import
{
class ImportExport ReaderIges
{
public:
explicit ReaderIges(const Base::FileInfo& file);
void read(Handle(TDocStd_Document) hDoc);
private:
Base::FileInfo file;
};
} // namespace Import
#endif // IMPORT_READER_IGES_H

View File

@@ -0,0 +1,68 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <Standard_Version.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <Transfer_TransientProcess.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
#endif
#include "ReaderStep.h"
#include <Base/Exception.h>
#include <Mod/Part/App/encodeFilename.h>
#include <Mod/Part/App/ProgressIndicator.h>
using namespace Import;
ReaderStep::ReaderStep(const Base::FileInfo& file) // NOLINT
: file {file}
{}
void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
aReader.SetSHUOMode(true);
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
throw Base::FileException("Cannot read STEP file", file);
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
}

View File

@@ -0,0 +1,47 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef IMPORT_READER_STEP_H
#define IMPORT_READER_STEP_H
#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <TDocStd_Document.hxx>
namespace Import
{
class ImportExport ReaderStep
{
public:
explicit ReaderStep(const Base::FileInfo& file);
void read(Handle(TDocStd_Document) hDoc);
private:
Base::FileInfo file;
};
} // namespace Import
#endif // IMPORT_READER_STEP_H

View File

@@ -24,7 +24,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <sstream>
#include <Standard_Version.hxx>
#include <TColStd_IndexedDataMapOfStringString.hxx>
#if OCC_VERSION_HEX >= 0x070500
@@ -35,16 +34,19 @@
#include "WriterGltf.h"
#include <Base/Exception.h>
#include <Mod/Part/App/encodeFilename.h>
using namespace Import;
WriterGltf::WriterGltf(std::string name8bit, const Base::FileInfo& file) // NOLINT
: name8bit {std::move(name8bit)}
, file {file}
WriterGltf::WriterGltf(const Base::FileInfo& file) // NOLINT
: file {file}
{}
void WriterGltf::write(Handle(TDocStd_Document) hDoc) const // NOLINT
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
#if OCC_VERSION_HEX >= 0x070500
TColStd_IndexedDataMapOfStringString aMetadata;
RWGltf_CafWriter aWriter(name8bit.c_str(), file.hasExtension("glb"));
@@ -57,9 +59,7 @@ void WriterGltf::write(Handle(TDocStd_Document) hDoc) const // NOLINT
#endif
Standard_Boolean ret = aWriter.Perform(hDoc, aMetadata, Message_ProgressRange());
if (!ret) {
std::stringstream str;
str << "Cannot save to file '"
<< "" << file.filePath() << "'";
throw Base::FileException("Cannot save to file: ", file);
}
#else
throw Base::RuntimeError("gITF support requires OCCT 7.5.0 or later");

View File

@@ -34,12 +34,11 @@ namespace Import
class ImportExport WriterGltf
{
public:
WriterGltf(std::string name8bit, const Base::FileInfo& file);
explicit WriterGltf(const Base::FileInfo& file);
void write(Handle(TDocStd_Document) hDoc) const;
private:
std::string name8bit;
Base::FileInfo file;
};
} // namespace Import

View File

@@ -0,0 +1,63 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <IGESControl_Controller.hxx>
#include <IGESCAFControl_Writer.hxx>
#include <IGESData_GlobalSection.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESToBRep_Actor.hxx>
#endif
#include "WriterIges.h"
#include <Base/Exception.h>
#include <App/Application.h>
#include <Mod/Part/App/encodeFilename.h>
#include <Mod/Part/App/Interface.h>
using namespace Import;
WriterIges::WriterIges(const Base::FileInfo& file) // NOLINT
: file {file}
{}
void WriterIges::write(Handle(TDocStd_Document) hDoc) const // NOLINT
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
IGESControl_Controller::Init();
IGESCAFControl_Writer writer;
IGESData_GlobalSection header = writer.Model()->GlobalSection();
header.SetAuthorName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor()));
header.SetCompanyName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany()));
header.SetSendName(new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct()));
writer.Model()->SetGlobalSection(header);
writer.Transfer(hDoc);
Standard_Boolean ret = writer.Write(name8bit.c_str());
if (!ret) {
throw Base::FileException("Cannot open file: ", file);
}
}

View File

@@ -0,0 +1,46 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef IMPORT_WRITER_IGES_H
#define IMPORT_WRITER_IGES_H
#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <TDocStd_Document.hxx>
namespace Import
{
class ImportExport WriterIges
{
public:
explicit WriterIges(const Base::FileInfo& file);
void write(Handle(TDocStd_Document) hDoc) const;
private:
Base::FileInfo file;
};
} // namespace Import
#endif // IMPORT_WRITER_IGES_H

View File

@@ -0,0 +1,76 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <APIHeaderSection_MakeHeader.hxx>
#include <NCollection_Vector.hxx>
#include <STEPCAFControl_Writer.hxx>
#endif
#include "WriterStep.h"
#include <Base/Exception.h>
#include <App/Application.h>
#include <Mod/Part/App/encodeFilename.h>
#include <Mod/Part/App/Interface.h>
using namespace Import;
WriterStep::WriterStep(const Base::FileInfo& file) // NOLINT
: file {file}
{}
void WriterStep::write(Handle(TDocStd_Document) hDoc) const // NOLINT
{
std::string utf8Name = file.filePath();
std::string name8bit = Part::encodeFilename(utf8Name);
STEPCAFControl_Writer writer;
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
writer.Transfer(hDoc, STEPControl_AsIs);
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("STEP");
// Don't set name because STEP doesn't support UTF-8
// https://forum.freecad.org/viewtopic.php?f=8&t=52967
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::Application::getExecutableName().c_str()));
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) {
throw Base::FileException("Cannot open file: ", file);
}
}

View File

@@ -0,0 +1,46 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef IMPORT_WRITER_STEP_H
#define IMPORT_WRITER_STEP_H
#include <Mod/Import/ImportGlobal.h>
#include <Base/FileInfo.h>
#include <TDocStd_Document.hxx>
namespace Import
{
class ImportExport WriterStep
{
public:
explicit WriterStep(const Base::FileInfo& file);
void write(Handle(TDocStd_Document) hDoc) const;
private:
Base::FileInfo file;
};
} // namespace Import
#endif // IMPORT_WRITER_GLTF_H

View File

@@ -45,17 +45,8 @@
#pragma clang diagnostic ignored "-Wextra-semi"
#endif
#include <APIHeaderSection_MakeHeader.hxx>
#include <IGESCAFControl_Reader.hxx>
#include <IGESCAFControl_Writer.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESData_GlobalSection.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESToBRep_Actor.hxx>
#include <Interface_Static.hxx>
#include <OSD_Exception.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <STEPCAFControl_Writer.hxx>
#include <Standard_Version.hxx>
#include <TColStd_IndexedDataMapOfStringString.hxx>
#include <TDF_AttributeIterator.hxx>
@@ -105,7 +96,11 @@
#include <Gui/ViewProviderLink.h>
#include <Mod/Import/App/ImportOCAF2.h>
#include <Mod/Import/App/ReaderGltf.h>
#include <Mod/Import/App/ReaderIges.h>
#include <Mod/Import/App/ReaderStep.h>
#include <Mod/Import/App/WriterGltf.h>
#include <Mod/Import/App/WriterIges.h>
#include <Mod/Import/App/WriterStep.h>
#include <Mod/Part/App/ImportIges.h>
#include <Mod/Part/App/ImportStep.h>
#include <Mod/Part/App/Interface.h>
@@ -453,25 +448,8 @@ private:
}
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
aReader.SetSHUOMode(true);
if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
Import::ReaderStep reader(file);
reader.read(hDoc);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
@@ -482,39 +460,9 @@ private:
}
}
else if (file.hasExtension({"igs", "iges"})) {
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("IGES");
try {
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(
hGrp->GetBool("SkipBlankEntities", true) ? Standard_True : Standard_False);
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((const char*)name8bit.c_str()) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read IGES file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
// http://opencascade.blogspot.de/2009/03/unnoticeable-memory-leaks-part-2.html
Handle(IGESToBRep_Actor)::DownCast(aReader.WS()->TransferReader()->Actor())
->SetModel(new IGESData_IGESModel);
Import::ReaderIges reader(file);
reader.read(hDoc);
}
catch (OSD_Exception& e) {
Base::Console().Error("%s\n", e.GetMessageString());
@@ -640,7 +588,6 @@ private:
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
// determine export options
Part::OCAF::ImportExportSettings settings;
@@ -716,67 +663,23 @@ private:
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension({"stp", "step"})) {
ParameterGrp::handle hGrp_stp = App::GetApplication().GetParameterGroupByPath(
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Part/STEP");
std::string scheme =
hGrp_stp->GetASCII("Scheme", Part::Interface::writeStepScheme());
std::string scheme = hGrp->GetASCII("Scheme", Part::Interface::writeStepScheme());
std::list<std::string> supported = Part::supportedSTEPSchemes();
if (std::find(supported.begin(), supported.end(), scheme) != supported.end()) {
Part::Interface::writeStepScheme(scheme.c_str());
}
STEPCAFControl_Writer writer;
Part::Interface::writeStepAssembly(Part::Interface::Assembly::On);
writer.Transfer(hDoc, STEPControl_AsIs);
// edit STEP header
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("STEP");
// Don't set name because STEP doesn't support UTF-8
// https://forum.freecad.org/viewtopic.php?f=8&t=52967
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::Application::getExecutableName().c_str()));
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());
throw Py::Exception();
}
Import::WriterStep writer(file);
writer.write(hDoc);
}
else if (file.hasExtension({"igs", "iges"})) {
IGESControl_Controller::Init();
IGESCAFControl_Writer writer;
IGESData_GlobalSection header = writer.Model()->GlobalSection();
header.SetAuthorName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderAuthor()));
header.SetCompanyName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderCompany()));
header.SetSendName(
new TCollection_HAsciiString(Part::Interface::writeIgesHeaderProduct()));
writer.Model()->SetGlobalSection(header);
writer.Transfer(hDoc);
Standard_Boolean ret = writer.Write((const char*)name8bit.c_str());
if (!ret) {
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
throw Py::Exception();
}
Import::WriterIges writer(file);
writer.write(hDoc);
}
else if (file.hasExtension({"glb", "gltf"})) {
Import::WriterGltf writer(name8bit, file);
Import::WriterGltf writer(file);
writer.write(hDoc);
}
@@ -807,58 +710,12 @@ private:
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
if (file.hasExtension({"stp", "step"})) {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
aReader.SetSHUOMode(true);
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
Import::ReaderStep reader(file);
reader.read(hDoc);
}
else if (file.hasExtension({"igs", "iges"})) {
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("Mod/Part")
->GetGroup("IGES");
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(hGrp->GetBool("SkipBlankEntities", true) ? Standard_True
: Standard_False);
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)Name) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read IGES file");
}
#if OCC_VERSION_HEX < 0x070500
Handle(Message_ProgressIndicator) pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
#endif
aReader.Transfer(hDoc);
#if OCC_VERSION_HEX < 0x070500
pi->EndScope();
#endif
// http://opencascade.blogspot.de/2009/03/unnoticeable-memory-leaks-part-2.html
Handle(IGESToBRep_Actor)::DownCast(aReader.WS()->TransferReader()->Actor())
->SetModel(new IGESData_IGESModel);
Import::ReaderIges reader(file);
reader.read(hDoc);
}
else {
throw Py::Exception(PyExc_IOError, "no supported file format");