FreeCAD

Форк
0
/
GeometryDoubleExtensionPyImp.cpp 
106 строк · 3.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2019 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25

26
#include "GeometryDefaultExtension.h"
27

28
#include "GeometryDoubleExtensionPy.h"
29
#include "GeometryDoubleExtensionPy.cpp"
30

31
using namespace Part;
32

33
// returns a string which represents the object e.g. when printed in python
34
std::string GeometryDoubleExtensionPy::representation() const
35
{
36
    std::stringstream str;
37
    double val = getGeometryDoubleExtensionPtr()->getValue();
38
    str << "<GeometryDoubleExtension (" ;
39

40
    if(!getGeometryDoubleExtensionPtr()->getName().empty())
41
        str << "\'" << getGeometryDoubleExtensionPtr()->getName() << "\', ";
42

43
    str << val << ") >";
44

45

46
    return str.str();
47
}
48

49
PyObject *GeometryDoubleExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
50
{
51
    // create a new instance of the python object and the Twin object
52
    return new GeometryDoubleExtensionPy(new GeometryDoubleExtension);
53
}
54

55
// constructor method
56
int GeometryDoubleExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
57
{
58

59
    if (PyArg_ParseTuple(args, "")) {
60
        // default extension
61
        return 0;
62
    }
63

64
    PyErr_Clear();
65
    double val;
66
    if (PyArg_ParseTuple(args, "d", &val)) {
67
        this->getGeometryDoubleExtensionPtr()->setValue(val);
68
        return 0;
69
    }
70

71
    PyErr_Clear();
72
    char * pystr;
73
    if (PyArg_ParseTuple(args, "ds", &val,&pystr)) {
74
        this->getGeometryDoubleExtensionPtr()->setValue(val);
75
        this->getGeometryDoubleExtensionPtr()->setName(pystr);
76
        return 0;
77
    }
78

79
    PyErr_SetString(PyExc_TypeError, "GeometryDoubleExtension constructor accepts:\n"
80
    "-- empty parameter list\n"
81
    "-- double\n"
82
    "-- double, string\n");
83
    return -1;
84
}
85

86
Py::Float GeometryDoubleExtensionPy::getValue() const
87
{
88
    return Py::Float(this->getGeometryDoubleExtensionPtr()->getValue());
89
}
90

91
void GeometryDoubleExtensionPy::setValue(Py::Float value)
92
{
93
    this->getGeometryDoubleExtensionPtr()->setValue(float(value));
94
}
95

96

97

98
PyObject *GeometryDoubleExtensionPy::getCustomAttributes(const char* /*attr*/) const
99
{
100
    return nullptr;
101
}
102

103
int GeometryDoubleExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
104
{
105
    return 0;
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.