Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
TulipMetaTypes.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 TULIPMETATYPES_H
22 #define TULIPMETATYPES_H
23 
24 #include <QtCore/QFileInfo>
25 #include <QtCore/QVariant>
26 #include <QtCore/QStringList>
27 
28 #include <tulip/DataSet.h>
29 #include <tulip/Graph.h>
30 #include <tulip/DataSet.h>
31 #include <tulip/Color.h>
32 #include <tulip/Coord.h>
33 #include <tulip/Size.h>
34 #include <tulip/BooleanProperty.h>
35 #include <tulip/DoubleProperty.h>
36 #include <tulip/ColorProperty.h>
37 #include <tulip/SizeProperty.h>
38 #include <tulip/StringProperty.h>
39 #include <tulip/LayoutProperty.h>
40 #include <tulip/GraphProperty.h>
41 #include <tulip/IntegerProperty.h>
42 #include <tulip/ColorScale.h>
43 #include <tulip/GlGraphStaticData.h>
44 #include <tulip/GlLabel.h>
45 #include <tulip/TulipFont.h>
46 #include <tulip/PropertyTypes.h>
47 
48 #include <vector>
49 
50 // Helper class for filesystem types handling
51 struct TulipFileDescriptor {
52  enum FileType {File,Directory};
53 
54  TulipFileDescriptor() {}
55  TulipFileDescriptor(const QString& absolutePath,FileType fileType):absolutePath(absolutePath),type(fileType) {}
56  TulipFileDescriptor(const TulipFileDescriptor& d) {
57  absolutePath = d.absolutePath;
58  type = d.type;
59  }
60  QString absolutePath;
61  FileType type;
62  QString fileFilterPattern;
63 };
64 
65 
66 struct NodeShape {
67  unsigned int nodeShapeId;
68  NodeShape(unsigned int nodeShapeId=0):nodeShapeId(nodeShapeId) {}
69  operator unsigned int() const {
70  return nodeShapeId;
71  }
72 };
73 
74 struct EdgeExtremityShape {
75  unsigned int edgeExtremityShapeId;
76  EdgeExtremityShape(unsigned int edgeExtremityShapeId=0):edgeExtremityShapeId(edgeExtremityShapeId) {}
77  operator unsigned int() const {
78  return edgeExtremityShapeId;
79  }
80 };
81 
82 //Declare tulip type compatible with QVariant
83 Q_DECLARE_METATYPE(tlp::DataSet)
84 
85 Q_DECLARE_METATYPE(tlp::DoubleProperty*)
86 Q_DECLARE_METATYPE(tlp::DoubleVectorProperty*)
87 Q_DECLARE_METATYPE(std::vector<double>)
88 
89 Q_DECLARE_METATYPE(tlp::Color)
90 Q_DECLARE_METATYPE(tlp::ColorProperty*)
91 Q_DECLARE_METATYPE(tlp::ColorVectorProperty*)
92 Q_DECLARE_METATYPE(std::vector<tlp::Color>)
93 
94 Q_DECLARE_METATYPE(tlp::Size)
95 Q_DECLARE_METATYPE(tlp::SizeProperty*)
96 Q_DECLARE_METATYPE(tlp::SizeVectorProperty*)
97 Q_DECLARE_METATYPE(std::vector<tlp::Size>)
98 
99 Q_DECLARE_METATYPE(std::string)
100 Q_DECLARE_METATYPE(tlp::StringProperty*)
101 Q_DECLARE_METATYPE(tlp::StringVectorProperty*)
102 Q_DECLARE_METATYPE(std::vector<std::string>)
103 
104 //Q_DECLARE_METATYPE(tlp::Coord)
105 Q_DECLARE_METATYPE(tlp::LayoutProperty*)
106 Q_DECLARE_METATYPE(tlp::CoordVectorProperty*)
107 //Q_DECLARE_METATYPE(std::vector<tlp::Coord>)
108 
109 Q_DECLARE_METATYPE(tlp::Graph*)
110 Q_DECLARE_METATYPE(tlp::GraphProperty*)
111 
112 Q_DECLARE_METATYPE(tlp::IntegerProperty*)
113 Q_DECLARE_METATYPE(tlp::IntegerVectorProperty*)
114 Q_DECLARE_METATYPE(std::vector<int>)
115 
116 Q_DECLARE_METATYPE(tlp::BooleanProperty*)
117 Q_DECLARE_METATYPE(tlp::BooleanVectorProperty*)
118 Q_DECLARE_METATYPE(std::vector<bool>)
119 
120 Q_DECLARE_METATYPE(std::set<tlp::edge>)
121 
122 Q_DECLARE_METATYPE(tlp::PropertyInterface*)
123 
124 Q_DECLARE_METATYPE(tlp::ColorScale)
125 
126 Q_DECLARE_METATYPE(tlp::StringCollection)
127 
128 Q_DECLARE_METATYPE(TulipFileDescriptor)
129 
130 Q_DECLARE_METATYPE(NodeShape)
131 Q_DECLARE_METATYPE(tlp::EdgeShape)
132 Q_DECLARE_METATYPE(EdgeExtremityShape)
133 
134 Q_DECLARE_METATYPE(tlp::LabelPosition)
135 Q_DECLARE_METATYPE(tlp::TulipFont)
136 
137 Q_DECLARE_METATYPE(QStringList)
138 
139 namespace tlp {
140 class TLP_QT_SCOPE TulipMetaTypes {
141  TulipMetaTypes() {}
142 
143  template<typename T>
144  inline static QVariant typedVariant(tlp::DataType *dm) {
145  T result;
146 
147  if (dm)
148  result = *((T*)dm->value);
149 
150  return QVariant::fromValue<T>(result);
151  }
152 
153 public:
154  static tlp::DataType *qVariantToDataType(const QVariant &);
155  static QVariant dataTypeToQvariant(tlp::DataType *,const std::string& paramName);
156 };
157 
158 class TLP_QT_SCOPE QStringListType: public TypeInterface<QStringList> {
159 public:
160  static void write(std::ostream&, const RealType&);
161  static bool read(std::istream&, RealType&);
162  FORWARD_STRING_METHODS(QStringListType)
163 };
164 
165 class TLP_QT_SCOPE QStringType: public TypeInterface<QString> {
166 public:
167  static void write(std::ostream&, const RealType&);
168  static bool read(std::istream&, RealType&);
169  static std::string toString(const RealType &);
170  static bool fromString(RealType &, const std::string &);
171 };
172 
173 extern void initQTypeSerializers();
174 
175 }
176 
177 #endif // TULIPMETATYPES_H
178 ///@endcond