+ add Axis class to Base

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5252 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81 2011-12-10 14:36:26 +00:00
parent 6e138c79d7
commit f8866986b6
7 changed files with 408 additions and 7 deletions

View File

@ -66,6 +66,7 @@
#include <Base/Reader.h>
#include <Base/MatrixPy.h>
#include <Base/VectorPy.h>
#include <Base/AxisPy.h>
#include <Base/BoundBoxPy.h>
#include <Base/PlacementPy.h>
#include <Base/RotationPy.h>
@ -157,7 +158,7 @@ PyDoc_STRVAR(Console_doc,
"FreeCAD Console\n"
);
Application::Application(ParameterManager * /*pcSysParamMngr*/,
Application::Application(ParameterManager * /*pcSysParamMngr*/,
ParameterManager * /*pcUserParamMngr*/,
std::map<std::string,std::string> &mConfig)
://_pcSysParamMngr(pcSysParamMngr),
@ -202,17 +203,22 @@ Application::Application(ParameterManager * /*pcSysParamMngr*/,
union PyType_Object pyRotationPyType = {&Base::RotationPy::Type};
PyModule_AddObject(pAppModule, "Rotation", pyRotationPyType.o);
if (PyType_Ready(&Base::AxisPy::Type) < 0) return;
union PyType_Object pyAxisPyType = {&Base::AxisPy::Type};
PyModule_AddObject(pAppModule, "Axis", pyAxisPyType.o);
// Note: Create an own module 'Base' which should provide the python
// binding classes from the base module. At a later stage we should
// binding classes from the base module. At a later stage we should
// remove these types from the FreeCAD module.
PyObject* pBaseModule = Py_InitModule3("__FreeCADBase__", NULL,
"The Base module contains the classes for the geometric basics\n"
"like vector, matrix, bounding box, placement, rotation, ...");
"like vector, matrix, bounding box, placement, rotation, axis, ...");
Base::Interpreter().addType(&Base::VectorPy ::Type,pBaseModule,"Vector");
Base::Interpreter().addType(&Base::MatrixPy ::Type,pBaseModule,"Matrix");
Base::Interpreter().addType(&Base::BoundBoxPy ::Type,pBaseModule,"BoundBox");
Base::Interpreter().addType(&Base::PlacementPy ::Type,pBaseModule,"Placement");
Base::Interpreter().addType(&Base::RotationPy ::Type,pBaseModule,"Rotation");
Base::Interpreter().addType(&Base::AxisPy ::Type,pBaseModule,"Axis");
//insert Base and Console
Py_INCREF(pBaseModule);
@ -1285,7 +1291,7 @@ void Application::LoadParameters(void)
// fix weird error while linking boost (all versions of VC)
namespace boost { namespace program_options { std::string arg="arg"; } }
#if (defined (BOOST_VERSION) && (BOOST_VERSION == 104100))
namespace boost { namespace program_options {
namespace boost { namespace program_options {
const unsigned options_description::m_default_line_length = 80;
} }
#endif
@ -1295,7 +1301,7 @@ namespace boost { namespace program_options {
// reported for SUSE in issue #0000208
#if defined(__GNUC__)
#if BOOST_VERSION == 104400
namespace boost { namespace filesystem {
namespace boost { namespace filesystem {
bool no_check( const std::string & ) { return true; }
} }
#endif
@ -1597,7 +1603,7 @@ void Application::ExtractUserPath()
}
appData += PATHSEP;
}
appData += mConfig["ExeName"];
fi.setFile(appData.c_str());
if (!fi.exists() && !Py_IsInitialized()) {
@ -1652,7 +1658,7 @@ void Application::ExtractUserPath()
}
appData += PATHSEP;
}
appData += mConfig["ExeName"];
fi.setFile(appData.c_str());
if (!fi.exists() && !Py_IsInitialized()) {

94
src/Base/Axis.cpp Normal file
View File

@ -0,0 +1,94 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel *
* *
* 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., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "Axis.h"
using namespace Base;
Axis::Axis()
{
}
Axis::Axis(const Axis& that)
{
this->_base = that._base;
this->_dir = that._dir;
}
Axis::Axis(const Vector3d& Orig, const Vector3d& Dir)
{
this->_base = Orig;
this->_dir = Dir;
}
void Axis::reverse()
{
this->_dir = -this->_dir;
}
Axis Axis::reversed() const
{
Axis a(*this);
a.reverse();
return a;
}
void Axis::move(const Vector3d& MovVec)
{
_base += MovVec;
}
bool Axis::operator ==(const Axis& that) const
{
return (this->_base == that._base) && (this->_dir == that._dir);
}
bool Axis::operator !=(const Axis& that) const
{
return !(*this == that);
}
Axis& Axis::operator *=(const Placement &p)
{
p.multVec(this->_base, this->_base);
return *this;
}
Axis Axis::operator *(const Placement &p) const
{
Axis a(*this);
a *= p;
return a;
}
Axis& Axis::operator = (const Axis &New)
{
this->_base = New._base;
this->_dir = New._dir;
return *this;
}

72
src/Base/Axis.h Normal file
View File

@ -0,0 +1,72 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel *
* *
* 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., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_AXIS_H
#define BASE_AXIS_H
#include "Vector3D.h"
#include "Placement.h"
namespace Base {
/**
* The Axis class.
*/
class BaseExport Axis
{
public:
/// default constructor
Axis(void);
Axis(const Axis&);
Axis(const Vector3d& Orig, const Vector3d& Dir);
/// Destruction
~Axis () {};
const Vector3d& getBase(void) const {return _base;}
const Vector3d& getDirection(void) const {return _dir;}
void setBase(const Vector3d& Orig) {_base=Orig;}
void setDirection(const Vector3d& Dir) {_dir=Dir;}
void reverse();
Axis reversed() const;
void move(const Vector3d& MovVec);
/** Operators. */
//@{
Axis& operator *=(const Placement &p);
Axis operator *(const Placement &p) const;
bool operator ==(const Axis&) const;
bool operator !=(const Axis&) const;
Axis& operator =(const Axis&);
//@}
protected:
Vector3d _base;
Vector3d _dir;
};
} // namespace Base
#endif // BASE_AXIS_H

71
src/Base/AxisPy.xml Normal file
View File

@ -0,0 +1,71 @@
<?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="AxisPy"
Twin="Axis"
TwinPointer="Axis"
Include="Base/Axis.h"
FatherInclude="Base/PyObjectBase.h"
Namespace="Base"
Constructor="true"
Delete="true"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Axis
An defines a direction and a position (base) in 3D space.
The following constructors are supported:
Axis() -- empty constructor
Axis(Axis) -- copy constructor
Axis(Base, Direction) -- define position and direction
</UserDocu>
<DeveloperDocu>Axis</DeveloperDocu>
</Documentation>
<Methode Name="copy">>
<Documentation>
<UserDocu>
copy()
Returns a copy of this Axis
</UserDocu>
</Documentation>
</Methode>
<Methode Name="move">
<Documentation>
<UserDocu>
move(Vector)
Move the axis base along the vector
</UserDocu>
</Documentation>
</Methode>
<Methode Name="multiply">
<Documentation>
<UserDocu>
multiply(Placement)
Multiply this axis with a placement
</UserDocu>
</Documentation>
</Methode>
<Methode Name="reversed">
<Documentation>
<UserDocu>
reversed() -> Axis
compute the reversed axis
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Base" ReadOnly="false">
<Documentation>
<UserDocu>Vector to the Base position of the Axis</UserDocu>
</Documentation>
<Parameter Name="Base" Type="Object" />
</Attribute>
<Attribute Name="Direction" ReadOnly="false">
<Documentation>
<UserDocu>Direction vector of the Axis</UserDocu>
</Documentation>
<Parameter Name="Direction" Type="Object" />
</Attribute>
</PythonExport>
</GenerateModel>

147
src/Base/AxisPyImp.cpp Normal file
View File

@ -0,0 +1,147 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel *
* *
* 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., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include "Axis.h"
#include "GeometryPyCXX.h"
// inclusion of the generated files (generated out of AxisPy.xml)
#include "AxisPy.h"
#include "AxisPy.cpp"
#include "VectorPy.h"
#include "PlacementPy.h"
using namespace Base;
// returns a string which represents the object e.g. when printed in python
std::string AxisPy::representation(void) const
{
AxisPy::PointerType ptr = reinterpret_cast<AxisPy::PointerType>(_pcTwinPointer);
std::stringstream str;
str << "Axis [Base=(";
str << ptr->getBase().x << ","<< ptr->getBase().y << "," << ptr->getBase().z;
str << "), Direction=(";
str << ptr->getDirection().x << ","<< ptr->getDirection().y << "," << ptr->getDirection().z << ")]";
return str.str();
}
PyObject *AxisPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of AxisPy and the Twin object
return new AxisPy(new Axis);
}
// constructor method
int AxisPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
PyObject* o;
if (PyArg_ParseTuple(args, "")) {
return 0;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!", &(Base::AxisPy::Type), &o)) {
Base::Axis *a = static_cast<Base::AxisPy*>(o)->getAxisPtr();
*(getAxisPtr()) = *a;
return 0;
}
PyErr_Clear();
PyObject* d;
if (PyArg_ParseTuple(args, "O!O", &(Base::VectorPy::Type), &o,
&(Base::VectorPy::Type), &d)) {
// NOTE: The first parameter defines the base (origin) and the second the direction.
*getAxisPtr() = Base::Axis(static_cast<Base::VectorPy*>(o)->value(),
static_cast<Base::VectorPy*>(d)->value());
return 0;
}
PyErr_SetString(PyExc_Exception, "empty parameter list, axis or base and direction expected");
return -1;
}
PyObject* AxisPy::move(PyObject * args)
{
PyObject *vec;
if (!PyArg_ParseTuple(args, "O!", &(VectorPy::Type), &vec))
return NULL;
getAxisPtr()->move(static_cast<VectorPy*>(vec)->value());
Py_Return;
}
PyObject* AxisPy::multiply(PyObject * args)
{
PyObject *plm;
if (!PyArg_ParseTuple(args, "O!", &(PlacementPy::Type), &plm))
return NULL;
Axis mult = (*getAxisPtr()) * (*static_cast<PlacementPy*>(plm)->getPlacementPtr());
return new AxisPy(new Axis(mult));
}
PyObject* AxisPy::copy(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
return new AxisPy(new Axis(*getAxisPtr()));
}
PyObject* AxisPy::reversed(PyObject * args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
Base::Axis a = getAxisPtr()->reversed();
return new AxisPy(new Axis(a));
}
Py::Object AxisPy::getBase(void) const
{
return Py::Vector(getAxisPtr()->getBase());
}
void AxisPy::setBase(Py::Object arg)
{
getAxisPtr()->setBase(Py::Vector(arg).toVector());
}
Py::Object AxisPy::getDirection(void) const
{
return Py::Vector(getAxisPtr()->getDirection());
}
void AxisPy::setDirection(Py::Object arg)
{
getAxisPtr()->setDirection(Py::Vector(arg).toVector());
}
PyObject *AxisPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int AxisPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@ -61,6 +61,7 @@ generate_from_xml(VectorPy)
generate_from_xml(MatrixPy)
generate_from_xml(RotationPy)
generate_from_xml(PlacementPy)
generate_from_xml(AxisPy)
if(SWIG_FOUND)
execute_process(COMMAND ${SWIG_EXECUTABLE} -python -external-runtime ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h)
@ -137,6 +138,7 @@ SET(pycxx_SRCS
SOURCE_GROUP("pycxx" FILES ${pycxx_SRCS})
SET(FreeCADBase_XML_SRCS
AxisPy.xml
BaseClassPy.xml
BoundBoxPy.xml
MatrixPy.xml
@ -170,6 +172,8 @@ SET(FreeCADBase_UNITAPI_SRCS
SOURCE_GROUP("Units" FILES ${FreeCADBase_UNITAPI_SRCS})
SET(FreeCADBase_CPP_SRCS
Axis.cpp
AxisPyImp.cpp
Base64.cpp
BaseClass.cpp
BaseClassPyImp.cpp
@ -222,6 +226,7 @@ SET(FreeCADBase_CPP_SRCS
)
SET(FreeCADBase_HPP_SRCS
Axis.h
Base64.h
BaseClass.h
BoundBox.h

View File

@ -3,6 +3,7 @@ lib_LTLIBRARIES=libFreeCADBase.la
BUILT_SOURCES=\
moc_FutureWatcherProgress.cpp \
AxisPy.cpp \
BaseClassPy.cpp \
BoundBoxPy.cpp \
MatrixPy.cpp \
@ -17,6 +18,7 @@ endif
libFreeCADBase_la_BUILT=\
AxisPy.h \
BaseClassPy.h \
BoundBoxPy.h \
MatrixPy.h \
@ -26,6 +28,8 @@ libFreeCADBase_la_BUILT=\
VectorPy.h
libFreeCADBase_la_SOURCES=\
Axis.cpp \
AxisPyImp.cpp \
Base64.cpp \
BaseClass.cpp \
BaseClassPyImp.cpp \
@ -103,6 +107,7 @@ nodist_include_HEADERS=\
$(libFreeCADBase_la_BUILT)
include_HEADERS=\
Axis.h \
Base64.h \
BaseClass.h \
BoundBox.h \
@ -177,6 +182,7 @@ libFreeCADBase_la_CPPFLAGS = -DHAVE_SWIG=$(HAVE_SWIG)
EXTRA_DIST = \
CMakeLists.txt \
AxisPy.xml \
BaseClassPy.xml \
BoundBoxPy.xml \
MatrixPy.xml \