1 /* This file is part of Step. 2 Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 3 Copyright (C) 2014 Inge Wallin <inge@lysator.liu.se> 4 5 Step is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 Step is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with Step; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 #ifndef STEP_SOFTBODYGRAPHICS_H 21 #define STEP_SOFTBODYGRAPHICS_H 22 23 #include "worldgraphics.h" 24 #include "particlegraphics.h" 25 #include "springgraphics.h" 26 27 namespace Ui { 28 class WidgetCreateSoftBodyItems; 29 } 30 31 namespace StepCore{ 32 class SoftBody; 33 } 34 35 class SoftBodyCreator: public ItemCreator 36 { 37 public: SoftBodyCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)38 SoftBodyCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 39 : ItemCreator(className, worldModel, worldScene) {} 40 41 bool sceneEvent(QEvent* event) override; 42 void start() override; 43 44 public: 45 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 46 }; 47 48 class QDialog; 49 class SoftBodyMenuHandler: public ItemMenuHandler 50 { 51 Q_OBJECT 52 53 public: SoftBodyMenuHandler(StepCore::Object * object,WorldModel * worldModel,QObject * parent)54 SoftBodyMenuHandler(StepCore::Object* object, WorldModel* worldModel, QObject* parent) 55 : ItemMenuHandler(object, worldModel, parent), _applied(false) {} 56 57 void populateMenu(QMenu* menu, KActionCollection* actions) override; 58 applied()59 bool applied() const { return _applied; } 60 61 public slots: 62 void createSoftBodyItems(const StepCore::Vector2d& pos); 63 64 protected slots: 65 void createSoftBodyItemsApply(); 66 void clearSoftBody(); 67 68 protected: 69 StepCore::SoftBody* softBody() const; 70 Ui::WidgetCreateSoftBodyItems* _createSoftBodyItemsUi; 71 QDialog* _createSoftBodyItemsDialog; 72 bool _applied; 73 // bool _confChanged; 74 }; 75 76 class SoftBodyGraphicsItem: public StepGraphicsItem 77 { 78 public: 79 SoftBodyGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 80 81 QPainterPath shape() const override; 82 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 83 84 void viewScaleChanged() override; 85 void stateChanged() override; 86 void worldDataChanged(bool dynamicOnly) override; 87 88 protected: 89 void mouseSetPos(const QPointF& pos, const QPointF& diff, MovingState) override; 90 StepCore::SoftBody* softBody() const; 91 QPainterPath _painterPath; 92 93 ArrowHandlerGraphicsItem *_velocityHandler; 94 95 static const int RADIUS = 7; 96 }; 97 98 class SoftBodyParticleGraphicsItem: public ParticleGraphicsItem 99 { 100 public: SoftBodyParticleGraphicsItem(StepCore::Item * item,WorldModel * worldModel)101 SoftBodyParticleGraphicsItem(StepCore::Item* item, WorldModel* worldModel) 102 : ParticleGraphicsItem(item, worldModel) {} 103 104 void worldDataChanged(bool dynamicOnly) override; 105 }; 106 107 class SoftBodySpringGraphicsItem: public SpringGraphicsItem 108 { 109 public: SoftBodySpringGraphicsItem(StepCore::Item * item,WorldModel * worldModel)110 SoftBodySpringGraphicsItem(StepCore::Item* item, WorldModel* worldModel) 111 : SpringGraphicsItem(item, worldModel) {} 112 113 void worldDataChanged(bool dynamicOnly) override; 114 }; 115 116 #endif 117 118