Tulip  6.0.0
Large graphs analysis and drawing
MouseEdgeBendEditor.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef MOUSEEDGEBENDEDITION_H
22 #define MOUSEEDGEBENDEDITION_H
23 
24 #include <tulip/GlCircle.h>
25 #include <tulip/GlTriangle.h>
26 #include <tulip/GLInteractor.h>
27 #include <tulip/GlScene.h>
28 #include <tulip/GlLines.h>
29 
30 namespace tlp {
31 
32 class LayoutProperty;
33 class BooleanProperty;
34 class SizeProperty;
35 class DoubleProperty;
36 class CoordVectorProperty;
37 class IntegerProperty;
38 
39 class EdgeEntity : public GlSimpleEntity {
40 
41  Coord start;
42  Coord end;
43  std::vector<Coord> bends;
44 
45 public:
46  void setCoordinates(const Coord &startPos, const Coord &endPos,
47  const std::vector<Coord> &bendsPos) {
48  start = startPos;
49  end = endPos;
50  bends = bendsPos;
51  boundingBox.init(start);
52  boundingBox.expand(end, true);
53 
54  for (auto &coord : bends) {
55  boundingBox.expand(coord, true);
56  }
57  }
58 
59  void draw(float, Camera *) override {
60  GlLines::glDrawCurve(start, bends, end, 10, 0, Color(127, 127, 127, 255),
61  Color(127, 127, 127, 255));
62  }
63 
64  void getXML(std::string &) override {}
65  void setWithXML(const std::string &, unsigned int &) override {}
66 };
67 
68 /// This interactor allows to move/add/delete EdgeBends
69 class TLP_QT_SCOPE MouseEdgeBendEditor : public GLInteractorComponent {
70 
71 public:
72  MouseEdgeBendEditor();
73  ~MouseEdgeBendEditor() override;
74  bool compute(GlMainWidget *glMainWidget) override;
75  bool draw(GlMainWidget *) override;
76  void clear() override;
77  bool eventFilter(QObject *, QEvent *) override;
78 
79 protected:
80  enum EditOperation { NONE_OP = 0, TRANSLATE_OP, NEW_OP, DELETE_OP };
81 
82  EditOperation operation() const {
83  return _operation;
84  }
85 
86  tlp::edge getEdge() const {
87  return mEdge;
88  }
89 
90  void stopEdition();
91 
92 private:
93  enum OperationTarget { COORD = 0, SIZE, COORD_AND_SIZE };
94 
95  Graph *_graph;
96  GlMainWidget *glMainWidget;
97  LayoutProperty *_layout;
98  BooleanProperty *_selection;
99  DoubleProperty *_rotation;
100  SizeProperty *_sizes;
101  IntegerProperty *_shape;
102  CoordVectorProperty *_coordsVectorProperty;
103 
104  void initProxies(GlMainWidget *glMainWidget);
105 
106  EditOperation _operation;
107  OperationTarget mode;
108 
109  Coord editPosition;
110 
111  GlLayer *layer;
112  std::vector<tlp::GlCircle> circles;
113  EdgeEntity *edgeEntity;
114  std::vector<Coord> coordinates;
115  GlCircle basicCircle;
116  GlTriangle targetTriangle;
117  GlCircle sourceCircle;
118  GlComposite *circleString;
119  bool edgeSelected;
120  tlp::edge mEdge;
121  node mNode;
122  Coord start, end;
123  std::string selectedEntity;
124  bool mouseButtonPressOnEdge;
125  bool belong(const Coord &, const Coord &, const Coord &, GlMainWidget *);
126  bool haveSelection(GlMainWidget *);
127  void computeSrcTgtEntities(GlMainWidget *);
128  bool computeBendsCircles(GlMainWidget *);
129  void mMouseTranslate(int, int, GlMainWidget *);
130  void mMouseDelete();
131  void mMouseCreate(int, int, GlMainWidget *);
132 };
133 } // namespace tlp
134 
135 #endif
136 ///@endcond
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40