21 #ifndef CSVGRAPHIMPORT_H
22 #define CSVGRAPHIMPORT_H
24 #include <tulip/CSVParser.h>
25 #include <tulip/CSVContentHandler.h>
26 #include <tulip/Graph.h>
28 #include <QtGui/QWidget>
29 #include <QtGui/QMessageBox>
30 #include <tulip/tuliphash.h>
32 class PropertyInterface;
39 class TLP_QT_SCOPE CSVColumn {
41 CSVColumn(
const std::string& columnName=
"",
bool isUsed=
false,
const std::string& columnType=
""):name(columnName),used(isUsed),type(columnType) {
48 std::string columnName()
const {
61 std::string columnDataType()
const {
76 class TLP_QT_SCOPE CSVImportParameters {
78 CSVImportParameters(
unsigned int fromLine=0,
unsigned int toLine=UINT_MAX,
const std::vector<CSVColumn>& columns = std::vector<CSVColumn>());
79 virtual ~CSVImportParameters();
84 unsigned int columnNumber()
const;
89 bool importColumn(
unsigned int column)
const;
93 std::string getColumnName(
unsigned int column)
const;
97 std::string getColumnDataType(
unsigned int column)
const;
102 unsigned int getFirstLineIndex()
const;
106 unsigned int getLastLineIndex()
const;
110 bool importRow(
unsigned int row)
const;
112 unsigned int fromLine;
114 std::vector<CSVColumn> columns;
130 class TLP_QT_SCOPE CSVToGraphDataMapping {
132 virtual ~CSVToGraphDataMapping() {}
133 virtual std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens)=0;
134 virtual void init(
unsigned int rowNumber)=0;
143 class TLP_QT_SCOPE AbstractCSVToGraphDataMapping :
public CSVToGraphDataMapping {
145 AbstractCSVToGraphDataMapping(
tlp::Graph* graph,tlp::ElementType type,
unsigned int columnIndex,
const std::string& propertyName);
146 virtual ~AbstractCSVToGraphDataMapping() {}
148 void init(
unsigned int rowNumber);
149 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
158 TLP_HASH_MAP<std::string,unsigned int> valueToId;
160 tlp::ElementType type;
161 unsigned int columnIndex;
167 class TLP_QT_SCOPE CSVToNewNodeIdMapping:
public CSVToGraphDataMapping {
170 void init(
unsigned int rowNumber);
171 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
181 class TLP_QT_SCOPE CSVToGraphNodeIdMapping:
public AbstractCSVToGraphDataMapping {
191 CSVToGraphNodeIdMapping(
tlp::Graph* graph,
unsigned int columnIndex,
const std::string& propertyName,
bool createNode=
false);
192 void init(
unsigned int rowNumber);
196 bool createMissingNodes;
203 class TLP_QT_SCOPE CSVToGraphEdgeIdMapping:
public AbstractCSVToGraphDataMapping {
212 CSVToGraphEdgeIdMapping(
tlp::Graph* graph,
unsigned int columnIndex,
const std::string& propertyName);
222 class TLP_QT_SCOPE CSVToGraphEdgeSrcTgtMapping:
public CSVToGraphDataMapping {
234 CSVToGraphEdgeSrcTgtMapping(
tlp::Graph* graph,
unsigned int srcColumnIndex,
unsigned int tgtColumnIndex,
const std::string& propertyName,
bool createMissinElements=
false);
235 std::pair<tlp::ElementType,unsigned int> getElementForRow(
unsigned int row);
236 void init(
unsigned int lineNumbers);
237 std::pair<tlp::ElementType,unsigned int> getElementForRow(
const std::vector<std::string>& tokens);
240 TLP_HASH_MAP<std::string,unsigned int> valueToId;
241 unsigned int srcColumnIndex;
242 unsigned int tgtColumnIndex;
244 bool buildMissingElements;
251 class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMapping {
253 virtual ~CSVImportColumnToGraphPropertyMapping() {}
269 class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMappingProxy :
public CSVImportColumnToGraphPropertyMapping {
271 CSVImportColumnToGraphPropertyMappingProxy(
tlp::Graph* graph,
const CSVImportParameters& importParameters,QWidget* parent=NULL);
272 virtual ~CSVImportColumnToGraphPropertyMappingProxy() {}
278 CSVImportParameters importParameters;
279 TLP_HASH_MAP<unsigned int,tlp::PropertyInterface*>propertiesBuffer;
280 QMessageBox::StandardButton overwritePropertiesButton;
288 class TLP_QT_SCOPE CSVGraphImport :
public tlp::CSVContentHandler {
290 CSVGraphImport(CSVToGraphDataMapping* mapping,CSVImportColumnToGraphPropertyMapping* propertiesManager,
const CSVImportParameters& importParameters);
291 virtual ~CSVGraphImport();
293 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
294 void end(
unsigned int rowNumber,
unsigned int columnNumber);
297 CSVToGraphDataMapping* mapping;
298 CSVImportColumnToGraphPropertyMapping* propertiesManager;
299 CSVImportParameters importParameters;
303 #endif // CSVGRAPHIMPORT_H