GrxGraphView.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxGraphView.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 
19 package com.generalrobotix.ui.view;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 import org.eclipse.jface.resource.StringConverter;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.graphics.RGB;
27 import org.eclipse.swt.widgets.Composite;
28 
46 
47 @SuppressWarnings("serial")
48 public class GrxGraphView extends GrxBaseView {
49  public static final String TITLE = "Graph";
50  public static final int NumOfGraph = 3;
51 
52  private GrxWorldStateItem currentWorld_ = null;
53  private GrxSimulationItem simItem_ = null;
54  private GrxGraphItem currentGraph_ = null;
55  private List<GrxModelItem> currentModels_ = new ArrayList<GrxModelItem>();
58 
59  public GrxGraphView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
60  super(name, manager, vp, parent);
61  isScrollable_ = false;
62  graphManager_ = new TrendGraphModel(NumOfGraph );
63 
64  gpanel_ = new GraphPanel(manager_, graphManager_, composite_ );
65  setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
66  graphManager_.setPanel(gpanel_);
67 
68  setUp();
69  manager_.registerItemChangeListener(this, GrxSimulationItem.class);
70  manager_.registerItemChangeListener(this, GrxWorldStateItem.class);
71  manager_.registerItemChangeListener(this, GrxGraphItem.class);
72  manager_.registerItemChangeListener(this, GrxModelItem.class);
73  }
74 
75  public void setUp(){
76  if(currentGraph_!=null){
77  _updateGraph(null);
78  }
79  currentGraph_ = manager_.<GrxGraphItem>getSelectedItem(GrxGraphItem.class, null);
80  if(currentGraph_!=null){
81  _updateGraph(currentGraph_);
82  }
83  if(currentWorld_!=null){
84  currentWorld_.deleteObserver(this);
85  currentWorld_.deletePosObserver(this);
86  }
87  currentWorld_ = manager_.<GrxWorldStateItem>getSelectedItem(GrxWorldStateItem.class, null);
88  if(currentWorld_!=null){
89  currentWorld_.addObserver(this);
90  currentWorld_.addPosObserver(this);
91  graphManager_.setWorldState(currentWorld_);
92  }else
93  graphManager_.setWorldState(null);
94  graphManager_.updateGraph();
95 
96  if(simItem_!=null)
97  simItem_.deleteObserver(this);
98  simItem_ = manager_.<GrxSimulationItem>getSelectedItem(GrxSimulationItem.class, null);
99  if(simItem_!=null)
100  simItem_.addObserver(this);
101 
102  currentModels_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
103  gpanel_.setModelList(currentModels_);
104  }
105 
106  public void registerItemChange(GrxBaseItem item, int event){
107  if(item instanceof GrxWorldStateItem){
108  GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
109  switch(event){
111  if(currentWorld_!=worldStateItem){
112  currentWorld_ = worldStateItem;
113  currentWorld_.addObserver(this);
114  currentWorld_.addPosObserver(this);
115  graphManager_.setWorldState(currentWorld_);
116  graphManager_.updateGraph();
117  }
118  break;
121  if(currentWorld_==worldStateItem){
122  currentWorld_.deleteObserver(this);
123  currentWorld_.deletePosObserver(this);
124  currentWorld_ = null;
125  graphManager_.setWorldState(null);
126  graphManager_.updateGraph();
127  }
128  break;
129  default:
130  break;
131  }
132  }else if(item instanceof GrxGraphItem){
133  GrxGraphItem graphItem = (GrxGraphItem) item;
134  switch(event){
136  _updateGraph(graphItem);
137  currentGraph_ = graphItem;
138  break;
141  _updateGraph(null);
142  currentGraph_ = null;
143  break;
144  default:
145  break;
146  }
147  }else if(item instanceof GrxModelItem){
148  GrxModelItem modelItem = (GrxModelItem) item;
149  switch(event){
151  if(!currentModels_.contains(modelItem)){
152  currentModels_.add(modelItem);
153  gpanel_.setModelList(currentModels_);
154  }
155  break;
158  if(currentModels_.contains(modelItem)){
159  currentModels_.remove(modelItem);
160  gpanel_.setModelList(currentModels_);
161  }
162  break;
163  default:
164  break;
165  }
166  }else if(item instanceof GrxSimulationItem){
167  GrxSimulationItem simItem = (GrxSimulationItem) item;
168  switch(event){
170  if(simItem_!=simItem){
171  simItem_ = simItem;
172  simItem_.addObserver(this);
173  }
174  break;
177  if(simItem_==simItem){
178  simItem_.deleteObserver(this);
179  simItem_ = null;
180  }
181  break;
182  default:
183  break;
184  }
185  }
186  }
187 
188 
189  private void _updateGraph(GrxBasePlugin p) {
190  graphManager_.clearDataItem();
191 
192  if (p == null) {
193  gpanel_.setEnabledRangeButton(false);
194  graphManager_.updateGraph();
195  return;
196  }
197 
198  gpanel_.setEnabledRangeButton(true);
199 
200  for (int i = 0; i < graphManager_.getNumGraph(); i++) {
201  String graphName = "Graph" + i;
202  String header = graphName + ".";
203  String ditems = p.getStr(header + "dataItems");
204  if (ditems == null)
205  continue;
206 
207  TrendGraph tgraph = graphManager_.getTrendGraph(i);
208  List<String> addedList = new ArrayList<String>();
209  String[] str = ditems.split(",");
210  for (int j = 0; j < str.length; j++) {
211  if (str[j].equals(""))
212  continue;
213  String object= p.getStr(header + str[j] + ".object");
214  String node = p.getStr(header + str[j] + ".node");
215  String attr = p.getStr(header + str[j] + ".attr");
216  int index = p.getInt(header + str[j] + ".index", -1);
217  String sColor= p.getStr(header + str[j] + ".color");
218  RGB color=null;
219  if(sColor!=null)
220  color=StringConverter.asRGB(sColor);
221  String legend= p.getStr(header + str[j] + ".legend");
222  String type = "";
223  if(attr.equals("angle"))
224  type = "Joint";
225  else if (attr.equals("force"))
226  type = "ForceSensor";
227  else if (attr.equals("torque"))
228  type = "ForceSensor";
229  else if (attr.equals("acceleration"))
230  type = "AccelerationSensor";
231  else if (attr.equals("angularVelocity"))
232  type = "Gyro";
233 
234  DataItem ditem = new DataItem(object, node, attr, index, type);
235  if (!addedList.contains(ditem.toString())){
236  addedList.add(ditem.toString());
237  tgraph.addDataItem(new DataItemInfo(ditem, color, legend));
238  }
239  }
240 
241  double[] vRange = p.getDblAry(header + "vRange", null);
242  if (vRange != null) {
243  tgraph.setRange(vRange[0], vRange[1]);
244  }
245  }
246 
247  double[] timeRange = p.getDblAry("timeRange", new double[]{1.0, 0.8});
248  graphManager_.setRangeAndPos(timeRange[0], timeRange[1]);
249 
250  graphManager_.updateGraph();
251  }
252 
253  private boolean isSimulation = false;
254  public void update(GrxBasePlugin plugin, Object... arg) {
255  if(simItem_==plugin){
256  if((String)arg[0]=="StartSimulation"){ //$NON-NLS-1$
257  double step = currentWorld_.getDbl("logTimeStep", 0.001);
258  graphManager_.setStepTime((long)(1000000*step));
259  graphManager_.initGetData();
260  isSimulation = true;
261  }else if((String)arg[0]=="StopSimulation"){
262  isSimulation = false;
263  graphManager_.setTotalTime(currentWorld_.getTime(currentWorld_.getLogSize()-1));
264  }
265  } else if(currentWorld_==plugin) {
266  if((String)arg[0]=="ClearLog"){ //$NON-NLS-1$
267  graphManager_.setWorldState(currentWorld_);
268  graphManager_.updateGraph();
269  }else if((String)arg[0]=="LoadLog"){
270  graphManager_.setWorldState(currentWorld_);
271  graphManager_.updateGraph();
272  }
273  }
274  }
275 
276  public void updatePosition(GrxBasePlugin plugin, Integer arg_pos){
277  if(currentWorld_!=plugin) return;
278 
279  int pos = arg_pos.intValue();
280  WorldStateEx state = currentWorld_.getValue(pos);
281  if (state == null){
282  updateGraph(new Time(0));
283  }else{
284  Time time_ = new Time();
285  time_.set(state.time);
286  updateGraph(time_);
287  }
288  }
289 
290  private void updateGraph(Time time_){
291  if(isSimulation)
292  graphManager_.setTotalTime(((GrxTimeSeriesItem)currentWorld_).getTime(currentWorld_.getLogSize()-1));
293  graphManager_.worldTimeChanged(time_);
294  }
295 
296  public void shutdown() {
297  manager_.removeItemChangeListener(this, GrxGraphItem.class);
298  manager_.removeItemChangeListener(this, GrxModelItem.class);
299  manager_.removeItemChangeListener(this, GrxWorldStateItem.class);
300  manager_.removeItemChangeListener(this, GrxSimulationItem.class);
301  if(currentWorld_!=null)
302  {
303  currentWorld_.deleteObserver(this);
304  currentWorld_.deletePosObserver(this);
305  }
306 
307  if(simItem_!=null)
308  simItem_.deleteObserver(this);
309  }
310 
311 }
png_infop png_charp png_int_32 png_int_32 int * type
Definition: png.h:2332
final Integer getInt(String key, Integer defaultVal)
get integer value associated to key
state
final double[] getDblAry(String key, double[] defaultVal)
get double array associated to key
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop png_charpp name
Definition: png.h:2382
item corresponds to a robot model
void registerItemChange(GrxBaseItem item, int event)
png_uint_32 i
Definition: png.h:2735
def j(str, encoding="cp932")
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
list index
GrxGraphView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
final Double getDbl(String key, Double defaultVal)
get double value associated to key
void setRangeAndPos(double timeRange, double markerPos)
final String getStr(String key)
get value associated to keyword
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void update(GrxBasePlugin plugin, Object...arg)
void setModelList(List< GrxModelItem > list)
org
char * arg
Definition: cdjpeg.h:136
void setRange(double base, double extent)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21