File indexing completed on 2024-04-28 03:51:18

0001 /*.
0002     SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef STEP_POLYGONGRAPHICS_H
0008 #define STEP_POLYGONGRAPHICS_H
0009 
0010 /*+++++++++ XXX +++++++++++
0011  * This need to be redone
0012  */
0013 
0014 #include "worldgraphics.h"
0015 #include "stepgraphicsitem.h"
0016 
0017 #include <QPainterPath>
0018 
0019 namespace StepCore {
0020     class RigidBody;
0021     class Disk;
0022     class BasePolygon;
0023     class Polygon;
0024     class Box;
0025 }
0026 
0027 /////////////////////////////////////////////////////////////////////////////////////////
0028 
0029 class RigidBodyGraphicsItem : public StepGraphicsItem
0030 {
0031 public:
0032     RigidBodyGraphicsItem(StepCore::Item* item, WorldModel* worldModel);
0033 
0034     QPainterPath shape() const override;
0035     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0036 
0037     void viewScaleChanged() override;
0038     void stateChanged() override;
0039     void worldDataChanged(bool dynamicOnly) override;
0040 
0041 protected:
0042     StepCore::RigidBody* rigidBody() const;
0043     QPainterPath _painterPath;
0044     QPainterPath _markPath;
0045 
0046     ArrowHandlerGraphicsItem*         _velocityHandler;
0047     CircularArrowHandlerGraphicsItem* _angularVelocityHandler;
0048     CircularArrowHandlerGraphicsItem* _angleHandler;
0049 };
0050 
0051 /////////////////////////////////////////////////////////////////////////////////////////
0052 
0053 class DiskCreator: public ItemCreator
0054 {
0055 public:
0056     DiskCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene)
0057                         : ItemCreator(className, worldModel, worldScene) {}
0058     bool sceneEvent(QEvent* event) override;
0059     void start() override;
0060 };
0061 
0062 class DiskVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     DiskVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel,
0068                                         QGraphicsItem* parent, int vertexNum)
0069         : OnHoverHandlerGraphicsItem(item, worldModel, parent, nullptr, nullptr, vertexNum) {}
0070 
0071 protected:
0072     StepCore::Disk* disk() const;
0073     StepCore::Vector2d value() override;
0074     void setValue(const StepCore::Vector2d& value) override;
0075 };
0076 
0077 class DiskGraphicsItem: public RigidBodyGraphicsItem
0078 {
0079 public:
0080     DiskGraphicsItem(StepCore::Item* item, WorldModel* worldModel);
0081     void viewScaleChanged() override;
0082 
0083 protected:
0084     OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override;
0085     StepCore::Disk* disk() const;
0086 };
0087 
0088 /////////////////////////////////////////////////////////////////////////////////////////
0089 
0090 class BasePolygonGraphicsItem: public RigidBodyGraphicsItem
0091 {
0092 public:
0093     BasePolygonGraphicsItem(StepCore::Item* item, WorldModel* worldModel);
0094     void viewScaleChanged() override;
0095 
0096 protected:
0097     StepCore::BasePolygon* basePolygon() const;
0098 };
0099 
0100 /////////////////////////////////////////////////////////////////////////////////////////
0101 
0102 class BoxCreator: public ItemCreator
0103 {
0104 public:
0105     BoxCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene)
0106                         : ItemCreator(className, worldModel, worldScene) {}
0107     bool sceneEvent(QEvent* event) override;
0108     void start() override;
0109 
0110 protected:
0111     StepCore::Vector2d _topLeft;
0112 
0113 public:
0114     EIGEN_MAKE_ALIGNED_OPERATOR_NEW
0115 };
0116 
0117 class BoxVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem
0118 {
0119     Q_OBJECT
0120 
0121 public:
0122     BoxVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel,
0123                                         QGraphicsItem* parent, int vertexNum)
0124         : OnHoverHandlerGraphicsItem(item, worldModel, parent, nullptr, nullptr, vertexNum) {}
0125 
0126 protected:
0127     StepCore::Box* box() const;
0128     StepCore::Vector2d value() override;
0129     void setValue(const StepCore::Vector2d& value) override;
0130 };
0131 
0132 class BoxGraphicsItem: public BasePolygonGraphicsItem
0133 {
0134 public:
0135     BoxGraphicsItem(StepCore::Item* item, WorldModel* worldModel)
0136         : BasePolygonGraphicsItem(item, worldModel) {}
0137 
0138 protected:
0139     OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override;
0140 };
0141 
0142 /////////////////////////////////////////////////////////////////////////////////////////
0143 
0144 class PolygonCreator: public ItemCreator
0145 {
0146 public:
0147     PolygonCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene)
0148                         : ItemCreator(className, worldModel, worldScene) {}
0149     bool sceneEvent(QEvent* event) override;
0150     void start() override;
0151 
0152 protected:
0153     void fixCenterOfMass();
0154     void fixInertia();
0155 };
0156 
0157 class PolygonVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem
0158 {
0159     Q_OBJECT
0160 
0161 public:
0162     PolygonVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel,
0163                                         QGraphicsItem* parent, int vertexNum)
0164         : OnHoverHandlerGraphicsItem(item, worldModel, parent, nullptr, nullptr, vertexNum) {}
0165 
0166 protected:
0167     StepCore::Polygon* polygon() const;
0168     StepCore::Vector2d value() override;
0169     void setValue(const StepCore::Vector2d& value) override;
0170 };
0171 
0172 class PolygonGraphicsItem: public BasePolygonGraphicsItem
0173 {
0174 public:
0175     PolygonGraphicsItem(StepCore::Item* item, WorldModel* worldModel)
0176         : BasePolygonGraphicsItem(item, worldModel) {}
0177 
0178     static void changePolygonVertex(WorldModel* worldModel, StepCore::Item* item,
0179                                 int vertexNum, const StepCore::Vector2d& value);
0180 
0181 protected:
0182     OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override;
0183     StepCore::Polygon* polygon() const;
0184 };
0185 
0186 
0187 
0188 #endif
0189