X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=dsl%2Fxtend%2Fsrc%2Frobots%2Fmissions%2Fvalidation%2FTaskDSLValidator.xtend;fp=dsl%2Fxtend%2Fsrc%2Frobots%2Fmissions%2Fvalidation%2FTaskDSLValidator.xtend;h=e9f20fb319d3e2eea055eb022389ae2c34ae2d22;hb=844ff9a744d2c253bd5b76475a84370435329405;hp=f3926b5257882326ddcc937e5757d85a5dcc7e33;hpb=f92a71770aa8fc8abe3a60660df2965ec18cb479;p=des2015.git diff --git a/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend b/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend index f3926b5..e9f20fb 100644 --- a/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend +++ b/dsl/xtend/src/robots/missions/validation/TaskDSLValidator.xtend @@ -3,6 +3,14 @@ */ package robots.missions.validation +import java.util.LinkedList +import java.util.List +import org.eclipse.xtext.validation.Check +import robots.missions.taskDSL.Action +import robots.missions.taskDSL.Behaviour +import robots.missions.taskDSL.Mission +import robots.missions.taskDSL.Robot + //import org.eclipse.xtext.validation.Check /** * This class contains custom validation rules. @@ -10,23 +18,44 @@ package robots.missions.validation * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation */ class TaskDSLValidator extends AbstractTaskDSLValidator { -// @Check -// def checkOnlyOneBehaviourPerMissionEmptyTakeControl(Mission m) { -// var List empty = new LinkedList(); -// var List all = new LinkedList(); -// for(Behaviour b : m.behaviours){ -// if(b.tc == null){ -// empty.add(b.name); -// } -// all.add(b.name); -// } -// if(empty.size > 1){ -// warning("Multiple behaviours without takeControl predicate. You might want to remove some of: " + empty.toString(), m.eContainingFeature); -// } -// if(all.toSet().size() < all.size()){ -// warning("You have duplicate behaviours.", m, TaskDSLPackage.Literals::MISSION__BEHAVIOURS); -// } -// } + @Check + def checkRobot(Robot r){ + if(r.acc == 0){ + warning("Acceleration set to zero, this could lead to non moving robot", null); + } + if(r.spd == 0){ + warning("Acceleration set to zero, this could lead to non moving robot", null); + } + } + + @Check + def checkBehavioursl(Mission m) { + var List empty = new LinkedList(); + var List all = new LinkedList(); + var List warned = new LinkedList(); + for(Behaviour b : m.behaviours){ + if(b.tc == null){ + empty.add(b.name); + } + if(all.contains(b.name) && !warned.contains(b.name)){ + warning("Behaviour '" + b.name + "' multiple times in the behaviourlist.", null); + warned.add(b.name); + } + all.add(b.name); + } + if(empty.size() > 1){ + warning("Multiple behaviours without takeControl predicate. You might want to remove some of: " + empty.toString(), null); + } + } -//Validate if the random degrees are correct + @Check + def checkActions(Action a) { + if(a.turnType != null && a.turnType.turnDir == null){ + if(a.turnType.start == a.turnType.end){ + error("Start and end cannot be the same", null); + } else if(a.turnType.start > a.turnType.end){ + error("Start should be smaller then end", null); + } + } + } }