File: DatasetTools.cpp

package info (click to toggle)
tulip 6.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 196,224 kB
  • sloc: cpp: 571,851; ansic: 13,983; python: 4,105; sh: 1,555; yacc: 522; xml: 484; makefile: 168; pascal: 148; lex: 55
file content (139 lines) | stat: -rw-r--r-- 4,397 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
/**
 *
 * This file is part of Tulip (https://tulip.labri.fr)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux
 *
 * 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.
 *
 */
#include "DatasetTools.h"
#include <tulip/StringCollection.h>

#define ORTHOGONAL "orthogonal"
#define ORIENTATION "top to bottom;bottom to top;right to left;left to right;"
#define ORIENTATION_ID "orientation"

using namespace tlp;

static const char *paramHelp[] = {
    // orientation
    "Choose a desired orientation.",

    // orthogonal
    "If true then use orthogonal edges.",

    // layer spacing
    "This parameter enables to set up the minimum space between two layers in the drawing.",

    // node spacing
    "This parameter enables to set up the minimum space between two nodes in the same layer.",

    // node size
    "This parameter defines the property used for node sizes."};

//====================================================================
void addOrientationParameters(LayoutAlgorithm *pLayout) {
  pLayout->addInParameter<StringCollection>(
      ORIENTATION_ID, paramHelp[0], ORIENTATION, true,
      "top to bottom <br> bottom to top <br> right to left <br> left to right");
}

//====================================================================
void addOrthogonalParameters(LayoutAlgorithm *pLayout) {
  pLayout->addInParameter<bool>(ORTHOGONAL, paramHelp[1], "false");
}

//====================================================================
void addSpacingParameters(LayoutAlgorithm *pLayout) {
  pLayout->addInParameter<float>("layer spacing", paramHelp[2], "64.");
  pLayout->addInParameter<float>("node spacing", paramHelp[3], "18.");
}
void getSpacingParameters(DataSet *dataSet, float &nodeSpacing, float &layerSpacing) {
  layerSpacing = 64.;
  nodeSpacing = 18.;

  if (dataSet) {
    dataSet->get("node spacing", nodeSpacing);
    dataSet->get("layer spacing", layerSpacing);
  }
}
//====================================================================
void addNodeSizePropertyParameter(LayoutAlgorithm *pLayout, bool inout) {
  if (inout)
    pLayout->addInOutParameter<SizeProperty>("node size", paramHelp[4], "viewSize");
  else
    pLayout->addInParameter<SizeProperty>("node size", paramHelp[4], "viewSize");
}

bool getNodeSizePropertyParameter(DataSet *dataSet, SizeProperty *&sizes) {
  return (dataSet != nullptr) && dataSet->get("node size", sizes) && sizes;
}

//====================================================================
DataSet setOrientationParameters(int pOrientation) {
  DataSet dataSet;
  StringCollection stringOrientation(ORIENTATION);
  stringOrientation.setCurrent(pOrientation);
  dataSet.set(ORIENTATION_ID, stringOrientation);
  return dataSet;
}

//====================================================================
orientationType getMask(DataSet *dataSet) {
  StringCollection orientation(ORIENTATION);
  orientation.setCurrent(0);
  int current = 0;

  if (dataSet != nullptr) {
    StringCollection dataSetOrientation;

    if (dataSet->get(ORIENTATION_ID, dataSetOrientation)) {
      // the order of ORIENTATION items may have change
      // because the default value may have change (see DataSetDialog.cpp)
      std::string currentString = dataSetOrientation.getCurrentString();

      for (current = 0; current < 4; ++current) {
        if (currentString == orientation.at(current))
          break;
      }
    }
  }

  switch (current) {
  case 0:
    return ORI_DEFAULT;

  case 1:
    return ORI_INVERSION_VERTICAL;

  case 2:
    return ORI_ROTATION_XY;

  case 3:
    return orientationType(ORI_ROTATION_XY | ORI_INVERSION_HORIZONTAL);

  default:
    return ORI_DEFAULT;
  }
}

//====================================================================
bool hasOrthogonalEdge(DataSet *dataSet) {
  bool orthogonalEdge = false;

  if (dataSet != nullptr) {
    dataSet->get(ORTHOGONAL, orthogonalEdge);
  }

  return orthogonalEdge;
}