AppSketcherPy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Jürgen Riegel (juergen.riegel@web.de)              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 // Things from the part module
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 /* module functions */
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         //Base::Console().Log("Open in Part with %s",Name);
00060         Base::FileInfo file(Name);
00061 
00062         // extract ending
00063         if (file.extension() == "")
00064             Py_Error(PyExc_Exception,"no file ending");
00065 
00066         //if (file.hasExtension("igs") || file.hasExtension("iges")) {
00067         //    // create new document and add Import feature
00068         //    App::Document *pcDoc = App::GetApplication().newDocument(file.fileNamePure().c_str());
00069         //    Part::ImportIges *pcFeature = (Part::ImportIges*) pcDoc->addObject("Part::ImportIges",file.fileNamePure().c_str());
00070         //    pcFeature->FileName.setValue(Name);
00071         //    pcDoc->recompute();
00072         //}
00073         // else {
00074             Py_Error(PyExc_Exception,"unknown file ending");
00075         //}
00076 
00077     Py_Return;
00078 }
00079 
00080 /* module functions */
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         //Base::Console().Log("Insert in Part with %s",Name);
00090         Base::FileInfo file(Name);
00091 
00092         // extract ending
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 /* module functions */
00117 //static PyObject * read(PyObject *self, PyObject *args)
00118 //{
00119 //    const char* Name;
00120 //    if (!PyArg_ParseTuple(args, "s",&Name))
00121 //        return NULL;
00122 //    PY_TRY {
00123 //    } PY_CATCH;
00124 //  
00125 //    Py_Return;
00126 //}
00127 
00128 /* registration table  */
00129 struct PyMethodDef Sketcher_methods[] = {
00130     {"open"   , open,    1},
00131     {"insert" , insert,  1},
00132 //    {"read"   , read,  1},
00133     {NULL, NULL}        /* end of table marker */
00134 };

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1