File: Module.sip

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (425 lines) | stat: -rw-r--r-- 12,917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/**
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */

// +-------------------------------------------------------------------------+
// | Tulip Python Bindings                                                   |
// | inspired from bindings by the Booggie project development team          |
// | (http://booggie.org/)                                                   |
// +-------------------------------------------------------------------------+

%Module _tulip

// Plus set up type aliases for tlp.Coord and tlp.Size
%PreInitialisationCode
    // Try to load plugins when importing the module from the Python shell
    if (tlp::TulipPluginsPath.empty()) {
      tlp::initTulipLib();
      tlp::PluginLibraryLoader::loadPlugins();
    }
%End

%PostInitialisationCode
    // Set up some type aliases
    PyObject *moduleDict = PyModule_GetDict(sipModule);
    PyObject *tlpClass = PyDict_GetItemString(moduleDict, "tlp");
    PyObject *tlpVec3f = PyObject_GetAttrString(tlpClass, "Vec3f");
    PyObject_SetAttrString(tlpClass, "Coord", tlpVec3f);
    PyObject_SetAttrString(tlpClass, "Size", tlpVec3f);
%End

%ModuleHeaderCode
#include <tulip/Graph.h>
#include <tulip/PluginLister.h>
#include <tulip/PropertyAlgorithm.h>
#include <tulip/PythonCppTypesConverter.h>
#include <tulip/Vector.h>
#include <tulip/Color.h>
#include <string>
#include <sstream>
#include <iostream>

tlp::PropertyInterface* copyValue(tlp::PropertyInterface* value);

tlp::Graph* copyValue(tlp::Graph* value);

std::string* copyValue(const std::string &value);

std::string getValue(const std::string *value);;

tlp::node* copyValue(const tlp::node &value);

tlp::edge* copyValue(const tlp::edge &value);

int copyValue(const int &value);

int getValue(const int &value);

double copyValue(const double &value);

double getValue(const double &value);

tlp::Vec3f *copyValue(const tlp::Vec3f &value);

tlp::Vec3f getValue(const tlp::Vec3f *value);

tlp::Color *copyValue(const tlp::Color &value);

tlp::Color getValue(const tlp::Color *value);

std::vector<tlp::Vec3f> *copyValue(const std::vector<tlp::Vec3f> &value);

std::vector<tlp::Vec3f> getValue(const std::vector<tlp::Vec3f> *value);

template <typename T>
bool pluginExists(std::string pluginName) {
  if (typeid(T).name() == typeid(tlp::Algorithm).name()) {
    std::list<std::string> algoList = tlp::PluginLister::instance()->availablePlugins<tlp::Algorithm>();
    std::list<std::string> propAlgoList = tlp::PluginLister::instance()->availablePlugins<tlp::PropertyAlgorithm>();
    std::list<std::string> realAlgoList;
    for (std::list<std::string>::iterator it = algoList.begin() ; it != algoList.end() ; ++it) {
      if (std::find(propAlgoList.begin(), propAlgoList.end(), *it) == propAlgoList.end()) {
        realAlgoList.push_back(*it);
      }
    }
    return std::find(realAlgoList.begin(), realAlgoList.end(), pluginName) != realAlgoList.end();
  } else {
    return tlp::PluginLister::instance()->pluginExists<T>(pluginName);
  }
}

template <typename PROP>
bool canGetProperty(const tlp::Graph *graph, const std::string &propName) {
  if (!graph->existProperty(propName)) {
    return true;
  }
  return dynamic_cast<PROP*>(graph->getProperty(propName)) != NULL;
}

extern int throwInvalidNodeException(const tlp::Graph *graph, tlp::node n);

extern int throwInvalidEdgeException(const tlp::Graph *graph, tlp::edge e);

extern int throwInvalidSgException(const tlp::Graph *graph, const tlp::Graph *sg);

extern int throwPropertyNameExistsException(const tlp::Graph *graph, const std::string &propertyName);

extern void printErrorMessage(const std::string &errMsg);

extern void releaseSIPWrapper(void *wrappedCppObject, const sipTypeDef *td);

extern void replaceAll(std::string &s, const std::string& replaceWhat, const std::string& replaceWithWhat);

extern bool isValidGraphSelection(const tlp::Graph *graph, tlp::BooleanProperty *selection);

extern PyObject* evalPythonStatement(const std::string &pythonStatement);

#if PY_MAJOR_VERSION >= 3
extern std::string convertPythonUnicodeObjectToStdString(PyObject *pyUnicodeObj);
#endif

%End


%ModuleCode

tlp::PropertyInterface* copyValue(tlp::PropertyInterface* value) {
  return value;
}

tlp::Graph* copyValue(tlp::Graph* value) {
  return value;
}

std::string* copyValue(const std::string &value) {
  return new std::string(value);
}

