File indexing completed on 2024-10-13 06:32:54
0001 /* 0002 SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 0003 SPDX-FileCopyrightText: 2014 Inge Wallin <inge@lysator.liu.se> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 /** \file item.h 0009 * \brief Contains the Item object. 0010 */ 0011 0012 #ifndef STEPCORE_ITEM_H 0013 #define STEPCORE_ITEM_H 0014 0015 0016 #include <vector> // XXX: Replace if Qt is enabled. 0017 0018 #include "types.h" 0019 #include "object.h" 0020 #include "objecterrors.h" 0021 0022 0023 namespace StepCore 0024 { 0025 0026 class World; 0027 class ItemGroup; 0028 0029 /** \ingroup world 0030 * \brief The root class for any world items (bodies and forces) 0031 */ 0032 class Item : public Object 0033 { 0034 /*Q_OBJECT*/ 0035 STEPCORE_OBJECT(Item) 0036 0037 public: 0038 /** Constructs Item */ 0039 explicit Item(const QString& name = QString()) 0040 : Object(name) 0041 , _world(nullptr) 0042 , _group(nullptr) 0043 , _objectErrors(nullptr) 0044 , _color(0xff000000) {} 0045 /** Constructs a copy of item */ 0046 Item(const Item& item) : Object() { *this = item; } 0047 /** Destroys Item */ 0048 virtual ~Item() { delete _objectErrors; } 0049 0050 /** Assignment operator (copies objectErrors if necessary) */ 0051 Item& operator=(const Item& item); 0052 0053 /** Set/change pointer to World in which this object lives */ 0054 virtual void setWorld(World* world) { _world = world; } 0055 0056 /** Get pointer to World in which this object lives */ 0057 World* world() const { return _world; } 0058 0059 /** Set/change pointer to ItemGroup in which this object lives */ 0060 virtual void setGroup(ItemGroup* group) { _group = group; } 0061 0062 /** Get pointer to ItemGroup in which this object lives */ 0063 ItemGroup* group() const { return _group; } 0064 0065 /** Get ObjectErrors only if it already exists */ 0066 ObjectErrors* tryGetObjectErrors() const { return _objectErrors; } 0067 0068 /** Get existing ObjectErrors or try to create it */ 0069 ObjectErrors* objectErrors(); 0070 0071 /** Delete objectErrors */ 0072 void deleteObjectErrors() { delete _objectErrors; _objectErrors = nullptr; } 0073 0074 /** Get item color (for use in GUI) */ 0075 Color color() const { return _color; } 0076 0077 /** Set item color (for use in GUI) */ 0078 void setColor(Color color) { _color = color; } 0079 0080 /** Called by the World when any item is about to be removed 0081 * from the world 0082 * \param item Pointer to item about to be removed 0083 * \todo XXX rename 0084 */ 0085 virtual void worldItemRemoved(Item* item STEPCORE_UNUSED) {} 0086 0087 protected: 0088 /** \internal Creates specific ObjectErrors-derived class 0089 * (to be reimplemented in derived classes) */ 0090 virtual ObjectErrors* createObjectErrors() { return nullptr; } // XXX: rename to createObjectVariances 0091 0092 private: 0093 World* _world; 0094 ItemGroup* _group; 0095 ObjectErrors* _objectErrors; 0096 Color _color; 0097 }; 0098 0099 0100 /** List of pointers to Item */ 0101 typedef std::vector<Item*> ItemList; 0102 0103 0104 } // namespace StepCore 0105 0106 0107 #endif