View | Details | Raw Unified | Return to bug 2509
Collapse All | Expand All

(-)a/src/visualizer/model/visual-simulator-impl.cc (-4 / +8 lines)
 Lines 108-124    Link Here 
108
  return m_simulator->IsFinished ();
108
  return m_simulator->IsFinished ();
109
}
109
}
110
110
111
111
void
112
void
112
VisualSimulatorImpl::Run (void)
113
VisualSimulatorImpl::Run (void)
113
{
114
{
115
  std::ostringstream str; 
116
  str << m_stopTime;
117
  std::string pystring = std::string("import visualizer\nvisualizer.start(\'") + str.str () + std::string ("\');\n");
114
  if (!Py_IsInitialized ()) 
118
  if (!Py_IsInitialized ()) 
115
    {
119
    {
116
      const char *argv[] = { "python", NULL};
120
      const char *argv[] = { "python", NULL};
117
      Py_Initialize ();
121
      Py_Initialize ();
118
      PySys_SetArgv (1, (char**) argv);
122
      PySys_SetArgv (1, (char**) argv);
119
      PyRun_SimpleString (
123
      PyRun_SimpleString (
120
                          "import visualizer\n"
124
                          pystring.c_str()
121
                          "visualizer.start();\n"
122
                          );
125
                          );
123
    }
126
    }
124
  else
127
  else
 Lines 126-139    Link Here 
126
      PyGILState_STATE __py_gil_state = PyGILState_Ensure ();
129
      PyGILState_STATE __py_gil_state = PyGILState_Ensure ();
127
    
130
    
128
      PyRun_SimpleString (
131
      PyRun_SimpleString (
129
                          "import visualizer\n"
132
                          pystring.c_str()
130
                          "visualizer.start();\n"
131
                          );
133
                          );
132
134
133
      PyGILState_Release (__py_gil_state);
135
      PyGILState_Release (__py_gil_state);
134
    }
136
    }
135
}
137
}
136
138
139
137
void 
140
void 
138
VisualSimulatorImpl::Stop (void)
141
VisualSimulatorImpl::Stop (void)
139
{
142
{
 Lines 143-148    Link Here 
143
void 
146
void 
144
VisualSimulatorImpl::Stop (Time const &delay)
147
VisualSimulatorImpl::Stop (Time const &delay)
145
{
148
{
149
  m_stopTime = delay;
146
  m_simulator->Stop (delay);
150
  m_simulator->Stop (delay);
147
}
151
}
148
152
(-)a/src/visualizer/model/visual-simulator-impl.h (+1 lines)
 Lines 80-85    Link Here 
80
  Ptr<SimulatorImpl> m_simulator;
80
  Ptr<SimulatorImpl> m_simulator;
81
  ObjectFactory m_simulatorImplFactory;
81
  ObjectFactory m_simulatorImplFactory;
82
82
83
  Time m_stopTime;
83
};
84
};
84
85
85
} // namespace ns3
86
} // namespace ns3
(-)a/src/visualizer/visualizer/core.py (-1 / +13 lines)
 Lines 365-370    Link Here 
365
        self.quit = False
365
        self.quit = False
366
        self.sim_helper = ns.visualizer.PyViz()
366
        self.sim_helper = ns.visualizer.PyViz()
367
        self.pause_messages = []
367
        self.pause_messages = []
368
        self.simtime = ''
368
369
369
    def set_nodes_of_interest(self, nodes):
370
    def set_nodes_of_interest(self, nodes):
370
        self.lock.acquire()
371
        self.lock.acquire()
 Lines 372-380    Link Here 
372
            self.sim_helper.SetNodesOfInterest(nodes)
373
            self.sim_helper.SetNodesOfInterest(nodes)
373
        finally:
374
        finally:
374
            self.lock.release()
375
            self.lock.release()
376
377
    def set_sim_time (self, simtime):
378
        self.simtime = simtime
375
        
379
        
376
    def run(self):
380
    def run(self):
377
        while not self.quit:
381
        while not self.quit:
382
            if not self.simtime == '':
383
                if ns.core.Simulator.Now () >= ns.core.Time(self.simtime):
384
                    self.viz.play_button.set_sensitive(False)
385
                    break
378
            #print "sim: Wait for go"
386
            #print "sim: Wait for go"
379
            self.go.wait() # wait until the main (view) thread gives us the go signal
387
            self.go.wait() # wait until the main (view) thread gives us the go signal
380
            self.go.clear()
388
            self.go.clear()
 Lines 1185-1190    Link Here 
1185
1193
1186
        gtk.main()
1194
        gtk.main()
1187
1195
1196
    def setSimTime (self, simtime):
1197
        self.simulation.set_sim_time (simtime)
1198
1188
1199
1189
    def on_root_button_press_event(self, view, target, event):
1200
    def on_root_button_press_event(self, view, target, event):
1190
        if event.button == 1:
1201
        if event.button == 1:
 Lines 1479-1485    Link Here 
1479
    add_initialization_hook(hook)
1490
    add_initialization_hook(hook)
1480
1491
1481
1492
1482
def start():
1493
def start(simtime):
1483
    assert Visualizer.INSTANCE is None
1494
    assert Visualizer.INSTANCE is None
1484
    if _import_error is not None:
1495
    if _import_error is not None:
1485
        import sys
1496
        import sys
 Lines 1491-1494    Link Here 
1491
    for hook, args in initialization_hooks:
1502
    for hook, args in initialization_hooks:
1492
        gobject.idle_add(hook, viz, *args)
1503
        gobject.idle_add(hook, viz, *args)
1493
    ns.network.Packet.EnablePrinting()
1504
    ns.network.Packet.EnablePrinting()
1505
    viz.setSimTime(simtime)
1494
    viz.start()
1506
    viz.start()

Return to bug 2509