# -*- coding: utf-8 -*- from copy import copy from tools import trace, timer from Model.Except import NotImplementedMethodeError from Model.BoundaryCondition.BoundaryConditionTypes import ( NotDefined, PonctualContribution, TimeOverZ, TimeOverDebit, ZOverDebit ) class BoundaryConditionList(list): def __init__(self): super(BoundaryConditionList, self).__init__() def new(self, index): n = NotDefined() self.insert(index, n) return n def delete(self, bcs): for bc in bcs: self.remove(bc) def delete_i(self, indexes): bcs = map( lambda x: x[1], filter( lambda x: x[0] in indexes, enumerate(self) ) ) for bc in bcs: self.remove(bc) def move_up(self, index): if index < len(self): next = index - 1 self[index], self[next] = self[next], self[index] def move_down(self, index): if index >= 0: prev = index + 1 self[index], self[prev] = self[prev], self[index] def __copy__(self): new = BoundaryConditionList() for bc in self: new.append(bc) return new def __deepcopy__(self): new = BoundaryConditionList() for bc in self: new.append(deepcopy(bc)) return new def copy(self): return copy(self)