IseBehaviorHandler.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  */
17 package com.generalrobotix.ui.view.tdview;
18 
19 import java.awt.event.*;
20 import javax.media.j3d.TransformGroup;
21 
22 import org.eclipse.swt.widgets.Display;
23 
29 class IseBehaviorHandler implements BehaviorHandler {
30  //--------------------------------------------------------------------
31  // 定数
32 
33  // OperationHandlerの具象クラスのインスタンス
34  private static final ObjectRotationHandler
35  OBJECT_ROTATION_HANDLER = new ObjectRotationHandler();
36  private static final ObjectTranslationHandler
37  OBJECT_TRANSLATION_HANDLER = new ObjectTranslationHandler();
38  private static final JointRotationHandler
39  JOINT_ROTATION_HANDLER = new JointRotationHandler();
40  private static final ObjectFittingHandler
41  OBJECT_FITTING_HANDLER = new ObjectFittingHandler();
42  private static final InvKinemaHandler
43  INV_KINEMA_HANDLER = new InvKinemaHandler();
44 
45  // ViewHandlerの具象クラスのインスタンス
46  private static final WalkViewHandler
47  WALK_VIEW_HANDLER = new WalkViewHandler();
48  private static final RoomViewHandler
49  ROOM_VIEW_HANDLER = new RoomViewHandler();
50 
51  public static final String
52  BUTTON_MODE_ROTATION = "button_mode_rotation";
53  public static final String
54  BUTTON_MODE_TRANSLATION = "button_mode_translation";
55  public static final String BUTTON_MODE_ZOOM = "button_mode_zoom";
56  public static final String CTRL_PRESSED = "ctrl_pressed";
57  public static final String ALT_PRESSED = "alt_pressed";
58 
59  private static final int TIMER_MODE_OFF = 0;
60  private static final int TIMER_MODE_OPERATION = 1;
61  private static final int TIMER_MODE_VIEW = 2;
62 
63  //--------------------------------------------------------------------
64  // インスタンス変数
65  private ViewHandler viewHandler_;
66  private OperationHandler operationHandler_;
67  private BehaviorHandler indicator_;
68  private int timerMode_;
69  private BehaviorManager bManager_;
70 
71  //--------------------------------------------------------------------
72  // コンストラクタ
73  public IseBehaviorHandler(BehaviorManager bManager) {
74  viewHandler_ = ROOM_VIEW_HANDLER;
75  ROOM_VIEW_HANDLER.setParallelMode(false);
76  bManager_ = bManager;
77  }
78 
79  //--------------------------------------------------------------------
80  // 公開メソッド
81  public void setViewIndicator(BehaviorHandler handler) {
82  indicator_ = handler;
83  }
84 
85  public void setViewMode(int mode) {
86  switch (mode) {
87  case BehaviorManager.WALK_VIEW_MODE:
88  viewHandler_ = WALK_VIEW_HANDLER;
89  break;
90  case BehaviorManager.ROOM_VIEW_MODE:
91  viewHandler_ = ROOM_VIEW_HANDLER;
92  ROOM_VIEW_HANDLER.setParallelMode(false);
93  break;
94  case BehaviorManager.PARALLEL_VIEW_MODE:
95  viewHandler_ = ROOM_VIEW_HANDLER;
96  ROOM_VIEW_HANDLER.setParallelMode(true);
97  break;
98  }
99  }
100 
101  public void setViewHandlerMode(String str) {
102  WALK_VIEW_HANDLER.setMode(str);
103  ROOM_VIEW_HANDLER.setMode(str);
104  }
105 
106  public void setOperationMode(int mode) {
107  switch (mode) {
108  case BehaviorManager.OPERATION_MODE_NONE:
109  if (operationHandler_ != null) {
110  operationHandler_.disableHandler();
111  }
112  operationHandler_ = null;
113  break;
114  case BehaviorManager.OBJECT_ROTATION_MODE:
115  if (operationHandler_ != null) {
116  operationHandler_.disableHandler();
117  }
118  operationHandler_ = OBJECT_ROTATION_HANDLER;
119  break;
120  case BehaviorManager.OBJECT_TRANSLATION_MODE:
121  if (operationHandler_ != null) {
122  operationHandler_.disableHandler();
123  }
124  operationHandler_ = OBJECT_TRANSLATION_HANDLER;
125  break;
126  case BehaviorManager.JOINT_ROTATION_MODE:
127  if (operationHandler_ != null) {
128  operationHandler_.disableHandler();
129  }
130  operationHandler_ = JOINT_ROTATION_HANDLER;
131  break;
132  case BehaviorManager.FITTING_FROM_MODE:
133  if (operationHandler_ != null &&
134  operationHandler_ != OBJECT_FITTING_HANDLER
135  ) {
136  operationHandler_.disableHandler();
137  }
138  operationHandler_ = OBJECT_FITTING_HANDLER;
139  OBJECT_FITTING_HANDLER.setFittingMode(
140  ObjectFittingHandler.FITTING_FROM
141  );
142  break;
143  case BehaviorManager.FITTING_TO_MODE:
144  if (operationHandler_ != null &&
145  operationHandler_ != OBJECT_FITTING_HANDLER
146  ) {
147  operationHandler_.disableHandler();
148  }
149  operationHandler_ = OBJECT_FITTING_HANDLER;
150  OBJECT_FITTING_HANDLER.setFittingMode(
151  ObjectFittingHandler.FITTING_TO
152  );
153  break;
154  case BehaviorManager.INV_KINEMA_FROM_MODE:
155  if (operationHandler_ != null &&
156  operationHandler_ != INV_KINEMA_HANDLER
157  ) {
158  operationHandler_.disableHandler();
159  }
160  operationHandler_ = INV_KINEMA_HANDLER;
161  INV_KINEMA_HANDLER.setInvKinemaMode(InvKinemaHandler.FROM_MODE);
162  break;
163  case BehaviorManager.INV_KINEMA_TRANSLATION_MODE:
164  if (operationHandler_ != null &&
165  operationHandler_ != INV_KINEMA_HANDLER
166  ) {
167  operationHandler_.disableHandler();
168  }
169  operationHandler_ = INV_KINEMA_HANDLER;
170  INV_KINEMA_HANDLER.setInvKinemaMode(
171  InvKinemaHandler.TRANSLATION_MODE
172  );
173  break;
174  case BehaviorManager.INV_KINEMA_ROTATION_MODE:
175  if (operationHandler_ != null &&
176  operationHandler_ != INV_KINEMA_HANDLER
177  ) {
178  operationHandler_.disableHandler();
179  }
180  operationHandler_ = INV_KINEMA_HANDLER;
181  INV_KINEMA_HANDLER.setInvKinemaMode(
182  InvKinemaHandler.ROTATION_MODE
183  );
184  break;
185  }
186  }
187 
188  public void setInvKinemaResolver(InvKinemaResolver resolver) {
189  INV_KINEMA_HANDLER.setInvKinemaResolver(resolver);
190  }
191 
192  private boolean ret_;
193  public boolean fit(final BehaviorInfo info) {
194  if (operationHandler_ == OBJECT_FITTING_HANDLER) {
195  syncExec(new Runnable(){
196  public void run(){
197  ret_ = OBJECT_FITTING_HANDLER.fit(info);
198  }
199  });
200  return ret_;
201  } else {
202  return false;
203  }
204  }
205 
206  public void setPickTarget(TransformGroup tg, BehaviorInfo info) {
207  if (operationHandler_ != null) {
208  operationHandler_.setPickTarget(tg, info);
209  }
210  }
211 
212  //--------------------------------------------------------------------
213  // BehaviorHandlerの実装
214  public void processPicking(final MouseEvent evt, final BehaviorInfo info) {
215  if (!evt.isAltDown() && !evt.isMetaDown()) {
216  if (operationHandler_ != null) {
217  syncExec(new Runnable(){
218  public void run(){
219  operationHandler_.processPicking(evt, info);
220  }
221  });
222  }
223  }
224 
225  if (!evt.isConsumed()) {
226  viewHandler_.processPicking(evt, info);
227  indicator_.processPicking(evt, info);
228  }
229  }
230 
231  public void processStartDrag(final MouseEvent evt, final BehaviorInfo info) {
232  int mode = TIMER_MODE_OFF;
233  timerMode_ = TIMER_MODE_OFF;
234 
235  if (!evt.isAltDown() && !evt.isMetaDown()) {
236  if (operationHandler_ != null) {
237  syncExec(new Runnable(){
238  public void run(){
239  operationHandler_.processStartDrag(evt, info);
240  }
241  });
242  mode = TIMER_MODE_OPERATION;
243  }
244  }
245 
246  if (!evt.isConsumed()) {
247  viewHandler_.processStartDrag(evt, info);
248  mode = TIMER_MODE_VIEW;
249  }
250 
251  if (info.isTimerEnabled()) {
252  timerMode_ = mode;
253  }
254  }
255 
256  public void processDragOperation(final MouseEvent evt, final BehaviorInfo info) {
257  if (!evt.isAltDown() && !evt.isMetaDown()) {
258  if (operationHandler_ != null) {
259  syncExec(new Runnable(){
260  public void run(){
261  operationHandler_.processDragOperation(evt, info);
262  }
263  });
264  }
265  }
266 
267  if (!evt.isConsumed()) {
268  viewHandler_.processDragOperation(evt, info);
269  }
270  }
271 
272  public void processReleased(final MouseEvent evt, final BehaviorInfo info) {
273  if (!evt.isAltDown() && !evt.isMetaDown()) {
274  if (operationHandler_ != null) {
275  syncExec(new Runnable(){
276  public void run(){
277  operationHandler_.processReleased(evt, info);
278  }
279  });
280  }
281  }
282 
283  if (!evt.isConsumed()) {
284  viewHandler_.processReleased(evt, info);
285  indicator_.processReleased(evt, info);
286  }
287  }
288 
289  public boolean processTimerOperation(final BehaviorInfo info) {
290  switch (timerMode_) {
291  case TIMER_MODE_OFF:
292  break;
293  case TIMER_MODE_OPERATION:
294  if(operationHandler_ instanceof InvKinemaHandler)
295  if(!bManager_.initDynamicsSimulator())
296  return false;
297  syncExec(new Runnable(){
298  public void run(){
299  operationHandler_.processTimerOperation(info);
300  }
301  });
302  break;
303  case TIMER_MODE_VIEW:
304  viewHandler_.processTimerOperation(info);
305  break;
306  }
307  return true;
308  }
309 
310  private boolean syncExec(Runnable r){
311  Display display = Display.getDefault();
312  if ( display!=null && !display.isDisposed()){
313  display.syncExec( r );
314  return true;
315  }else
316  return false;
317  }
318 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
void processReleased(MouseEvent evt, BehaviorInfo info)
void processStartDrag(MouseEvent evt, BehaviorInfo info)
void processDragOperation(MouseEvent evt, BehaviorInfo info)
void processPicking(MouseEvent evt, BehaviorInfo info)
def run(tree, args)
backing_store_ptr info
Definition: jmemsys.h:181
boolean processTimerOperation(BehaviorInfo info)
org


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38