Commit 3c723680 authored by Inge Wallin's avatar Inge Wallin

Separate out classes Item and ObjectErrors too from world.[h,cc]

parent f1f5576f
......@@ -2,7 +2,9 @@
set(stepcore_SRCS
object.cc
constants.cc
item.cc
body.cc
objecterrors.cc
world.cc
solver.cc
collisionsolver.cc
......
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -16,8 +17,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** \file world.h
* \brief Item, Body, Force and Tool interfaces, World class
/** \file body.h
* \brief Contains the Body object.
*/
#ifndef STEPCORE_BODY_H
......
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
StepCore 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "objecterrors.h"
#include "item.h"
namespace StepCore
{
STEPCORE_META_OBJECT(Item, QT_TRANSLATE_NOOP("ObjectClass", "Item"), QT_TR_NOOP("Item"),
MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object),
STEPCORE_PROPERTY_RW(StepCore::Color, color, QT_TRANSLATE_NOOP("PropertyName", "color"),
STEPCORE_UNITS_NULL, QT_TR_NOOP("Item color"), color, setColor))
Item& Item::operator=(const Item& item)
{
Object::operator=(item);
_world = item._world;
_group = item._group;
if(item._objectErrors) {
_objectErrors = static_cast<ObjectErrors*>(
item._objectErrors->metaObject()->cloneObject(*item._objectErrors) );
_objectErrors->setOwner(this);
} else {
_objectErrors = NULL;
}
_color = item._color;
return *this;
}
ObjectErrors* Item::objectErrors()
{
if(!_objectErrors) _objectErrors = createObjectErrors();
return _objectErrors;
}
} // namespace StepCore
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
StepCore 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** \file item.h
* \brief Contains the Ítem object.
*/
#ifndef STEPCORE_ITEM_H
#define STEPCORE_ITEM_H
#include <vector> // XXX: Replace if Qt is enabled.
#include "types.h"
#include "object.h"
#include "objecterrors.h"
namespace StepCore
{
class World;
class ItemGroup;
/** \ingroup world
* \brief The root class for any world items (bodies and forces)
*/
class Item : public Object
{
/*Q_OBJECT*/
STEPCORE_OBJECT(Item)
public:
/** Constructs Item */
Item(const QString& name = QString())
: Object(name), _world(NULL), _group(NULL),
_objectErrors(NULL), _color(0xff000000) {}
/** Constructs a copy of item */
Item(const Item& item) : Object() { *this = item; }
/** Destroys Item */
virtual ~Item() { delete _objectErrors; }
/** Assignment operator (copies objectErrors if necessary) */
Item& operator=(const Item& item);
/** Set/change pointer to World in which this object lives */
virtual void setWorld(World* world) { _world = world; }
/** Get pointer to World in which this object lives */
World* world() const { return _world; }
/** Set/change pointer to ItemGroup in which this object lives */
virtual void setGroup(ItemGroup* group) { _group = group; }
/** Get pointer to ItemGroup in which this object lives */
ItemGroup* group() const { return _group; }
/** Get ObjectErrors only if it already exists */
ObjectErrors* tryGetObjectErrors() const { return _objectErrors; }
/** Get existing ObjectErrors or try to create it */
ObjectErrors* objectErrors();
/** Delete objectErrors */
void deleteObjectErrors() { delete _objectErrors; _objectErrors = NULL; }
/** Get item color (for use in GUI) */
Color color() const { return _color; }
/** Set item color (for use in GUI) */
void setColor(Color color) { _color = color; }
/** Called by the World when any item is about to be removed
* from the world
* \param item Pointer to item about to be removed
* \todo XXX rename
*/
virtual void worldItemRemoved(Item* item STEPCORE_UNUSED) {}
protected:
/** \internal Creates specific ObjectErrors-derived class
* (to be reimplemented in derived classes) */
virtual ObjectErrors* createObjectErrors() { return NULL; } // XXX: rename to createObjectVariances
private:
World* _world;
ItemGroup* _group;
ObjectErrors* _objectErrors;
Color _color;
};
/** List of pointers to Item */
typedef std::vector<Item*> ItemList;
} // namespace StepCore
#endif
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
StepCore 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "objecterrors.h"
namespace StepCore
{
STEPCORE_META_OBJECT(ObjectErrors, QT_TRANSLATE_NOOP("ObjectClass", "ObjectErrors"), QT_TR_NOOP("ObjectErrors"),
MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object),)
} // namespace StepCore
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se>
StepCore library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
StepCore 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** \file objecterrors.h
* \brief Contains the Objecterrors object.
*/
#ifndef STEPCORE_OBJECTERRORS_H
#define STEPCORE_OBJECTERRORS_H
#include <vector> // XXX: Replace if Qt is enabled.
#include "types.h"
#include "object.h"
namespace StepCore
{
class Item;
/** \ingroup errors
* \brief Base class for all errors objects
*/
class ObjectErrors: public Object
{
STEPCORE_OBJECT(ObjectErrors)
public:
/** Constructs ObjectErrors */
ObjectErrors(Item* owner = NULL): _owner(owner) {}
/** Get the owner of ObjectErrors */
Item* owner() const { return _owner; }
/** Set the owner of ObjectErrors */
void setOwner(Item* owner) { _owner = owner; }
private:
Item* _owner;
};
} // namespace StepCore
#endif
......@@ -27,14 +27,10 @@
namespace StepCore
{
STEPCORE_META_OBJECT(Item, QT_TRANSLATE_NOOP("ObjectClass", "Item"), QT_TR_NOOP("Item"), MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object),
STEPCORE_PROPERTY_RW(StepCore::Color, color, QT_TRANSLATE_NOOP("PropertyName", "color"), STEPCORE_UNITS_NULL, QT_TR_NOOP("Item color"), color, setColor))
STEPCORE_META_OBJECT(Force, QT_TRANSLATE_NOOP("ObjectClass", "Force"), QT_TR_NOOP("Force"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(Joint, QT_TRANSLATE_NOOP("ObjectClass", "Joint"), QT_TR_NOOP("Joint"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(Tool, QT_TRANSLATE_NOOP("ObjectClass", "Tool"), QT_TR_NOOP("Tool"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(ObjectErrors, QT_TRANSLATE_NOOP("ObjectClass", "ObjectErrors"), QT_TR_NOOP("ObjectErrors"), MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object),)
STEPCORE_META_OBJECT(ItemGroup, QT_TRANSLATE_NOOP("ObjectClass", "ItemGroup"), QT_TR_NOOP("ItemGroup"), 0, STEPCORE_SUPER_CLASS(Item),)
STEPCORE_META_OBJECT(World, QT_TRANSLATE_NOOP("ObjectClass", "World"), QT_TR_NOOP("World"), 0, STEPCORE_SUPER_CLASS(ItemGroup),
......@@ -43,32 +39,6 @@ STEPCORE_META_OBJECT(World, QT_TRANSLATE_NOOP("ObjectClass", "World"), QT_TR_NOO
STEPCORE_PROPERTY_RW (bool, errorsCalculation, QT_TR_NOOP("errorsCalculation"), STEPCORE_UNITS_NULL,
QT_TR_NOOP("Enable global error calculation"), errorsCalculation, setErrorsCalculation))
Item& Item::operator=(const Item& item)
{
Object::operator=(item);
_world = item._world;
_group = item._group;
if(item._objectErrors) {
_objectErrors = static_cast<ObjectErrors*>(
item._objectErrors->metaObject()->cloneObject(*item._objectErrors) );
_objectErrors->setOwner(this);
} else {
_objectErrors = NULL;
}
_color = item._color;
return *this;
}
ObjectErrors* Item::objectErrors()
{
if(!_objectErrors) _objectErrors = createObjectErrors();
return _objectErrors;
}
ItemGroup::ItemGroup(const ItemGroup& group)
: Item()
{
......
......@@ -26,7 +26,9 @@
#include "types.h"
#include "util.h"
#include "object.h"
#include "item.h"
#include "body.h"
#include "vector.h"
#include <vector> // XXX: replace if QT is enabled
......@@ -44,93 +46,6 @@ class ItemGroup;
class CollisionSolver;
class ConstraintSolver;
/** \ingroup errors
* \brief Base class for all errors objects
*/
class ObjectErrors: public Object
{
STEPCORE_OBJECT(ObjectErrors)
public:
/** Constructs ObjectErrors */
ObjectErrors(Item* owner = NULL): _owner(owner) {}
/** Get the owner of ObjectErrors */
Item* owner() const { return _owner; }
/** Set the owner of ObjectErrors */
void setOwner(Item* owner) { _owner = owner; }
private:
Item* _owner;
};
/** \ingroup world
* \brief The root class for any world items (bodies and forces)
*/
class Item : public Object
{
/*Q_OBJECT*/
STEPCORE_OBJECT(Item)
public:
/** Constructs Item */
Item(const QString& name = QString())
: Object(name), _world(NULL), _group(NULL),
_objectErrors(NULL), _color(0xff000000) {}
/** Constructs a copy of item */
Item(const Item& item) : Object() { *this = item; }
/** Destroys Item */
virtual ~Item() { delete _objectErrors; }
/** Assignment operator (copies objectErrors if necessary) */
Item& operator=(const Item& item);
/** Set/change pointer to World in which this object lives */
virtual void setWorld(World* world) { _world = world; }
/** Get pointer to World in which this object lives */
World* world() const { return _world; }
/** Set/change pointer to ItemGroup in which this object lives */
virtual void setGroup(ItemGroup* group) { _group = group; }
/** Get pointer to ItemGroup in which this object lives */
ItemGroup* group() const { return _group; }
/** Get ObjectErrors only if it already exists */
ObjectErrors* tryGetObjectErrors() const { return _objectErrors; }
/** Get existing ObjectErrors or try to create it */
ObjectErrors* objectErrors();
/** Delete objectErrors */
void deleteObjectErrors() { delete _objectErrors; _objectErrors = NULL; }
/** Get item color (for use in GUI) */
Color color() const { return _color; }
/** Set item color (for use in GUI) */
void setColor(Color color) { _color = color; }
/** Called by the World when any item is about to be removed
* from the world
* \param item Pointer to item about to be removed
* \todo XXX rename
*/
virtual void worldItemRemoved(Item* item STEPCORE_UNUSED) {}
protected:
/** \internal Creates specific ObjectErrors-derived class
* (to be reimplemented in derived classes) */
virtual ObjectErrors* createObjectErrors() { return NULL; } // XXX: rename to createObjectVariances
private:
World* _world;
ItemGroup* _group;
ObjectErrors* _objectErrors;
Color _color;
};
/** \ingroup forces
* \brief Interface for forces
*
......@@ -234,8 +149,6 @@ public:
virtual ~Tool() {}
};
/** List of pointers to Item */
typedef std::vector<Item*> ItemList;
/** List of pointers to Force */
typedef std::vector<Force*> ForceList;
/** List of pointers to Joint */
......
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