Grx3DView.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  * Grx3DView.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.awt.BorderLayout;
22 import java.awt.Color;
23 import java.awt.Component;
24 import java.awt.Dimension;
25 import java.awt.Font;
26 import java.awt.Frame;
27 import java.awt.GraphicsConfiguration;
28 import java.awt.GridLayout;
29 import java.awt.MenuItem;
30 import java.awt.Panel;
31 import java.awt.PopupMenu;
32 import java.awt.TextField;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.KeyAdapter;
36 import java.awt.event.KeyEvent;
37 import java.awt.event.MouseEvent;
38 import java.awt.event.MouseListener;
39 import java.awt.image.BufferedImage;
40 import java.io.File;
41 import java.io.IOException;
42 import java.net.MalformedURLException;
43 import java.net.URL;
44 import java.util.ArrayList;
45 import java.util.Iterator;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Vector;
49 
50 import javax.swing.*;
51 import javax.media.j3d.*;
52 import javax.vecmath.*;
53 
54 import org.eclipse.swt.SWT;
55 import org.eclipse.swt.awt.SWT_AWT;
56 import org.eclipse.swt.events.ControlEvent;
57 import org.eclipse.swt.events.ControlListener;
58 import org.eclipse.swt.graphics.RGB;
59 import org.eclipse.swt.widgets.ColorDialog;
60 import org.eclipse.swt.widgets.Composite;
61 import org.eclipse.swt.widgets.Display;
62 import org.eclipse.swt.widgets.FileDialog;
63 import org.omg.CosNaming.NameComponent;
64 import org.omg.CosNaming.NamingContext;
65 //import org.omg.PortableServer.POAPackage.ObjectNotActive;
66 //import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
67 import org.omg.PortableServer.POAPackage.ServantNotActive;
68 import org.omg.PortableServer.POAPackage.WrongPolicy;
69 import org.eclipse.jface.dialogs.MessageDialog;
70 
71 //import com.sun.j3d.utils.pickfast.PickCanvas;
72 import com.sun.j3d.utils.universe.SimpleUniverse;
73 
74 import jp.go.aist.hrp.simulator.*;
75 import jp.go.aist.hrp.simulator.OnlineViewerPackage.OnlineViewerException;
76 
77 import com.generalrobotix.ui.*;
78 import com.generalrobotix.ui.util.*;
90 
91 @SuppressWarnings("serial") //$NON-NLS-1$
92 public class Grx3DView
93  extends GrxBaseView
94  implements ThreeDDrawable
95 {
96  public static final String TITLE = "3DView"; //$NON-NLS-1$
97  // java3D 1.4.1のバグ? 対策
98  public static final GraphicsConfiguration graphicsConfiguration = SimpleUniverse.getPreferredConfiguration();
99  // items
100  private GrxWorldStateItem currentWorld_ = null;
101  private List<GrxModelItem> currentModels_ = new ArrayList<GrxModelItem>();
102  private List<GrxCollisionPairItem> currentCollisionPairs_ = new ArrayList<GrxCollisionPairItem>();
103  private WorldStateEx currentState_ = null;
104  private GrxSimulationItem simItem_ = null;
105  private final static int VIEW=0;
106  private final static int EDIT=1;
107  private final static int SIMULATION = 2;
108  private int viewMode_ = VIEW;
109  private double dAngle_ = Math.toRadians(0.1);
110 
111  // for scene graph
112  private static VirtualUniverse universe_;
113  private javax.media.j3d.Locale locale_;
114  private BranchGroup bgRoot_;
115  private BranchGroup unclickableBgRoot_;
116 
117  private BranchGroup rulerBg_;
118  private float LineWidth_ = 1.0f;
119  private float colprop = 10.0f;
120  private float coldiff = 0.1f;
121 
122  // for view
123  private Canvas3D canvas_;
124  private Canvas3D offscreen_;
125  private View view_;
126  private TransformGroup tgView_;
127  private Transform3D t3dViewHome_ = new Transform3D();
128  private ViewInfo info_;
129  private BehaviorManager behaviorManager_ = new BehaviorManager(manager_);
130  private Background backGround_ = new Background(0.0f, 0.0f, 0.0f);
131  private double[] default_eye = new double[]{2.0, 2.0, 0.8};
132  private double[] default_lookat = new double[]{0.0, 0.0, 0.8};
133  private double[] default_upward = new double[]{0.0, 0.0, 1.0};
134 
135  // for recording movie
137  private String lastMovieFileName;
138 
139  // UI objects
140  private ObjectToolBar objectToolBar_ = new ObjectToolBar();
141  private ViewToolBar viewToolBar_ = new ViewToolBar(this);
142  private JButton btnHomePos_ = new JButton(new ImageIcon(getClass().getResource("/resources/images/home.png"))); //$NON-NLS-1$
143  private JToggleButton btnFloor_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/floor.png"))); //$NON-NLS-1$
144  private JToggleButton btnCollision_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/collision.png"))); //$NON-NLS-1$
145  private JToggleButton btnDistance_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/distance.png"))); //$NON-NLS-1$
146  private JToggleButton btnIntersection_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/proximity.png"))); //$NON-NLS-1$
147  private JToggleButton btnCoM_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/com.png"))); //$NON-NLS-1$
148  private JToggleButton btnCoMonFloor_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/com_z0.png"))); //$NON-NLS-1$
149  private JToggleButton btnRec_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/record.png"))); //$NON-NLS-1$
150  private JButton btnPlayer_ = new JButton(new ImageIcon(getClass().getResource("/resources/images/movie_player.png"))); //$NON-NLS-1$
151  private JButton btnRestore_ = new JButton(new ImageIcon(getClass().getResource("/resources/images/undo.png"))); //$NON-NLS-1$
152  private JToggleButton btnBBdisp_ = new JToggleButton(new ImageIcon(getClass().getResource("/resources/images/AABB.png")));
153 
154  private JLabel lblMode_ = new JLabel(MessageBundle.get("Grx3DView.label.view")); //$NON-NLS-1$
155  private JLabel lblTarget_ = new JLabel(""); //$NON-NLS-1$
156  private JLabel lblValue_ = new JLabel(""); //$NON-NLS-1$
157 
158  private Shape3D collision_;
159  private Shape3D distance_;
160  private Vector<GrxLinkItem> intersectingLinks_;
161 
162  private boolean showActualState_ = true;
163 
164  // for "Linux resize problem"
165  Frame frame_;
166  Composite comp;
167 
168  public Grx3DView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
169  {
170  super(name, manager, vp, parent);
171  isScrollable_ = false;
172 
173  //----
174  // Linuxでリサイズイベントが発行されない問題対策
175  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=168330
176 
177  comp = new Composite( getComposite(), SWT.EMBEDDED);
178  frame_ = SWT_AWT.new_Frame( comp );
179 
180  comp.addControlListener( new ControlListener() {
181  public void controlMoved(ControlEvent e) {}
182  public void controlResized(ControlEvent e) {
183  frame_.setBounds(0, 0, comp.getSize().x, comp.getSize().y );
184  }
185  });
186 
187  //----
188 
189  //----
190  // JCombo等がマウスで開けない問題対策
191  // http://www.eclipsezone.com/forums/thread.jspa?messageID=92230432&
192  // JPanelでなくAWTのPanelを使う
193  Panel contentPane = new Panel();
194 
195  //----
196 
197  frame_.add(contentPane);
198 
199  contentPane.setLayout(new BorderLayout());
200  contentPane.setBackground(Color.lightGray);
201  //contentPane.setAlignmentX(JPanel.LEFT_ALIGNMENT);
202 
203  lblMode_.setForeground(Color.black);
204  lblMode_.setFont(new Font("Monospaced", Font.BOLD, 12)); //$NON-NLS-1$
205  lblMode_.setPreferredSize(new Dimension(300, 20));
206 
207  lblTarget_.setForeground(Color.white);
208  lblTarget_.setFont(new Font("Monospaced", Font.BOLD, 12)); //$NON-NLS-1$
209  lblTarget_.setPreferredSize(new Dimension(500, 20));
210 
211  lblValue_.setForeground(Color.white);
212  lblValue_.setFont(new Font("Monospaced", Font.BOLD, 12)); //$NON-NLS-1$
213  lblValue_.setPreferredSize(new Dimension(300, 20));
214 
215  JPanel southPanel = new JPanel();
216  southPanel.setLayout(new GridLayout(1,0));
217  southPanel.add( lblMode_ );
218  Box clipPanel = Box.createHorizontalBox();
219  JLabel clipDistLabel0 = new JLabel(MessageBundle.get("Grx3DView.label.clipDistance0"));
220  JLabel clipDistLabel1 = new JLabel(MessageBundle.get("Grx3DView.label.clipDistance1"));
221  final TextField frontText = new TextField(6);
222  final TextField backText = new TextField(6);
223  frontText.addActionListener(new ActionListener(){
224  public void actionPerformed(ActionEvent arg0) {
225  String str = frontText.getText();
226  try{
227  info_.frontClipDistance=Double.parseDouble(str);
228  view_.setFrontClipDistance(info_.frontClipDistance);
229  }catch(NumberFormatException e){
230  frontText.setText(String.valueOf(info_.frontClipDistance));
231  }
232  }
233  });
234  backText.addActionListener(new ActionListener(){
235  public void actionPerformed(ActionEvent arg0) {
236  String str = backText.getText();
237  try{
238  info_.backClipDistance=Double.parseDouble(str);
239  view_.setBackClipDistance(info_.backClipDistance);
240  }catch(NumberFormatException e){
241  backText.setText(String.valueOf(info_.backClipDistance));
242  }
243  }
244  });
245 
246  clipPanel.add(clipDistLabel0);
247  clipPanel.add(frontText);
248  clipPanel.add(clipDistLabel1);
249  clipPanel.add(backText);
250  southPanel.add(clipPanel);
251 
252  canvas_ = new Canvas3D(graphicsConfiguration);
253  canvas_.setDoubleBufferEnable(true);
254  canvas_.addKeyListener(new ModelEditKeyAdapter());
255  _setupSceneGraph();
256 
257  frontText.setText(String.valueOf(info_.frontClipDistance));
258  backText.setText(String.valueOf(info_.backClipDistance));
259  JPanel mainPane = new JPanel(new BorderLayout());
260  mainPane.setBackground(Color.black);
261  contentPane.add(southPanel, BorderLayout.SOUTH);
262  mainPane.add(canvas_, BorderLayout.CENTER);
263  contentPane.add(mainPane, BorderLayout.CENTER);
264 
265  _setupToolBars();
266  contentPane.add(objectToolBar_, BorderLayout.WEST);
267  contentPane.add(viewToolBar_, BorderLayout.NORTH);
268 
269  collision_ = new Shape3D();
270  collision_.setPickable(false);
271  collision_.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
272  try {
273  Appearance app = new Appearance();
274  LineAttributes latt = new LineAttributes();
275  latt.setLineWidth(LineWidth_);
276  app.setLineAttributes(latt);
277  collision_.setAppearance(app);
278  } catch (Exception ex) {
279  ex.printStackTrace();
280  }
281  BranchGroup bg = new BranchGroup();
282  bg.addChild(collision_);
283  bgRoot_.addChild(bg);
284 
285  distance_ = new Shape3D();
286  distance_.setPickable(false);
287  distance_.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
288  try {
289  Appearance app = new Appearance();
290  LineAttributes latt = new LineAttributes();
291  latt.setLineWidth(LineWidth_);
292  app.setLineAttributes(latt);
293  distance_.setAppearance(app);
294  } catch (Exception ex) {
295  ex.printStackTrace();
296  }
297  BranchGroup bgDistance = new BranchGroup();
298  bgDistance.addChild(distance_);
299  bgRoot_.addChild(bgDistance);
300 
301  intersectingLinks_ = new Vector<GrxLinkItem>();
302 
303  setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
304 
305  //setup
306  behaviorManager_.setThreeDViewer(this);
307  behaviorManager_.setViewIndicator(viewToolBar_);
308  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
309  behaviorManager_.initDynamicsSimulator();
311  behaviorManager_.setViewMode(BehaviorManager.ROOM_VIEW_MODE);
312  behaviorManager_.setViewHandlerMode("button_mode_rotation"); //$NON-NLS-1$
313  behaviorManager_.replaceWorld(null);
314  viewToolBar_.setMode(ViewToolBar.ROOM_MODE);
315  viewToolBar_.setOperation(ViewToolBar.ROTATE);
316 
317  registerCORBA();
318 
319  setUp();
320  manager_.registerItemChangeListener(this, GrxModelItem.class);
321  manager_.registerItemChangeListener(this, GrxWorldStateItem.class);
322  manager_.registerItemChangeListener(this, GrxCollisionPairItem.class);
323  manager_.registerItemChangeListener(this, GrxSimulationItem.class);
324 
325  }
326 
327  public void setUp(){
328  Iterator<GrxModelItem> it = currentModels_.iterator();
329  while(it.hasNext()) {
330  GrxModelItem model = it.next();
331  if(model.bgRoot_.isLive())
332  model.bgRoot_.detach();
333  model.deleteObserver(this);
334  }
335  currentModels_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
336  currentCollisionPairs_ = manager_.<GrxCollisionPairItem>getSelectedItemList(GrxCollisionPairItem.class);
337  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
338  it = currentModels_.iterator();
339  boolean modelModified = false;
340  while(it.hasNext()) {
341  GrxModelItem model = it.next();
342  bgRoot_.addChild(model.bgRoot_);
343  model.setWireFrame(viewToolBar_.isWireFrameSelected());
344  modelModified |= model.isModified();
345  model.addObserver(this);
346  }
347  if(modelModified)
348  optionButtonEnable(false);
349  else
350  optionButtonEnable(true);
351  if(btnBBdisp_.isSelected()){
352  btnBBdisp_.doClick();
353  }
354 
355  if(currentWorld_ != null){
356  currentWorld_.deleteObserver(this);
357  currentWorld_.deletePosObserver(this);
358  }
359  currentWorld_ = manager_.<GrxWorldStateItem>getSelectedItem(GrxWorldStateItem.class, null);
360  if(currentWorld_!=null){
361  currentState_ = currentWorld_.getValue(currentWorld_.getPosition());
362  currentWorld_.addObserver(this);
363  currentWorld_.addPosObserver(this);
364  }else
365  currentState_ = null;
366  if(currentState_ == null)
367  updateViewSimulator(0);
368  else
369  updatePosition(currentWorld_, currentWorld_.getPosition());
370  showOption();
371 
372  if(simItem_ != null)
373  simItem_.deleteObserver(this);
374  simItem_ = manager_.<GrxSimulationItem>getSelectedItem(GrxSimulationItem.class, null);
375  if(simItem_!=null){
376  simItem_.addObserver(this);
377  if(simItem_.isSimulating())
378  viewMode_ = SIMULATION;
379  }
380  if(viewMode_==SIMULATION){
381  disableButton();
382  objectToolBar_.setMode(ObjectToolBar.DISABLE_MODE);
383  }
384  }
385 
386  private void _setupSceneGraph() {
387  universe_ = new VirtualUniverse();
388  locale_ = new javax.media.j3d.Locale(universe_);
389  bgRoot_ = new BranchGroup();
390 
391  bgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
392  bgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
393  bgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
394 
395  //locale_.addBranchGraph(_createView());
396  bgRoot_.addChild(_createLights());
397  bgRoot_.addChild(_createView());
398  bgRoot_.compile();
399  locale_.addBranchGraph(bgRoot_);
400 
401  unclickableBgRoot_ = new BranchGroup();
402  unclickableBgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
403  unclickableBgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
404  unclickableBgRoot_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
405 
406  locale_.addBranchGraph( unclickableBgRoot_ );
407  }
408 
409  private BranchGroup _createView() {
410  BranchGroup bg = new BranchGroup();
411  ViewPlatform platform = new ViewPlatform();
412  info_ = new ViewInfo(ViewInfo.VIEW_MODE_ROOM | ViewInfo.FRONT_VIEW, 3.0 );
413  view_ = new View();
414  view_.setScreenScalePolicy(View.SCALE_EXPLICIT);
415  view_.setScreenScale(0.1);
416  tgView_ = new TransformGroup();
417 
418  view_.setPhysicalBody(new PhysicalBody());
419  view_.setPhysicalEnvironment(new PhysicalEnvironment());
420  view_.setFrontClipPolicy(View.VIRTUAL_EYE);
421  view_.setBackClipPolicy(View.VIRTUAL_EYE);
422  view_.setFrontClipDistance(info_.frontClipDistance);
423  view_.setBackClipDistance(info_.backClipDistance);
424  view_.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
425  view_.setFieldOfView(Math.PI/4);
426  view_.addCanvas3D(canvas_);
427 
428  tgView_.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
429  tgView_.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
430  tgView_.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
431  tgView_.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
432  tgView_.setCapability(TransformGroup.ALLOW_LOCAL_TO_VWORLD_READ);
433 
434  view_.attachViewPlatform(platform);
435  tgView_.addChild(platform);
436  bg.addChild(tgView_);
437 
438  _setViewHomePosition();
439 
440  return bg;
441  }
442 
443  private BranchGroup _createLights() {
444  BranchGroup bg = new BranchGroup();
445  DirectionalLight[] light = new DirectionalLight[4];
446  TransformGroup[] tg = new TransformGroup[4];
447  BoundingSphere bounds =
448  new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
449 
450  //DirectionalLight dlight = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-0.8f, -1.2f, -1.5f));
451  //dlight.setInfluencingBounds(bounds);
452  //tgView_.addChild(dlight);
453 
454  light[0] = new DirectionalLight(true, // lightOn
455  new Color3f(0.7f, 0.7f, 0.7f), // color
456  new Vector3f(0.0f, 0.0f, -1.0f) // direction
457  );
458 
459  light[1] = new DirectionalLight(true, // lightOn
460  new Color3f(0.4f, 0.4f, 0.4f), // color
461  new Vector3f(0.0f, 0.0f, -1.0f) // direction
462  );
463 
464  light[2] = new DirectionalLight(true, // lightOn
465  new Color3f(0.7f, 0.7f, 0.7f), // color
466  new Vector3f(0.0f, 0.0f, -1.0f) // direction
467  );
468 
469  light[3] = new DirectionalLight(true, // lightOn
470  new Color3f(0.4f, 0.4f, 0.4f), // color
471  new Vector3f(0.0f, 0.0f, -1.0f) // direction
472  );
473 
474  for (int i = 0; i < 4; i ++) {
475  light[i].setInfluencingBounds(bounds);
476  tg[i] = new TransformGroup();
477  bg.addChild(tg[i]);
478  tg[i].addChild(light[i]);
479  }
480 
481  Transform3D transform = new Transform3D();
482  Vector3d pos = new Vector3d();
483  AxisAngle4d rot = new AxisAngle4d();
484 
485  pos.set(10.0, 10.0, 5.0);
486  transform.set(pos);
487  rot.set(-0.5, 0.5, 0.0, 1.2);
488  transform.set(rot);
489  tg[0].setTransform(transform);
490 
491  pos.set(10.0, -10.0, -5.0);
492  transform.set(pos);
493  rot.set(0.5, 0.5, 0.0, 3.14 - 1.2);
494  transform.set(rot);
495  tg[1].setTransform(transform);
496 
497  pos.set(-10.0, -10.0, 5.0);
498  transform.set(pos);
499  rot.set(0.5, -0.5, 0.0, 1.2);
500  transform.set(rot);
501  tg[2].setTransform(transform);
502 
503  pos.set(-10.0, 10.0, -5.0);
504  transform.set(pos);
505  rot.set(-0.5, -0.5, 0.0, 3.14 - 1.2);
506  transform.set(rot);
507  tg[3].setTransform(transform);
508 
509  // Ambient Light for Alert
510  AmbientLight alight = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));
511  alight.setInfluencingBounds(bounds);
512  tg[0].addChild(alight);
513 
514  // background
515  backGround_.setCapability(Background.ALLOW_COLOR_READ);
516  backGround_.setCapability(Background.ALLOW_COLOR_WRITE);
517  backGround_.setApplicationBounds(bounds);
518  bg.addChild(backGround_);
519 
520  return bg;
521  }
522 
523  private void _setupToolBars() {
524  btnHomePos_.setToolTipText(MessageBundle.get("Grx3DView.text.goHomeEyePos")); //$NON-NLS-1$
525  btnHomePos_.addActionListener(new ActionListener() {
526  public void actionPerformed(ActionEvent arg0) {
527  tgView_.setTransform(t3dViewHome_);
528  }
529  });
530  btnHomePos_.addMouseListener(new MouseListener(){
531  public void mouseClicked(MouseEvent arg0) {
532  }
533  public void mouseEntered(MouseEvent arg0) {
534  }
535  public void mouseExited(MouseEvent arg0) {
536  }
537  public void mousePressed(MouseEvent arg0) {
538  if(arg0.getButton()==MouseEvent.BUTTON2 || arg0.getButton()==MouseEvent.BUTTON3){
539  PopupMenu popupMenu = new PopupMenu();
540  final MenuItem menu0 = new MenuItem(MessageBundle.get("Grx3DView.popupmenu.setHomeEyePos"));
541  menu0.addActionListener(new ActionListener(){
542  public void actionPerformed(ActionEvent arg0) {
543  if(arg0.getSource()==menu0){
544  tgView_.getTransform(t3dViewHome_);
545  final double[] eyeHomePosition = new double[16];
546  t3dViewHome_.get(eyeHomePosition);
547  syncExec(new Runnable(){
548  public void run(){
549  setDblAry("eyeHomePosition", eyeHomePosition, 5); //$NON-NLS-1$ //$NON-NLS-2$
550  }
551  });
552  }
553  }
554  });
555  final MenuItem menu1 = new MenuItem(MessageBundle.get("Grx3DView.popupmenu.restoreDefault"));
556  menu1.addActionListener(new ActionListener(){
557  public void actionPerformed(ActionEvent arg0) {
558  if(arg0.getSource()==menu1){
559  _setViewHomePosition();
560  final double[] eyeHomePosition = new double[16];
561  t3dViewHome_.get(eyeHomePosition);
562  syncExec(new Runnable(){
563  public void run(){
564  setDblAry("eyeHomePosition", eyeHomePosition, 5); //$NON-NLS-1$ //$NON-NLS-2$
565  }
566  });
567  }
568  }
569  });
570  popupMenu.add(menu0);
571  popupMenu.add(menu1);
572  btnHomePos_.add(popupMenu);
573  popupMenu.show(btnHomePos_, arg0.getX(), arg0.getY());
574  }
575  }
576  public void mouseReleased(MouseEvent arg0) {
577  }
578  });
579 
580  btnFloor_.setToolTipText(MessageBundle.get("Grx3DView.text,showZPlane")); //$NON-NLS-1$
581  btnFloor_.setSelected(false);
582  btnFloor_.addActionListener(new ActionListener() {
583  public void actionPerformed(ActionEvent arg0) {
584  if (btnFloor_.isSelected()) {
585  btnFloor_.setToolTipText(MessageBundle.get("Grx3DView.text.hideZPlane")); //$NON-NLS-1$
586  syncExec(new Runnable(){
587  public void run(){
588  setProperty("showScale", "true"); //$NON-NLS-1$ //$NON-NLS-2$
589  }
590  });
591  if (bgRoot_.indexOfChild(getRuler()) == -1)
592  bgRoot_.addChild(getRuler());
593  } else {
594  btnFloor_.setToolTipText(MessageBundle.get("Grx3DView.text.showZPlane")); //$NON-NLS-1$
595  syncExec(new Runnable(){
596  public void run(){
597  setProperty("showScale", "false"); //$NON-NLS-1$ //$NON-NLS-2$
598  }
599  });
600  if (bgRoot_.indexOfChild(getRuler()) != -1)
601  getRuler().detach();
602  }
603  }
604  });
605 
606  btnCollision_.setToolTipText(MessageBundle.get("Grx3DView.text.showCollision")); //$NON-NLS-1$
607  btnCollision_.setSelected(false);
608  btnCollision_.addActionListener(new ActionListener() {
609  public void actionPerformed(ActionEvent arg0) {
610  if (btnCollision_.isSelected()){
611  btnCollision_.setToolTipText(MessageBundle.get("Grx3DView.text.hideCollision")); //$NON-NLS-1$
612  syncExec(new Runnable(){
613  public void run(){
614  setProperty("showCollision", "true"); //$NON-NLS-1$ //$NON-NLS-2$
615  }
616  });
617  if (viewMode_ == SIMULATION || ( viewMode_ == VIEW && currentState_ != null))
618  _showCollision(currentState_.collisions);
619  else
620  _showCollision(behaviorManager_.getCollision());
621  }else{
622  btnCollision_.setToolTipText(MessageBundle.get("Grx3DView.text.showCollision")); //$NON-NLS-1$
623  syncExec(new Runnable(){
624  public void run(){
625  setProperty("showCollision", "false"); //$NON-NLS-1$ //$NON-NLS-2$
626  }
627  });
628  _showCollision(null);
629  }
630  }
631  });
632 
633  btnDistance_.setToolTipText(MessageBundle.get("Grx3DView.text.showDistance")); //$NON-NLS-1$
634  btnDistance_.setSelected(false);
635  btnDistance_.addActionListener(new ActionListener() {
636  public void actionPerformed(ActionEvent arg0) {
637  if (btnDistance_.isSelected()){
638  btnDistance_.setToolTipText(MessageBundle.get("Grx3DView.text.hideDistance")); //$NON-NLS-1$
639  syncExec(new Runnable(){
640  public void run(){
641  setProperty("showDistance", "true");
642  }
643  });
644  if (viewMode_ != SIMULATION)
645  _showDistance(behaviorManager_.getDistance());
646  }else {
647  btnDistance_.setToolTipText(MessageBundle.get("Grx3DView.text.showDistance")); //$NON-NLS-1$
648  syncExec(new Runnable(){
649  public void run(){
650  setProperty("showDistance", "false");
651  }
652  });
653  _showDistance(null);
654  }
655  }
656  });
657 
658  btnIntersection_.setToolTipText(MessageBundle.get("Grx3DView.text.checkIntersection")); //$NON-NLS-1$
659  btnIntersection_.setSelected(false);
660  btnIntersection_.addActionListener(new ActionListener() {
661  public void actionPerformed(ActionEvent arg0) {
662  if (btnIntersection_.isSelected()){
663  btnIntersection_.setToolTipText(MessageBundle.get("Grx3DView.text.nocheckIntersection")); //$NON-NLS-1$
664  syncExec(new Runnable(){
665  public void run(){
666  setProperty("showIntersection", "true");
667  }
668  });
669  if (viewMode_ != SIMULATION)
670  _showIntersection(behaviorManager_.getIntersection());
671  }else{
672  btnIntersection_.setToolTipText(MessageBundle.get("Grx3DView.text.checkIntersection")); //$NON-NLS-1$
673  syncExec(new Runnable(){
674  public void run(){
675  setProperty("showIntersection", "false");
676  }
677  });
678  _showIntersection(null);
679  }
680  }
681  });
682 
683  btnCoM_.setToolTipText(MessageBundle.get("Grx3DView.text.showCom")); //$NON-NLS-1$
684  btnCoM_.setSelected(false);
685  btnCoM_.addActionListener(new ActionListener() {
686  public void actionPerformed(ActionEvent arg0) {
687  boolean b = btnCoM_.isSelected();
688  for (int i=0; i<currentModels_.size(); i++)
689  currentModels_.get(i).setVisibleCoM(b);
690  if(b)
691  syncExec(new Runnable(){
692  public void run(){
693  setProperty("showCoM", "true");
694  }
695  });
696  else
697  syncExec(new Runnable(){
698  public void run(){
699  setProperty("showCoM", "false");
700  }
701  });
702  };
703  });
704 
705  btnCoMonFloor_.setToolTipText(MessageBundle.get("Grx3DView.text.showcomFloor")); //$NON-NLS-1$
706  btnCoMonFloor_.setSelected(false);
707  btnCoMonFloor_.addActionListener(new ActionListener() {
708  public void actionPerformed(ActionEvent arg0) {
709  boolean b = btnCoMonFloor_.isSelected();
710  for (int i=0; i<currentModels_.size(); i++)
711  currentModels_.get(i).setVisibleCoMonFloor(b);
712  if(b)
713  syncExec(new Runnable(){
714  public void run(){
715  setProperty("showCoMonFloor", "true");
716  }
717  });
718  else
719  syncExec(new Runnable(){
720  public void run(){
721  setProperty("showCoMonFloor", "false");
722  }
723  });
724  };
725  });
726 
727  btnRec_.setToolTipText(MessageBundle.get("Grx3DView.text.record")); //$NON-NLS-1$
728  btnRec_.addActionListener(new ActionListener() {
729  public void actionPerformed(ActionEvent e) {
730  if (btnRec_.isSelected()) {
731  if (currentWorld_ != null && currentWorld_.getLogSize() > 0)
732  rec();
733  else
734  btnRec_.setSelected(false);
735  } else {
736  btnRec_.setSelected(false);
737  }
738  }
739  });
740 
741  btnPlayer_.setToolTipText(MessageBundle.get("Grx3DView.text.moviePlayer")); //$NON-NLS-1$
742  btnPlayer_.addActionListener(new ActionListener() {
743  public void actionPerformed(ActionEvent e) {
744  Display.getDefault().syncExec( new Runnable(){
745  public void run(){
746  new SWTMoviePlayer( getParent().getShell(), lastMovieFileName );
747  }
748  });
749 
750  }
751  });
752 
753 
754  final JButton btnCamera = new JButton("C"); //$NON-NLS-1$
755  btnCamera.addActionListener(new ActionListener(){
756  public void actionPerformed(ActionEvent e) {
757  for (int i=0; i<currentModels_.size(); i++) {
758  List<Camera_impl> l = currentModels_.get(i).getCameraSequence();
759  for (int j=0; j<l.size(); j++) {
760  Camera_impl c = l.get(j);
761  c.setVisible(!c.isVisible());
762  }
763  }
764  }
765  });
766 
767  btnBBdisp_.addActionListener(new ActionListener() {
768  public void actionPerformed(ActionEvent e) {
769  boolean b = btnBBdisp_.isSelected();
770  if(b){
771  List<GrxModelItem> visibleModels = setNumOfAABB();
772  Iterator<GrxModelItem> it = visibleModels.iterator();
773  while(it.hasNext())
774  it.next().setVisibleAABB(b);
775  if(visibleModels.isEmpty())
776  btnBBdisp_.setSelected(false);
777  }else
778  for (int i=0; i<currentModels_.size(); i++)
779  currentModels_.get(i).setVisibleAABB(b);
780  }
781  });
782 
783  viewToolBar_.add(btnHomePos_,0);
784  viewToolBar_.add(btnFloor_, 8);
785  viewToolBar_.add(btnCollision_, 9);
786  viewToolBar_.add(btnDistance_, 10);
787  viewToolBar_.add(btnIntersection_, 11);
788  viewToolBar_.add(btnCoM_, 12);
789  viewToolBar_.add(btnCoMonFloor_, 13);
790  viewToolBar_.add(btnRec_);
791  viewToolBar_.add(btnPlayer_);
792  viewToolBar_.add(btnCamera);
793  viewToolBar_.add(btnBBdisp_);
794 
795  btnRestore_.setToolTipText(MessageBundle.get("Grx3DView.text.restoreModel")); //$NON-NLS-1$
796  btnRestore_.addActionListener(new ActionListener() {
797  public void actionPerformed(ActionEvent e) {
798  for (int i=0; i<currentModels_.size(); i++) {
799  final GrxModelItem item = currentModels_.get(i);
800  syncExec(new Runnable(){
801  public void run(){
802  item.restoreProperties();
803  }
804  });
805 
806  }
807  showOption();
808  }
809  });
810 
811  objectToolBar_.add(btnRestore_, 0);
812  objectToolBar_.setOrientation(JToolBar.VERTICAL);
813 
814  JToolBar bars[] = new JToolBar[]{viewToolBar_, objectToolBar_};
815  for (int i=0; i<bars.length; i++) {
816  JToolBar bar = bars[i];
817  bar.setFloatable(false);
818  for (int j=0; j<bar.getComponentCount(); j++) {
819  Component c = bar.getComponent(j);
820  if (c instanceof AbstractButton) {
821  AbstractButton b = (AbstractButton)c;
822  b.setPreferredSize(GrxBaseView.getDefaultButtonSize());
823  b.setMaximumSize(GrxBaseView.getDefaultButtonSize());
824  }
825  }
826  }
827 
828  _registerAction();
829  }
830 
831  public Canvas3D getCanvas3D() {
832  return canvas_;
833  }
834 
835  public BranchGroup getBranchGroupRoot() {
836  return bgRoot_;
837  }
838 
839  private void _setViewHomePosition() {
840  t3dViewHome_.lookAt(
841  new Point3d(default_eye),
842  new Point3d(default_lookat),
843  new Vector3d(default_upward));
844  t3dViewHome_.invert();
845  tgView_.setTransform(t3dViewHome_);
846  }
847 
848  public void restoreProperties(){
849  super.restoreProperties();
850  if(getStr("showScale")==null) propertyChanged("showScale", "true");
851  if(getStr("showCollision")==null) propertyChanged("showCollision", "true");
852  if(getStr("showDistance")==null) propertyChanged("showDistance", "false");
853  if(getStr("showIntersection")==null) propertyChanged("showIntersection", "false");
854  if(getStr("showCoM")==null) propertyChanged("showCoM", "false");
855  if(getStr("showCoMonFloor")==null) propertyChanged("showCoMonFloor", "false");
856  if(getStr("view.mode")==null) propertyChanged("view.mode", ViewToolBar.COMBO_SELECT_ROOM);
857  if(getStr("showActualState")==null) propertyChanged("showActualState", "true");
858  if(getStr("eyeHomePosition")==null){
859  final double[] eyeHomePosition = new double[16];
860  _setViewHomePosition();
861  t3dViewHome_.get(eyeHomePosition);
862  syncExec(new Runnable(){
863  public void run(){
864  setDblAry("eyeHomePosition", eyeHomePosition, 5); //$NON-NLS-1$ //$NON-NLS-2$
865  }
866  });
867  propertyChanged("eyeHomePosiotion", getProperty("eyeHomePosition"));
868  }
869  }
870 
871  public void registerItemChange(GrxBaseItem item, int event){
872  if(item instanceof GrxModelItem){
873  GrxModelItem modelItem = (GrxModelItem) item;
874  switch(event){
876  if(!modelItem.bgRoot_.isLive()){
877  modelItem.setWireFrame(viewToolBar_.isWireFrameSelected());
878  bgRoot_.addChild(modelItem.bgRoot_);
879  currentModels_.add(modelItem);
880  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
881  if(viewMode_ == VIEW && currentState_!=null){
882  updateModels(currentState_);
883  updateViewSimulator(currentState_.time);
884  }else
885  updateViewSimulator(0);
886  if(modelItem.isModified())
887  optionButtonEnable(false);
888  showOption();
889  if(btnBBdisp_.isSelected()){
890  btnBBdisp_.doClick();
891  }
892  modelItem.addObserver(this);
893  }
894  break;
897  if(modelItem.bgRoot_.isLive()){
898  modelItem.bgRoot_.detach();
899  currentModels_.remove(modelItem);
900  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
901  if(modelItem.isModified())
902  optionButtonEnable(true);
903  showOption();
904  modelItem.deleteObserver(this);
905  }
906  //if(currentModels_.size()==0)
907  // _showCollision(null);
908  break;
909  default:
910  break;
911  }
912  }else if(item instanceof GrxWorldStateItem){
913  GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
914  switch(event){
916  if(currentWorld_!=worldStateItem){
917  currentWorld_ = worldStateItem;
918  currentWorld_.addObserver(this);
919  currentWorld_.addPosObserver(this);
920  currentState_ = currentWorld_.getValue();
921  updatePosition(currentWorld_, currentWorld_.getPosition());
922  }
923  break;
926  if(currentWorld_==worldStateItem){
927  currentWorld_.deleteObserver(this);
928  currentWorld_.deletePosObserver(this);
929  currentWorld_ = null;
930  currentState_ = null;
931  }
932  break;
933  default:
934  break;
935  }
936  }else if(item instanceof GrxCollisionPairItem){
937  GrxCollisionPairItem collisionPairItem = (GrxCollisionPairItem) item;
938  switch(event){
940  if(!currentCollisionPairs_.contains(collisionPairItem)){
941  currentCollisionPairs_.add(collisionPairItem);
942  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
943  showOption();
944  }
945  break;
948  if(currentCollisionPairs_.contains(collisionPairItem)){
949  currentCollisionPairs_.remove(collisionPairItem);
950  behaviorManager_.setItem(currentModels_, currentCollisionPairs_);
951  showOption();
952  }
953  break;
954  }
955  }else if(item instanceof GrxSimulationItem){
956  GrxSimulationItem simItem = (GrxSimulationItem) item;
957  switch(event){
959  if(simItem_!=simItem){
960  simItem_ = simItem;
961  simItem_.addObserver(this);
962  }
963  break;
966  if(simItem_==simItem){
967  simItem_.deleteObserver(this);
968  simItem_ = null;
969  }
970  break;
971  default:
972  break;
973  }
974  }
975  }
976 
977  public void update(GrxBasePlugin plugin, Object... arg) {
978  if(simItem_==plugin){
979  if((String)arg[0]=="StartSimulation"){ //$NON-NLS-1$
980  disableButton();
981  objectToolBar_.setMode(ObjectToolBar.DISABLE_MODE);
982  if((Boolean)arg[1])
983  showViewSimulator(true);
984  viewMode_ = SIMULATION;
985  }else if((String)arg[0]=="StopSimulation"){ //$NON-NLS-1$
986  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
987  enableButton();
988  viewMode_ = VIEW;
989  }
990  }else if(currentModels_.contains(plugin)){
991  if((String)arg[0]=="PropertyChange"){
992  if((String)arg[1]=="name" ){
993  behaviorManager_.setItemChange();
994  showOption();
995  }
996  if(((String)arg[1]).contains("translation") || ((String)arg[1]).contains("rotation") ||
997  ((String)arg[1]).contains("angle"))
998  showOption();
999  }
1000  else if((String)arg[0]=="BodyInfoChange"){
1001  behaviorManager_.setItemChange();
1002  showOption();
1003  }else if((String)arg[0]=="Modified"){
1004  optionButtonEnable(false);
1005  }else if((String)arg[0]=="ClearModified"){
1006  optionButtonEnable(true);
1007  }
1008  }else if(currentWorld_==plugin){
1009  if((String)arg[0]=="ClearLog"){ //$NON-NLS-1$
1010  currentState_ = null;
1011  }
1012  }
1013  }
1014 
1015  public void updatePosition(GrxBasePlugin plugin, Integer arg_pos){
1016  if(currentWorld_ != plugin)
1017  return;
1018 
1019  if(viewMode_ == VIEW || viewMode_ == SIMULATION){
1020  int pos = arg_pos.intValue();
1021  currentState_ = currentWorld_.getValue(pos);
1022  if(currentState_!=null){
1023  _showCollision(currentState_.collisions);
1024  updateModels(currentState_);
1025  updateViewSimulator(currentState_.time);
1026  }
1027  if(viewMode_ == VIEW)
1028  showOptionWithoutCollision();
1029  }
1030  }
1031 
1032  private void disableButton(){
1033  disableOperation();
1034  if (btnDistance_.isSelected())
1035  btnDistance_.doClick();
1036  if (btnIntersection_.isSelected())
1037  btnIntersection_.doClick();
1038  btnDistance_.setEnabled(false);
1039  btnIntersection_.setEnabled(false);
1040  btnRestore_.setEnabled(false);
1041  btnRec_.setEnabled(false);
1042  btnPlayer_.setEnabled(false);
1043  }
1044 
1045  private void enableButton(){
1046  btnDistance_.setEnabled(true);
1047  btnIntersection_.setEnabled(true);
1048  btnRestore_.setEnabled(true);
1049  btnRec_.setEnabled(true);
1050  btnPlayer_.setEnabled(true);
1051  }
1052 
1053  public void showOption(){
1054  if(viewMode_==SIMULATION) return;
1055  if (btnCollision_.isSelected()) {
1056  _showCollision(behaviorManager_.getCollision());
1057  behaviorManager_.setMessageSkip(true);
1058  }
1059  if (btnDistance_.isSelected()){
1060  _showDistance(behaviorManager_.getDistance());
1061  behaviorManager_.setMessageSkip(true);
1062  }
1063  if (btnIntersection_.isSelected()){
1064  _showIntersection(behaviorManager_.getIntersection());
1065  }
1066  behaviorManager_.setMessageSkip(false);
1067  }
1068 
1070  if(viewMode_==SIMULATION) return;
1071  if (btnDistance_.isSelected()){
1072  _showDistance(behaviorManager_.getDistance());
1073  behaviorManager_.setMessageSkip(true);
1074  }
1075  if (btnIntersection_.isSelected()){
1076  _showIntersection(behaviorManager_.getIntersection());
1077  }
1078  behaviorManager_.setMessageSkip(false);
1079  }
1080 
1081  public void showViewSimulator(boolean b) {
1082  for (int i=0; i<currentModels_.size(); i++) {
1083  List<Camera_impl> l = currentModels_.get(i).getCameraSequence();
1084  for (int j=0; j<l.size(); j++) {
1085  Camera_impl c = l.get(j);
1086  c.setVisible(b);
1087  }
1088  }
1089  }
1090 
1091  public void updateModels(WorldStateEx state){
1092  // update models with new WorldState
1093  for (int i=0; i<currentModels_.size(); i++) {
1094  GrxModelItem model = currentModels_.get(i);
1095  CharacterStateEx charStat = state.get(model.getName());
1096  if (charStat != null) {
1097  if (charStat.sensorState != null){
1098  double[] angles;
1099  if (showActualState_) {
1100  angles = charStat.sensorState.q;
1101  } else {
1102  angles = charStat.targetState;
1103  }
1104  model.setCharacterPos(charStat.position, angles);
1105  if (charStat.sensorState.range != null && charStat.sensorState.range.length > 0){
1106  List<GrxSensorItem> sensors = model.getSensors("Range"); //$NON-NLS-1$
1107  for (int j=0; j<sensors.size(); j++){
1108  GrxSensorItem sensor = sensors.get(j);
1109  if (sensor.isVisible() && sensor.id_ >= 0 && sensor.id_ < charStat.sensorState.range.length){
1110  sensor.updateShapeOfVisibleArea(charStat.sensorState.range[sensor.id_]);
1111  }
1112  }
1113  }
1114  }
1115  else
1116  model.setCharacterPos(charStat.position, null);
1117  }
1118  }
1119  }
1120 
1121  private void rec(){
1122  RecordingDialog dialog = new RecordingDialog(frame_, currentWorld_.getTime(currentWorld_.getLogSize()-1));
1123  if (dialog.showModalDialog() != ModalDialog.OK_BUTTON){
1124  btnRec_.setSelected(false);
1125  return;
1126  }
1127 
1128  Dimension canvasSize = dialog.getImageSize();
1129  int framerate=10;
1130  try{
1131  framerate = dialog.getFrameRate();
1132  }catch(Exception NumberFormatException ){
1133  new ErrorDialog(frame_, MessageBundle.get("Grx3DView.dialog.title.error"), MessageBundle.get("Grx3DView.dialog.message.error") ).showModalDialog(); //$NON-NLS-1$ //$NON-NLS-2$
1134  btnRec_.setSelected(false);
1135  return;
1136  }
1137  double playbackRate = dialog.getPlaybackRate();
1138 
1139  GrxDebugUtil.println("ScreenSize: " + canvasSize.width + "x" + canvasSize.height + " (may be)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1140 
1141  BufferedImage image=new BufferedImage(canvasSize.width,canvasSize.height,BufferedImage.TYPE_INT_ARGB);
1142  // 参照型で画像を設定
1143  ImageComponent2D buffer=new ImageComponent2D(ImageComponent.FORMAT_RGBA,image,true,false);
1144  buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
1145 
1146  // オフスクリーンレンダリングの設定
1147  offscreen_=new Canvas3D(graphicsConfiguration,true);
1148  offscreen_.setOffScreenBuffer(buffer);
1149  view_.addCanvas3D(offscreen_);
1150 
1151  Screen3D screen = canvas_.getScreen3D();
1152  offscreen_.getScreen3D().setSize(screen.getSize());
1153  offscreen_.getScreen3D().setPhysicalScreenWidth(screen.getPhysicalScreenWidth());
1154  offscreen_.getScreen3D().setPhysicalScreenHeight(screen.getPhysicalScreenHeight());
1155 
1156  recordingMgr_ = RecordingManager.getInstance();
1157  recordingMgr_.setImageSize(canvasSize.width , canvasSize.height);
1158  recordingMgr_.setFrameRate((float)framerate);
1159 
1160  String fileName = dialog.getFileName();
1161  if (new File(fileName).exists()) {
1162  if (!fileOverwriteDialog(fileName)){
1163  btnRec_.setSelected(false);
1164  return;
1165  }
1166  }
1167 
1168  lastMovieFileName = pathToURL(fileName);
1169  ComboBoxDialog cmb = new ComboBoxDialog(
1170  frame_,
1171  MessageBundle.get("Grx3DView.dialog.title.videoFormat"), //$NON-NLS-1$
1172  MessageBundle.get("Grx3DView.dialog.message.videoFormat"), //$NON-NLS-1$
1173  recordingMgr_.preRecord(lastMovieFileName, ImageToMovie.QUICKTIME));
1174  String format__ = (String)cmb.showComboBoxDialog();
1175  if (format__ == null) {
1176  btnRec_.setSelected(false);
1177  return;
1178  }
1179 
1180  try {
1181  if(!recordingMgr_.startRecord(format__)){
1182  btnRec_.setSelected(false);
1183  return;
1184  }
1185  } catch (Exception e) {
1186  GrxDebugUtil.printErr("Grx3DView.rec():",e); //$NON-NLS-1$
1187  syncExec(new Runnable(){
1188  public void run(){
1189  MessageDialog.openError( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.error"), MessageBundle.get("Grx3DView.dialog.message.recError")); //$NON-NLS-1$ //$NON-NLS-2$
1190  }
1191  });
1192  btnRec_.setSelected(false);
1193  return;
1194  }
1195 
1196  disableButton();
1197  viewMode_ = VIEW;
1198  objectToolBar_.setMode(ObjectToolBar.DISABLE_MODE);
1199 
1200  final double stepTime = 1.0/framerate*playbackRate;
1201  double startTime = dialog.getStartTime();
1202  double endTime = dialog.getEndTime();
1203  final int startPosition = currentWorld_.getPositionAt(startTime);
1204  final int endPosition = currentWorld_.getPositionAt(endTime);
1205  Thread recThread_ = new Thread() {
1206  public void run() {
1207  try {
1208  double playRateLogTime_ = currentWorld_.getTime(startPosition);
1209  for (int position=startPosition; position <= endPosition; position++) {
1210  if(!btnRec_.isSelected())break;
1211  double time = currentWorld_.getTime(position);
1212  if (time >= playRateLogTime_) {
1213  playRateLogTime_ += stepTime;
1214  final int _position = position;
1215  syncExec(new Runnable(){
1216  public void run() {
1217  currentWorld_.setPosition(_position);
1218  }
1219  });
1220  _doRecording();
1221  }
1222  }
1223  stopRecording();
1224  } catch (Exception e) {
1225  syncExec(new Runnable(){
1226  public void run(){
1227  MessageDialog.openError( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.error"), MessageBundle.get("Grx3DView.dialog.message.recException")); //$NON-NLS-1$ //$NON-NLS-2$
1228  }
1229  });
1230  stopRecording();
1231  GrxDebugUtil.printErr("Recording Interrupted by Exception:",e); //$NON-NLS-1$
1232  }
1233  }
1234  };
1235 
1236  recThread_.start();
1237  }
1238 
1239  private void stopRecording(){
1240  recordingMgr_.endRecord();
1241  btnRec_.setSelected(false);
1242  view_.removeCanvas3D(offscreen_);
1243  syncExec(new Runnable(){
1244  public void run(){
1245  MessageDialog.openInformation( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.Infomation"), MessageBundle.get("Grx3DView.dialog.message.recFinish")); //$NON-NLS-1$ //$NON-NLS-2$
1246  }
1247  });
1248  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
1249  enableButton();
1250  }
1251 
1252  private boolean ret_;
1253  private boolean fileOverwriteDialog(final String fileName){
1254  if (new File(fileName).isDirectory())
1255  return false;
1256 
1257  syncExec(new Runnable(){
1258  public void run(){
1259  ret_ = MessageDialog.openConfirm( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.fileExist"), //$NON-NLS-1$
1260  fileName + " " + MessageBundle.get("Grx3DView.dialog.message.fileExist")); //$NON-NLS-1$ //$NON-NLS-2$
1261  }
1262  });
1263  if(ret_)
1264  return true;
1265  else
1266  return false;
1267  }
1268 
1269  private String pathToURL(String path) {
1270  if (path.startsWith("file:///")) { //$NON-NLS-1$
1271  //String filePath = path.substring(8);
1272  path = path.replace(java.io.File.separatorChar, '/');
1273  return path;
1274  }
1275  if (path.startsWith("http://")) { //$NON-NLS-1$
1276  return path;
1277  }
1278  if (!path.startsWith(java.io.File.separator) && (path.indexOf(':') != 1)) {
1279  path = System.getProperty("user.dir") + java.io.File.separator + path; //$NON-NLS-1$
1280  }
1281  if (path.indexOf(':') == 1) {
1282  path = path.replace(java.io.File.separatorChar, '/');
1283  return "file:///" + path; //$NON-NLS-1$
1284  }
1285  return "file://" + path; //$NON-NLS-1$
1286  }
1287 
1288  private void _doRecording() {
1289  offscreen_.renderOffScreenBuffer();
1290  offscreen_.waitForOffScreenRendering();
1291  recordingMgr_.pushImage( offscreen_.getOffScreenBuffer().getImage() );
1292  }
1293 
1294  public void _showCollision(Collision[] collisions) {
1295  collision_.removeAllGeometries();
1296  if (collisions == null || collisions.length <= 0 || !btnCollision_.isSelected())
1297  return;
1298 
1299  int length = 0;
1300  for (int i = 0; i < collisions.length; i++) {
1301  if (collisions[i].points != null)
1302  length += collisions[i].points.length;
1303  }
1304  if (length > 0) {
1305  CollisionPoint[] cd = new CollisionPoint[length];
1306  for (int i=0, n=0; i<collisions.length; i++) {
1307  for (int j=0; j<collisions[i].points.length; j++)
1308  cd[n++] = collisions[i].points[j];
1309  }
1310 
1311  Point3d[] p3d = new Point3d[cd.length * 2];
1312  for (int j=0; j<cd.length; j++) {
1313  p3d[j*2] = new Point3d(cd[j].position);
1314 
1315  Vector3d pole = new Vector3d(cd[j].normal);
1316  pole.normalize();
1317  float depth = (float) cd[j].idepth*colprop+coldiff;
1318  p3d[j*2+1] = new Point3d(
1319  cd[j].position[0] + pole.x*depth,
1320  cd[j].position[1] + pole.y*depth,
1321  cd[j].position[2] + pole.z*depth
1322  );
1323  }
1324 
1325  LineArray la = new LineArray(p3d.length, LineArray.COLOR_3
1326  | LineArray.COORDINATES | LineArray.NORMALS);
1327  la.setCoordinates(0, p3d);
1328 
1329  Vector3f[] v3f = new Vector3f[p3d.length];
1330  Color3f[] c3f = new Color3f[p3d.length];
1331  for (int i=0; i<v3f.length; i++) {
1332  v3f[i] = new Vector3f(0.0f, 0.0f, 1.0f);
1333  if ((i % 2) == 0)
1334  c3f[i] = new Color3f(0.0f, 0.8f, 0.8f);
1335  else
1336  c3f[i] = new Color3f(0.8f, 0.0f, 0.8f);
1337  }
1338  la.setNormals(0, v3f);
1339  la.setColors(0, c3f);
1340  collision_.addGeometry(la);
1341  } else {
1342  collision_.addGeometry(null);
1343  }
1344  }
1345 
1346  private void _showDistance(Distance[] distances) {
1347  distance_.removeAllGeometries();
1348  if (distances == null || distances.length <= 0 || !btnDistance_.isSelected())
1349  return;
1350 
1351  int length = distances.length;
1352 
1353  if (length > 0) {
1354  Point3d[] p3d = new Point3d[length * 2];
1355  for (int j=0; j<length; j++) {
1356  p3d[j*2] = new Point3d(distances[j].point0);
1357  p3d[j*2+1] = new Point3d(distances[j].point1);
1358  }
1359 
1360  LineArray la = new LineArray(p3d.length, LineArray.COLOR_3
1361  | LineArray.COORDINATES | LineArray.NORMALS);
1362  la.setCoordinates(0, p3d);
1363 
1364  Vector3f[] v3f = new Vector3f[p3d.length];
1365  Color3f[] c3f = new Color3f[p3d.length];
1366  for (int i=0; i<v3f.length; i++) {
1367  v3f[i] = new Vector3f(0.0f, 0.0f, 1.0f);
1368  c3f[i] = new Color3f(1.0f, 0.0f, 0.0f);
1369  }
1370  la.setNormals(0, v3f);
1371  la.setColors(0, c3f);
1372  distance_.addGeometry(la);
1373  } else {
1374  distance_.addGeometry(null);
1375  }
1376  }
1377 
1378  @SuppressWarnings("unchecked") //$NON-NLS-1$
1379  private void _showIntersection(LinkPair[] pairs){
1380  if (pairs == null){
1381  for (int i=0; i<intersectingLinks_.size(); i++){
1382  intersectingLinks_.get(i).restoreColor();
1383  }
1384  intersectingLinks_.clear();
1385  return;
1386  }else{
1387  Map<String, GrxModelItem> modelMap = (Map<String, GrxModelItem>)manager_.getItemMap(GrxModelItem.class);
1388  Vector<GrxLinkItem> links = new Vector<GrxLinkItem>();
1389  for (int i=0; i<pairs.length; i++){
1390  GrxModelItem m1 = modelMap.get(pairs[i].charName1);
1391  if (m1 != null){
1392  GrxLinkItem l = m1.getLink(pairs[i].linkName1);
1393  if (l != null){
1394  links.add(l);
1395  if (!intersectingLinks_.contains(l)){
1396  l.setColor(java.awt.Color.RED);
1397  }
1398  }
1399  }
1400  GrxModelItem m2 = modelMap.get(pairs[i].charName2);
1401  if (m2 != null){
1402  GrxLinkItem l = m2.getLink(pairs[i].linkName2);
1403  if (l != null) links.add(l);
1404  if (!intersectingLinks_.contains(l)){
1405  l.setColor(java.awt.Color.RED);
1406  }
1407  }
1408  }
1409  for (int i=0; i<intersectingLinks_.size(); i++){
1410  GrxLinkItem l = intersectingLinks_.get(i);
1411  if (!links.contains(l)){
1412  l.restoreColor();
1413  }
1414  }
1415  intersectingLinks_ = links;
1416  }
1417  }
1418 
1419  public void updateViewSimulator(double time) {
1420  for (int i=0; i<currentModels_.size(); i++) {
1421  List<Camera_impl> l = currentModels_.get(i).getCameraSequence();
1422  for (int j=0; j<l.size(); j++) {
1423  Camera_impl c = l.get(j);
1424  if (c.isVisible()) c.updateView(time);
1425  }
1426  }
1427  }
1428 
1429  public BranchGroup getRuler() {
1430  if (rulerBg_ == null) {
1431  rulerBg_ = new BranchGroup();
1432  rulerBg_.setCapability(BranchGroup.ALLOW_DETACH);
1433  int n = 40; // number of lines
1434  Point3d[] p = new Point3d[n * 4];
1435  double width = n/2.0;
1436  for (int i=0; i<n; i++) {
1437  p[2*i] = new Point3d(-width+i, -width, 0.0);
1438  p[2*i+1] = new Point3d(-width+i, width, 0.0);
1439  p[2*i+n*2] = new Point3d(-width, -width+i, 0.0);
1440  p[2*i+n*2+1] = new Point3d( width, -width+i, 0.0);
1441  }
1442  LineArray geometry = new LineArray(p.length,
1443  GeometryArray.COORDINATES | GeometryArray.COLOR_3);
1444  geometry.setCoordinates(0, p);
1445  for (int i = 0; i < p.length; i++)
1446  geometry.setColor(i, new Color3f(Color.white));
1447 
1448  Shape3D shape = new Shape3D(geometry);
1449  shape.setPickable(false);
1450  rulerBg_.addChild(shape);
1451  rulerBg_.compile();
1452  }
1453  return rulerBg_;
1454  }
1455 
1456  public boolean registerCORBA() {
1458 
1459  OnlineViewer_impl olvImpl = new OnlineViewer_impl();
1460  OnlineViewer olv = olvImpl._this(manager_.orb_);//GrxCorbaUtil.getORB());
1461  NameComponent[] path1 = {new NameComponent("OnlineViewer", "")}; //$NON-NLS-1$ //$NON-NLS-2$
1462  ViewSimulator_impl viewImpl = new ViewSimulator_impl();
1463  ViewSimulator view = viewImpl._this(manager_.orb_);//GrxCorbaUtil.getORB());
1464  NameComponent[] path2 = {new NameComponent("ViewSimulator", "")}; //$NON-NLS-1$ //$NON-NLS-2$
1465  // ViewSimulatorFactory_impl viewImplFactory = new ViewSimulatorFactory_impl();
1466  // ViewSimulatorFactory viewFactory = viewImplFactory._this(manager_.orb_);//GrxCorbaUtil.getORB());
1467  // NameComponent[] path3 = {new NameComponent("ViewSimulatorFactory", "")}; //$NON-NLS-1$ //$NON-NLS-2$
1468  try {
1469  rootnc.rebind(path1, olv);
1470  rootnc.rebind(path2, view);
1471  //rootnc.rebind(path3, viewFactory);
1472  } catch (Exception ex) {
1473  GrxDebugUtil.println("3DVIEW : failed to bind to localhost NameService"); //$NON-NLS-1$
1474  return false;
1475  }
1476 
1477  GrxDebugUtil.println("3DVIEW : successfully bound to localhost NameService"); //$NON-NLS-1$
1478  return true;
1479  }
1480 
1481 
1482  public void unregisterCORBA() {
1484  NameComponent[] path1 = {new NameComponent("OnlineViewer", "")};
1485  NameComponent[] path2 = {new NameComponent("ViewSimulator", "")};
1486  // NameComponent[] path3 = {new NameComponent("ViewSimulatorFactory", "")};
1487  try{
1488  rootnc.unbind(path1);
1489  rootnc.unbind(path2);
1490  //rootnc.unbind(path3);
1491  GrxDebugUtil.println("3DVIEW : successfully unbound to localhost NameService");
1492  }catch(Exception ex){
1493  GrxDebugUtil.println("3DVIEW : failed to unbind to localhost NameService");
1494  }
1495  }
1496 
1497  private class ModelEditKeyAdapter extends KeyAdapter {
1498  public void keyPressed(KeyEvent arg0) {
1499  GrxLinkItem li = null;
1500  GrxBaseItem bitem = manager_.focusedItem();
1501  if (bitem instanceof GrxLinkItem){
1502  li = (GrxLinkItem)bitem;
1503  }else{
1504  arg0.consume();
1505  return;
1506  }
1507  GrxModelItem item = li.model();
1508 
1509  KeyStroke ks = KeyStroke.getKeyStrokeForEvent(arg0);
1510  if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_UP,0) ||
1511  ks == KeyStroke.getKeyStroke(KeyEvent.VK_K,0)) {
1512  int next = li.jointId_-1;
1513  if (next >= 0) {
1514  for (int j=0; j<item.links_.size(); j++) {
1515  if (next == item.links_.get(j).jointId_) {
1516  behaviorManager_.setPickTarget(item.links_.get(j).tg_);
1517  break;
1518  }
1519  }
1520  }
1521  } else if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0) ||
1522  ks == KeyStroke.getKeyStroke(KeyEvent.VK_J,0)) {
1523  int next = li.jointId_+1;
1524  for (int j=0; j<item.links_.size(); j++) {
1525  if (next == item.links_.get(j).jointId_) {
1526  behaviorManager_.setPickTarget(item.links_.get(j).tg_);
1527  break;
1528  }
1529  }
1530  } else if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,KeyEvent.SHIFT_MASK) ||
1531  ks == KeyStroke.getKeyStroke(KeyEvent.VK_H,KeyEvent.SHIFT_MASK)) {
1532  li.jointValue(li.jointValue_-dAngle_);
1533 
1534  if (li.llimit_[0] < li.ulimit_[0])
1535  li.jointValue(Math.max(li.jointValue_, li.llimit_[0]));
1536  item.calcForwardKinematics();
1537  item.setProperty(li.getName()+".angle",String.valueOf(li.jointValue_)); //$NON-NLS-1$
1538 
1539  } else if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,KeyEvent.SHIFT_MASK) ||
1540  ks == KeyStroke.getKeyStroke(KeyEvent.VK_L,KeyEvent.SHIFT_MASK)) {
1541  li.jointValue(li.jointValue_+dAngle_);
1542  if (li.llimit_[0] < li.ulimit_[0])
1543  li.jointValue(Math.min(li.jointValue_, li.ulimit_[0]));
1544  item.calcForwardKinematics();
1545  item.setProperty(li.getName()+".angle",String.valueOf(li.jointValue_)); //$NON-NLS-1$
1546 
1547  } else if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_H,0) ||
1548  ks == KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0)) {
1549  li.jointValue(li.jointValue_-dAngle_*20);
1550  if (li.llimit_[0] < li.ulimit_[0])
1551  li.jointValue(Math.max(li.jointValue_, li.llimit_[0]));
1552  item.calcForwardKinematics();
1553  item.setProperty(li.getName()+".angle",String.valueOf(li.jointValue_)); //$NON-NLS-1$
1554 
1555  } else if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_L,0) ||
1556  ks == KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0)) {
1557  li.jointValue(li.jointValue_+dAngle_*20);
1558  if (li.llimit_[0] < li.ulimit_[0])
1559  li.jointValue(Math.min(li.jointValue_, li.ulimit_[0]));
1560  item.calcForwardKinematics();
1561  item.setProperty(li.getName()+".angle",String.valueOf(li.jointValue_)); //$NON-NLS-1$
1562  }
1563  arg0.consume();
1564  }
1565  }
1566 /*
1567  private class ViewSimulatorFactory_impl extends ViewSimulatorFactoryPOA{
1568 
1569  public ViewSimulator create() {
1570  ViewSimulator_impl viewImpl = new ViewSimulator_impl();
1571  try {
1572  manager_.poa_.activate_object(viewImpl);
1573  } catch (ServantAlreadyActive e) {
1574  e.printStackTrace();
1575  } catch (WrongPolicy e) {
1576  e.printStackTrace();
1577  }
1578  return viewImpl._this(manager_.orb_);
1579  }
1580 
1581  public void shutdown() {
1582  }
1583 
1584  }
1585 */
1586  private class ViewSimulator_impl extends ViewSimulatorPOA {
1587  public void destroy() {
1588  /*
1589  byte[] id;
1590  try {
1591  id = manager_.poa_.servant_to_id(this);
1592  manager_.poa_.deactivate_object(id);
1593  } catch (ServantNotActive e) {
1594 
1595  e.printStackTrace();
1596  } catch (WrongPolicy e) {
1597 
1598  e.printStackTrace();
1599  } catch (ObjectNotActive e) {
1600 
1601  e.printStackTrace();
1602  }
1603  */
1604  }
1605 
1606  public void getCameraSequence(CameraSequenceHolder arg0) {
1607  List<Camera_impl> allList = new ArrayList<Camera_impl>();
1608  for (int i=0; i<currentModels_.size(); i++) {
1609  List<Camera_impl> l = currentModels_.get(i).getCameraSequence();
1610  allList.addAll(l);
1611  }
1612 
1613  arg0.value = new Camera[allList.size()];
1614  for (int i=0; i<allList.size(); i++) {
1615  try {
1616  arg0.value[i] = CameraHelper.narrow(manager_.poa_.servant_to_reference(allList.get(i)));
1617  } catch (ServantNotActive e) {
1618  e.printStackTrace();
1619  } catch (WrongPolicy e) {
1620  e.printStackTrace();
1621  }
1622  }
1623  }
1624 
1625  public void getCameraSequenceOf(String objectName, CameraSequenceHolder arg1) {
1626  for (int i=0; i<currentModels_.size(); i++) {
1627  GrxModelItem item = currentModels_.get(i);
1628  if (item.getName().equals(objectName)) {
1629  List<Camera_impl> l = item.getCameraSequence();
1630  arg1.value = new Camera[l.size()];
1631  for (int j=0; j<l.size(); j++) {
1632  try {
1633  arg1.value[j] = CameraHelper.narrow(manager_.poa_.servant_to_reference(l.get(j)));
1634  } catch (ServantNotActive e) {
1635  e.printStackTrace();
1636  } catch (WrongPolicy e) {
1637  e.printStackTrace();
1638  }
1639  }
1640  return;
1641  }
1642  }
1643  arg1.value = new Camera[0];
1644  }
1645 
1646  public void registerCharacter(final String name, final BodyInfo bInfo) {
1647  syncExec(new Runnable(){
1648  public void run(){
1649  GrxBaseItem newItem = manager_.createItem(GrxModelItem.class, name);
1650  if(newItem!=null){
1651  manager_.itemChange(newItem, GrxPluginManager.ADD_ITEM);
1652  manager_.setSelectedItem(newItem, true);
1653  ((GrxModelItem)newItem).registerCharacter(bInfo);
1654  ((GrxModelItem)newItem).setURL(bInfo.url());
1655  }
1656  }
1657  });
1658  }
1659 
1660  public void updateScene(WorldState worldState) {
1661  final WorldStateEx statex = new WorldStateEx(worldState);
1662  syncExec(new Runnable(){
1663  public void run(){
1664  updateModels(statex);
1665  updateViewSimulator(0);
1666  }
1667  });
1668  }
1669  }
1670 
1671  private class OnlineViewer_impl extends OnlineViewerPOA {
1672  private double prevTime = 0.0;
1673  private boolean firstTime_ = true;
1674  private double logTimeStep_ = 0.0;
1675  private boolean updateTimer_ = false;
1676  private GrxBaseItem newItem = null;
1677 
1678  public void clearLog() {
1679  if (currentWorld_ != null){
1680  syncExec(new Runnable(){
1681  public void run(){
1682  currentWorld_.clearLog();
1683  }
1684  });
1685  currentState_=null;
1686  }
1687  firstTime_ = true;
1688  }
1689 
1690  public void load(final String name, String url) throws OnlineViewerException{
1691  System.out.println(name+":"+url); //$NON-NLS-1$
1692  final String url0 = url;
1693  try {
1694  URL u = new URL(url);
1695  final String url_ = u.getFile();
1696  syncExec(new Runnable(){
1697  public void run(){
1698  newItem = manager_.loadItem(GrxModelItem.class, name, url_);
1699  if(newItem!=null){
1700  manager_.itemChange(newItem, GrxPluginManager.ADD_ITEM);
1701  manager_.setSelectedItem(newItem, true);
1702  }
1703  }
1704  });
1705  } catch (MalformedURLException e) {
1706  e.printStackTrace();
1707  syncExec(new Runnable(){
1708  public void run(){
1709  MessageDialog.openError( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.error"), MessageBundle.get("OnlineViewer.dialog.message.MalformedURLException")); //$NON-NLS-1$ //$NON-NLS-2$
1710  }
1711  });
1712  throw new OnlineViewerException("Malformed URL Exception");
1713  }
1714  if(newItem==null){
1715  syncExec(new Runnable(){
1716  public void run(){
1717  MessageDialog.openError( comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.error"), url0+MessageBundle.get("OnlineViewer.dialog.message.loadError")); //$NON-NLS-1$ //$NON-NLS-2$
1718  }
1719  });
1720  throw new OnlineViewerException(url+"cannot be loaded.");
1721  }
1722  }
1723 
1724  public boolean getPosture(String name , DblSequenceHolder posture) {
1725  Object obj = manager_.getItem(GrxModelItem.class, name);
1726  if (obj != null) {
1727  GrxModelItem model = (GrxModelItem)obj;
1728  posture.value = model.getJointValues();
1729  return true;
1730  }
1731  posture.value = new double[0];
1732  return false;
1733  }
1734 
1735  public void update(WorldState arg0) {
1737  if (currentWorld_ == null) {
1738  syncExec(new Runnable(){
1739  public void run(){
1740  GrxWorldStateItem item = (GrxWorldStateItem)manager_.createItem(GrxWorldStateItem.class, null);
1741  manager_.itemChange(item, GrxPluginManager.ADD_ITEM);
1742  manager_.setSelectedItem(item, true);
1743  }
1744  });
1745  }
1746  if (firstTime_) {
1747  firstTime_ = false;
1748  prevTime = 0.0;
1749  logTimeStep_ = 0.0;
1750  String[] chars = statex.characters();
1751  for (int i=0; i<chars.length; i++) {
1752  GrxModelItem model = (GrxModelItem)manager_.getItem(GrxModelItem.class, chars[i]);
1753  BodyInfo bodyInfo = model.getBodyInfo();
1754  if(bodyInfo==null) return;
1755  currentWorld_.registerCharacter(chars[i], bodyInfo);
1756  }
1757  syncExec(new Runnable(){
1758  public void run(){
1759  if(statex.time > 0){
1760  logTimeStep_ = statex.time;
1761  currentWorld_.setDbl("logTimeStep", logTimeStep_); //$NON-NLS-1$
1762  }
1763  }
1764  });
1765  }
1766 
1767  final double stepTime = statex.time - prevTime;
1768  if(stepTime > 0 && Math.abs(stepTime-logTimeStep_)>10e-9){
1769  logTimeStep_ = stepTime;
1770  syncExec(new Runnable(){
1771  public void run(){
1772  currentWorld_.setDbl("logTimeStep", logTimeStep_); //$NON-NLS-1$
1773  }
1774  });
1775  }
1776 
1777  currentWorld_.addValue(statex.time, statex);
1778  Thread.yield();
1779  if(!updateTimer_){
1780  java.util.Timer timer = new java.util.Timer();
1781  timer.schedule(new updateView(),20);
1782  updateTimer_ = true;
1783  }
1784  prevTime = statex.time;
1785  }
1786 
1787  public void clearData() {}
1788 
1789  public void drawScene(WorldState arg0) {
1791  _showCollision(statex.collisions);
1792  updateModels(statex);
1793  updateViewSimulator(statex.time);
1794  }
1795 
1796  public void setLineScale(float arg0) {}
1797  public void setLineWidth(float arg0) {}
1798 
1799  private class updateView extends java.util.TimerTask {
1800  public void run() {
1801  updateTimer_ = false;
1802  final int pos = currentWorld_.getLogSize()-1;
1803  syncExec(new Runnable(){
1804  public void run(){
1805  currentWorld_.setPosition(pos);
1806  }
1807  });
1808  }
1809  }
1810 
1811  public void setLogName(final String name){
1812  syncExec(new Runnable(){
1813  public void run(){
1814  GrxWorldStateItem item = (GrxWorldStateItem)manager_.getItem(GrxWorldStateItem.class, name);
1815  if(item==null){
1816  item = (GrxWorldStateItem)manager_.createItem(GrxWorldStateItem.class, name);
1817  manager_.itemChange(item, GrxPluginManager.ADD_ITEM);
1818  firstTime_ = true;
1819  }
1820  manager_.setSelectedItem(item, true);
1821  }
1822  });
1823  }
1824  }
1825 
1826  public void attach(BranchGroup bg) {
1827  bgRoot_.addChild(bg);
1828  }
1829 
1830  public void attachUnclickable( BranchGroup bg) {
1831  unclickableBgRoot_.addChild(bg);
1832  }
1833 
1834  public String getFullName() {
1835  return getName();
1836  }
1837 
1838  public TransformGroup getTransformGroupRoot() {
1839  return tgView_;
1840  }
1841 
1843  return info_;
1844  }
1845 
1846  public void setDirection(int dir) {
1847  }
1848 
1849  public void setTransform(Transform3D transform) {
1850  tgView_.setTransform(transform);
1851  }
1852 
1853  public void setViewMode(int mode) {
1854  }
1855 
1856  private void _registerAction() {
1857  GUIAction.ROOM_VIEW.addActionListener(new ActionListener() {
1858  public void actionPerformed(ActionEvent e) {
1860  view_.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
1861  behaviorManager_.setViewMode(BehaviorManager.ROOM_VIEW_MODE);
1862  viewToolBar_.setMode(ViewToolBar.ROOM_MODE);
1863  syncExec(new Runnable(){
1864  public void run(){
1865  setProperty("view.mode", ViewToolBar.COMBO_SELECT_ROOM); //$NON-NLS-1$
1866  }
1867  });
1868  }
1869  });
1870 
1871  GUIAction.WALK_VIEW.addActionListener(new ActionListener() {
1872  public void actionPerformed(ActionEvent e) {
1874  view_.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
1875  behaviorManager_.setViewMode(BehaviorManager.WALK_VIEW_MODE);
1876  viewToolBar_.setMode(ViewToolBar.WALK_MODE);
1877  syncExec(new Runnable(){
1878  public void run(){
1879  setProperty("view.mode", ViewToolBar.COMBO_SELECT_WALK); //$NON-NLS-1$
1880  }
1881  });
1882  }
1883  });
1884 
1885  GUIAction.FRONT_VIEW.addActionListener(new ActionListener() {
1886  public void actionPerformed(ActionEvent e) {
1887  if (info_.getDirection() != ViewInfo.FRONT_VIEW)
1890  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1891  setTransform(info_.getTransform());
1893  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1894  syncExec(new Runnable(){
1895  public void run(){
1896  setProperty("view.mode", ViewToolBar.COMBO_SELECT_FRONT); //$NON-NLS-1$
1897  }
1898  });
1899  }
1900  });
1901 
1902  GUIAction.BACK_VIEW.addActionListener(new ActionListener() {
1903  public void actionPerformed(ActionEvent e) {
1904  if (info_.getDirection() != ViewInfo.BACK_VIEW)
1907  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1908  setTransform(info_.getTransform());
1910  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1911  syncExec(new Runnable(){
1912  public void run(){
1913  setProperty("view.mode", ViewToolBar.COMBO_SELECT_BACK); //$NON-NLS-1$
1914  }
1915  });
1916  }
1917  });
1918 
1919  GUIAction.LEFT_VIEW.addActionListener(new ActionListener() {
1920  public void actionPerformed(ActionEvent e) {
1921  if (info_.getDirection() != ViewInfo.LEFT_VIEW)
1924  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1925  setTransform(info_.getTransform());
1927  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1928  syncExec(new Runnable(){
1929  public void run(){
1930  setProperty("view.mode", ViewToolBar.COMBO_SELECT_LEFT); //$NON-NLS-1$
1931  }
1932  });
1933  }
1934  });
1935 
1936  GUIAction.RIGHT_VIEW.addActionListener(new ActionListener() {
1937  public void actionPerformed(ActionEvent e) {
1938  if (info_.getDirection() != ViewInfo.RIGHT_VIEW)
1941  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1942  setTransform(info_.getTransform());
1944  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1945  syncExec(new Runnable(){
1946  public void run(){
1947  setProperty("view.mode", ViewToolBar.COMBO_SELECT_RIGHT); //$NON-NLS-1$
1948  }
1949  });
1950  }
1951  });
1952 
1953  GUIAction.TOP_VIEW.addActionListener(new ActionListener() {
1954  public void actionPerformed(ActionEvent e) {
1955  if (info_.getDirection() != ViewInfo.TOP_VIEW)
1958  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1959  setTransform(info_.getTransform());
1961  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1962  syncExec(new Runnable(){
1963  public void run(){
1964  setProperty("view.mode", ViewToolBar.COMBO_SELECT_TOP); //$NON-NLS-1$
1965  }
1966  });
1967  }
1968  });
1969 
1970  GUIAction.BOTTOM_VIEW.addActionListener(new ActionListener() {
1971  public void actionPerformed(ActionEvent e) {
1972  if (info_.getDirection() != ViewInfo.BOTTOM_VIEW)
1975  view_.setProjectionPolicy(View.PARALLEL_PROJECTION);
1976  setTransform(info_.getTransform());
1978  viewToolBar_.setMode(ViewToolBar.PARALLEL_MODE);
1979  syncExec(new Runnable(){
1980  public void run(){
1981  setProperty("view.mode", ViewToolBar.COMBO_SELECT_BOTTOM); //$NON-NLS-1$
1982  }
1983  });
1984  }
1985  });
1986  GUIAction.VIEW_ZOOM_MODE.addActionListener(new ActionListener() {
1987  public void actionPerformed(ActionEvent e) {
1988  behaviorManager_.setViewHandlerMode("button_mode_zoom"); //$NON-NLS-1$
1989  // viewHandlerMode_[currentViewer_] = "button_mode_zoom";
1990  viewToolBar_.setOperation(ViewToolBar.ZOOM);
1991  //objectToolBar_.selectNone();
1992  //lblMode_.setText("[ VIEW ]");
1993  }
1994  });
1995 
1996  GUIAction.VIEW_ROTATION_MODE.addActionListener(new ActionListener() {
1997  public void actionPerformed(ActionEvent e) {
1998  behaviorManager_.setViewHandlerMode("button_mode_rotation"); //$NON-NLS-1$
1999  // viewHandlerMode_[currentViewer_] = "button_mode_rotation";
2000  viewToolBar_.setOperation(ViewToolBar.ROTATE);
2001  //objectToolBar_.selectNone();
2002  //lblMode_.setText("[ VIEW ]");
2003  }
2004  });
2005 
2006  GUIAction.VIEW_PAN_MODE.addActionListener(new ActionListener() {
2007  public void actionPerformed(ActionEvent e) {
2008  behaviorManager_.setViewHandlerMode("button_mode_translation"); //$NON-NLS-1$
2009  // viewHandlerMode_[currentViewer_] = "button_mode_translation";
2010  viewToolBar_.setOperation(ViewToolBar.PAN);
2011  //objectToolBar_.selectNone();
2012  //lblMode_.setText("[ VIEW ]");
2013  }
2014  });
2015 
2016  GUIAction.WIRE_FRAME.addActionListener(new ActionListener() {
2017  public void actionPerformed(ActionEvent e) {
2018  Iterator<?> it = manager_.getItemMap(GrxModelItem.class).values().iterator();
2019  while (it.hasNext()) {
2020  ((GrxModelItem)it.next()).setWireFrame(viewToolBar_.isWireFrameSelected());
2021  }
2022  }
2023  });
2024 
2025  GUIAction.BG_COLOR.addActionListener(new ActionListener() {
2026  public void actionPerformed(ActionEvent e) {
2027  // Bring up a color chooser
2028  /*
2029  Color3f oldColor = new Color3f();
2030  backGround_.getColor(oldColor);
2031  Color c = JColorChooser.showDialog(frame_,
2032  MessageBundle.get("dialog.bgcolor"), new Color(
2033  oldColor.x, oldColor.y, oldColor.z));
2034  if (c != null) {
2035  backGround_.setColor(new Color3f(c));
2036  }
2037  */
2038 
2039  Display display = Display.getDefault();
2040  if ( display!=null && !display.isDisposed())
2041  display.asyncExec(
2042  new Runnable(){
2043  public void run() {
2044  ColorDialog dialog = new ColorDialog( getParent().getShell() );
2045  RGB color = dialog.open();
2046  Color3f c = new Color3f( color.red/255f, color.green/255f, color.blue/255f );
2047  backGround_.setColor(new Color3f(c));
2048  }
2049  }
2050  );
2051  }
2052  });
2053 
2054 
2055  GUIAction.CAPTURE.addActionListener(new ActionListener() {
2056  public void actionPerformed(ActionEvent e) {
2057  Display display = Display.getDefault();
2058  if ( display!=null && !display.isDisposed())
2059  display.asyncExec(
2060  new Runnable(){
2061  public void run() {
2062  FileDialog fdlg = new FileDialog( getParent().getShell(), SWT.SAVE);
2063  String[] fe = { "*.png" }; //$NON-NLS-1$
2064  fdlg.setFilterExtensions( fe );
2065  String fPath = fdlg.open();
2066  if( fPath != null ){
2067  saveScreenShot( new File( fPath ) );
2068  }
2069  }
2070  }
2071  );
2072  }
2073  });
2074 
2075  GUIAction.OBJECT_TRANSLATION.addActionListener(new ActionListener() {
2076  public void actionPerformed(ActionEvent e) {
2077  if (behaviorManager_.getOperationMode() != BehaviorManager.OBJECT_TRANSLATION_MODE){
2079  viewMode_ = EDIT;
2080  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
2081  lblMode_.setText(MessageBundle.get("Grx3DView.text.editTranslate")); //$NON-NLS-1$
2082  showOption();
2083  }
2084  }
2085  });
2086 
2087  GUIAction.OBJECT_ROTATION.addActionListener(new ActionListener() {
2088  public void actionPerformed(ActionEvent e) {
2089  if (behaviorManager_.getOperationMode() != BehaviorManager.OBJECT_ROTATION_MODE){
2091  viewMode_ = EDIT;
2092  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
2093  lblMode_.setText(MessageBundle.get("Grx3DView.text,editRotate")); //$NON-NLS-1$
2094  showOption();
2095  }
2096  }
2097  });
2098  GUIAction.JOINT_ROTATION.addActionListener(new ActionListener() {
2099  public void actionPerformed(ActionEvent e) {
2100  if (behaviorManager_.getOperationMode() != BehaviorManager.JOINT_ROTATION_MODE){
2102  viewMode_ = EDIT;
2103  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
2104  lblMode_.setText(MessageBundle.get("Grx3DView.text.editMove")); //$NON-NLS-1$
2105  showOption();
2106  }
2107  }
2108  });
2109 
2110  GUIAction.FITTING_SRC.addActionListener(new ActionListener() {
2111  public void actionPerformed(ActionEvent e) {
2112  if (behaviorManager_.getOperationMode() != BehaviorManager.FITTING_FROM_MODE){
2113  objectToolBar_.setMode(ObjectToolBar.FITTING_MODE);
2114  viewToolBar_.setEnabled(true);
2116  viewMode_ = EDIT;
2117  lblMode_.setText(MessageBundle.get("Grx3DView.text.editObjectSelect")); //$NON-NLS-1$
2118  showOption();
2119  }
2120  }
2121  });
2122 
2123  GUIAction.FITTING_DEST.addActionListener(new ActionListener() {
2124  public void actionPerformed(ActionEvent e) {
2125  if (behaviorManager_.getOperationMode() != BehaviorManager.FITTING_TO_MODE){
2126  objectToolBar_.setMode(ObjectToolBar.FITTING_MODE);
2127  viewToolBar_.setEnabled(true);
2129  viewMode_ = EDIT;
2130  lblMode_.setText(MessageBundle.get("Grx3DView.text,editObjectDestination")); //$NON-NLS-1$
2131  showOption();
2132  }
2133  }
2134  });
2135 
2136  GUIAction.DO_FIT.addActionListener(new ActionListener() {
2137  public void actionPerformed(ActionEvent e) {
2138  //setModelUpdate(false);
2139  behaviorManager_.fit();
2140  objectToolBar_.setMode(ObjectToolBar.FITTING_START_MODE);
2141  viewToolBar_.setEnabled(true);
2143  viewMode_ = EDIT;
2144  lblMode_.setText(MessageBundle.get("Grx3DView.text.editObjectSelect")); //$NON-NLS-1$
2145  showOption();
2146  }
2147  });
2148 
2149  GUIAction.INV_KINEMA_FROM.addActionListener(new ActionListener() {
2150  public void actionPerformed(ActionEvent e) {
2151  if (behaviorManager_.getOperationMode() != BehaviorManager.INV_KINEMA_FROM_MODE){
2152  objectToolBar_.setMode(ObjectToolBar.INV_KINEMA_MODE);
2154  viewMode_ = EDIT;
2155  lblMode_.setText(MessageBundle.get("Grx3DView.text.IKbaseLink")); //$NON-NLS-1$
2156  showOption();
2157  }
2158  }
2159  });
2160 
2161  GUIAction.INV_KINEMA_TRANS.addActionListener(new ActionListener() {
2162  public void actionPerformed(ActionEvent e) {
2164  objectToolBar_.setMode(ObjectToolBar.INV_KINEMA_MODE);
2166  viewMode_ = EDIT;
2167  lblMode_.setText(MessageBundle.get("Grx3DView.text.IKtranslate")); //$NON-NLS-1$
2168  showOption();
2169  }
2170  }
2171  });
2172 
2173  GUIAction.INV_KINEMA_ROT.addActionListener(new ActionListener() {
2174  public void actionPerformed(ActionEvent e) {
2175  if (behaviorManager_.getOperationMode() != BehaviorManager.INV_KINEMA_ROTATION_MODE){
2176  objectToolBar_.setMode(ObjectToolBar.INV_KINEMA_MODE);
2178  viewMode_ = EDIT;
2179  lblMode_.setText(MessageBundle.get("Grx3DView.text.IKRotate")); //$NON-NLS-1$
2180  showOption();
2181  }
2182  }
2183  });
2184 
2185  GUIAction.OPERATION_DISABLE.addActionListener(new ActionListener() {
2186  public void actionPerformed(ActionEvent e) {
2187  disableOperation();
2188  viewMode_ = VIEW;
2189  }
2190  });
2191  }
2192 
2193  public void disableOperation(){
2194  //setModelUpdate(true);
2195 
2197  objectToolBar_.setMode(ObjectToolBar.OBJECT_MODE);
2198  objectToolBar_.selectNone();
2199  viewToolBar_.setEnabled(true);
2200  lblMode_.setText(MessageBundle.get("Grx3DView.text.view")); //$NON-NLS-1$
2201 
2202  if(currentState_!=null){
2203  syncExec(new Runnable(){
2204  public void run(){
2205  updateModels(currentState_);
2206  _showCollision(currentState_.collisions);
2207  }
2208  });
2209  updateViewSimulator(currentState_.time);
2210  showOptionWithoutCollision();
2211  }
2212  }
2213 
2214  public void addClickListener( Grx3DViewClickListener listener ){
2215  behaviorManager_.addClickListener( listener );
2216  }
2217 
2219  behaviorManager_.removeClickListener( listener );
2220  }
2221 
2222  /*
2223  private PickCanvas initPickCanvas(int x, int y){
2224  PickCanvas pickCanvas = new PickCanvas(
2225  getCanvas3D(),
2226  getBranchGroupRoot()
2227  );
2228 
2229  pickCanvas.setShapeLocation( x, y );
2230 
2231  pickCanvas.setMode(PickInfo.NODE);
2232 
2233  PickCone pickCone = (PickCone)pickCanvas.getPickShape();
2234  Point3d pickOrig = new Point3d();
2235  Vector3d pickDir = new Vector3d();
2236  pickCone.getOrigin( pickOrig );
2237  pickCone.getDirection( pickDir );
2238  pickCanvas.setShapeRay( pickOrig, pickDir );
2239 
2240  // PickInfoの取得。フラグ設定が重要。
2241  pickCanvas.setFlags(PickInfo.NODE | PickInfo.CLOSEST_INTERSECTION_POINT |PickInfo.SCENEGRAPHPATH |PickInfo.LOCAL_TO_VWORLD );
2242 
2243  return pickCanvas;
2244  }
2245 
2246  public Point3d getClickPoint(int x, int y){
2247  PickCanvas canvas = initPickCanvas(x,y);
2248  PickInfo pickInfo = canvas.pickClosest();
2249  if (pickInfo == null) {
2250  GrxDebugUtil.println("[3DView] PickInfo Null.");
2251  }
2252 
2253  if(pickInfo == null)
2254  return null;
2255 
2256  //クリック位置の取得、世界座標への変換
2257  Point3d intersectionPoint = pickInfo.getClosestIntersectionPoint();
2258  Transform3D ltov = pickInfo.getLocalToVWorld();
2259  ltov.transform(intersectionPoint);
2260 
2261  if( intersectionPoint == null ){
2262  GrxDebugUtil.println("[3dView] Not Intersect point.");
2263  }else{
2264  NumberFormat format = NumberFormat.getInstance();
2265  format.setMaximumFractionDigits(2);
2266  GrxDebugUtil.println( "CLICK="+"("
2267  +format.format(intersectionPoint.x)+","
2268  +format.format(intersectionPoint.y)+","
2269  +format.format(intersectionPoint.z)+")" );
2270  }
2271 
2272  return intersectionPoint;
2273  }
2274 
2275  public TransformGroup getClickNode(int x, int y, int type){
2276  PickCanvas pickCanvas = initPickCanvas(x,y);
2277  PickInfo pickInfo = pickCanvas.pickClosest();
2278  if (pickInfo == null) {
2279  GrxDebugUtil.println("[3DView] PickInfo Null.");
2280  }
2281 
2282  //クリックされたノードを取得する
2283  TransformGroup tg = null;
2284  try {
2285  tg = (TransformGroup) pickCanvas.getNode(pickInfo, type );
2286  if (tg == null)
2287  GrxDebugUtil.println("[3DView] Node Null.");
2288  } catch (CapabilityNotSetException ex) {
2289  ex.printStackTrace();
2290  }
2291 
2292  return tg;
2293  }
2294 */
2295 
2296 
2297  public void saveScreenShot( File file ){
2298  if ( file == null )
2299  return;
2300 
2301  //onScreen方式
2302  Raster raster = null;
2303  // 読み込み用カラー情報 : type int, Alpha:8bit, R:8bit, G:8bit, B:8bit
2304  BufferedImage bimageRead = new BufferedImage(canvas_.getWidth(),
2305  canvas_.getHeight(), BufferedImage.TYPE_INT_RGB);
2306  ImageComponent2D readImage = new ImageComponent2D(
2307  ImageComponent.FORMAT_RGB, bimageRead);
2308  // 読み込み用ラスタ
2309  raster = new Raster(new Point3f(0.0f, 0.0f, 0.0f),
2310  Raster.RASTER_COLOR, 0, 0, bimageRead.getWidth(),
2311  bimageRead.getHeight(), readImage, null
2312  //readDepthFloat
2313  //readDepthInt
2314  );
2315  //raster.setCapability(Raster.ALLOW_DEPTH_COMPONENT_READ);
2316  raster.setCapability(Raster.ALLOW_IMAGE_READ);
2317  canvas_.getGraphicsContext3D().readRaster(raster);
2318  // カラー情報読み込み
2319  BufferedImage image = raster.getImage().getImage();
2320 
2321  /*
2322  //offScreen方式
2323  if(imageChooser_.showSaveDialog(GUIManager.this) == JFileChooser.APPROVE_OPTION ){
2324  //視点をセット
2325  recordingMgr_ = RecordingManager.getInstance(); // 録画マネージャ
2326  recordingMgr_.setView(viewer_[currentViewer_].getDrawable());
2327  //カメラ
2328  ImageCamera camera = recordingMgr_.getImageCamera();
2329  //サイズをセット
2330  Dimension d = viewer_[currentViewer_].getCanvas3D().getSize();
2331  camera.setSize(d.width,d.height);
2332  //イメージ取り出し
2333  java.awt.image.BufferedImage image = camera.getImage();
2334  */
2335 
2336  //保存
2337  try {
2338  javax.imageio.ImageIO.write(image, "PNG", file); //$NON-NLS-1$
2339  } catch (IOException ex) {
2340  // この関数はSWTのEDTから呼ばれるのでSWT.syncExec()とかしなくていいはず
2341  MessageDialog.openWarning( getParent().getShell(), "", MessageBundle.get("message.ioexception") ); //$NON-NLS-1$ //$NON-NLS-2$
2342  }
2343  }
2344 
2345  public View getView(){
2346  return view_;
2347  }
2348 
2349  private boolean xor(boolean a, boolean b){
2350  return (a || b) && (!a || !b);
2351  }
2352 
2353  public boolean propertyChanged(String key, String value){
2354  if (super.propertyChanged(key, value)){
2355  return true;
2356  }else {
2357  if (key.equals("showScale")){ //$NON-NLS-1$
2358  if(xor(btnFloor_.isSelected(), value.equals("true")))
2359  btnFloor_.doClick();
2360  }else if (key.equals("showCollision")){ //$NON-NLS-1$
2361  if(xor(btnCollision_.isSelected(), value.equals("true")))
2362  btnCollision_.doClick();
2363  }else if (key.equals("showDistance")){ //$NON-NLS-1$
2364  if(xor(btnDistance_.isSelected(), value.equals("true")))
2365  btnDistance_.doClick();
2366  }else if (key.equals("showIntersection")){ //$NON-NLS-1$
2367  if(xor(btnIntersection_.isSelected(), value.equals("true")))
2368  btnIntersection_.doClick();
2369  }else if (key.equals("showCoM")){ //$NON-NLS-1$
2370  if(xor(btnCoM_.isSelected(), value.equals("true")))
2371  btnCoM_.doClick();
2372  }else if (key.equals("showCoMonFloor")){ //$NON-NLS-1$
2373  if(xor(btnCoMonFloor_.isSelected(), value.equals("true")))
2374  btnCoMonFloor_.doClick();
2375  }else if (key.equals("view.mode")){ //$NON-NLS-1$
2376  value = viewToolBar_.selectViewMode(value);
2377  }else if (key.equals("showActualState")){ //$NON-NLS-1$
2378  showActualState_ = value.equals("true");
2379  }else if (key.equals("eyeHomePosition")){ //$NON-NLS-1$
2380  double[] eyeHomePosition = getDblAry(value);
2381  t3dViewHome_.set(eyeHomePosition);
2382  setTransform(t3dViewHome_);
2383  }else{
2384  return false;
2385  }
2386  final String key_ = key;
2387  final String value_ = value;
2388  syncExec(new Runnable(){
2389  public void run(){
2390  setProperty(key_, value_);
2391  }
2392  });
2393  return true;
2394  }
2395  }
2396 
2397  // view が閉じられたときの処理
2398  public void shutdown() {
2399  showViewSimulator(false);
2400  behaviorManager_.destroyDynamicsSimulator();
2401  Iterator<GrxModelItem> it = currentModels_.iterator();
2402  while(it.hasNext()) {
2403  GrxModelItem model = it.next();
2404  model.bgRoot_.detach();
2405  model.deleteObserver(this);
2406  }
2407  manager_.removeItemChangeListener(this, GrxModelItem.class);
2408  manager_.removeItemChangeListener(this, GrxWorldStateItem.class);
2409  if(currentWorld_!=null)
2410  {
2411  currentWorld_.deleteObserver(this);
2412  currentWorld_.deletePosObserver(this);
2413  }
2414  manager_.removeItemChangeListener(this, GrxCollisionPairItem.class);
2415  if(simItem_!=null)
2416  simItem_.deleteObserver(this);
2417  manager_.removeItemChangeListener(this, GrxSimulationItem.class);
2418  }
2419 
2420  public void repaint(){
2421  view_.repaint();
2422  objectToolBar_.repaint();
2423  viewToolBar_.repaint();
2424  }
2425 
2426  private boolean ans_;
2427  private List<GrxModelItem> setNumOfAABB(){
2428  List<GrxModelItem> ret = new ArrayList<GrxModelItem>();
2429  List<GrxModelItem> models = new ArrayList<GrxModelItem>();
2430  models.addAll(currentModels_);
2431  while(!models.isEmpty()){
2432  final GrxModelItem model = models.get(0);
2433  final List<GrxModelItem> sameModels = model.getSameUrlModels();
2434  boolean flg=false;
2435  for(int i=0; i<model.links_.size(); i++){
2436  if(model.links_.get(i).getStr("NumOfAABB").equals("original data")){
2437  flg = true;
2438  break;
2439  }
2440  }
2441  if(flg){
2442  syncExec(new Runnable(){
2443  public void run(){
2444  ans_ = MessageDialog.openConfirm(comp.getShell(), MessageBundle.get("Grx3DView.dialog.title.confirmation"), model.getName()+" "+MessageBundle.get("Grx3DView.dialog.message.setAABBdepth")); //$NON-NLS-1$ //$NON-NLS-2$
2445  if(ans_){
2446  for(int i=0; i<model.links_.size(); i++){
2447  if(model.links_.get(i).getStr("NumOfAABB").equals("original data")){
2448  model.links_.get(i).setInt("NumOfAABB",1);
2449  model.setProperty(model.links_.get(i).getName()+".NumOfAABB", "1");
2450  }
2451  }
2452  model.makeAABBforSameUrlModels();
2453  }
2454  }
2455  });
2456  if(ans_){
2457  ret.addAll(sameModels);
2458  ret.add(model);
2459  }
2460  }else{
2461  ret.add(model);
2462  ret.addAll(sameModels);
2463  }
2464  models.removeAll(sameModels);
2465  models.remove(model);
2466  }
2467  return ret;
2468  }
2469 
2470  private boolean btnStateCollision_=true;
2471  private boolean btnStateDistance_=false;
2472  private boolean btnStateIntersection_=false;
2473  private boolean modelModified_ = false;
2474  private void optionButtonEnable(boolean enable){
2475  if(!modelModified_ && enable )
2476  return;
2477  if(modelModified_ && !enable)
2478  return;
2479  if(enable){
2480  for(GrxModelItem model : currentModels_ ){
2481  if(model.isModified())
2482  return;
2483  }
2484  }
2485  if(!enable){
2486  btnStateCollision_ = btnCollision_.isSelected();
2487  btnStateDistance_ = btnDistance_.isSelected();
2488  btnStateIntersection_ = btnIntersection_.isSelected();
2489  if(btnCollision_.isSelected())
2490  btnCollision_.doClick();
2491  if(btnDistance_.isSelected())
2492  btnDistance_.doClick();
2493  if(btnIntersection_.isSelected())
2494  btnIntersection_.doClick();
2495  modelModified_ = true;
2496  }
2497  btnCollision_.setEnabled(enable);
2498  btnDistance_.setEnabled(enable);
2499  btnIntersection_.setEnabled(enable);
2500  if(enable){
2501  if(btnStateCollision_)
2502  btnCollision_.doClick();
2503  if(btnStateDistance_)
2504  btnDistance_.doClick();
2505  if(btnStateIntersection_)
2506  btnIntersection_.doClick();
2507  modelModified_ = false;
2508  }
2509  }
2510 
2511  public ValueEditType GetValueEditType(String key) {
2512  if(key.equals("showCoM") || key.equals("showCoMonFloor") || key.equals("showDistance") ||
2513  key.equals("showIntersection") || key.equals("showCollision") || key.equals("showActualState") ||
2514  key.equals("showScale"))
2515  {
2516  return new ValueEditCombo(booleanComboItem_);
2517  }else if(key.equals("view.mode")){
2518  return new ValueEditCombo(ViewToolBar.VIEW_MODE);
2519  }
2520  return super.GetValueEditType(key);
2521  }
2522 }
rootnc
Definition: hrp.py:10
void setColor(java.awt.Color color)
void registerCharacter(String cname, BodyInfo binfo)
static final String get(String key)
boolean xor(boolean a, boolean b)
int c
Definition: autoplay.py:16
javax.media.j3d.Locale locale_
Definition: Grx3DView.java:113
Distance [] getDistance()
get distance information
void registerItemChange(GrxBaseItem item, int event)
Definition: Grx3DView.java:871
boolean fileOverwriteDialog(final String fileName)
void addActionListener(ActionListener listener)
Definition: GUIAction.java:127
boolean getPosture(String name, DblSequenceHolder posture)
void updateModels(WorldStateEx state)
#define null
our own NULL pointer
Definition: IceTypes.h:57
void setWireFrame(boolean b)
switch display mode between fill and line
GrxLinkItem getLink(String name)
get link from name
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
item corresponds to a robot model
static VirtualUniverse universe_
Definition: Grx3DView.java:112
void restoreProperties()
restore properties
void setURL(String url)
set URL property
png_bytep png_bytep png_size_t length
Definition: png.h:1541
png_uint_32 i
Definition: png.h:2735
void setTransform(Transform3D transform)
long b
Definition: jpegint.h:371
void _showCollision(Collision[] collisions)
png_bytepp image
Definition: png.h:1772
void update(GrxBasePlugin plugin, Object... arg)
Definition: Grx3DView.java:977
final void setDbl(String key, double value)
associate double value to key
png_infop png_uint_32 * width
Definition: png.h:2309
LinkPair [] getIntersection()
get intersection information
void updateShapeOfVisibleArea(double[] distances)
update shape of visible area(only used for RangeSensor)
void registerCharacter(final String name, final BodyInfo bInfo)
boolean propertyChanged(String key, String value)
List< GrxSensorItem > getSensors(String type)
void optionButtonEnable(boolean enable)
boolean initDynamicsSimulator()
initialize dynamics server
void getCameraSequenceOf(String objectName, CameraSequenceHolder arg1)
def run(tree, args)
Vector< GrxLinkItem > intersectingLinks_
Definition: Grx3DView.java:160
void removeClickListener(Grx3DViewClickListener listener)
void calcForwardKinematics()
compute forward kinematics
Object setProperty(String key, String value)
set property value associated with a keyword
void _showDistance(Distance[] distances)
void load(final String name, String url)
void addClickListener(Grx3DViewClickListener listener)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void jointValue(double jv)
set new joint value
void attachUnclickable(BranchGroup bg)
GrxModelItem model()
get model item to which this item belongs
png_infop png_bytep buffer
Definition: png.h:2042
ValueEditType GetValueEditType(String key)
Object [] preRecord(String fileName, String fileType)
void setCharacterPos(LinkPosition[] lpos, double[] q)
set transformation of the root joint and all joint values
void setItem(List< GrxModelItem > models, List< GrxCollisionPairItem > cols)
org
void removeClickListener(Grx3DViewClickListener listener)
char * arg
Definition: cdjpeg.h:136
Grx3DView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
Definition: Grx3DView.java:168
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
static Dimension getDefaultButtonSize()
get default button size
static NamingContext getNamingContext()
get naming context
NamingContext
Definition: hrpPrep.py:134
List< GrxModelItem > setNumOfAABB()
Collision [] getCollision()
get collision information
List< Camera_impl > getCameraSequence()
get sequence of cameras
NameComponent
Definition: hrpPrep.py:128
void addClickListener(Grx3DViewClickListener listener)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03