File: DatasetTools.cpp

package info (click to toggle)
tulip 3.7.0dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 39,428 kB
  • sloc: cpp: 231,403; php: 11,023; python: 1,128; sh: 671; yacc: 522; makefile: 315; xml: 63; lex: 55
file content (169 lines) | stat: -rwxr-xr-x 5,265 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
/**
 *
 * 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.
 *
 */
#include "DatasetTools.h"

#define ORTHOGONAL "orthogonal"
#define ORIENTATION "up to down;down to up;right to left;left to right;"
#define ORIENTATION_ID "orientation"

using namespace tlp;

namespace {
const char* paramHelp[] = {
  //Orientation
  HTML_HELP_OPEN() \
  HTML_HELP_DEF("Type", "StringCollection") \
  HTML_HELP_DEF("Values", "up to down <BR> down to up <BR> right to left <BR> left to right") \
  HTML_HELP_DEF("Default", "up to down") \
  HTML_HELP_BODY() \
  "Choose your <BR> wished orientation" \
  HTML_HELP_CLOSE(),

  //Orthogonal Edge
  HTML_HELP_OPEN() \
  HTML_HELP_DEF("Type", "Boolean") \
  HTML_HELP_DEF("Values", "true <BR> false") \
  HTML_HELP_DEF("Default", "false") \
  HTML_HELP_BODY() \
  "If true then use orthogonal edges" \
  HTML_HELP_CLOSE(),

  //Layer Spacing
  HTML_HELP_OPEN()         \
  HTML_HELP_DEF( "type", "float" ) \
  HTML_HELP_DEF( "default", "64." )  \
  HTML_HELP_BODY() \
  "This parameter enables to set up the minimum space between two layers in the drawing" \
  HTML_HELP_CLOSE(),
  //Node Spacing
  HTML_HELP_OPEN()         \
  HTML_HELP_DEF( "type", "float" ) \
  HTML_HELP_DEF( "default", "18." )  \
  HTML_HELP_BODY() \
  "This parameter enables to set up the minimum space between two nodes in the same layer" \
  HTML_HELP_CLOSE(),

  // node size
  HTML_HELP_OPEN() \
  HTML_HELP_DEF( "type", "Size" ) \
  HTML_HELP_DEF( "values", "An existing size property" ) \
  HTML_HELP_DEF( "default", "viewSize" ) \
  HTML_HELP_BODY() \
  "This parameter defines the property used for node's sizes." \
  HTML_HELP_CLOSE(),
};
}

//====================================================================
void addOrientationParameters(LayoutAlgorithm* pLayout) {
  pLayout->addParameter<StringCollection>(ORIENTATION_ID, paramHelp[0], ORIENTATION);
}

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

//====================================================================
void addSpacingParameters(LayoutAlgorithm* pLayout) {
  pLayout->addParameter<float>("layer spacing", paramHelp[2], "64." );
  pLayout->addParameter<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 != 0) && dataSet->get("node size", sizes);
}

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

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

  if (dataSet != 0) {
    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 != 0) {
    dataSet->get(ORTHOGONAL, orthogonalEdge);
  }

  return orthogonalEdge;
}