Import: DXF, add dedicated import dialog
This commit is contained in:
@@ -53,6 +53,7 @@
|
||||
#include <gp_Vec.hxx>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <App/Annotation.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
@@ -80,6 +81,35 @@ using namespace Import;
|
||||
using BRepAdaptor_HCurve = BRepAdaptor_Curve;
|
||||
#endif
|
||||
|
||||
std::map<std::string, int> ImpExpDxfRead::PreScan(const std::string& filepath)
|
||||
{
|
||||
std::map<std::string, int> counts;
|
||||
std::ifstream ifs(filepath);
|
||||
if (!ifs) {
|
||||
// Could throw an exception or log an error
|
||||
return counts;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
bool next_is_entity_name = false;
|
||||
|
||||
while (std::getline(ifs, line)) {
|
||||
// Simple trim for Windows-style carriage returns
|
||||
if (!line.empty() && line.back() == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
|
||||
if (next_is_entity_name) {
|
||||
// The line after a " 0" group code is the entity type
|
||||
counts[line]++;
|
||||
next_is_entity_name = false;
|
||||
}
|
||||
else if (line == " 0") {
|
||||
next_is_entity_name = true;
|
||||
}
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// reading
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
{
|
||||
Py_XDECREF(DraftModule);
|
||||
}
|
||||
|
||||
static std::map<std::string, int> PreScan(const std::string& filepath);
|
||||
void StartImport() override;
|
||||
|
||||
Py::Object getStatsAsPyObject();
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
add_keyword_method("insert",
|
||||
&Module::insert,
|
||||
"insert(string,string) -- Insert the file into the given document.");
|
||||
add_varargs_method("preScanDxf", &Module::preScanDxf, "preScanDxf(filepath) -> dict");
|
||||
add_varargs_method("readDXF",
|
||||
&Module::readDXF,
|
||||
"readDXF(filename,[document,ignore_errors,option_source]): Imports a "
|
||||
@@ -112,6 +113,26 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
Py::Object preScanDxf(const Py::Tuple& args)
|
||||
{
|
||||
char* filepath_char = nullptr;
|
||||
if (!PyArg_ParseTuple(args.ptr(), "et", "utf-8", &filepath_char)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
std::string filepath(filepath_char);
|
||||
PyMem_Free(filepath_char);
|
||||
|
||||
#include <Mod/Import/App/dxf/ImpExpDxf.h>
|
||||
|
||||
std::map<std::string, int> counts = Import::ImpExpDxfRead::PreScan(filepath);
|
||||
|
||||
Py::Dict result;
|
||||
for (const auto& pair : counts) {
|
||||
result.setItem(Py::String(pair.first), Py::Long(pair.second));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Py::Object importOptions(const Py::Tuple& args)
|
||||
{
|
||||
char* Name {};
|
||||
|
||||
Reference in New Issue
Block a user