1
/***************************************************************************
2
* Copyright (c) Juergen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
27
# if defined (_POSIX_C_SOURCE)
28
# undef _POSIX_C_SOURCE
29
# endif // (re-)defined in pyconfig.h
33
#include <Base/Console.h>
34
#include <Base/Interpreter.h>
35
#include <Base/FileInfo.h>
37
#include <App/Application.h>
38
#include <App/Document.h>
39
#include <App/Feature.h>
40
#include <App/Property.h>
44
#include "PointsAlgos.h"
45
#include "FeaturePointsImportAscii.h"
47
using namespace Points;
49
/* module functions */
51
open(PyObject *self, PyObject *args)
54
if (! PyArg_ParseTuple(args, "s",&Name))
59
Base::Console().Log("Open in Points with %s",Name);
60
Base::FileInfo file(Name);
63
if(file.extension() == "")
64
Py_Error(PyExc_Exception,"no file ending");
66
if(file.hasExtension("asc"))
68
// create new document and add Import feature
69
App::Document *pcDoc = App::GetApplication().newDocument("Unnamed");
70
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
71
Points::PointKernel pkTemp;
73
pcFeature->Points.setValue( pkTemp );
78
Py_Error(PyExc_Exception,"unknown file ending");
86
insert(PyObject *self, PyObject *args)
90
if (! PyArg_ParseTuple(args, "ss",&Name,&DocName))
95
Base::Console().Log("Import in Points with %s",Name);
96
Base::FileInfo file(Name);
99
if(file.extension() == "")
100
Py_Error(PyExc_Exception,"no file ending");
102
if(file.hasExtension("asc"))
104
// add Import feature
105
App::Document *pcDoc = App::GetApplication().getDocument(DocName);
108
PyErr_Format(PyExc_Exception, "Import called to the non-existing document '%s'", DocName);
112
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", file.fileNamePure().c_str());
113
Points::PointKernel pkTemp;
115
pcFeature->Points.setValue( pkTemp );
119
Py_Error(PyExc_Exception,"unknown file ending");
127
show(PyObject *self, PyObject *args)
130
if (!PyArg_ParseTuple(args, "O!", &(PointsPy::Type), &pcObj)) // convert args: Python->C
131
return NULL; // NULL triggers exception
134
App::Document *pcDoc = App::GetApplication().getActiveDocument();
136
pcDoc = App::GetApplication().newDocument();
137
PointsPy* pPoints = static_cast<PointsPy*>(pcObj);
138
Points::Feature *pcFeature = (Points::Feature *)pcDoc->addObject("Points::Feature", "Points");
140
//TopoShape* shape = new MeshObject(*pShape->getTopoShapeObjectPtr());
141
pcFeature->Points.setValue(*(pPoints->getPointKernelPtr()));
142
//pcDoc->recompute();
148
// registration table
149
struct PyMethodDef Points_Import_methods[] = {
150
{"open", open, 1}, /* method name, C func ptr, always-tuple */
151
{"insert",insert, 1},
154
{NULL, NULL} /* end of table marker */