AppSketcherPy.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <BRepPrimAPI_MakeBox.hxx>
00027 # include <TopoDS_Face.hxx>
00028 # include <Geom_Plane.hxx>
00029 # include <Handle_Geom_Plane.hxx>
00030 #endif
00031
00032 #include <Base/Console.h>
00033 #include <Base/PyObjectBase.h>
00034 #include <Base/Exception.h>
00035 #include <Base/FileInfo.h>
00036 #include <App/Application.h>
00037 #include <App/Document.h>
00038
00039
00040 #include <Mod/Part/App/TopoShape.h>
00041 #include <Mod/Part/App/TopoShapePy.h>
00042
00043 #include "SketchObjectSF.h"
00044
00045 using Base::Console;
00046 using namespace Part;
00047 using namespace std;
00048
00049
00050
00051 static PyObject * open(PyObject *self, PyObject *args)
00052 {
00053 const char* Name;
00054 if (!PyArg_ParseTuple(args, "s",&Name))
00055 return NULL;
00056
00057 PY_TRY {
00058 } PY_CATCH;
00059
00060 Base::FileInfo file(Name);
00061
00062
00063 if (file.extension() == "")
00064 Py_Error(PyExc_Exception,"no file ending");
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 Py_Error(PyExc_Exception,"unknown file ending");
00075
00076
00077 Py_Return;
00078 }
00079
00080
00081 static PyObject * insert(PyObject *self, PyObject *args)
00082 {
00083 const char* Name;
00084 const char* DocName;
00085 if (!PyArg_ParseTuple(args, "ss",&Name,&DocName))
00086 return NULL;
00087
00088 PY_TRY {
00089
00090 Base::FileInfo file(Name);
00091
00092
00093 if (file.extension() == "")
00094 Py_Error(PyExc_Exception,"no file ending");
00095 App::Document *pcDoc = App::GetApplication().getDocument(DocName);
00096 if (!pcDoc) {
00097 pcDoc = App::GetApplication().newDocument(DocName);
00098 }
00099
00100 if (file.hasExtension("skf")) {
00101
00102 Sketcher::SketchObjectSF *pcFeature = (Sketcher::SketchObjectSF *)pcDoc->addObject("Sketcher::SketchObjectSF",file.fileNamePure().c_str());
00103 pcFeature->SketchFlatFile.setValue(Name);
00104
00105 pcDoc->recompute();
00106 }
00107 else {
00108 Py_Error(PyExc_Exception,"unknown file ending");
00109 }
00110
00111 } PY_CATCH;
00112
00113 Py_Return;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 struct PyMethodDef Sketcher_methods[] = {
00130 {"open" , open, 1},
00131 {"insert" , insert, 1},
00132
00133 {NULL, NULL}
00134 };