1 /* This file is part of Step. 2 Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 3 4 Step is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 Step is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Step; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef STEP_POLYGONGRAPHICS_H 20 #define STEP_POLYGONGRAPHICS_H 21 22 /*+++++++++ XXX +++++++++++ 23 * This need to be redone 24 */ 25 26 #include "worldgraphics.h" 27 #include "stepgraphicsitem.h" 28 29 #include <QPainterPath> 30 31 namespace StepCore { 32 class RigidBody; 33 class Disk; 34 class BasePolygon; 35 class Polygon; 36 class Box; 37 } 38 39 ///////////////////////////////////////////////////////////////////////////////////////// 40 41 class RigidBodyGraphicsItem : public StepGraphicsItem 42 { 43 public: 44 RigidBodyGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 45 46 QPainterPath shape() const override; 47 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 48 49 void viewScaleChanged() override; 50 void stateChanged() override; 51 void worldDataChanged(bool dynamicOnly) override; 52 53 protected: 54 StepCore::RigidBody* rigidBody() const; 55 QPainterPath _painterPath; 56 QPainterPath _markPath; 57 58 ArrowHandlerGraphicsItem* _velocityHandler; 59 CircularArrowHandlerGraphicsItem* _angularVelocityHandler; 60 CircularArrowHandlerGraphicsItem* _angleHandler; 61 }; 62 63 ///////////////////////////////////////////////////////////////////////////////////////// 64 65 class DiskCreator: public ItemCreator 66 { 67 public: DiskCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)68 DiskCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 69 : ItemCreator(className, worldModel, worldScene) {} 70 bool sceneEvent(QEvent* event) override; 71 void start() override; 72 }; 73 74 class DiskVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem 75 { 76 Q_OBJECT 77 78 public: DiskVertexHandlerGraphicsItem(StepCore::Item * item,WorldModel * worldModel,QGraphicsItem * parent,int vertexNum)79 DiskVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel, 80 QGraphicsItem* parent, int vertexNum) 81 : OnHoverHandlerGraphicsItem(item, worldModel, parent, NULL, NULL, vertexNum) {} 82 83 protected: 84 StepCore::Disk* disk() const; 85 StepCore::Vector2d value() override; 86 void setValue(const StepCore::Vector2d& value) override; 87 }; 88 89 class DiskGraphicsItem: public RigidBodyGraphicsItem 90 { 91 public: 92 DiskGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 93 void viewScaleChanged() override; 94 95 protected: 96 OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override; 97 StepCore::Disk* disk() const; 98 }; 99 100 ///////////////////////////////////////////////////////////////////////////////////////// 101 102 class BasePolygonGraphicsItem: public RigidBodyGraphicsItem 103 { 104 public: 105 BasePolygonGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 106 void viewScaleChanged() override; 107 108 protected: 109 StepCore::BasePolygon* basePolygon() const; 110 }; 111 112 ///////////////////////////////////////////////////////////////////////////////////////// 113 114 class BoxCreator: public ItemCreator 115 { 116 public: BoxCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)117 BoxCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 118 : ItemCreator(className, worldModel, worldScene) {} 119 bool sceneEvent(QEvent* event) override; 120 void start() override; 121 122 protected: 123 StepCore::Vector2d _topLeft; 124 125 public: 126 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 127 }; 128 129 class BoxVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem 130 { 131 Q_OBJECT 132 133 public: BoxVertexHandlerGraphicsItem(StepCore::Item * item,WorldModel * worldModel,QGraphicsItem * parent,int vertexNum)134 BoxVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel, 135 QGraphicsItem* parent, int vertexNum) 136 : OnHoverHandlerGraphicsItem(item, worldModel, parent, NULL, NULL, vertexNum) {} 137 138 protected: 139 StepCore::Box* box() const; 140 StepCore::Vector2d value() override; 141 void setValue(const StepCore::Vector2d& value) override; 142 }; 143 144 class BoxGraphicsItem: public BasePolygonGraphicsItem 145 { 146 public: BoxGraphicsItem(StepCore::Item * item,WorldModel * worldModel)147 BoxGraphicsItem(StepCore::Item* item, WorldModel* worldModel) 148 : BasePolygonGraphicsItem(item, worldModel) {} 149 150 protected: 151 OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override; 152 }; 153 154 ///////////////////////////////////////////////////////////////////////////////////////// 155 156 class PolygonCreator: public ItemCreator 157 { 158 public: PolygonCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)159 PolygonCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 160 : ItemCreator(className, worldModel, worldScene) {} 161 bool sceneEvent(QEvent* event) override; 162 void start() override; 163 164 protected: 165 void fixCenterOfMass(); 166 void fixInertia(); 167 }; 168 169 class PolygonVertexHandlerGraphicsItem: public OnHoverHandlerGraphicsItem 170 { 171 Q_OBJECT 172 173 public: PolygonVertexHandlerGraphicsItem(StepCore::Item * item,WorldModel * worldModel,QGraphicsItem * parent,int vertexNum)174 PolygonVertexHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel, 175 QGraphicsItem* parent, int vertexNum) 176 : OnHoverHandlerGraphicsItem(item, worldModel, parent, NULL, NULL, vertexNum) {} 177 178 protected: 179 StepCore::Polygon* polygon() const; 180 StepCore::Vector2d value() override; 181 void setValue(const StepCore::Vector2d& value) override; 182 }; 183 184 class PolygonGraphicsItem: public BasePolygonGraphicsItem 185 { 186 public: PolygonGraphicsItem(StepCore::Item * item,WorldModel * worldModel)187 PolygonGraphicsItem(StepCore::Item* item, WorldModel* worldModel) 188 : BasePolygonGraphicsItem(item, worldModel) {} 189 190 static void changePolygonVertex(WorldModel* worldModel, StepCore::Item* item, 191 int vertexNum, const StepCore::Vector2d& value); 192 193 protected: 194 OnHoverHandlerGraphicsItem* createOnHoverHandler(const QPointF& pos) override; 195 StepCore::Polygon* polygon() const; 196 }; 197 198 199 200 #endif 201 202