Commit 36729159 authored by Jan Möbius's avatar Jan Möbius

Internally cache the number of objects and targets to speed up things

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8427 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9aefc4ea
......@@ -120,6 +120,12 @@ static QGLWidget* shareGLWidget_ = 0;
*/
static int viewerId_ = 0;
/// Number of currently open objects
static int objectCounter_ = 0;
/// Number of current target objects
static int targetCounter_ = 0;
void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root;
}
......@@ -832,30 +838,13 @@ void addObjectRenderingNode(ACG::SceneGraph::BaseNode* _node){
}
int objectCount() {
int count = 0;
// find changed manipulator
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
++count;
}
return ( count );
return(objectCounter_);
}
int targetCount() {
int count = 0;
// find changed manipulator
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
++count;
}
return ( count );
int targetCount() {
return ( targetCounter_ );
}
int sourceCount() {
......@@ -925,4 +914,28 @@ BaseObject*& objectRoot() {
return (objectRoot_);
}
void increaseObjectCount() {
objectCounter_++;
}
// Increase the number of current Object
void decreaseObjectCount() {
objectCounter_--;
if ( objectCounter_ < 0 )
std::cerr << "Deleted more objects than created!!!" << std::endl;
}
void increaseTargetCount() {
targetCounter_++;
}
// Increase the number of current Object
void decreaseTargetCount() {
targetCounter_--;
if ( targetCounter_ < 0 )
std::cerr << "target object counter underflow!!!" << std::endl;
}
}
......@@ -93,6 +93,29 @@ void setDataSeparatorNodes( SeparatorNode* _dataRootNode );
/** @} */
//=======================================
// Handle object count internally
/** @name Internal Counters
* @{ */
//=======================================
/// Decrease the number of current Object
DLLEXPORT
void increaseObjectCount();
/// Increase the number of current Object
DLLEXPORT
void decreaseObjectCount();
/// Decrease the number of current Object
DLLEXPORT
void increaseTargetCount();
/// Increase the number of current Object
DLLEXPORT
void decreaseTargetCount();
/** @} */
}
#endif //PLUGINFUNCTIONSCORE_HH
......@@ -213,6 +213,8 @@ Core::init() {
// Bring up the object manager ( has to be done after the rootobject is created)
connect(getObjectManager(),SIGNAL(newObject(int)), this ,SLOT(newObject(int)));
connect(getObjectManager(),SIGNAL(deletedObject(int)), this ,SLOT(deletedObject(int)));
if ( OpenFlipper::Options::gui() ) {
......
......@@ -60,7 +60,7 @@
#include "OpenFlipper/BasePlugin/ToolboxInterface.hh"
#include "OpenFlipper/BasePlugin/TextureInterface.hh"
#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/BasePlugin/PluginFunctionsCore.hh"
//== IMPLEMENTATION ==========================================================
......@@ -326,19 +326,6 @@ void Core::newObject(int _objectId) {
/// This slot is called by the object manager when a object is deleted
void Core::deletedObject(int _objectId) {
// BaseObject* baseObject = 0;
// PluginFunctions::getObject(_objectId,baseObject);
//
// if ( baseObject ) {
// connect( baseObject, SIGNAL(visibilityChanged(int)), this, SLOT(slotVisibilityChanged(int)), Qt::DirectConnection) ;
// connect( baseObject, SIGNAL(objectSelectionChanged(int)), this, SLOT(slotObjectSelectionChanged(int)), Qt::DirectConnection );
// connect( baseObject, SIGNAL(objectPropertiesChanged(int)), this, SLOT(slotObjectPropertiesChanged(int)), Qt::DirectConnection );
// } else {
// emit log(LOGERR,tr("newObject received from objectManager with invalid id! This should not happen. The new Object will not work correctly!"));
// }
//
emit log(LOGERR,tr("deletedObject received from objectManager!"));
}
......
......@@ -557,6 +557,7 @@ void Core::slotObjectOpened ( int _id ) {
/// Slot gets called after a file-plugin has opened an object
void Core::slotEmptyObjectAdded ( int _id ) {
if ( OpenFlipper::Options::doSlotDebugging() ) {
if ( sender() != 0 ) {
if ( sender()->metaObject() != 0 ) {
......@@ -572,6 +573,7 @@ void Core::slotEmptyObjectAdded ( int _id ) {
BaseObjectData* object;
PluginFunctions::getObject(_id,object);
emit emptyObjectAdded( _id );
// Tell the Plugins that the Object List and the active object have changed
......
......@@ -56,6 +56,7 @@
#include "BaseObjectCore.hh"
#include "Types.hh"
#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
......@@ -106,6 +107,7 @@ BaseObject::BaseObject(const BaseObject& _object) :
if ( PluginFunctions::objectRoot() ) {
setParent(PluginFunctions::objectRoot());
PluginFunctions::objectRoot()->appendChild(this);
PluginFunctions::increaseObjectCount();
}
objectManager_.objectCreated(id());
......@@ -124,16 +126,18 @@ BaseObject::BaseObject(BaseObject* _parent) :
id_ = idGenerator;
++ idGenerator;
// If the pointer is 0 then something went wrong
// If the pointer is 0 then something went wrong or we are the root node
if ( _parent ) {
_parent->appendChild(this);
PluginFunctions::increaseObjectCount();
} else {
if ( PluginFunctions::objectRoot() ) {
setParent(PluginFunctions::objectRoot());
PluginFunctions::objectRoot()->appendChild(this);
PluginFunctions::increaseObjectCount();
}
}
......@@ -145,6 +149,10 @@ BaseObject::BaseObject(BaseObject* _parent) :
BaseObject::~BaseObject() {
deleteData();
PluginFunctions::decreaseObjectCount();
objectManager_.objectDeleted(id());
}
......@@ -240,7 +248,16 @@ bool BaseObject::target() {
}
void BaseObject::target(bool _target) {
if ( target() != _target ) {
if ( _target )
PluginFunctions::increaseTargetCount();
else
PluginFunctions::decreaseTargetCount();
}
setFlag("target", _target);
}
bool BaseObject::source() {
......@@ -248,7 +265,9 @@ bool BaseObject::source() {
}
void BaseObject::source(bool _source) {
setFlag("source", _source);
if ( source() != _source ) {
setFlag("source", _source);
}
}
bool BaseObject::flag(QString _flag)
......@@ -776,6 +795,12 @@ void ObjectManager::objectCreated(int _objectId)
emit newObject(_objectId);
}
void ObjectManager::objectDeleted(int _objectId)
{
emit deletedObject(_objectId);
}
ObjectManager* getObjectManager() {
return &objectManager_;
}
......
......@@ -68,11 +68,17 @@ class DLLEXPORT ObjectManager : public QObject {
signals:
void newObject( int _objectId );
void deletedObject( int _objectId );
public:
ObjectManager();
~ObjectManager();
// called when an object has been created
void objectCreated( int _objectId );
// called when an object has been deleted
void objectDeleted( int _objectId );
};
DLLEXPORT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment