Add hooks so Gui classes can be seen by DXF importer
This commit is contained in:
committed by
Yorik van Havre
parent
aa1f75ef0e
commit
37e6c19a4b
@@ -2800,8 +2800,12 @@ def open(filename):
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
doc.Label = docname
|
||||
FreeCAD.setActiveDocument(doc.Name)
|
||||
import Import
|
||||
Import.readDXF(filename)
|
||||
try:
|
||||
import ImportGui
|
||||
ImportGui.readDXF(filename)
|
||||
except Exception:
|
||||
import Import
|
||||
Import.readDXF(filename)
|
||||
Draft.convert_draft_texts() # convert annotations to Draft texts
|
||||
doc.recompute()
|
||||
|
||||
@@ -2842,8 +2846,12 @@ def insert(filename, docname):
|
||||
else:
|
||||
errorDXFLib(gui)
|
||||
else:
|
||||
import Import
|
||||
Import.readDXF(filename)
|
||||
try:
|
||||
import ImportGui
|
||||
ImportGui.readDXF(filename)
|
||||
except Exception:
|
||||
import Import
|
||||
Import.readDXF(filename)
|
||||
Draft.convert_draft_texts() # convert annotations to Draft texts
|
||||
doc.recompute()
|
||||
|
||||
|
||||
@@ -363,6 +363,13 @@ private:
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
// 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's functions so this shared code would need some place to live where
|
||||
// both places could include a declaration.
|
||||
Py::Object readDXF(const Py::Tuple& args)
|
||||
{
|
||||
char* Name = nullptr;
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include "ImportOCAFGui.h"
|
||||
#include "OCAFBrowser.h"
|
||||
|
||||
#include "dxf/ImpExpDxfGui.h"
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Base/Console.h>
|
||||
@@ -93,6 +94,10 @@ public:
|
||||
add_keyword_method("insert",
|
||||
&Module::insert,
|
||||
"insert(string,string) -- Insert the file into the given document.");
|
||||
add_varargs_method("readDXF",
|
||||
&Module::readDXF,
|
||||
"readDXF(filename,[document,ignore_errors,option_source]): Imports a "
|
||||
"DXF file into the given document. ignore_errors is True by default.");
|
||||
add_varargs_method("exportOptions",
|
||||
&Module::exportOptions,
|
||||
"exportOptions(string) -- Return the export options of a file type.");
|
||||
@@ -250,6 +255,70 @@ private:
|
||||
return {};
|
||||
}
|
||||
|
||||
// This readDXF method is an almost exact duplicate of the one in Import::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's functions so this shared code would need some place to live where
|
||||
// both places could include a declaration.
|
||||
Py::Object readDXF(const Py::Tuple& args)
|
||||
{
|
||||
char* Name = nullptr;
|
||||
const char* DocName = nullptr;
|
||||
const char* optionSource = nullptr;
|
||||
std::string defaultOptions = "User parameter:BaseApp/Preferences/Mod/Draft";
|
||||
bool IgnoreErrors = true;
|
||||
if (!PyArg_ParseTuple(args.ptr(),
|
||||
"et|sbs",
|
||||
"utf-8",
|
||||
&Name,
|
||||
&DocName,
|
||||
&IgnoreErrors,
|
||||
&optionSource)) {
|
||||
throw Py::Exception();
|
||||
}
|
||||
|
||||
std::string EncodedName = std::string(Name);
|
||||
PyMem_Free(Name);
|
||||
|
||||
Base::FileInfo file(EncodedName.c_str());
|
||||
if (!file.exists()) {
|
||||
throw Py::RuntimeError("File doesn't exist");
|
||||
}
|
||||
|
||||
if (optionSource) {
|
||||
defaultOptions = optionSource;
|
||||
}
|
||||
|
||||
App::Document* pcDoc = nullptr;
|
||||
if (DocName) {
|
||||
pcDoc = App::GetApplication().getDocument(DocName);
|
||||
}
|
||||
else {
|
||||
pcDoc = App::GetApplication().getActiveDocument();
|
||||
}
|
||||
if (!pcDoc) {
|
||||
pcDoc = App::GetApplication().newDocument(DocName);
|
||||
}
|
||||
|
||||
try {
|
||||
// read the DXF file
|
||||
ImpExpDxfReadGui dxf_file(EncodedName, pcDoc);
|
||||
dxf_file.setOptionSource(defaultOptions);
|
||||
dxf_file.setOptions();
|
||||
dxf_file.DoRead(IgnoreErrors);
|
||||
pcDoc->recompute();
|
||||
}
|
||||
catch (const Standard_Failure& e) {
|
||||
throw Py::RuntimeError(e.GetMessageString());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
throw Py::RuntimeError(e.what());
|
||||
}
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
Py::Object exportOptions(const Py::Tuple& args)
|
||||
{
|
||||
char* Name;
|
||||
|
||||
@@ -25,6 +25,8 @@ SET(ImportGui_SRCS
|
||||
Command.cpp
|
||||
ExportOCAFGui.cpp
|
||||
ExportOCAFGui.h
|
||||
dxf/ImpExpDxfGui.cpp
|
||||
dxf/ImpExpDxfGui.h
|
||||
ImportOCAFGui.cpp
|
||||
ImportOCAFGui.h
|
||||
OCAFBrowser.cpp
|
||||
|
||||
71
src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp
Normal file
71
src/Mod/Import/Gui/dxf/ImpExpDxfGui.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Yorik van Havre (yorik@uncreated.net) *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <Standard_Version.hxx>
|
||||
#if OCC_VERSION_HEX < 0x070600
|
||||
#include <BRepAdaptor_HCurve.hxx>
|
||||
#endif
|
||||
#include <Approx_Curve3d.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeVertex.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <GCPnts_UniformAbscissa.hxx>
|
||||
#include <GeomAPI_Interpolate.hxx>
|
||||
#include <GeomAPI_PointsToBSpline.hxx>
|
||||
#include <Geom_BSplineCurve.hxx>
|
||||
#include <TColgp_Array1OfPnt.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Compound.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Circ.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Elips.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#endif
|
||||
|
||||
//#include <App/Annotation.h>
|
||||
//#include <App/Application.h>
|
||||
//#include <App/Document.h>
|
||||
//#include <Base/Console.h>
|
||||
//#include <Base/Interpreter.h>
|
||||
//#include <Base/Matrix.h>
|
||||
//#include <Base/Parameter.h>
|
||||
//#include <Base/Vector3D.h>
|
||||
//#include <Base/PlacementPy.h>
|
||||
//#include <Mod/Part/App/PartFeature.h>
|
||||
|
||||
#include "ImpExpDxfGui.h"
|
||||
|
||||
using namespace ImportGui;
|
||||
|
||||
ImpExpDxfReadGui::ImpExpDxfReadGui(std::string filepath, App::Document* pcDoc)
|
||||
: ImpExpDxfRead(filepath, pcDoc)
|
||||
{}
|
||||
|
||||
43
src/Mod/Import/Gui/dxf/ImpExpDxfGui.h
Normal file
43
src/Mod/Import/Gui/dxf/ImpExpDxfGui.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Yorik van Havre (yorik@uncreated.net) *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef IMPEXPDXFGUI_H
|
||||
#define IMPEXPDXFGUI_H
|
||||
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Mod/Part/App/TopoShape.h>
|
||||
|
||||
#include <Mod/Import/App/dxf/ImpExpDxf.h>
|
||||
|
||||
|
||||
namespace ImportGui
|
||||
{
|
||||
class ImpExpDxfReadGui: public Import::ImpExpDxfRead
|
||||
{
|
||||
public:
|
||||
ImpExpDxfReadGui(std::string filepath, App::Document* pcDoc);
|
||||
};
|
||||
} // namespace ImportGui
|
||||
|
||||
#endif // IMPEXPDXFGUI_H
|
||||
Reference in New Issue
Block a user