Add utility class to better debug algorithms
This commit is contained in:
parent
0d351e98e2
commit
1859ec2559
|
@ -152,6 +152,7 @@ SET(FreeCADBase_XML_SRCS
|
||||||
SOURCE_GROUP("XML" FILES ${FreeCADBase_XML_SRCS})
|
SOURCE_GROUP("XML" FILES ${FreeCADBase_XML_SRCS})
|
||||||
|
|
||||||
set(FreeCADBase_MOC_HDRS
|
set(FreeCADBase_MOC_HDRS
|
||||||
|
Debugger.h
|
||||||
FutureWatcherProgress.h
|
FutureWatcherProgress.h
|
||||||
)
|
)
|
||||||
fc_wrap_cpp(FreeCADBase_MOC_SRCS ${FreeCADBase_MOC_HDRS})
|
fc_wrap_cpp(FreeCADBase_MOC_SRCS ${FreeCADBase_MOC_HDRS})
|
||||||
|
@ -182,6 +183,7 @@ SET(FreeCADBase_CPP_SRCS
|
||||||
BoundBoxPyImp.cpp
|
BoundBoxPyImp.cpp
|
||||||
Builder3D.cpp
|
Builder3D.cpp
|
||||||
Console.cpp
|
Console.cpp
|
||||||
|
Debugger.cpp
|
||||||
Exception.cpp
|
Exception.cpp
|
||||||
Factory.cpp
|
Factory.cpp
|
||||||
FileInfo.cpp
|
FileInfo.cpp
|
||||||
|
@ -234,6 +236,7 @@ SET(FreeCADBase_HPP_SRCS
|
||||||
BoundBox.h
|
BoundBox.h
|
||||||
Builder3D.h
|
Builder3D.h
|
||||||
Console.h
|
Console.h
|
||||||
|
Debugger.h
|
||||||
Exception.h
|
Exception.h
|
||||||
Factory.h
|
Factory.h
|
||||||
FileInfo.h
|
FileInfo.h
|
||||||
|
|
80
src/Base/Debugger.cpp
Normal file
80
src/Base/Debugger.cpp
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2012 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"
|
||||||
|
#ifndef _PreComp_
|
||||||
|
# include <QCoreApplication>
|
||||||
|
# include <QEvent>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Debugger.h"
|
||||||
|
#include "Console.h"
|
||||||
|
|
||||||
|
using namespace Base;
|
||||||
|
|
||||||
|
Debugger::Debugger(QObject* parent)
|
||||||
|
: QObject(parent), isAttached(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Debugger::~Debugger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::attach()
|
||||||
|
{
|
||||||
|
QCoreApplication::instance()->installEventFilter(this);
|
||||||
|
isAttached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::detach()
|
||||||
|
{
|
||||||
|
QCoreApplication::instance()->removeEventFilter(this);
|
||||||
|
isAttached = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Debugger::eventFilter(QObject*, QEvent* event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::KeyPress) {
|
||||||
|
if (loop.isRunning()) {
|
||||||
|
loop.quit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Debugger::exec()
|
||||||
|
{
|
||||||
|
if (isAttached)
|
||||||
|
Base::Console().Message("TO CONTINUE PRESS ANY KEY...\n");
|
||||||
|
return loop.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Debugger::quit()
|
||||||
|
{
|
||||||
|
loop.quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_Debugger.cpp"
|
76
src/Base/Debugger.h
Normal file
76
src/Base/Debugger.h
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2012 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 *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BASE_DEBUGGER_H
|
||||||
|
#define BASE_DEBUGGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
|
namespace Base {
|
||||||
|
/**
|
||||||
|
This is a utility class to break the application at a point to inspect e.g. the result of
|
||||||
|
an algorithm.
|
||||||
|
You usually use it like this
|
||||||
|
\code
|
||||||
|
...
|
||||||
|
Base::Debugger dbg;
|
||||||
|
dbg.attach();
|
||||||
|
dbg.exec();
|
||||||
|
...
|
||||||
|
\endcode
|
||||||
|
Or you can connect it with a button and let the user click it in order to continue.
|
||||||
|
\code
|
||||||
|
QPushButton* btn = new QPushButton();
|
||||||
|
btn->setText("Continue");
|
||||||
|
btn->show();
|
||||||
|
Base::Debugger dbg;
|
||||||
|
connect(btn, SIGNAL(clicked()), &dbg, SLOT(quit()));
|
||||||
|
dbg.exec();
|
||||||
|
\endcode
|
||||||
|
\author Werner Mayer
|
||||||
|
*/
|
||||||
|
class BaseExport Debugger : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Debugger(QObject* parent=0);
|
||||||
|
~Debugger();
|
||||||
|
|
||||||
|
void attach();
|
||||||
|
void detach();
|
||||||
|
bool eventFilter(QObject*, QEvent*);
|
||||||
|
int exec();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void quit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isAttached;
|
||||||
|
QEventLoop loop;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BASE_DEBUGGER_H
|
|
@ -105,6 +105,8 @@
|
||||||
// QtCore
|
// QtCore
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QEvent>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QWriteLocker>
|
#include <QWriteLocker>
|
||||||
|
|
|
@ -255,6 +255,17 @@ float MeshAlgorithm::GetAverageEdgeLength() const
|
||||||
return fLen;
|
return fLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Base::Vector3f MeshAlgorithm::GetGravityPoint() const
|
||||||
|
{
|
||||||
|
Base::Vector3f center;
|
||||||
|
MeshPointIterator cP(_rclMesh);
|
||||||
|
for (cP.Init(); cP.More(); cP.Next()) {
|
||||||
|
center += *cP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return center / (float)_rclMesh.CountPoints();
|
||||||
|
}
|
||||||
|
|
||||||
void MeshAlgorithm::GetMeshBorders (std::list<std::vector<Base::Vector3f> > &rclBorders) const
|
void MeshAlgorithm::GetMeshBorders (std::list<std::vector<Base::Vector3f> > &rclBorders) const
|
||||||
{
|
{
|
||||||
std::vector<unsigned long> aulAllFacets(_rclMesh.CountFacets());
|
std::vector<unsigned long> aulAllFacets(_rclMesh.CountFacets());
|
||||||
|
|
|
@ -115,6 +115,10 @@ public:
|
||||||
* Calculates the average length of edges.
|
* Calculates the average length of edges.
|
||||||
*/
|
*/
|
||||||
float GetAverageEdgeLength() const;
|
float GetAverageEdgeLength() const;
|
||||||
|
/**
|
||||||
|
* Calculates the gravity point of the mesh.
|
||||||
|
*/
|
||||||
|
Base::Vector3f GetGravityPoint() const;
|
||||||
/**
|
/**
|
||||||
* Returns all boundaries of the mesh.
|
* Returns all boundaries of the mesh.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user