|
1
|
|
|
from synergine.core.Map import Map |
|
2
|
|
|
from synergine.core.Signals import Signals |
|
3
|
|
|
from synergine.synergy.collection.SynergyCollection import SynergyCollection |
|
4
|
|
|
from synergine.core.simulation.EventManager import EventManager |
|
5
|
|
|
from synergine.core.Signals import Signals |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class SynergyObjectManager(): |
|
9
|
|
|
# todo refactoriser getcoll |
|
10
|
|
|
# todo renommer en synergy manager |
|
11
|
|
|
|
|
12
|
|
|
def __init__(self, simulations, context): |
|
13
|
|
|
self._simulations = simulations |
|
14
|
|
|
self._context = context |
|
15
|
|
|
self._initialize_objects() |
|
16
|
|
|
self._map = Map() |
|
17
|
|
|
self._initialize_map() |
|
18
|
|
|
Signals.signal(SynergyCollection.SIGNAL_ADD_OBJECT).connect(self._collection_add_object) |
|
19
|
|
|
Signals.signal(SynergyCollection.SIGNAL_REMOVE_OBJECT).connect(self._collection_remove_object) |
|
20
|
|
|
|
|
21
|
|
|
def _initialize_objects(self): |
|
22
|
|
|
for simulation in self._simulations: |
|
23
|
|
|
for collection in simulation.get_collections(): |
|
24
|
|
|
collection.initialize_objects(self._context) |
|
25
|
|
|
simulation.connect_actions_signals(Signals) |
|
26
|
|
|
|
|
27
|
|
|
def _initialize_map(self): |
|
28
|
|
|
for obj in self.get_objects(): |
|
29
|
|
|
self._map.add_object(obj) |
|
30
|
|
|
|
|
31
|
|
|
def _collection_add_object(self, collection, obj): |
|
32
|
|
|
self._map.add_object(obj) |
|
33
|
|
|
|
|
34
|
|
|
def _collection_remove_object(self, collection, obj): |
|
35
|
|
|
self._map.remove_object(obj) |
|
36
|
|
|
|
|
37
|
|
|
def get_simulations(self): |
|
38
|
|
|
return self._simulations |
|
39
|
|
|
|
|
40
|
|
|
def get_collections(self): |
|
41
|
|
|
collections = [] |
|
42
|
|
|
for simulation in self._simulations: |
|
43
|
|
|
for collection in simulation.get_collections(): |
|
44
|
|
|
collections.append(collection) |
|
45
|
|
|
return collections |
|
46
|
|
|
|
|
47
|
|
|
def get_objects(self): |
|
48
|
|
|
objects = [] |
|
49
|
|
|
for simulation in self._simulations: |
|
50
|
|
|
for collection in simulation.get_collections(): |
|
51
|
|
|
for collection_object in collection.get_objects(): |
|
52
|
|
|
objects.append(collection_object) |
|
53
|
|
|
return objects |
|
54
|
|
|
|
|
55
|
|
|
# todo: la func ci-dessous sont-elles a leurs place ? |
|
56
|
|
|
def get_objects_to_display(self): |
|
57
|
|
|
objects_to_display = [] |
|
58
|
|
|
for simulation in self._simulations: |
|
59
|
|
|
for collection in simulation.get_collections(): |
|
60
|
|
|
for collection_object_to_display in collection.get_objects_to_display(): |
|
61
|
|
|
objects_to_display.append(collection_object_to_display) |
|
62
|
|
|
return objects_to_display |
|
63
|
|
|
|
|
64
|
|
|
def get_map(self): |
|
65
|
|
|
return self._map |