std::string getValue(const std::string *value) {
  return *value;
}

tlp::node* copyValue(const tlp::node &value) {
  return new tlp::node(value);
}

tlp::edge* copyValue(const tlp::edge &value) {
  return new tlp::edge(value);
}

int copyValue(const int &value) {
  return value;
}

int getValue(const int &value) {
  return value;
}

double copyValue(const double &value) {
  return value;
}

double getValue(const double &value) {
  return value;
}

tlp::Vec3f *copyValue(const tlp::Vec3f &value) {
  return new tlp::Vec3f(value);
}

tlp::Vec3f getValue(const tlp::Vec3f *value) {
  return *value;
}

tlp::Color *copyValue(const tlp::Color &value) {
  return new tlp::Color(value);
}

tlp::Color getValue(const tlp::Color *value) {
  return *value;
}

std::vector<tlp::Vec3f> *copyValue(const std::vector<tlp::Vec3f> &value) {
  return new std::vector<tlp::Vec3f>(value);
}

std::vector<tlp::Vec3f> getValue(const std::vector<tlp::Vec3f> *value) {
  return *value;
}

int throwInvalidNodeException(const tlp::Graph *graph, tlp::node n) {
  std::ostringstream oss;
  oss << "Node with id " << n.id << " does not belong to graph \"" << graph->getName() <<"\" (id " << graph->getId() <<")";
  PyErr_SetString(PyExc_Exception, oss.str().c_str());
  return -1;
}

int throwInvalidEdgeException(const tlp::Graph *graph, tlp::edge e) {
  std::ostringstream oss;
  oss << "Edge with id " << e.id << " does not belong to graph \"" << graph->getName() <<"\" (id " << graph->getId() <<")";
  PyErr_SetString(PyExc_Exception, oss.str().c_str());
  return -1;
}

int throwInvalidSgException(const tlp::Graph *graph, const tlp::Graph *sg) {
  std::ostringstream oss;
  oss << "Graph \"" << sg->getName() <<"\" (id " << sg->getId() <<") is not a sub-graph of graph \"" << graph->getName() <<"\" (id " << graph->getId() <<")";
  PyErr_SetString(PyExc_Exception, oss.str().c_str());
  return -1;
}

int throwPropertyNameExistsException(const tlp::Graph *graph, const std::string &propertyName) {
  tlp::PropertyInterface *prop = graph->getProperty(propertyName);
  std::ostringstream oss;
  oss << "A property named \"" << propertyName << "\" of type " << prop->getTypename() << " already exists in graph \"" << graph->getName() <<"\" (id " << graph->getId() <<")";
  PyErr_SetString(PyExc_Exception, oss.str().c_str());
  return -1;
}

void printErrorMessage(const std::string &errMsg) {
  std::string pythonCode = "import sys\n"
                           "sys.stderr.write(\"";
  pythonCode += errMsg;
  pythonCode += "\\n\")";
  PyRun_SimpleString(pythonCode.c_str());
}

void releaseSIPWrapper(void *wrappedCppObject, const sipTypeDef *td) {
  PyObject *pyObj = sipGetPyObject(wrappedCppObject, td);
  if (pyObj) {
    sipTransferTo(pyObj, pyObj);
    sipSimpleWrapper *wrapper = reinterpret_cast<sipSimpleWrapper *>(pyObj);
    sipCommonDtor(wrapper);
  }
}

void replaceAll(std::string &s, const std::string& replaceWhat, const std::string& replaceWithWhat) {
  while(1) {
    const int pos = s.find(replaceWhat);
    if (pos==std::string::npos) break;
    s.replace(pos,replaceWhat.size(),replaceWithWhat);
  }
}

bool isValidGraphSelection(const tlp::Graph *graph, tlp::BooleanProperty *selection) {
  tlp::edge e;
  forEach(e, graph->getEdges()) {
    if (selection->getEdgeValue(e)) {
      if (!selection->getNodeValue(graph->source(e)) || !selection->getNodeValue(graph->target(e))) {
        return false;
      }
    }
  }
  return true;
}

#if PY_MAJOR_VERSION >= 3
std::string convertPythonUnicodeObjectToStdString(PyObject *pyUnicodeObj) {
  PyObject *utf8Str = PyUnicode_AsUTF8String(pyUnicodeObj);
  std::string ret(PyBytes_AsString(utf8Str));
  Py_DECREF(utf8Str);
  return ret;
}
#endif

PyObject* evalPythonStatement(const std::string &pythonStatement) {
#if PY_MAJOR_VERSION >= 3
  PyObject *pName = PyUnicode_FromString("__main__");
#else
  PyObject *pName = PyString_FromString("__main__");
#endif
  PyObject *pMainModule = PyImport_Import(pName);
  Py_XDECREF(pName);
  PyObject *pMainDict = PyModule_GetDict(pMainModule);

  PyObject *ret = PyRun_String(pythonStatement.c_str(), Py_eval_input, pMainDict, pMainDict);

  if (PyErr_Occurred()) {
    PyErr_Print();
    PyErr_Clear();
  }

  return ret;
}

