IseBehaviorHandler.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00017 package com.generalrobotix.ui.view.tdview;
00018 
00019 import java.awt.event.*;
00020 import javax.media.j3d.TransformGroup;
00021 
00022 import org.eclipse.swt.widgets.Display;
00023 
00029 class IseBehaviorHandler implements BehaviorHandler {
00030     //--------------------------------------------------------------------
00031     // 定数
00032 
00033     // OperationHandlerの具象クラスのインスタンス
00034     private static final ObjectRotationHandler
00035         OBJECT_ROTATION_HANDLER = new ObjectRotationHandler();
00036     private static final ObjectTranslationHandler
00037         OBJECT_TRANSLATION_HANDLER = new ObjectTranslationHandler();
00038     private static final JointRotationHandler
00039         JOINT_ROTATION_HANDLER = new JointRotationHandler();
00040     private static final ObjectFittingHandler
00041         OBJECT_FITTING_HANDLER = new ObjectFittingHandler();
00042     private static final InvKinemaHandler
00043         INV_KINEMA_HANDLER = new InvKinemaHandler();
00044 
00045     // ViewHandlerの具象クラスのインスタンス
00046     private static final WalkViewHandler
00047         WALK_VIEW_HANDLER = new WalkViewHandler();
00048     private static final RoomViewHandler
00049         ROOM_VIEW_HANDLER = new RoomViewHandler();
00050 
00051     public static final String
00052         BUTTON_MODE_ROTATION = "button_mode_rotation";
00053     public static final String
00054         BUTTON_MODE_TRANSLATION = "button_mode_translation"; 
00055     public static final String BUTTON_MODE_ZOOM = "button_mode_zoom";
00056     public static final String CTRL_PRESSED = "ctrl_pressed";
00057     public static final String ALT_PRESSED = "alt_pressed";
00058 
00059     private static final int TIMER_MODE_OFF       = 0;
00060     private static final int TIMER_MODE_OPERATION = 1;
00061     private static final int TIMER_MODE_VIEW      = 2;
00062 
00063     //--------------------------------------------------------------------
00064     // インスタンス変数
00065     private ViewHandler viewHandler_;
00066     private OperationHandler operationHandler_;
00067     private BehaviorHandler indicator_;
00068     private int timerMode_;
00069     private BehaviorManager bManager_;
00070 
00071     //--------------------------------------------------------------------
00072     // コンストラクタ
00073     public IseBehaviorHandler(BehaviorManager bManager) {
00074         viewHandler_ = ROOM_VIEW_HANDLER;
00075         ROOM_VIEW_HANDLER.setParallelMode(false);
00076         bManager_ = bManager;
00077     }
00078 
00079     //--------------------------------------------------------------------
00080     // 公開メソッド
00081     public void setViewIndicator(BehaviorHandler handler) {
00082         indicator_ = handler;
00083     }
00084     
00085     public void setViewMode(int mode) {
00086         switch (mode) {
00087         case BehaviorManager.WALK_VIEW_MODE:
00088             viewHandler_ = WALK_VIEW_HANDLER;
00089             break;
00090         case BehaviorManager.ROOM_VIEW_MODE:
00091             viewHandler_ = ROOM_VIEW_HANDLER;
00092             ROOM_VIEW_HANDLER.setParallelMode(false);
00093             break;
00094         case BehaviorManager.PARALLEL_VIEW_MODE:
00095             viewHandler_ = ROOM_VIEW_HANDLER;
00096             ROOM_VIEW_HANDLER.setParallelMode(true);
00097             break;
00098         }
00099     }
00100 
00101     public void setViewHandlerMode(String str) {
00102         WALK_VIEW_HANDLER.setMode(str);
00103         ROOM_VIEW_HANDLER.setMode(str);
00104     }
00105 
00106     public void setOperationMode(int mode) {
00107         switch (mode) {
00108         case BehaviorManager.OPERATION_MODE_NONE:
00109             if (operationHandler_ != null) {
00110                 operationHandler_.disableHandler();
00111             }
00112             operationHandler_ = null;
00113             break;
00114         case BehaviorManager.OBJECT_ROTATION_MODE:
00115             if (operationHandler_ != null) {
00116                 operationHandler_.disableHandler();
00117             }
00118             operationHandler_ = OBJECT_ROTATION_HANDLER;
00119             break;
00120         case BehaviorManager.OBJECT_TRANSLATION_MODE:
00121             if (operationHandler_ != null) {
00122                 operationHandler_.disableHandler();
00123             }
00124             operationHandler_ = OBJECT_TRANSLATION_HANDLER;
00125             break;
00126         case BehaviorManager.JOINT_ROTATION_MODE:
00127             if (operationHandler_ != null) {
00128                 operationHandler_.disableHandler();
00129             }
00130             operationHandler_ = JOINT_ROTATION_HANDLER;
00131             break;
00132         case BehaviorManager.FITTING_FROM_MODE:
00133             if (operationHandler_ != null &&
00134                 operationHandler_ != OBJECT_FITTING_HANDLER
00135             ) {
00136                 operationHandler_.disableHandler();
00137             }
00138             operationHandler_ = OBJECT_FITTING_HANDLER;
00139             OBJECT_FITTING_HANDLER.setFittingMode(
00140                 ObjectFittingHandler.FITTING_FROM
00141             );
00142             break;
00143         case BehaviorManager.FITTING_TO_MODE:
00144             if (operationHandler_ != null &&
00145                 operationHandler_ != OBJECT_FITTING_HANDLER
00146             ) {
00147                 operationHandler_.disableHandler();
00148             }
00149             operationHandler_ = OBJECT_FITTING_HANDLER;
00150             OBJECT_FITTING_HANDLER.setFittingMode(
00151                 ObjectFittingHandler.FITTING_TO
00152             );
00153             break;
00154         case BehaviorManager.INV_KINEMA_FROM_MODE:
00155             if (operationHandler_ != null &&
00156                 operationHandler_ != INV_KINEMA_HANDLER
00157             ) {
00158                 operationHandler_.disableHandler();
00159             }
00160             operationHandler_ = INV_KINEMA_HANDLER;
00161             INV_KINEMA_HANDLER.setInvKinemaMode(InvKinemaHandler.FROM_MODE);
00162             break;
00163         case BehaviorManager.INV_KINEMA_TRANSLATION_MODE:
00164             if (operationHandler_ != null &&
00165                 operationHandler_ != INV_KINEMA_HANDLER
00166             ) {
00167                 operationHandler_.disableHandler();
00168             }
00169             operationHandler_ = INV_KINEMA_HANDLER;
00170             INV_KINEMA_HANDLER.setInvKinemaMode(
00171                 InvKinemaHandler.TRANSLATION_MODE
00172             );
00173             break;
00174         case BehaviorManager.INV_KINEMA_ROTATION_MODE:
00175             if (operationHandler_ != null &&
00176                 operationHandler_ != INV_KINEMA_HANDLER
00177             ) {
00178                 operationHandler_.disableHandler();
00179             }
00180             operationHandler_ = INV_KINEMA_HANDLER;
00181             INV_KINEMA_HANDLER.setInvKinemaMode(
00182                 InvKinemaHandler.ROTATION_MODE
00183             );
00184             break;
00185         }
00186     }
00187 
00188     public void setInvKinemaResolver(InvKinemaResolver resolver) {
00189         INV_KINEMA_HANDLER.setInvKinemaResolver(resolver);
00190     }
00191 
00192     private boolean ret_;
00193     public boolean fit(final BehaviorInfo info) {
00194         if (operationHandler_ == OBJECT_FITTING_HANDLER) {
00195                 syncExec(new Runnable(){
00196                 public void run(){
00197                         ret_ = OBJECT_FITTING_HANDLER.fit(info);
00198                 }
00199             });
00200                 return ret_;
00201         } else {
00202             return false;
00203         }
00204     }
00205 
00206     public void setPickTarget(TransformGroup tg, BehaviorInfo info) {
00207         if (operationHandler_ != null) {
00208             operationHandler_.setPickTarget(tg, info);
00209         }
00210     }
00211 
00212     //--------------------------------------------------------------------
00213     // BehaviorHandlerの実装
00214     public void processPicking(final MouseEvent evt, final BehaviorInfo info) {
00215         if (!evt.isAltDown() && !evt.isMetaDown()) {
00216             if (operationHandler_ != null) {
00217                 syncExec(new Runnable(){
00218                         public void run(){
00219                                 operationHandler_.processPicking(evt, info);
00220                         }
00221                 });
00222             }
00223         }
00224 
00225         if (!evt.isConsumed()) {
00226             viewHandler_.processPicking(evt, info);
00227             indicator_.processPicking(evt, info);
00228         }
00229     }
00230 
00231     public void processStartDrag(final MouseEvent evt, final BehaviorInfo info) {
00232         int mode = TIMER_MODE_OFF;
00233         timerMode_ = TIMER_MODE_OFF;
00234 
00235         if (!evt.isAltDown() && !evt.isMetaDown()) {
00236             if (operationHandler_ != null) {
00237                 syncExec(new Runnable(){
00238                         public void run(){
00239                                 operationHandler_.processStartDrag(evt, info);
00240                         }
00241                 });
00242                 mode = TIMER_MODE_OPERATION;
00243             }
00244         }
00245 
00246         if (!evt.isConsumed()) {
00247             viewHandler_.processStartDrag(evt, info);
00248             mode = TIMER_MODE_VIEW;
00249         }
00250 
00251         if (info.isTimerEnabled()) {
00252             timerMode_ = mode;
00253         }
00254     }
00255 
00256     public void processDragOperation(final MouseEvent evt, final BehaviorInfo info) {
00257         if (!evt.isAltDown() && !evt.isMetaDown()) {
00258             if (operationHandler_ != null) {
00259                 syncExec(new Runnable(){
00260                         public void run(){
00261                                 operationHandler_.processDragOperation(evt, info);
00262                         }
00263                 });
00264             }
00265         }
00266 
00267         if (!evt.isConsumed()) {
00268             viewHandler_.processDragOperation(evt, info);
00269         }
00270     }
00271 
00272     public void processReleased(final MouseEvent evt, final BehaviorInfo info) {
00273         if (!evt.isAltDown() && !evt.isMetaDown()) {
00274             if (operationHandler_ != null) {
00275                 syncExec(new Runnable(){
00276                         public void run(){
00277                                 operationHandler_.processReleased(evt, info);
00278                         }
00279                 });
00280             }
00281         }
00282 
00283         if (!evt.isConsumed()) {
00284             viewHandler_.processReleased(evt, info);
00285             indicator_.processReleased(evt, info);
00286         }
00287     }
00288 
00289     public boolean processTimerOperation(final BehaviorInfo info) {
00290         switch (timerMode_) {
00291         case TIMER_MODE_OFF:
00292             break;
00293         case TIMER_MODE_OPERATION:
00294                 if(operationHandler_ instanceof InvKinemaHandler)
00295             if(!bManager_.initDynamicsSimulator())      
00296                 return false;
00297                 syncExec(new Runnable(){
00298                 public void run(){
00299                         operationHandler_.processTimerOperation(info);
00300                 }
00301             });
00302             break;
00303         case TIMER_MODE_VIEW:
00304             viewHandler_.processTimerOperation(info);
00305             break;
00306         }
00307         return true;
00308     }
00309     
00310     private boolean syncExec(Runnable r){
00311                 Display display = Display.getDefault();
00312         if ( display!=null && !display.isDisposed()){
00313             display.syncExec( r );
00314             return true;
00315         }else
00316                 return false;
00317         }
00318 }


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:17