MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / readDXF

Method readDXF

src/Mod/Import/App/AppImportPy.cpp:383–440  ·  view source on GitHub ↗

This readDXF method is an almost exact duplicate of the one in ImportGui::Module. The only difference is the CDxfRead class derivation that is created. It would seem desirable to have most of this code in just one place, passing it e.g. a pointer to a function that does the 4 lines during the lifetime of the CDxfRead object, but right now Import::Module and ImportGui::Module cannot see each other'

Source from the content-addressed store, hash-verified

381 // each other's functions so this shared code would need some place to live where
382 // both places could include a declaration.
383 Py::Object readDXF(const Py::Tuple& args)
384 {
385 char* Name = nullptr;
386 const char* DocName = nullptr;
387 const char* optionSource = nullptr;
388 std::string defaultOptions = "User parameter:BaseApp/Preferences/Mod/Draft";
389 bool IgnoreErrors = true;
390 if (
391 !PyArg_ParseTuple(args.ptr(), "et|sbs", "utf-8", &Name, &DocName, &IgnoreErrors, &optionSource)
392 ) {
393 throw Py::Exception();
394 }
395
396 std::string EncodedName = std::string(Name);
397 PyMem_Free(Name);
398
399 Base::FileInfo file(EncodedName.c_str());
400 if (!file.exists()) {
401 throw Py::RuntimeError("File doesn't exist");
402 }
403
404 if (optionSource) {
405 defaultOptions = optionSource;
406 }
407
408 App::Document* pcDoc = nullptr;
409 if (DocName) {
410 pcDoc = App::GetApplication().getDocument(DocName);
411 }
412 else {
413 pcDoc = App::GetApplication().getActiveDocument();
414 }
415 if (!pcDoc) {
416 pcDoc = App::GetApplication().newDocument(DocName);
417 }
418
419 try {
420 // read the DXF file
421 ImpExpDxfRead dxf_file(EncodedName, pcDoc);
422 dxf_file.setOptionSource(defaultOptions);
423 dxf_file.setOptions();
424
425 auto startTime = std::chrono::high_resolution_clock::now();
426 dxf_file.DoRead(IgnoreErrors);
427 auto endTime = std::chrono::high_resolution_clock::now();
428 std::chrono::duration<double> elapsed = endTime - startTime;
429 dxf_file.setImportTime(elapsed.count());
430
431 pcDoc->recompute();
432 return dxf_file.getStatsAsPyObject();
433 }
434 catch (const Standard_Failure& e) {
435 throw Py::RuntimeError(e.GetMessageString());
436 }
437 catch (const Base::Exception& e) {
438 throw Py::RuntimeError(e.what());
439 }
440 }

Callers 1

executeMethod · 0.45

Calls 14

setOptionsMethod · 0.80
DoReadMethod · 0.80
getStatsAsPyObjectMethod · 0.80
ExceptionClass · 0.50
nowFunction · 0.50
ptrMethod · 0.45
c_strMethod · 0.45
existsMethod · 0.45
getDocumentMethod · 0.45
getActiveDocumentMethod · 0.45
newDocumentMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected