Skip to content

Commit

Permalink
Import: fix lint warnings
Browse files Browse the repository at this point in the history
* Make constructors explicit
* Fix a regression from PR 10783
  • Loading branch information
wwmayer committed Oct 1, 2023
1 parent 70ca90f commit c878609
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/Mod/Import/App/AppImportPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ class Module: public Py::ExtensionModule<Module>

std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);

try {
Py::Sequence list(object);
Expand Down Expand Up @@ -344,7 +343,7 @@ class Module: public Py::ExtensionModule<Module>
writer.write(hDoc);
}
else if (file.hasExtension({"glb", "gltf"})) {
Import::WriterGltf writer(name8bit, file);
Import::WriterGltf writer(file);
writer.write(hDoc);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Mod/Import/App/ReaderGltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "PreCompiled.h"
#ifndef _PreComp_
#include <sstream>
#include <Standard_Version.hxx>
#include <TDF_Label.hxx>
#include <TDF_TagSource.hxx>
Expand Down Expand Up @@ -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());
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Import/App/ReaderIges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ReaderIges::read(Handle(TDocStd_Document) hDoc) // NOLINT
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
throw Base::FileException("cannot read IGES file", utf8Name.c_str());
throw Base::FileException("Cannot read IGES file", file);
}

#if OCC_VERSION_HEX < 0x070500
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Import/App/ReaderStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ReaderStep::read(Handle(TDocStd_Document) hDoc) // NOLINT
aReader.SetLayerMode(true);
aReader.SetSHUOMode(true);
if (aReader.ReadFile(name8bit.c_str()) != IFSelect_RetDone) {
throw Base::FileException("Cannot read STEP file");
throw Base::FileException("Cannot read STEP file", file);
}

#if OCC_VERSION_HEX < 0x070500
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/Import/App/WriterGltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "PreCompiled.h"
#ifndef _PreComp_
#include <sstream>
#include <Standard_Version.hxx>
#include <TColStd_IndexedDataMapOfStringString.hxx>
#if OCC_VERSION_HEX >= 0x070500
Expand All @@ -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"));
Expand All @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/Import/App/WriterGltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Import/App/WriterIges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#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;
Expand All @@ -44,6 +45,9 @@ WriterIges::WriterIges(const Base::FileInfo& file) // NOLINT

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();
Expand All @@ -54,7 +58,6 @@ void WriterIges::write(Handle(TDocStd_Document) hDoc) const // NOLINT
writer.Transfer(hDoc);
Standard_Boolean ret = writer.Write(name8bit.c_str());
if (!ret) {
std::string utf8Name = file.filePath();
throw Base::FileException("Cannot open file '%s'", utf8Name.c_str());
throw Base::FileException("Cannot open file: ", file);
}
}
3 changes: 1 addition & 2 deletions src/Mod/Import/App/WriterIges.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ namespace Import
class ImportExport WriterIges
{
public:
WriterIges(const Base::FileInfo& file);
explicit WriterIges(const Base::FileInfo& file);

void write(Handle(TDocStd_Document) hDoc) const;

private:
std::string name8bit;
Base::FileInfo file;
};
} // namespace Import
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Import/App/WriterStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#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;
Expand All @@ -42,6 +43,9 @@ WriterStep::WriterStep(const Base::FileInfo& file) // NOLINT

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);
Expand All @@ -67,7 +71,6 @@ void WriterStep::write(Handle(TDocStd_Document) hDoc) const // NOLINT
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) {
std::string utf8Name = file.filePath();
throw Base::FileException("Cannot open file '%s'", utf8Name.c_str());
throw Base::FileException("Cannot open file: ", file);
}
}
3 changes: 1 addition & 2 deletions src/Mod/Import/App/WriterStep.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ namespace Import
class ImportExport WriterStep
{
public:
WriterStep(const Base::FileInfo& file);
explicit WriterStep(const Base::FileInfo& file);

void write(Handle(TDocStd_Document) hDoc) const;

private:
std::string name8bit;
Base::FileInfo file;
};
} // namespace Import
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/Import/Gui/AppImportGuiPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ class Module: public Py::ExtensionModule<Module>

std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);

// determine export options
Part::OCAF::ImportExportSettings settings;
Expand Down Expand Up @@ -680,7 +679,7 @@ class Module: public Py::ExtensionModule<Module>
writer.write(hDoc);
}
else if (file.hasExtension({"glb", "gltf"})) {
Import::WriterGltf writer(name8bit, file);
Import::WriterGltf writer(file);
writer.write(hDoc);
}

Expand Down

0 comments on commit c878609

Please sign in to comment.