Commit fa777cef authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

traci personapi: retrieve all targets with agentId = -1

If the getTargetId TraCI-Command is executed with the targetId "-1" (invalid for any agent) then the command returns a list of all targetIds currently in the simulation.
parent b71107de
......@@ -9,6 +9,31 @@
- Added new scenario element `TargetChanger`. This scenario element has an arbitrary shape and changes the target of an agent. Either to another static target or to another agent (to get a follower behavior). A `TargetChanger` has two important parameters:
* `changeTargetProbability`: This defines how many percent of the agents, who enter the area, should change their target.
* `nextTargetIsPedestrian`: If `nextTargetIsPedestrian == false`, assign a new static target. Otherwise, randomly choose a pedestrian (with given target id) to follow.
- Add Scenario Hash to info panel below of the TopographyCreator and Post-Visualisation View:
* will show if changes to the scenario will change the floorfield
* Hover over hash to see full value
* Left-Click to copy full hash to clipboard.
- TraCI commands:
* getHash: return Scenario hash for given scenario
* CompoundObject implementation to allow complex get/set commands (i.e. create pedestrian hat
random location during simulation run)
- osm2vadere converter:
* it is possible to specify a way with the tag `area-of-intrest` (AOI). If this is present and the
corresponding command line argument is given, only elements within the bounding box of the
AOI will be converted.
- Add INET environment export:
* create an INET environment xml file based on the current topography. For now only prism shapes
are possible with a fixed height of 5m.
- vadere-console `utils` subCommand:
* A miscellaneous collector of simple function operating on a single scenario file.
* -f (input file or directory depending on method m [required])
* -o (ouput file or directory depending on method m [optional])
* -m (name of method.) See subparser help for allowed functions.
* currently implementd:
* `getHash`: Hash value of given scenario. (-o option ignored)
* `binCache`: calculate binary cache (-o must be a directory. If missing it will be created)
* `txtCache`: calculate text based cache (-o must be a directory. If missing it will be created)
### Changed
......@@ -19,8 +44,22 @@ Was previously known as `PedestrianFootStepProcessor`
* Mouse Wheel Scroll: Scroll vertically.
* Shift + Mouse Wheel Scroll: Scroll horizontally.
* Use Alt key to decrease the step size while scrolling.
# v1.4 (2019-09-05)
- CachePath lookup:
The new cache lookup now allows a 'global' lookup. Previously all cache files are saved in
a `__cache__` folder relative (as sibling) to the currently running scenario file. This works
good for local testing and runs. However, if one scenario is duplicated and integrated in other
projects the same cache would be created at multiple locations. The current solution would be
to enter an absolute path as the `cacheDir` but this will break interoperatbility between
windows and linux as well as sharing scenario files with other users. CacheDir Lookup order:
1. `cacheDir` is an absolute path: Use it; and log the path to console.
2. `cacheDir` is relative and `Vadere.cache.useGlobalCacheBaseDir=false` (default):
save cache in a `__cache__` folder relative (as sibling) to the currently running scenario file
3. `cacheDir` is relative and `Vadere.cache.useGlobalCacheBaseDir=true`:
Lookup `Vadere.cache.flobalCacheBaseDir` and use this as the base path for the relative
`cacheDir` path. `Vadere.cache.flobalCacheBaseDir` defaults to `${user.home}\.cache\vadere`
## v1.4 (2019-09-05)
### Changed
......
This diff is collapsed.
This diff is collapsed.
<environment>
<object id="0" orientation="0.000000 0.000000 0.000000" position="min -0.000100 141.499900 0.000000" shape="prism 5.000000 0.000000 0.500200 86.000200 0.500200 86.000200 0.000000 0.000000 0.000000" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="1" orientation="0.000000 0.000000 0.000000" position="min 85.499900 -0.000100 0.000000" shape="prism 5.000000 0.500200 142.000200 0.500200 0.000000 0.000000 0.000000 0.000000 142.000200" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="2" orientation="0.000000 0.000000 0.000000" position="min -0.000100 -0.000100 0.000000" shape="prism 5.000000 86.000200 0.000000 0.000000 0.000000 0.000000 0.500200 86.000200 0.500200" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="3" orientation="0.000000 0.000000 0.000000" position="min -0.000100 -0.000100 0.000000" shape="prism 5.000000 0.000000 0.000000 0.000000 142.000200 0.500200 142.000200 0.500200 0.000000" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927194" orientation="0.000000 0.000000 0.000000" position="min 65.023721 18.141951 0.000000" shape="prism 5.000000 0.097967 0.000000 2.600431 0.500010 7.451206 1.469227 11.744796 2.327111 11.646830 2.817419 7.353239 1.959535 2.502463 0.990319 0.000000 0.490308" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927197" orientation="0.000000 0.000000 0.000000" position="min 67.330239 0.452397 0.000000" shape="prism 5.000000 0.000000 18.384617 0.823824 14.357496 1.371477 11.549834 1.869042 9.032050 2.384619 6.397758 2.867939 3.913338 3.570679 0.000000 4.062804 0.088387 3.357628 4.014305 2.872547 6.507776 2.355919 9.147441 1.859638 11.658724 1.315062 14.450614 0.489856 18.484822" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927211" orientation="0.000000 0.000000 0.000000" position="min 48.786631 131.029021 0.000000" shape="prism 5.000000 0.000000 9.112117 2.385684 0.000000 8.798161 1.746132 6.280449 10.970979 5.798091 10.839331 8.184104 2.097146 2.741502 0.615114 0.483697 9.238757" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927216" orientation="0.000000 0.000000 0.000000" position="min 12.546889 6.208962 0.000000" shape="prism 5.000000 0.638360 0.008004 0.508036 8.148201 3.117876 8.153694 3.190592 0.010322 3.690572 0.014784 3.613457 8.654681 0.000000 8.647077 0.138424 0.000000" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927222" orientation="0.000000 0.000000 0.000000" position="min 7.226045 16.476162 0.000000" shape="prism 5.000000 5.165752 0.000000 6.981243 0.128135 9.054575 0.183719 9.024160 2.644031 38.788409 7.892864 40.347377 2.106991 43.913163 2.975158 46.080824 3.427979 45.033199 8.347162 55.650080 10.545562 58.348680 11.140381 57.328551 15.692519 68.759934 17.710345 56.338881 76.108725 42.834482 72.698656 41.052201 79.262111 40.578544 81.469492 40.248282 83.169896 41.803341 83.396127 43.486497 74.860853 45.296898 75.300741 46.902064 75.524389 50.695269 76.301425 49.611418 81.924241 67.386772 85.641339 67.084657 87.446601 66.178007 92.545895 56.006298 90.481226 49.919773 115.062758 48.136741 114.527887 46.390585 114.051623 44.718182 113.540943 48.540095 98.519692 40.738110 96.709945 32.388204 94.698880 29.281547 106.185753 32.750205 107.029866 36.269330 107.875022 33.804643 116.878049 31.232507 116.289941 29.334982 115.740814 15.571897 112.275861 13.671772 111.739374 11.476298 111.179954 13.344634 102.334611 16.627379 103.120093 19.894870 103.913255 21.779681 93.146253 7.347226 90.261142 7.049103 97.223184 4.490086 97.157534 4.566063 94.106486 3.517874 94.080369 1.684452 94.029689 0.000000 93.981017 1.476866 64.518467 2.930439 64.548030 5.204956 64.572437 6.647673 64.550691 6.844521 71.291833 21.400376 74.372536 21.017713 76.683094 22.497091 76.960385 22.944108 74.739401 26.656666 75.481242 38.055564 13.062062 4.884845 6.933063 4.898136 0.248877 5.398122 0.249868 5.385708 6.517167 38.637054 12.661063 27.057211 76.071076 23.335806 75.327467 22.889980 77.542535 20.444273 77.084119 20.828750 74.762612 6.356148 71.699530 6.162213 65.058165 5.206672 65.072568 2.951070 65.048363 1.951948 65.028043 0.524940 93.495958 1.429385 93.522092 3.756052 93.586408 5.078281 93.619352 5.002295 96.670744 6.570610 96.710980 6.872696 89.656385 22.356372 92.751640 20.295367 104.525148 16.447499 103.591103 13.727708 102.940323 12.064593 110.814072 13.807031 111.258055 15.700146 111.792562 29.463251 115.257521 31.355057 115.804992 33.449010 116.283766 35.650933 108.240569 32.547496 107.495245 28.664978 106.550418 32.032523 94.098910 40.856962 96.224265 49.150556 98.148046 45.320305 113.202067 46.536768 113.573522 48.284617 114.050249 49.560612 114.433019 55.636144 89.895885 65.775370 91.953960 66.596999 87.332850 66.814624 86.032456 49.027212 82.312837 50.110644 76.692196 46.812773 76.016628 45.201698 75.792157 43.875948 75.470029 42.201850 83.959372 39.657616 83.589235 40.089827 81.363932 40.566344 79.143223 42.480631 72.093641 55.957845 75.496846 68.163171 18.112727 56.726126 16.093902 57.751010 11.520550 55.554340 11.036366 44.439411 8.734836 45.487196 3.814904 43.802890 3.463055 40.703121 2.708351 39.152110 8.464694 8.518951 3.062633 8.548529 0.670031 6.945828 0.627064 5.130506 0.498744" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
<object id="-2146927212" orientation="0.000000 0.000000 0.000000" position="min 78.035688 103.635593 0.000000" shape="prism 5.000000 6.932912 1.712890 0.802123 0.581607 0.586299 1.693593 6.655392 2.847185 6.562025 3.338390 0.000000 2.091034 0.405846 0.000000 7.023643 1.221190" material="brick" fill-color="200 0 0" opacity="0.750000" texture="brick.jpg" />
</environment>
{
"name" : "roVerTest002",
"description" : "",
"release" : "1.4",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
"filename" : "postvis.traj",
"processors" : [ 6, 7 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepProcessor",
"id" : 6
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 7
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 4,
"numberOfCircles" : 1,
"optimizationType" : "DISCRETE",
"varyStepDirection" : true,
"movementType" : "ARBITRARY",
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"minStepLength" : 0.1,
"minimumStepLength" : true,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : true,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
"pedPotentialPersonalSpaceWidth" : 1.2,
"pedPotentialHeight" : 50.0,
"obstPotentialWidth" : 0.8,
"obstPotentialHeight" : 6.0,
"intimateSpaceFactor" : 1.2,
"personalSpacePower" : 1,
"intimateSpacePower" : 1
},
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"cacheType" : "BIN_CACHE",
"cacheDir" : "roVerTest002",
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT",
"width" : 0.2,
"height" : 1.0
}
}
},
"attributesSimulation" : {
"finishTime" : 800.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : -359668230868604320,
"simulationSeed" : 0,
"useSalientBehavior" : false
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 250.0,
"height" : 250.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true,
"referenceCoordinateSystem" : null
},
"obstacles" : [ {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 184.0,
"y" : 0.3999999999999999
}, {
"x" : 184.0,
"y" : 121.4
}, {
"x" : 130.7,
"y" : 121.4
}, {
"x" : 130.7,
"y" : 0.3999999999999999
} ]
},
"id" : 3
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 249.5,
"y" : 180.0
}, {
"x" : 249.5,
"y" : 223.8
}, {
"x" : 158.6,
"y" : 223.8
}, {
"x" : 158.6,
"y" : 180.0
} ]
},
"id" : 4
}, {
"shape" : {
"x" : 50.7,
"y" : 82.6,
"width" : 16.7,
"height" : 150.4,
"type" : "RECTANGLE"
},
"id" : 11
} ],
"measurementAreas" : [ ],
"stairs" : [ ],
"targets" : [ {
"id" : 6,
"absorbing" : true,
"shape" : {
"x" : 16.3,
"y" : 202.2,
"width" : 14.9,
"height" : 17.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 7,
"absorbing" : true,
"shape" : {
"x" : 223.2,
"y" : 227.2,
"width" : 11.2,
"height" : 12.3,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 8,
"absorbing" : true,
"shape" : {
"x" : 209.8,
"y" : 16.7,
"width" : 23.5,
"height" : 11.9,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 9,
"absorbing" : false,
"shape" : {
"x" : 44.6,
"y" : 44.2,
"width" : 32.9,
"height" : 15.9,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 10,
"absorbing" : false,
"shape" : {
"x" : 133.3,
"y" : 140.2,
"width" : 32.3,
"height" : 18.9,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ ],
"absorbingAreas" : [ ],
"sources" : [ {
"id" : 1,
"shape" : {
"x" : 0.7,
"y" : 201.8,
"width" : 13.1,
"height" : 17.8,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 3,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 10.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 8 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
}, {
"id" : 2,
"shape" : {
"x" : 238.4,
"y" : 226.4,
"width" : 9.8,
"height" : 13.8,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 5,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 15.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 10, 6 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
}, {
"id" : 5,
"shape" : {
"x" : 209.1,
"y" : 2.5,
"width" : 25.7,
"height" : 11.3,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 5,
"maxSpawnNumberTotal" : -1,
"startTime" : 5.0,
"endTime" : 10.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 9, 7 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"angleCalculationType" : "USE_CENTER",
"targetOrientationAngleThreshold" : 45.0
},
"teleporter" : null,
"attributesCar" : null
},
"eventInfos" : [ ]
}
}
\ No newline at end of file
......@@ -136,10 +136,23 @@ class OsmConverter:
for f in self.osm.measurement_selectors:
self.measurement.extend(f())
def filter_area_of_interest(self):
aoi = self.osm.get_area_of_intrest()
if aoi:
self.obstacles = [o for o in self.obstacles if self.osm.contained_in_area_of_intrest(aoi, o)]
self.targets = [o for o in self.targets if self.osm.contained_in_area_of_intrest(aoi, o)]
self.sources = [o for o in self.sources if self.osm.contained_in_area_of_intrest(aoi, o)]
self.measurement = [o for o in self.measurement if self.osm.contained_in_area_of_intrest(aoi, o)]
@classmethod
def from_args(cls, arg):
c = cls(arg.input, arg.use_osm_id)
c.filter()
if arg.use_aoi:
c.filter_area_of_interest()
return c
@staticmethod
......@@ -487,6 +500,15 @@ def parse_command_line_arguments():
default=True,
help="Set to use osm ids for obstacles")
convert_parser.add_argument("--use-aoi",
dest='use_aoi',
type=str2bool,
const=True,
nargs="?",
default=False,
help="Set to reduce export to elements within an area of interest. "
"(way taged with vadere:area-of-intrest) ")
convert_parser.set_defaults(main_func=main_convert)
cmd_args = main.parse_args()
......@@ -557,5 +579,12 @@ def main_convert(cmd_args):
if __name__ == "__main__":
# i = '/home/stsc/repos/vadere/Scenarios/Demos/roVer/scenarios/mf_underground.osm'
# o = '/home/stsc/repos/vadere/Scenarios/Demos/roVer/scenarios/mf_underground.scenario'
# c = OsmConverter(i, True)
# c.filter()
# c.filter_area_of_interest()
#
# #
args = parse_command_line_arguments()
args.main_func(args)
......@@ -782,6 +782,44 @@ class OsmData:
print(f"created new hull-way (id:{hull_way.id}) containing {way_ids}")
return hull_way.id
def contained_in_area_of_intrest(self, aoi, way: Element):
min_lat = aoi[0][0]
max_lat = aoi[0][1]
min_lon = aoi[1][0]
max_lon = aoi[1][1]
nodes = [self.lookup.node_to_latlon[int(id)] for id in way.xpath("nd/@ref")]
for n in nodes:
if n[0] < min_lat or n[0] > max_lat or n[1] < min_lon or n[1] > max_lon:
return False
return True
def get_area_of_intrest(self):
'''
Return lat/lon min/max values for element within area of intrest
:return:
'''
self.xml.xpath("/osm/way/tag[@k='vadere:area-of-intrest']")
lat = [0,0]
lon = [0,0]
nodes = [self.lookup.node_to_latlon[int(id)] for id in self.xml.xpath("/osm/way[./tag/@k='vadere:area-of-intrest']/nd/@ref")][:-1]
if len(nodes) == 0:
raise RuntimeError(f"No area of interst found. Map does not contain a way with the tag 'vadere:area-of-intrest'")
elif len(nodes) < 2:
raise RuntimeError(f"area-of-intrest path contains only '{len(nodes)}' nodes. Need at least 3 nodes to "
f"create area of interest.")
node_lat = [n[0] for n in nodes]
node_lon = [n[1] for n in nodes]
return ([min(node_lat), max(node_lat)], [min(node_lon), max(node_lon)])
def lint_add_ids(self, dry_run=False):
ways_without_id: List[Element] = self.xml.xpath("/osm/way[@id < 0 and not (./tag[@k='rover:id'])]")
print(f"found {len(ways_without_id)} way elements without id")
......
......@@ -141,7 +141,7 @@ public class ClientAnnotationProcessor extends AbstractProcessor {
.substring(traCIApi.singleAnnotation.lastIndexOf(".") + 1).trim();
if (anName.equals(singeAn)){
ApiHandler apiHandler = new ApiHandler(traCIApi, element, anMirror);
apiMapping.append(String.format("\t\tconsoleReader.addCommand(\"%s.%s\", \"\", this::%s_%s);\n", traCIApi.name.toLowerCase(), apiHandler.name, traCIApi.name.toLowerCase(), apiHandler.name));
apiMapping.append(String.format("\t\tconsoleReader.addCommand(\"%s.%s\", \"\", this::%s_%s);\n", traCIApi.nameShort.toLowerCase(), apiHandler.name, traCIApi.name.toLowerCase(), apiHandler.name));
apiAbstract.append(String.format("\t\tabstract public void %s_%s (String args[]) throws IOException;\n",traCIApi.name.toLowerCase(), apiHandler.name));
switch (apiHandler.apiType){
case "GET":
......@@ -160,25 +160,37 @@ public class ClientAnnotationProcessor extends AbstractProcessor {
}
protected void writeGET(PrintWriter writer, ApiHandler apiHandler){
if (apiHandler.ignoreElementId){
writer.append("\tpublic TraCIGetResponse ").append(apiHandler.name).append("() throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", \"-1\");").println();
}
else {
writer.append("\tpublic TraCIGetResponse ").append(apiHandler.name).append("(String elementID) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", elementID);").println();
if (apiHandler.dataTypeStr.isEmpty()){
// standard GET command without additional data
if (apiHandler.ignoreElementId){
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("() throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", \"-1\");").println();
}
else {
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("(String elementID) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", ").append(apiHandler.varId).append(", elementID);").println();
}
} else {
// extended GET command which accepts any kind of data based on the standard traci data types
if (apiHandler.ignoreElementId){
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("(").append(apiHandler.dataTypeStr).append(" data) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", \"-1\" , ").append(apiHandler.varId).append(", ").append(apiHandler.varType).append(", data);").println();
} else {
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("(String elementId, ").append(apiHandler.dataTypeStr).append(" data) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCIGetCommand.build(").append(apiHandler.cmd).append(", elementId, ").append(apiHandler.varId).append(", ").append(apiHandler.varType).append(", data);").println();
}
}
writer.append("\n\t\tsocket.sendExact(p);\n").println();
writer.append("\t\treturn (TraCIGetResponse) socket.receiveResponse();").println();
writer.append("\t\treturn socket.receiveResponse();").println();
writer.append("\t}").println();
writer.println();
}
protected void writeSET(PrintWriter writer, ApiHandler apiHandler){
writer.append("\tpublic TraCIResponse ").append(apiHandler.name).append("(String elementId, ").append(apiHandler.dataTypeStr).append(" data) throws IOException {").println();
writer.append("\t\tTraCIPacket p = TraCISetCommand.build(")
.append(apiHandler.cmd).append(", elementId, ").append(apiHandler.varId).append(", ").append(apiHandler.varType).append(", data);").println();
writer.append("\t\tTraCIPacket p = TraCISetCommand.build(").append(apiHandler.cmd).append(", elementId, ").append(apiHandler.varId).append(", ").append(apiHandler.varType).append(", data);").println();
writer.append("\n\t\tsocket.sendExact(p);\n").println();
writer.append("\t\treturn socket.receiveResponse();").println();
......@@ -188,6 +200,7 @@ public class ClientAnnotationProcessor extends AbstractProcessor {
class TraCiApiWrapper {
String name;
String nameShort;
String singleAnnotation;
String multipleAnnotation;
String cmdEnum;
......@@ -201,6 +214,8 @@ public class ClientAnnotationProcessor extends AbstractProcessor {
name = traCIApi.name();
nameShort = traCIApi.nameShort();
nameShort = nameShort.isEmpty() ? name : nameShort;
packageName = traCIApi.packageName();
imports = traCIApi.imports();
extendedClassName = traCIApi.extendedClassName();
......
......@@ -15,14 +15,18 @@ public @interface TraCIApi {
"org.vadere.manager.TraCISocket",
"org.vadere.manager.traci.commands.TraCIGetCommand",
"org.vadere.manager.traci.commands.TraCISetCommand",
"org.vadere.manager.traci.compoundobjects.CompoundObject",
"org.vadere.manager.traci.respons.TraCIGetResponse",
"org.vadere.manager.traci.writer.TraCIPacket",
"org.vadere.manager.traci.respons.TraCIResponse",
"java.io.IOException",
"java.util.ArrayList"
"java.util.ArrayList",
"org.vadere.util.geometry.shapes.VPoint"
};
String extendedClassName() default "TraCIClientApi";