Tulip  5.3.0
Large graphs analysis and drawing
MouseEdgeBendEditor.h
1 /*
2  *
3  * This file is part of Tulip (http://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  boundingBox = BoundingBox();
49  start = startPos;
50  end = endPos;
51  bends = bendsPos;
52  boundingBox.expand(start);
53  boundingBox.expand(end);
54 
55  for (std::vector<Coord>::iterator it = bends.begin(); it != bends.end(); ++it) {
56  boundingBox.expand(*it);
57  }
58  }
59 
60  void draw(float, Camera *) override {
61  GlLines::glDrawCurve(start, bends, end, 10, 0, Color(127, 127, 127, 255),
62  Color(127, 127, 127, 255));
63  }
64 
65  void getXML(std::string &) override {}
66  void setWithXML(const std::string &, unsigned int &) override {}
67 };
68 
69 /// This interactor allows to move/add/delete EdgeBends
70 class TLP_QT_SCOPE MouseEdgeBendEditor : public GLInteractorComponent {
71 
72 public:
73  MouseEdgeBendEditor();
74  ~MouseEdgeBendEditor() override;
75  bool compute(GlMainWidget *glMainWidget) override;
76  bool draw(GlMainWidget *) override;
77  void clear() override;
78  bool eventFilter(QObject *, QEvent *) override;
79 
80 protected:
81  enum EditOperation { NONE_OP = 0, TRANSLATE_OP, NEW_OP, DELETE_OP };
82 
83  EditOperation operation() const {
84  return _operation;
85  }
86 
87  tlp::edge getEdge() const {
88  return mEdge;
89  }
90 
91  void stopEdition();
92 
93 private:
94  enum OperationTarget { COORD = 0, SIZE, COORD_AND_SIZE };
95 
96  Graph *_graph;
97  GlMainWidget *glMainWidget;
98  LayoutProperty *_layout;
99  BooleanProperty *_selection;
100  DoubleProperty *_rotation;
101  SizeProperty *_sizes;
102  IntegerProperty *_shape;
103  CoordVectorProperty *_coordsVectorProperty;
104 
105  void initProxies(GlMainWidget *glMainWidget);
106 
107  EditOperation _operation;
108  OperationTarget mode;
109 
110  Coord editPosition;
111 
112  GlLayer *layer;
113  std::vector<tlp::GlCircle> circles;
114  EdgeEntity *edgeEntity;
115  std::vector<Coord> coordinates;
116  GlCircle basicCircle;
117  GlTriangle targetTriangle;
118  GlCircle sourceCircle;
119  GlComposite *circleString;
120  std::vector<SelectedEntity> select;
121  bool edgeSelected;
122  tlp::edge mEdge;
123  node mNode;
124  Coord start, end;
125  std::string selectedEntity;
126  bool mouseButtonPressOnEdge;
127  bool belong(Coord, Coord, Coord, GlMainWidget *);
128  bool haveSelection(GlMainWidget *);
129  void computeSrcTgtEntities(GlMainWidget *);
130  bool computeBendsCircles(GlMainWidget *);
131  void mMouseTranslate(int, int, GlMainWidget *);
132  void mMouseDelete();
133  void mMouseCreate(int, int, GlMainWidget *);
134 };
135 } // namespace tlp
136 
137 #endif
138 ///@endcond
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40