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 #ifndef STEP_MOTORGRAPHICS_H 19 #define STEP_MOTORGRAPHICS_H 20 21 #include "worldgraphics.h" 22 #include "stepgraphicsitem.h" 23 #include <QGraphicsTextItem> 24 #include <QWidget> 25 #include <limits.h> 26 27 28 namespace StepCore { 29 class LinearMotor; 30 class CircularMotor; 31 } 32 33 class LinearMotorCreator: public ItemCreator 34 { 35 public: LinearMotorCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)36 LinearMotorCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 37 : ItemCreator(className, worldModel, worldScene) {} 38 bool sceneEvent(QEvent* event) override; 39 40 protected: 41 void tryAttach(const QPointF& pos); 42 }; 43 44 class LinearMotorGraphicsItem: public StepGraphicsItem 45 { 46 public: 47 LinearMotorGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 48 49 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 50 QPainterPath shape() const override; 51 52 void viewScaleChanged() override; 53 void worldDataChanged(bool dynamicOnly) override; 54 void stateChanged() override; 55 56 protected: 57 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; 58 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; 59 StepCore::LinearMotor* motor() const; 60 QPainterPath _path; 61 ArrowHandlerGraphicsItem* _forceHandler; 62 bool _moving; 63 static const int RADIUS = 5; 64 65 }; 66 ///////////////////////////////////////////////////////////////////////////////////////////// 67 68 class CircularMotorCreator: public ItemCreator 69 { 70 public: CircularMotorCreator(const QString & className,WorldModel * worldModel,WorldScene * worldScene)71 CircularMotorCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 72 : ItemCreator(className, worldModel, worldScene) {} 73 bool sceneEvent(QEvent* event) override; 74 75 protected: 76 void tryAttach(const QPointF& pos); 77 }; 78 79 class CircularMotorGraphicsItem: public StepGraphicsItem 80 { 81 public: 82 CircularMotorGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 83 84 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 85 QPainterPath shape() const override; 86 87 void viewScaleChanged() override; 88 void worldDataChanged(bool dynamicOnly) override; 89 void stateChanged() override; 90 91 protected: 92 void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; 93 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; 94 StepCore::CircularMotor* motor() const; 95 QPainterPath _path; 96 CircularArrowHandlerGraphicsItem* _torqueHandler; 97 bool _moving; 98 static const int RADIUS = 5; 99 static const int ARROW_RADIUS = 45; 100 }; 101 102 #endif 103 104