Пример #1
0
        public Program(string name, RobotSystem robotSystem, IEnumerable<IEnumerable<Target>> targets, Commands.Group initCommands = null, IEnumerable<int> multiFileIndices = null, double stepSize = 1.0)
        {
            if (targets.SelectMany(x => x).Count() == 0)
                throw new Exception(" The program has to contain at least 1 target");

            int targetCount = targets.First().Count();
            foreach (var subTargets in targets)
            {
                if (subTargets.Count() != targetCount) throw new Exception(" All sub programs have to contain the same number of targets");
            }

            this.Name = name;
            this.RobotSystem = robotSystem;

            this.InitCommands = new Commands.Group();
            if (initCommands != null) this.InitCommands.AddRange(initCommands.Flatten());

            if (multiFileIndices != null && multiFileIndices.Count() > 0)
            {
                multiFileIndices = multiFileIndices.Where(x => x < targetCount);
                this.MultiFileIndices = multiFileIndices.ToList();
                this.MultiFileIndices.Sort();
                if (this.MultiFileIndices.Count == 0 || this.MultiFileIndices[0] != 0) this.MultiFileIndices.Insert(0, 0);
            }
            else
                this.MultiFileIndices = new int[1].ToList();

            var cellTargets = new List<CellTarget>(targetCount);

            int targetIndex = 0;

            foreach (var subTargets in targets.Transpose())
            {
                var programTargets = subTargets.Select((x, i) => new ProgramTarget(subTargets[i], i));
                var cellTarget = new CellTarget(programTargets, targetIndex);
                cellTargets.Add(cellTarget);
                targetIndex++;
            }

            var checkProgram = new CheckProgram(this, cellTargets, stepSize);
            int indexError = checkProgram.indexError;
            if (indexError != -1) cellTargets = cellTargets.GetRange(0, indexError + 1).ToList();
            this.Targets = cellTargets;

            this.simulation = new Simulation(this, checkProgram.keyframes);

            if (Errors.Count == 0)
                Code = RobotSystem.Code(this);
        }
Пример #2
0
    public Program(string name, RobotSystem robotSystem, IEnumerable <IToolpath> toolpaths, Commands.Group?initCommands = null, IEnumerable <int>?multiFileIndices = null, double stepSize = 1.0)
    {
        RobotSystem  = robotSystem;
        InitCommands = initCommands?.Flatten().ToList() ?? new List <Command>(0);
        var targets = CreateCellTargets(toolpaths);

        if (targets.Count > 0)
        {
            var checkProgram = new CheckProgram(this, targets, stepSize);
            _simulation = new Simulation(this, checkProgram.Keyframes);
            targets     = checkProgram.FixedTargets;
        }

        Targets = targets;

        Name = name;
        CheckName(name, robotSystem);
        MultiFileIndices = FixMultiFileIndices(multiFileIndices, Targets.Count);

        if (Errors.Count == 0)
        {
            Code = RobotSystem.Code(this);
        }
    }