File indexing completed on 2024-04-28 07:39:37

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_MOTORGRAPHICS_H
0008 #define STEP_MOTORGRAPHICS_H
0009 
0010 #include "worldgraphics.h"
0011 #include "stepgraphicsitem.h"
0012 
0013 #include <QGraphicsTextItem>
0014 #include <QWidget>
0015 
0016 #include <limits.h>
0017 
0018 
0019 namespace StepCore {
0020     class LinearMotor;
0021     class CircularMotor;
0022 }
0023 
0024 class LinearMotorCreator: public ItemCreator
0025 {
0026 public:
0027     LinearMotorCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene)
0028                         : ItemCreator(className, worldModel, worldScene) {}
0029     bool sceneEvent(QEvent* event) override;
0030 
0031 protected:
0032     void tryAttach(const QPointF& pos);
0033 };
0034 
0035 class LinearMotorGraphicsItem: public StepGraphicsItem
0036 {
0037 public:
0038     LinearMotorGraphicsItem(StepCore::Item* item, WorldModel* worldModel);
0039 
0040     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0041     QPainterPath shape() const override;
0042 
0043     void viewScaleChanged() override;
0044     void worldDataChanged(bool dynamicOnly) override;
0045     void stateChanged() override;
0046 
0047 protected:
0048     void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
0049     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
0050     StepCore::LinearMotor* motor() const;
0051     QPainterPath _path;
0052     ArrowHandlerGraphicsItem* _forceHandler;
0053     bool      _moving;
0054     static const int RADIUS = 5;
0055 
0056 };
0057 /////////////////////////////////////////////////////////////////////////////////////////////
0058 
0059 class CircularMotorCreator: public ItemCreator
0060 {
0061 public:
0062     CircularMotorCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene)
0063                         : ItemCreator(className, worldModel, worldScene) {}
0064     bool sceneEvent(QEvent* event) override;
0065 
0066 protected:
0067     void tryAttach(const QPointF& pos);
0068 };
0069 
0070 class CircularMotorGraphicsItem: public StepGraphicsItem
0071 {
0072 public:
0073     CircularMotorGraphicsItem(StepCore::Item* item, WorldModel* worldModel);
0074 
0075     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
0076     QPainterPath shape() const override;
0077 
0078     void viewScaleChanged() override;
0079     void worldDataChanged(bool dynamicOnly) override;
0080     void stateChanged() override;
0081 
0082 protected:
0083     void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
0084     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
0085     StepCore::CircularMotor* motor() const;
0086     QPainterPath _path;
0087     CircularArrowHandlerGraphicsItem* _torqueHandler;
0088     bool      _moving;
0089     static const int RADIUS = 5;
0090     static const int ARROW_RADIUS = 45;
0091 };
0092 
0093 #endif
0094