Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd"> | ||
<PythonExport | ||
Father="PyObjectBase" | ||
Name="TypePy" | ||
Twin="BaseType" | ||
TwinPointer="BaseType" | ||
Include="Base/Type.h" | ||
FatherInclude="Base/PyObjectBase.h" | ||
Namespace="Base" | ||
FatherNamespace="Base" | ||
Delete="true"> | ||
<ForwardDeclarations> | ||
namespace Base { | ||
typedef Type BaseType; | ||
}</ForwardDeclarations> | ||
<Documentation> | ||
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" /> | ||
<DeveloperDocu>This is the Type class</DeveloperDocu> | ||
<UserDocu>This is the Type class</UserDocu> | ||
</Documentation> | ||
<Methode Name="fromName" Static="true"> | ||
<Documentation> | ||
<UserDocu>Returns a type object by name</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="fromKey" Static="true"> | ||
<Documentation> | ||
<UserDocu>Returns a type object by key</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getNumTypes" Static="true"> | ||
<Documentation> | ||
<UserDocu>Returns the number of type ids</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getBadType" Static="true"> | ||
<Documentation> | ||
<UserDocu>Returns an invalid type id</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getParent" Const="true"> | ||
<Documentation> | ||
<UserDocu>Returns the parent type id</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="isBad" Const="true"> | ||
<Documentation> | ||
<UserDocu>Checks if the type id is invalid</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="isDerivedFrom" Const="true"> | ||
<Documentation> | ||
<UserDocu>Returns true if given type is a father</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Methode Name="getAllDerivedFrom" Const="true"> | ||
<Documentation> | ||
<UserDocu>Returns all descendants</UserDocu> | ||
</Documentation> | ||
</Methode> | ||
<Attribute Name="Name" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>The name of the type id</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Name" Type="String" /> | ||
</Attribute> | ||
<Attribute Name="Key" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>The key of the type id</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Key" Type="Long" /> | ||
</Attribute> | ||
<Attribute Name="Module" ReadOnly="true"> | ||
<Documentation> | ||
<UserDocu>Module in which this class is defined</UserDocu> | ||
</Documentation> | ||
<Parameter Name="Module" Type="String"/> | ||
</Attribute> | ||
</PythonExport> | ||
</GenerateModel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2019 Werner Mayer <wmayer[at]users.sourceforge.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., 51 Franklin Street, * | ||
* Fifth Floor, Boston, MA 02110-1301, USA * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "PreCompiled.h" | ||
|
||
#include "Type.h" | ||
#include "TypePy.h" | ||
#include "TypePy.cpp" | ||
|
||
using namespace Base; | ||
|
||
// returns a string which represent the object e.g. when printed in python | ||
std::string TypePy::representation(void) const | ||
{ | ||
std::stringstream str; | ||
str << "<class '" << getBaseTypePtr()->getName() << "'>"; | ||
return str.str(); | ||
} | ||
|
||
PyObject* TypePy::staticCallback_fromName (PyObject * /*self*/, PyObject *args) | ||
{ | ||
const char *name; | ||
if (!PyArg_ParseTuple(args, "s", &name)) | ||
return NULL; | ||
|
||
Base::Type type = Base::Type::fromName(name); | ||
return new TypePy(new Base::Type(type)); | ||
} | ||
|
||
PyObject* TypePy::staticCallback_fromKey (PyObject * /*self*/, PyObject *args) | ||
{ | ||
unsigned int index; | ||
if (!PyArg_ParseTuple(args, "I", &index)) | ||
return NULL; | ||
|
||
Base::Type type = Base::Type::fromKey(index); | ||
return new TypePy(new Base::Type(type)); | ||
} | ||
|
||
PyObject* TypePy::staticCallback_getNumTypes (PyObject * /*self*/, PyObject *args) | ||
{ | ||
if (!PyArg_ParseTuple(args, "")) | ||
return NULL; | ||
|
||
int num = Base::Type::getNumTypes(); | ||
return PyLong_FromLong(num); | ||
} | ||
|
||
PyObject* TypePy::staticCallback_getBadType (PyObject * /*self*/, PyObject *args) | ||
{ | ||
if (!PyArg_ParseTuple(args, "")) | ||
return NULL; | ||
|
||
Base::Type type = Base::Type::badType(); | ||
return new TypePy(new Base::Type(type)); | ||
} | ||
|
||
PyObject* TypePy::getParent(PyObject *args) | ||
{ | ||
if (!PyArg_ParseTuple(args, "")) | ||
return NULL; | ||
|
||
Base::Type type = getBaseTypePtr()->getParent(); | ||
return new TypePy(new Base::Type(type)); | ||
} | ||
|
||
PyObject* TypePy::isBad(PyObject *args) | ||
{ | ||
if (!PyArg_ParseTuple(args, "")) | ||
return NULL; | ||
|
||
bool v = getBaseTypePtr()->isBad(); | ||
return PyBool_FromLong(v ? 1 : 0); | ||
} | ||
|
||
PyObject* TypePy::isDerivedFrom(PyObject *args) | ||
{ | ||
char *name; | ||
if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C | ||
return NULL; // NULL triggers exception | ||
|
||
Base::Type type = Base::Type::fromName(name); | ||
bool v = (type != Base::Type::badType() && getBaseTypePtr()->isDerivedFrom(type)); | ||
return PyBool_FromLong(v ? 1 : 0); | ||
} | ||
|
||
PyObject* TypePy::getAllDerivedFrom(PyObject *args) | ||
{ | ||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C | ||
return NULL; // NULL triggers exception | ||
|
||
std::vector<Base::Type> ary; | ||
Base::Type::getAllDerivedFrom(*getBaseTypePtr(), ary); | ||
Py::List res; | ||
for (std::vector<Base::Type>::iterator it = ary.begin(); it != ary.end(); ++it) | ||
res.append(Py::String(it->getName())); | ||
return Py::new_reference_to(res); | ||
} | ||
|
||
Py::String TypePy::getName(void) const | ||
{ | ||
return Py::String(std::string(getBaseTypePtr()->getName())); | ||
} | ||
|
||
Py::Long TypePy::getKey(void) const | ||
{ | ||
return Py::Long(static_cast<long>(getBaseTypePtr()->getKey())); | ||
} | ||
|
||
Py::String TypePy::getModule(void) const | ||
{ | ||
std::string module(getBaseTypePtr()->getName()); | ||
std::string::size_type pos = module.find_first_of("::"); | ||
|
||
if (pos != std::string::npos) | ||
module = std::string(module, 0, pos); | ||
else | ||
module.clear(); | ||
|
||
return Py::String(module); | ||
} | ||
|
||
PyObject *TypePy::getCustomAttributes(const char* /*attr*/) const | ||
{ | ||
return 0; | ||
} | ||
|
||
int TypePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) | ||
{ | ||
return 0; | ||
} |