17 package com.generalrobotix.ui.view.tdview;
19 import java.util.Iterator;
20 import java.util.List;
22 import java.util.Vector;
24 import javax.media.j3d.BranchGroup;
25 import javax.media.j3d.Transform3D;
26 import javax.media.j3d.TransformGroup;
28 import org.eclipse.jface.dialogs.MessageDialog;
29 import org.eclipse.swt.widgets.Display;
50 import com.sun.j3d.utils.picking.PickCanvas;
51 import com.sun.j3d.utils.picking.PickTool;
78 DynamicsSimulator currentDynamics_;
106 PickCanvas pickCanvas =
new PickCanvas(
110 pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
112 handler_ =
new IseBehaviorHandler(
this);
114 behavior_ =
new IseBehavior(handler_);
116 BranchGroup bg =
new BranchGroup();
117 bg.addChild(behavior_);
138 info_ =
new BehaviorInfo(manager_, pickCanvas, drawable_);
140 behavior_.setBehaviorInfo(info_);
144 indicator_ = handler;
149 handler_.setViewMode(viewMode_);
153 operationMode_ = mode;
154 handler_.setOperationMode(operationMode_);
158 handler_.setViewHandlerMode(str);
162 return handler_.fit(info_);
166 BehaviorInfo
info = behavior_.getBehaviorInfo();
167 handler_.setPickTarget(tg, info);
173 Transform3D transform =
new Transform3D();
174 evt.getTransformGroup().getTransform(transform);
197 if (handler_ !=
null)
198 handler_.setViewIndicator(indicator_);
208 if (update && currentDynamics_ !=
null) {
210 currentDynamics_.destroy();
211 }
catch (Exception e) {
214 currentDynamics_ =
null;
217 if (currentDynamics_ ==
null) {
219 org.omg.CORBA.Object
obj =
221 DynamicsSimulatorFactory ifactory = DynamicsSimulatorFactoryHelper
223 currentDynamics_ = ifactory.create();
224 currentDynamics_._non_existent();
227 }
catch (Exception e) {
229 currentDynamics_ =
null;
232 return currentDynamics_;
247 boolean ModelModified =
false;
248 Iterator<GrxModelItem> itr = currentModels_.iterator();
249 while(itr.hasNext()){
252 ModelModified =
true;
255 Display display = Display.getDefault();
256 display.syncExec(
new Runnable(){
258 MessageDialog.openInformation(
null,
"",
MessageBundle.
get(
"BehaviorManager.dialog.message.reloadModel")+name+
") ");
263 if(ModelModified)
return false;
265 if(!itemChangeFlag_)
return true;
270 for (
int i=0;
i<currentModels_.size();
i++) {
273 if(bodyInfo==
null)
return false;
274 currentDynamics_.registerCharacter(model.
getName(), bodyInfo);
277 IntegrateMethod m = IntegrateMethod.EULER;
278 currentDynamics_.init(0.005, m, SensorOption.ENABLE_SENSOR);
279 currentDynamics_.setGVector(
new double[] { 0.0, 0.0, 9.8});
282 for (
int i=0;
i<currentModels_.size();
i++) {
288 currentDynamics_.setCharacterLinkData(
292 currentDynamics_.setCharacterAllLinkData(
293 model.
getName(), LinkDataType.JOINT_VALUE,
299 for (
int i=0;
i<currentCollisionPairs_.size();
i++) {
303 if (m1 ==
null || m2 ==
null)
continue;
304 Vector<GrxLinkItem> links1, links2;
305 String lname1 = item.
getStr(
"jointName1",
"");
306 if (lname1.equals(
"")){
309 links1 =
new Vector<GrxLinkItem>();
311 if (l !=
null) links1.add(l);
313 String lname2 = item.
getStr(
"jointName2",
"");
314 if (lname2.equals(
"")){
317 links2 =
new Vector<GrxLinkItem>();
319 if (l !=
null) links2.add(l);
321 for (
int j=0;
j<links1.size();
j++){
322 for (
int k=0; k<links2.size(); k++){
323 currentDynamics_.registerIntersectionCheckPair(
324 m1.
getName(), links1.get(
j).getName(),
325 m2.
getName(), links2.get(k).getName(),
326 links1.get(
j).getDbl(
"tolerance",0.0)+links2.get(k).getDbl(
"tolerance",0.0));
331 }
catch (Exception e) {
336 handler_.setInvKinemaResolver(resolver_);
337 itemChangeFlag_ =
false;
342 behavior_.addClickListener( listener );
345 behavior_.removeClickListener( listener );
349 if(currentCollisionPairs_.isEmpty() || currentModels_.isEmpty())
return false;
351 if (currentDynamics_ ==
null)
return false;
352 for (
int i=0;
i<currentModels_.size();
i++) {
357 currentDynamics_.setCharacterLinkData(name, base.
getName(), LinkDataType.ABS_TRANSFORM,
data);
359 currentDynamics_.setCharacterAllLinkData(name, LinkDataType.JOINT_VALUE, data);
374 if (currentDynamics_.checkCollision(
true)){
375 WorldStateHolder wsH =
new WorldStateHolder();
376 currentDynamics_.getWorldState(wsH);
377 return wsH.value.collisions;
393 return currentDynamics_.checkDistance();
406 return currentDynamics_.checkIntersection(
true);
409 public void setItem(List<GrxModelItem> models, List<GrxCollisionPairItem> cols){
410 currentModels_ = models;
411 currentCollisionPairs_ = cols;
412 itemChangeFlag_ =
true;
417 currentDynamics_.destroy();
418 }
catch (Exception e) {
421 currentDynamics_ =
null;
429 itemChangeFlag_ =
true;
void replaceWorld(List< GrxBaseItem > list)
static final String get(String key)
void setOperationMode(int mode)
static final int VIEW_MODE_PARALLEL
static final int VIEW_MODE_WALK
Distance[] getDistance()
get distance information
static final int VIEW_MODE_ROOM
static final int INV_KINEMA_FROM_MODE
boolean setCharacterData()
#define null
our own NULL pointer
void setMessageSkip(boolean flg)
GrxPluginManager manager_
InvKinemaResolver resolver_
BodyInfo getBodyInfo()
get BodyInfo
GrxLinkItem getLink(String name)
get link from name
png_infop png_charpp name
item corresponds to a robot model
static final int OPERATION_MODE_NONE
static final int FITTING_TO_MODE
void setPickTarget(TransformGroup tg)
static final int OBJECT_ROTATION_MODE
List< GrxCollisionPairItem > currentCollisionPairs_
void setViewMode(int mode)
IseBehaviorHandler handler_
static void printErr(String s)
double[] getTransformArray(GrxLinkItem link)
get transform of link in array form
static final int ROOM_VIEW_MODE
void viewChanged(ViewChangeEvent evt)
void setThreeDViewer(Grx3DView viewer)
LinkPair[] getIntersection()
get intersection information
BranchGroup getBranchGroupRoot()
static final int INV_KINEMA_ROTATION_MODE
GrxLinkItem rootLink()
get root link
static final int JOINT_ROTATION_MODE
Vector< GrxLinkItem > links_
boolean initDynamicsSimulator()
initialize dynamics server
def j(str, encoding="cp932")
BehaviorManager(GrxPluginManager manager)
void setViewHandlerMode(String str)
BehaviorHandler indicator_
static final int WALK_VIEW_MODE
void removeClickListener(Grx3DViewClickListener listener)
List< GrxModelItem > currentModels_
void setTransform(Transform3D transform)
Map<?,?> getItemMap(Class<?extends GrxBaseItem > cls)
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
final String getStr(String key)
get value associated to keyword
static final int INV_KINEMA_TRANSLATION_MODE
void setViewIndicator(BehaviorHandler handler)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
DynamicsSimulator getDynamicsSimulator(boolean update)
create dynamics server
double[] getJointValues()
final String getName()
get name
void setItem(List< GrxModelItem > models, List< GrxCollisionPairItem > cols)
void destroyDynamicsSimulator()
static final int OBJECT_TRANSLATION_MODE
static final int PARALLEL_VIEW_MODE
Collision[] getCollision()
get collision information
static final int FITTING_FROM_MODE
void addClickListener(Grx3DViewClickListener listener)
void setDynamicsSimulator(DynamicsSimulator integrator)