GrxOpenHRPView.java
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil; tab-width: 4; -*-
00002 /*
00003  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00004  * All rights reserved. This program is made available under the terms of the
00005  * Eclipse Public License v1.0 which accompanies this distribution, and is
00006  * available at http://www.eclipse.org/legal/epl-v10.html
00007  * Contributors:
00008  * General Robotix Inc.
00009  * National Institute of Advanced Industrial Science and Technology (AIST) 
00010  */
00011 /*
00012  *  GrxOpenHRPView.java
00013  *
00014  *  Copyright (C) 2007 GeneralRobotix, Inc.
00015  *  All Rights Reserved
00016  *
00017  *  @author Yuichiro Kawasumi (General Robotix, Inc.)
00018  */
00019 
00020 package com.generalrobotix.ui.view;
00021 
00022 import jp.go.aist.hrp.simulator.DynamicsSimulator;
00023 import org.eclipse.jface.action.IAction;
00024 import org.eclipse.swt.SWT;
00025 import org.eclipse.swt.widgets.Composite;
00026 import com.generalrobotix.ui.GrxBaseItem;
00027 import com.generalrobotix.ui.GrxBasePlugin;
00028 import com.generalrobotix.ui.GrxBaseView;
00029 import com.generalrobotix.ui.GrxBaseViewPart;
00030 import com.generalrobotix.ui.GrxPluginManager;
00031 
00032 import com.generalrobotix.ui.item.GrxSimulationItem;
00033 import com.generalrobotix.ui.item.GrxWorldStateItem;
00034 import com.generalrobotix.ui.view.simulation.SimulationParameterPanel;
00035 
00036 @SuppressWarnings("serial") //$NON-NLS-1$
00037 public class GrxOpenHRPView extends GrxBaseView {
00038     public static final String TITLE = "OpenHRP"; //$NON-NLS-1$
00039     private GrxWorldStateItem currentWorld_;
00040     private GrxSimulationItem simItem_=null;
00041     private SimulationParameterPanel simParamPane_;
00042 
00043     public GrxOpenHRPView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
00044         super(name, manager,vp,parent);
00045         
00046         simParamPane_ = new SimulationParameterPanel(composite_, SWT.NONE);
00047         simParamPane_.setEnabled(true);//false
00048         
00049         setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
00050  
00051         setUp();
00052         manager_.registerItemChangeListener(this, GrxWorldStateItem.class);
00053                 manager_.registerItemChangeListener(this, GrxSimulationItem.class);
00054     }    
00055     
00056     public void setUp(){
00057         if(currentWorld_ != null)
00058                 currentWorld_.deleteObserver(this);
00059         currentWorld_ = manager_.<GrxWorldStateItem>getSelectedItem(GrxWorldStateItem.class, null);
00060         simParamPane_.updateLogTime(currentWorld_);
00061         if(currentWorld_!=null)
00062             currentWorld_.addObserver(this);
00063         if(simItem_ != null)
00064                 simItem_.deleteObserver(this);
00065         simItem_ = manager_.<GrxSimulationItem>getSelectedItem(GrxSimulationItem.class, null);
00066                 simParamPane_.updateItem(simItem_);
00067                 if(simItem_!=null){
00068                         simItem_.addObserver(this);
00069                 }
00070     }
00071    
00072     public void registerItemChange(GrxBaseItem item, int event){
00073         if(item instanceof GrxWorldStateItem){
00074             GrxWorldStateItem witem = (GrxWorldStateItem) item;
00075             switch(event){
00076             case GrxPluginManager.SELECTED_ITEM:
00077                 if(currentWorld_!=witem){
00078                     simParamPane_.updateLogTime(witem);
00079                     currentWorld_ = witem;
00080                     currentWorld_.addObserver(this);
00081                 }
00082                 break;
00083             case GrxPluginManager.REMOVE_ITEM:
00084             case GrxPluginManager.NOTSELECTED_ITEM:
00085                 if(currentWorld_==witem){
00086                     simParamPane_.updateLogTime(null);
00087                     currentWorld_.deleteObserver(this);
00088                     currentWorld_ = null;
00089                 }
00090                 break;
00091             default:
00092                 break;
00093             }
00094         }else if(item instanceof GrxSimulationItem){
00095                 GrxSimulationItem simItem = (GrxSimulationItem) item;
00096                 switch(event){
00097                 case GrxPluginManager.SELECTED_ITEM:
00098                         if(simItem_!=simItem){
00099                                 simParamPane_.updateItem(simItem);
00100                                 simItem_ = simItem;
00101                                 simItem_.addObserver(this);
00102                         }
00103                         break;
00104                 case GrxPluginManager.REMOVE_ITEM:
00105                 case GrxPluginManager.NOTSELECTED_ITEM:
00106                         if(simItem_==simItem){
00107                                 simParamPane_.updateItem(null);
00108                                 simItem_.deleteObserver(this);
00109                                 simItem_ = null;
00110                         }
00111                         break;
00112                 default:
00113                         break;
00114                 }
00115         }
00116     }
00117     
00118     public void update(GrxBasePlugin plugin, Object... arg) {
00119         if(simItem_==plugin){
00120                 if((String)arg[0]=="StartSimulation")
00121                 simParamPane_.setEnabled(false);
00122                 else if((String)arg[0]=="StopSimulation")
00123                 simParamPane_.setEnabled(true);
00124             else if((String)arg[0]=="PropertyChange") //$NON-NLS-1$
00125                 simParamPane_.updateItem(simItem_); 
00126         }else if(currentWorld_==plugin){
00127             if((String)arg[0]=="PropertyChange") //$NON-NLS-1$
00128                 simParamPane_.updateLogTime(currentWorld_);  
00129         }
00130     }
00131     
00132     public void shutdown() {
00133         if(currentWorld_!=null)
00134             currentWorld_.deleteObserver(this);
00135         
00136         manager_.removeItemChangeListener(this, GrxWorldStateItem.class);
00137         
00138         if(simItem_!=null)
00139                         simItem_.deleteObserver(this);
00140                 manager_.removeItemChangeListener(this, GrxSimulationItem.class);
00141     }
00142     
00143     //  Python scriptからの呼び出しのために public宣言されていたメソッドを残す   //
00148     public void startSimulation(boolean isInteractive, IAction action){
00149                 simParamPane_.fixParam();
00150                 if(simItem_==null){
00151                         simItem_ = (GrxSimulationItem)manager_.createItem(GrxSimulationItem.class, null);
00152                         simItem_.addObserver(this);
00153                         manager_.itemChange(simItem_, GrxPluginManager.ADD_ITEM);
00154                         manager_.setSelectedItem(simItem_, true);
00155                 }
00156                 simItem_.startSimulation(isInteractive);
00157     }
00158  
00159     public void waitStopSimulation() throws InterruptedException {
00160         simItem_.waitStopSimulation();
00161     }
00162     
00166     public void stopSimulation(){
00167         simItem_.stopSimulation();
00168     }
00169     
00170     public boolean registerCORBA() {
00171         if(simItem_==null){
00172                         simItem_ = (GrxSimulationItem)manager_.createItem(GrxSimulationItem.class, null);
00173                         simItem_.addObserver(this);
00174                         manager_.itemChange(simItem_, GrxPluginManager.ADD_ITEM);
00175                         manager_.setSelectedItem(simItem_, true);
00176                 }
00177         return simItem_.registerCORBA();
00178     }
00179     
00180     public void unregisterCORBA() {
00181         simItem_.unregisterCORBA();
00182     }
00183  
00184     public boolean initDynamicsSimulator() {
00185         if(simItem_==null){
00186                         simItem_ = (GrxSimulationItem)manager_.createItem(GrxSimulationItem.class, null);
00187                         simItem_.addObserver(this);
00188                         manager_.itemChange(simItem_, GrxPluginManager.ADD_ITEM);
00189                         manager_.setSelectedItem(simItem_, true);
00190                 }
00191         return simItem_.initDynamicsSimulator();
00192     }
00193 
00194     public DynamicsSimulator getDynamicsSimulator(boolean update) {
00195         if(simItem_==null){
00196                         simItem_ = (GrxSimulationItem)manager_.createItem(GrxSimulationItem.class, null);
00197                         simItem_.addObserver(this);
00198                         manager_.itemChange(simItem_, GrxPluginManager.ADD_ITEM);
00199                         manager_.setSelectedItem(simItem_, true);
00200                 }
00201         return simItem_.getDynamicsSimulator(update);
00202     }
00203   
00204     public boolean isSimulating(){
00205         if(simItem_!=null)
00206                 return simItem_.isSimulating();
00207         else
00208                 return false;
00209     }
00210 
00211     public void fixParam(){
00212         simParamPane_.fixParam();
00213     }
00214 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16