Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/vissim/NIImporter_Vissim.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file NIImporter_Vissim.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @author Lukas Grohmann (AIT)
18
/// @author Gerald Richter (AIT)
19
/// @date Sept 2002
20
///
21
// Importer for networks stored in Vissim format
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <string>
27
#include <map>
28
#include <vector>
29
#include <utils/common/RGBColor.h>
30
#include <utils/geom/Position.h>
31
#include "tempstructs/NIVissimExtendedEdgePoint.h"
32
#include "NIVissimElements.h"
33
#include <utils/xml/SUMOSAXHandler.h>
34
#include "tempstructs/NIVissimEdge.h"
35
#include "tempstructs/NIVissimConnection.h"
36
#include "tempstructs/NIVissimConflictArea.h"
37
38
#include <utils/common/SequentialStringBijection.h>
39
#include <utils/common/StringTokenizer.h>
40
#include <list>
41
42
// ===========================================================================
43
// class declarations
44
// ===========================================================================
45
class OptionsCont;
46
class NBNetBuilder;
47
48
49
// ===========================================================================
50
// class definitions
51
// ===========================================================================
52
/**
53
* @class NIImporter_Vissim
54
* @brief Importer for networks stored in Vissim format
55
*/
56
class NIImporter_Vissim {
57
public:
58
/** @brief Loads network definition from the assigned option and stores it in the given network builder
59
*
60
* If the option "vissim-file" is set, the file stored therein is read and
61
* the network definition stored therein is stored within the given network
62
* builder.
63
*
64
* If the option "vissim-file" is not set, this method simply returns.
65
*
66
* @param[in] oc The options to use
67
* @param[in] nb The network builder to fill
68
*/
69
static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
70
71
72
73
private:
74
75
typedef std::map<std::string, std::list<std::string> > nodeMap;
76
nodeMap elementData;
77
78
/**
79
* @class NIVissimSingleTypeXMLHandler_Streckendefinition
80
* @brief A class which extracts VISSIM-Strecken from a parsed VISSIM-file
81
*/
82
class NIVissimXMLHandler_Streckendefinition : public GenericSAXHandler {
83
public:
84
/** @brief Constructor
85
* @param[in] strecken_dic The strecken dictionary to fill
86
*/
87
//NIVissimXMLHandler_Streckendefinition(std::map<int, VissimXMLEdge>& toFill);
88
NIVissimXMLHandler_Streckendefinition(nodeMap& elemData);
89
90
91
/// @brief Destructor
92
~NIVissimXMLHandler_Streckendefinition();
93
94
protected:
95
/// @name inherited from GenericSAXHandler
96
//@{
97
98
/** @brief Called on the opening of a tag;
99
*
100
* @param[in] element ID of the currently opened element
101
* @param[in] attrs Attributes within the currently opened element
102
* @exception ProcessError If something fails
103
* @see GenericSAXHandler::myStartElement
104
*/
105
void myStartElement(int element, const SUMOSAXAttributes& attrs);
106
//@}
107
108
void myEndElement(int element);
109
//@}
110
111
private:
112
113
//std::map<int, VissimXMLEdge> myToFill;
114
nodeMap& myElemData;
115
116
/// @brief The current hierarchy level
117
int myHierarchyLevel;
118
119
/// @brief check if the link is a connector
120
bool isConnector;
121
122
/// @brief ID of the currently parsed node, for reporting mainly
123
int myLastNodeID;
124
125
/** @brief invalidated copy constructor */
126
NIVissimXMLHandler_Streckendefinition(const NIVissimXMLHandler_Streckendefinition& s);
127
128
/** @brief invalidated assignment operator */
129
NIVissimXMLHandler_Streckendefinition& operator=(const NIVissimXMLHandler_Streckendefinition& s);
130
};
131
132
133
private:
134
/**
135
* @class NIVissimSingleTypeXMLHandler_Zuflussdefinition
136
* @brief A class which extracts VISSIM-Zuflüsse from a parsed VISSIM-file
137
*/
138
class NIVissimXMLHandler_Zuflussdefinition : public GenericSAXHandler {
139
public:
140
/** @brief Constructor
141
*/
142
NIVissimXMLHandler_Zuflussdefinition();
143
144
145
/// @brief Destructor
146
~NIVissimXMLHandler_Zuflussdefinition();
147
148
protected:
149
/// @name inherited from GenericSAXHandler
150
//@{
151
152
/** @brief Called on the opening of a tag;
153
*
154
* @param[in] element ID of the currently opened element
155
* @param[in] attrs Attributes within the currently opened element
156
* @exception ProcessError If something fails
157
* @see GenericSAXHandler::myStartElement
158
*/
159
void myStartElement(int element, const SUMOSAXAttributes& attrs);
160
//@}
161
162
163
private:
164
165
166
167
/** @brief invalidated copy constructor */
168
NIVissimXMLHandler_Zuflussdefinition(const NIVissimXMLHandler_Zuflussdefinition& z);
169
170
/** @brief invalidated assignment operator */
171
NIVissimXMLHandler_Zuflussdefinition& operator=(const NIVissimXMLHandler_Zuflussdefinition& z);
172
};
173
174
175
private:
176
/**
177
* @class NIVissimSingleTypeXMLHandler_Parkplatzdefinition
178
* @brief A class which extracts VISSIM-Parkplätze from a parsed VISSIM-file
179
*/
180
class NIVissimXMLHandler_Parkplatzdefinition : public GenericSAXHandler {
181
public:
182
/** @brief Constructor
183
*/
184
NIVissimXMLHandler_Parkplatzdefinition();
185
186
187
/// @brief Destructor
188
~NIVissimXMLHandler_Parkplatzdefinition();
189
190
protected:
191
/// @name inherited from GenericSAXHandler
192
//@{
193
194
/** @brief Called on the opening of a tag;
195
*
196
* @param[in] element ID of the currently opened element
197
* @param[in] attrs Attributes within the currently opened element
198
* @exception ProcessError If something fails
199
* @see GenericSAXHandler::myStartElement
200
*/
201
void myStartElement(int element, const SUMOSAXAttributes& attrs);
202
//@}
203
204
205
private:
206
207
208
209
/** @brief invalidated copy constructor */
210
NIVissimXMLHandler_Parkplatzdefinition(const NIVissimXMLHandler_Parkplatzdefinition& z);
211
212
/** @brief invalidated assignment operator */
213
NIVissimXMLHandler_Parkplatzdefinition& operator=(const NIVissimXMLHandler_Parkplatzdefinition& z);
214
};
215
216
217
private:
218
/**
219
* @class NIVissimSingleTypeXMLHandler_Fahrzeugklassendefinition
220
* @brief A class which extracts VISSIM-Fahrzeugklassen from a parsed VISSIM-file
221
*/
222
class NIVissimXMLHandler_Fahrzeugklassendefinition : public GenericSAXHandler {
223
public:
224
/** @brief Constructor
225
* @param[in] elemData The string container to fill
226
*/
227
228
NIVissimXMLHandler_Fahrzeugklassendefinition(nodeMap& elemData);
229
230
231
/// @brief Destructor
232
~NIVissimXMLHandler_Fahrzeugklassendefinition();
233
234
protected:
235
/// @name inherited from GenericSAXHandler
236
//@{
237
238
/** @brief Called on the opening of a tag;
239
*
240
* @param[in] element ID of the currently opened element
241
* @param[in] attrs Attributes within the currently opened element
242
* @exception ProcessError If something fails
243
* @see GenericSAXHandler::myStartElement
244
*/
245
void myStartElement(int element, const SUMOSAXAttributes& attrs);
246
//@}
247
248
void myEndElement(int element);
249
//@}
250
251
private:
252
253
//std::map<int, VissimXMLEdge> myToFill;
254
nodeMap& myElemData;
255
256
/// @brief The current hierarchy level
257
int myHierarchyLevel;
258
259
/// @brief ID of the currently parsed node, for reporting mainly
260
int myLastNodeID;
261
262
/** @brief invalidated copy constructor */
263
NIVissimXMLHandler_Fahrzeugklassendefinition(const NIVissimXMLHandler_Fahrzeugklassendefinition& f);
264
265
/** @brief invalidated assignment operator */
266
NIVissimXMLHandler_Fahrzeugklassendefinition& operator=(const NIVissimXMLHandler_Fahrzeugklassendefinition& f);
267
};
268
269
private:
270
/**
271
* @class NIVissimSingleTypeXMLHandler_VWunschentscheidungsdefinition
272
* @brief A class which extracts VISSIM-VWunschentscheidungen from a parsed VISSIM-file
273
*/
274
class NIVissimXMLHandler_VWunschentscheidungsdefinition : public GenericSAXHandler {
275
public:
276
/** @brief Constructor
277
* @param[in] elemData The string container to fill
278
*/
279
280
NIVissimXMLHandler_VWunschentscheidungsdefinition(nodeMap& elemData);
281
282
283
/// @brief Destructor
284
~NIVissimXMLHandler_VWunschentscheidungsdefinition();
285
286
protected:
287
/// @name inherited from GenericSAXHandler
288
//@{
289
290
/** @brief Called on the opening of a tag;
291
*
292
* @param[in] element ID of the currently opened element
293
* @param[in] attrs Attributes within the currently opened element
294
* @exception ProcessError If something fails
295
* @see GenericSAXHandler::myStartElement
296
*/
297
void myStartElement(int element, const SUMOSAXAttributes& attrs);
298
//@}
299
300
void myEndElement(int element);
301
//@}
302
303
private:
304
305
//std::map<int, VissimXMLEdge> myToFill;
306
nodeMap& myElemData;
307
308
/// @brief The current hierarchy level
309
int myHierarchyLevel;
310
311
/// @brief ID of the currently parsed node, for reporting mainly
312
int myLastNodeID;
313
314
/** @brief invalidated copy constructor */
315
NIVissimXMLHandler_VWunschentscheidungsdefinition(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW);
316
317
/** @brief invalidated assignment operator */
318
NIVissimXMLHandler_VWunschentscheidungsdefinition& operator=(const NIVissimXMLHandler_VWunschentscheidungsdefinition& vW);
319
};
320
321
322
323
324
private:
325
/**
326
* @class NIVissimSingleTypeXMLHandler_Geschwindigkeitsverteilungsdefinition
327
* @brief A class which extracts VISSIM-Geschwindigkeitsverteilung from a parsed VISSIM-file
328
*/
329
class NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition : public GenericSAXHandler {
330
public:
331
/** @brief Constructor
332
* @param[in] elemData The string container to fill
333
*/
334
335
NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(nodeMap& elemData);
336
337
338
/// @brief Destructor
339
~NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition();
340
341
protected:
342
/// @name inherited from GenericSAXHandler
343
//@{
344
345
/** @brief Called on the opening of a tag;
346
*
347
* @param[in] element ID of the currently opened element
348
* @param[in] attrs Attributes within the currently opened element
349
* @exception ProcessError If something fails
350
* @see GenericSAXHandler::myStartElement
351
*/
352
void myStartElement(int element, const SUMOSAXAttributes& attrs);
353
//@}
354
355
void myEndElement(int element);
356
//@}
357
358
private:
359
360
//std::map<int, VissimXMLEdge> myToFill;
361
nodeMap& myElemData;
362
363
/// @brief The current hierarchy level
364
int myHierarchyLevel;
365
366
/// @brief ID of the currently parsed node, for reporting mainly
367
int myLastNodeID;
368
369
/** @brief invalidated copy constructor */
370
NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW);
371
372
/** @brief invalidated assignment operator */
373
NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& operator=(const NIVissimXMLHandler_Geschwindigkeitsverteilungsdefinition& vW);
374
};
375
376
377
private:
378
/**
379
* @class NIVissimXMLHandler_Routenentscheidungsdefinition
380
* @brief A class which extracts VISSIM-Routes from a parsed VISSIM-file
381
*/
382
class NIVissimXMLHandler_Routenentscheidungsdefinition : public GenericSAXHandler {
383
public:
384
/** @brief Constructor
385
* @param[in] elemData The string container to fill
386
*/
387
388
NIVissimXMLHandler_Routenentscheidungsdefinition(nodeMap& elemData);
389
390
391
/// @brief Destructor
392
~NIVissimXMLHandler_Routenentscheidungsdefinition();
393
394
protected:
395
/// @name inherited from GenericSAXHandler
396
//@{
397
398
/** @brief Called on the opening of a tag;
399
*
400
* @param[in] element ID of the currently opened element
401
* @param[in] attrs Attributes within the currently opened element
402
* @exception ProcessError If something fails
403
* @see GenericSAXHandler::myStartElement
404
*/
405
void myStartElement(int element, const SUMOSAXAttributes& attrs);
406
//@}
407
408
void myEndElement(int element);
409
//@}
410
411
private:
412
413
//std::map<int, VissimXMLEdge> myToFill;
414
nodeMap& myElemData;
415
416
/// @brief The current hierarchy level
417
int myHierarchyLevel;
418
419
/// @brief ID of the currently parsed node, for reporting mainly
420
int myLastNodeID;
421
422
/** @brief invalidated copy constructor */
423
NIVissimXMLHandler_Routenentscheidungsdefinition(const NIVissimXMLHandler_Routenentscheidungsdefinition& r);
424
425
/** @brief invalidated assignment operator */
426
NIVissimXMLHandler_Routenentscheidungsdefinition& operator=(const NIVissimXMLHandler_Routenentscheidungsdefinition& r);
427
};
428
429
430
private:
431
/**
432
* @class NIVissimSingleTypeXMLHandler_ConflictArea
433
* @brief A class which extracts VISSIM-ConflictAreas from a parsed VISSIM-file
434
*/
435
class NIVissimXMLHandler_ConflictArea : public GenericSAXHandler {
436
public:
437
/** @brief Constructor
438
*/
439
NIVissimXMLHandler_ConflictArea();
440
441
442
/// @brief Destructor
443
~NIVissimXMLHandler_ConflictArea();
444
445
446
protected:
447
/// @name inherited from GenericSAXHandler
448
//@{
449
450
/** @brief Called on the opening of a tag;
451
*
452
* @param[in] element ID of the currently opened element
453
* @param[in] attrs Attributes within the currently opened element
454
* @exception ProcessError If something fails
455
* @see GenericSAXHandler::myStartElement
456
*/
457
void myStartElement(int element, const SUMOSAXAttributes& attrs);
458
//@}
459
460
461
private:
462
463
464
/** @brief invalidated copy constructor */
465
NIVissimXMLHandler_ConflictArea(const NIVissimXMLHandler_ConflictArea& c);
466
467
/** @brief invalidated assignment operator */
468
NIVissimXMLHandler_ConflictArea& operator=(const NIVissimXMLHandler_ConflictArea& c);
469
};
470
471
472
protected:
473
/// constructor
474
NIImporter_Vissim(NBNetBuilder& nb);
475
476
/// destructor
477
~NIImporter_Vissim();
478
479
/// loads the vissim file
480
void load(const OptionsCont& options);
481
482
bool admitContinue(const std::string& tag);
483
484
public:
485
class VissimSingleTypeParser {
486
public:
487
/// Constructor
488
VissimSingleTypeParser(NIImporter_Vissim& parent);
489
490
/// Destructor
491
virtual ~VissimSingleTypeParser();
492
493
/** @brief Parses a single data type.
494
Returns whether no error occurred */
495
virtual bool parse(std::istream& from) = 0;
496
497
protected:
498
/// reads from the stream and returns the lower case version of the read value
499
std::string myRead(std::istream& from);
500
501
/// as myRead, but returns "DATAEND" when the current field has ended
502
std::string readEndSecure(std::istream& from,
503
const std::string& excl = "");
504
505
std::string readEndSecure(std::istream& from,
506
const std::vector<std::string>& excl);
507
508
/// overrides the optional label definition; returns the next tag as done by readEndSecure
509
std::string overrideOptionalLabel(std::istream& from,
510
const std::string& tag = "");
511
512
/// returns the 2d-position saved as next within the stream
513
Position getPosition(std::istream& from);
514
515
/** @brief parses a listof vehicle types assigned to the current data field
516
One should remeber, that -1 means "all" vehicle types */
517
std::vector<int> parseAssignedVehicleTypes(std::istream& from,
518
const std::string& next);
519
520
NIVissimExtendedEdgePoint readExtEdgePointDef(std::istream& from);
521
522
/** @brief Reads the structures name
523
We cannot use the "<<" operator, as names may contain more than one word
524
which are joined using '"'. */
525
std::string readName(std::istream& from);
526
527
/** @brief Overreads the named parameter (if) given and skips the rest until "DATAEND"
528
*/
529
bool skipOverreading(std::istream& from, const std::string& name = "");
530
531
/// Reads from the stream until the keywor occurs
532
void readUntil(std::istream& from, const std::string& name);
533
534
private:
535
NIImporter_Vissim& myVissimParent;
536
537
private:
538
/// @brief Invalidated assignment operator.
539
VissimSingleTypeParser& operator=(const VissimSingleTypeParser&);
540
541
};
542
543
544
/// definition of a map from color names to color definitions
545
typedef std::map<std::string, RGBColor> ColorMap;
546
547
private:
548
bool readContents(std::istream& strm);
549
void postLoadBuild(double offset);
550
551
552
/// adds name-to-id - relationships of known elements into myKnownElements
553
void insertKnownElements();
554
555
/// adds id-to-parser - relationships of elements to parse into myParsers
556
void buildParsers();
557
558
private:
559
/// Definition of a map from element names to their numerical representation
560
typedef std::map<std::string, NIVissimElement> ToElemIDMap;
561
562
/// Map from element names to their numerical representation
563
ToElemIDMap myKnownElements;
564
565
/// Definition of a map from an element's numerical id to his parser
566
typedef std::map<NIVissimElement, VissimSingleTypeParser*> ToParserMap;
567
568
/// Parsers by element id
569
ToParserMap myParsers;
570
571
/// a map from color names to color definitions
572
ColorMap myColorMap;
573
574
std::string myLastSecure;
575
576
NBNetBuilder& myNetBuilder;
577
578
private:
579
/// @brief Invalidated copy constructor.
580
NIImporter_Vissim(const NIImporter_Vissim&);
581
582
/// @brief Invalidated assignment operator.
583
NIImporter_Vissim& operator=(const NIImporter_Vissim&);
584
585
586
587
/**
588
* @enum VissimXMLTag
589
* @brief Numbers representing VISSIM-XML - element names
590
* @see GenericSAXHandler
591
*/
592
enum VissimXMLTag {
593
VISSIM_TAG_NOTHING = 0,
594
VISSIM_TAG_NETWORK,
595
VISSIM_TAG_LANES,
596
VISSIM_TAG_LANE,
597
VISSIM_TAG_LINK,
598
VISSIM_TAG_LINKS,
599
VISSIM_TAG_POINTS3D,
600
VISSIM_TAG_POINT3D,
601
VISSIM_TAG_LINKPOLYPOINT,
602
VISSIM_TAG_LINKPOLYPTS,
603
VISSIM_TAG_FROM,
604
VISSIM_TAG_TO,
605
VISSIM_TAG_VEHICLE_INPUT,
606
VISSIM_TAG_PARKINGLOT,
607
VISSIM_TAG_VEHICLE_CLASS,
608
VISSIM_TAG_INTOBJECTREF,
609
VISSIM_TAG_SPEED_DECISION,
610
VISSIM_TAG_SPEED_DIST,
611
VISSIM_TAG_DATAPOINT,
612
VISSIM_TAG_DECISION_STATIC,
613
VISSIM_TAG_ROUTE_STATIC,
614
VISSIM_TAG_CA
615
};
616
617
618
/**
619
* @enum VissimXMLAttr
620
* @brief Numbers representing VISSIM-XML - attributes
621
* @see GenericSAXHandler
622
*/
623
enum VissimXMLAttr {
624
VISSIM_ATTR_NOTHING = 0,
625
VISSIM_ATTR_NO,
626
VISSIM_ATTR_NAME,
627
VISSIM_ATTR_X,
628
VISSIM_ATTR_Y,
629
VISSIM_ATTR_ZOFFSET,
630
VISSIM_ATTR_ZUSCHLAG1,
631
VISSIM_ATTR_ZUSCHLAG2,
632
VISSIM_ATTR_WIDTH,
633
VISSIM_ATTR_LINKBEHAVETYPE,
634
VISSIM_ATTR_LANE,
635
VISSIM_ATTR_POS,
636
VISSIM_ATTR_LINK,
637
VISSIM_ATTR_INTLINK,
638
VISSIM_ATTR_PERCENTAGE,
639
VISSIM_ATTR_DISTRICT,
640
VISSIM_ATTR_COLOR,
641
VISSIM_ATTR_KEY,
642
VISSIM_ATTR_FX,
643
VISSIM_ATTR_DESTLINK,
644
VISSIM_ATTR_DESTPOS,
645
VISSIM_ATTR_LINK1,
646
VISSIM_ATTR_LINK2,
647
VISSIM_ATTR_STATUS
648
};
649
650
/// The names of VISSIM-XML elements (for passing to GenericSAXHandler)
651
static SequentialStringBijection::Entry vissimTags[];
652
653
/// The names of VISSIM-XML attributes (for passing to GenericSAXHandler)
654
static SequentialStringBijection::Entry vissimAttrs[];
655
656
657
};
658
659