%End

%Import ../stl/Module.sip

%Include Iterator.sip
%Include MapIterator.sip
%Include Node.sip
%Include Edge.sip	
%Include Vector.sip
%Include Color.sip
%Include Coord.sip
%Include Size.sip
%Include Matrix.sip
%Include BoundingBox.sip
%Include StringCollection.sip
%Include ColorScale.sip
%Include DataSet.sip

%Include PluginContext.sip
%Include Plugin.sip

%Include Algorithm.sip
%Include PropertyAlgorithm.sip

%Include ImportModule.sip
%Include ExportModule.sip

%Include PropertyInterface.sip


%Include BooleanProperty.sip
%Include DoubleProperty.sip
%Include ColorProperty.sip
%Include StringProperty.sip
%Include SizeProperty.sip
%Include IntegerProperty.sip
%Include LayoutProperty.sip
%Include NumericProperty.sip

%Include GraphProperty.sip

%Include WithParameter.sip
%Include WithDependency.sip
%Include PluginProgress.sip
%Include Graph.sip
%Include GraphMeasure.sip
%Include GraphTools.sip
%Include PluginLoader.sip
%Include PluginLoaderTxt.sip

%Include TlpTools.sip
%Include AcyclicTest.sip
%Include ConnectedTest.sip
%Include SimpleTest.sip
%Include TreeTest.sip
%Include OuterPlanarTest.sip
%Include BiconnectedTest.sip
%Include TriconnectedTest.sip
%Include PlanarityTest.sip

%Include DrawingTools.sip
%Include Observable.sip
%Include GraphEvent.sip
%Include PropertyEvent.sip
%Include TulipViewSettings.sip
%Include Delaunay.sip
%Include ConvexHull.sip
%Include TulipFontAwesome.sip

// force generation of wrappers for specialized template classes
typedef std::vector<tlp::Graph*> vectorGraphType;
typedef std::list<tlp::Graph*> listGraphType;
typedef std::set<tlp::Graph*> setGraphType;

typedef std::vector<tlp::node> vectorNodeType;
typedef std::list<tlp::node> listNodeType;
typedef std::set<tlp::node> setNodeType;

typedef std::vector<tlp::edge> vectorEdgeType;
typedef std::list<tlp::edge> listEdgeType;
typedef std::set<tlp::edge> setEdgeType;

typedef std::vector<tlp::Color> vectorColorType;
typedef std::list<tlp::Color> listColorType;
typedef std::set<tlp::Color> setColorType;

typedef std::vector<tlp::Coord> vectorCoordType;
typedef std::list<tlp::Coord> listCoordType;
typedef std::set<tlp::Coord> setCoordType;

typedef std::vector<tlp::Size> vectorSizeType;
typedef std::list<tlp::Size> listSizeType;
typedef std::set<tlp::Size> setSizeType;

typedef std::vector<tlp::DataSet> vectorDataSetType;
typedef std::list<tlp::DataSet> listDataSetType;

typedef std::vector<tlp::ColorScale> vectorColorScaleType;
typedef std::list<tlp::ColorScale> listColorScaleType;

typedef std::vector<tlp::StringCollection> vectorStringCollectionType;
typedef std::list<tlp::StringCollection> listStringCollectionType;

typedef std::vector<tlp::BooleanProperty*> vectorBooleanPropertyType;
typedef std::list<tlp::BooleanProperty*> listBooleanPropertyType;

typedef std::vector<tlp::ColorProperty*> vectorColorPropertyType;
typedef std::list<tlp::ColorProperty*> listColorPropertyType;

typedef std::vector<tlp::DoubleProperty*> vectorDoublePropertyType;
typedef std::list<tlp::DoubleProperty*> listDoublePropertyType;

typedef std::vector<tlp::IntegerProperty*> vectorIntegerPropertyType;
typedef std::list<tlp::IntegerProperty*> listIntegerPropertyType;

typedef std::vector<tlp::LayoutProperty*> vectorLayoutPropertyType;
typedef std::list<tlp::LayoutProperty*> listLayoutPropertyType;

typedef std::vector<tlp::SizeProperty*> vectorSizePropertyType;
typedef std::list<tlp::SizeProperty*> listSizePropertyType;

typedef std::vector<tlp::StringProperty*> vectorStringPropertyType;
typedef std::list<tlp::StringProperty*> listStringPropertyType;

typedef std::vector<tlp::PropertyInterface*> vectorPropertyInterfaceType;
typedef std::list<tlp::PropertyInterface*> listPropertyInterfaceType;