$search
00001 package edu.tum.cs.ias.knowrob.map; 00002 00003 import java.awt.event.KeyEvent; 00004 import java.util.ArrayList; 00005 import java.util.HashMap; 00006 00007 import javax.vecmath.Matrix4d; 00008 import javax.vecmath.Quat4d; 00009 import javax.vecmath.Vector3d; 00010 00011 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; 00012 import org.semanticweb.owlapi.model.*; 00013 00014 import controlP5.Button; 00015 import controlP5.ControlP5; 00016 import controlP5.ListBox; 00017 import controlP5.ListBoxItem; 00018 import controlP5.Textfield; 00019 import controlP5.Textlabel; 00020 import de.tum.in.fipm.kipm.gui.visualisation.applets.StandaloneKitchenVisApplet; 00021 import de.tum.in.fipm.kipm.gui.visualisation.base.PrologVisualizationCanvas; 00022 import de.tum.in.fipm.kipm.gui.visualisation.items.*; 00023 import edu.tum.cs.ias.knowrob.utils.owl.MapObject; 00024 import edu.tum.cs.ias.knowrob.utils.owl.MapJoint; 00025 import edu.tum.cs.ias.knowrob.utils.owl.OWLImportExport; 00026 import edu.tum.cs.ias.knowrob.utils.owl.OWLFileUtils; 00027 import processing.core.PApplet; 00028 import ros.NodeHandle; 00029 import ros.Ros; 00030 00031 00032 00043 public class SemanticMapEditorForms extends PApplet { 00044 00045 private static final long serialVersionUID = -4266603809510554926L; 00046 00048 // visualization and user interface stuff 00049 00050 private PrologVisualizationCanvas prologVisCanvas = null; 00051 public ControlP5 controlP5; 00052 boolean[] keys = new boolean[526]; 00053 boolean selectParentObj = false; // switch mode from normal obj selection to parent obj selection 00054 boolean selectChildObj = false; // switch mode from normal obj selection to child obj selection 00055 00056 private int[] grayValues = new int[] {160,190,210,170,220,180,200,165,185,205,175,195,215}; 00057 private static int grayLevelCounter = 0; 00058 00059 00060 // form elements 00061 Textfield t_id; 00062 ListBox t_types; 00063 00064 Textfield[] t_dim; 00065 Textfield[] t_matrix; 00066 Textfield[] t_quat; 00067 Textfield[] t_pos; 00068 Textfield[] t_qpos; 00069 Textfield[] t_jointdir; 00070 Textfield[] t_jointlim; 00071 Textfield t_filename; 00072 Textfield t_namespace; 00073 Textfield t_parent; 00074 Textfield t_radius; 00075 Textlabel l_jointdir; 00076 Textlabel l_jointlim; 00077 Textlabel l_radius; 00078 Textlabel l_dim; 00079 Button[] b_rot; 00080 Button b_child; 00081 Button b_new_obj; 00082 Button b_del_obj; 00083 Button b_update; 00084 Textfield t_child; 00085 ArrayList<Textfield> t_all_simple; // for using the tab key 00086 ArrayList<Textfield> t_all_matrix; // for using the tab key 00087 ArrayList<Textfield> t_all_quat; // for using the tab key 00088 ArrayList<Textfield> t_all_joint; // for using the tab key 00089 00090 public enum Tab {SIMPLE, MATRIX, QUATERNION, JOINTS, SETTINGS}; 00091 Tab tab; 00092 static Ros ros; 00093 static NodeHandle n; 00094 00096 00097 00098 00102 HashMap<String, MapObject> objects; 00103 00107 protected static final HashMap<Integer, String> objClasses = new HashMap<Integer, String>(); 00108 static { 00109 objClasses.put(1022, "Cupboard"); 00110 objClasses.put(1023, "Dishwasher"); 00111 objClasses.put(1024, "Drawer"); 00112 objClasses.put(1025, "Oven"); 00113 objClasses.put(1026, "Refrigerator"); 00114 objClasses.put(1027, "Door"); 00115 objClasses.put(1028, "Handle"); 00116 objClasses.put(1029, "ControlKnob"); 00117 objClasses.put(1030, "Cabinet-PieceOfFurniture"); 00118 objClasses.put(1031, "Bed-PieceOfFurniture"); 00119 objClasses.put(1032, "HingedJoint"); 00120 objClasses.put(1033, "PrismaticJoint"); 00121 objClasses.put(1034, "WallOfAConstruction"); 00122 00123 } 00124 00125 00129 public void setup() { 00130 00131 size(320, 600, P2D); 00132 lights(); 00133 objects = new HashMap<String, MapObject>(); 00134 tab=Tab.SIMPLE; 00135 00136 initControlP5Forms(); 00137 initRos("semantic_map_editor"); 00138 00139 draw(); 00140 prologVisCanvas.setSize(1050, 600); 00141 prologVisCanvas.validate(); 00142 00143 // dialog for selecting the input file 00144 String filename = selectInput(); 00145 if (filename != null) { 00146 this.objects = OWLImportExport.readMapObjectFromOWL(filename); 00147 } 00148 updateVisualization(); 00149 } 00150 00151 00155 public void draw() { 00156 00157 background(20, 20, 20); 00158 controlP5.draw(); 00159 00160 } 00161 00162 00166 protected static void initRos(String node_name) { 00167 00168 ros = Ros.getInstance(); 00169 00170 if(!Ros.getInstance().isInitialized()) { 00171 ros.init(node_name); 00172 } 00173 n = ros.createNodeHandle(); 00174 00175 } 00176 00177 00179 // 00180 // 00181 // INITIALIZE FORMS 00182 // 00183 // 00185 00186 00190 private void initControlP5Forms() { 00191 00192 // location definitions: 00193 00194 int OBJ_ID_X=10; 00195 int OBJ_ID_Y=25; 00196 00197 int OBJ_DIM_X=10; 00198 int OBJ_DIM_Y=200; 00199 00200 int TAB_X=10; 00201 int TAB_Y=300; 00202 00203 int UPDATE_X = 10; 00204 int UPDATE_Y = 500; 00205 00206 // for using the tab key 00207 t_all_simple = new ArrayList<Textfield>(); 00208 t_all_matrix = new ArrayList<Textfield>(); 00209 t_all_quat = new ArrayList<Textfield>(); 00210 t_all_joint = new ArrayList<Textfield>(); 00211 00212 00213 00214 controlP5 = new ControlP5(this); 00215 00216 controlP5.tab("default").setId(0); 00217 controlP5.tab("default").setLabel("simple"); 00218 controlP5.tab("default").activateEvent(true); 00219 00220 controlP5.tab("matrix").setId(1); 00221 controlP5.tab("matrix").activateEvent(true); 00222 00223 controlP5.tab("quaternion").setId(2); 00224 controlP5.tab("quaternion").activateEvent(true); 00225 00226 controlP5.tab("joint properties").setId(3); 00227 controlP5.tab("joint properties").activateEvent(true); 00228 00229 controlP5.tab("settings").setId(4); 00230 controlP5.tab("settings").activateEvent(true); 00231 00232 00233 // text field for object name 00234 t_id = controlP5.addTextfield("object id", OBJ_ID_X, OBJ_ID_Y, 200, 20); 00235 t_id.moveTo("global"); 00236 t_all_simple.add(t_id); t_all_matrix.add(t_id); t_all_quat.add(t_id); 00237 t_id.setAutoClear(false); 00238 00239 00240 b_new_obj = controlP5.addButton("new", 17, OBJ_ID_X, OBJ_ID_Y+40, 24, 20); 00241 b_new_obj.moveTo("global"); 00242 00243 b_del_obj = controlP5.addButton("delete", 18, OBJ_ID_X + 30, OBJ_ID_Y+40, 34, 20); 00244 b_del_obj.moveTo("global"); 00245 00246 b_update = controlP5.addButton("add to map", 23, OBJ_ID_X+70, OBJ_ID_Y+40, 55, 20); 00247 b_update.setId(23); 00248 b_update.moveTo("global"); 00249 00250 00251 t_types = controlP5.addListBox("object class", OBJ_ID_X, OBJ_ID_Y+100,200,60); 00252 t_types.setId(42); 00253 t_types.setItemHeight(15); 00254 t_types.setBarHeight(15); 00255 t_types.captionLabel().style().marginTop = 3; 00256 t_types.valueLabel().style().marginTop = 3; 00257 t_types.captionLabel().style().marginBottom = 3; 00258 t_types.valueLabel().style().marginBottom = 3; 00259 t_types.setColorBackground(color(255,128)); 00260 t_types.moveTo("global"); 00261 00262 ListBoxItem b; 00263 for(int i: objClasses.keySet()) { 00264 b = t_types.addItem(objClasses.get(i),i); 00265 b.setId(i); 00266 } 00267 00268 // object dimensions 00269 l_dim = controlP5.addTextlabel("l_dim","OBJECT DIMENSIONS",OBJ_DIM_X,OBJ_DIM_Y); 00270 l_dim.setWidth(200); 00271 l_dim.moveTo("global"); 00272 00273 t_dim = new Textfield[3]; 00274 t_dim[0] = controlP5.addTextfield("x_dim",OBJ_DIM_X, OBJ_DIM_Y+15, 40,20); 00275 t_dim[1] = controlP5.addTextfield("y_dim",OBJ_DIM_X+50, OBJ_DIM_Y+15,40,20); 00276 t_dim[2] = controlP5.addTextfield("z_dim",OBJ_DIM_X+100, OBJ_DIM_Y+15,40,20); 00277 00278 for(Textfield t : t_dim) { 00279 t.moveTo("global"); 00280 t.setAutoClear(false); 00281 t_all_simple.add(t); 00282 t_all_matrix.add(t); 00283 t_all_quat.add(t); 00284 } 00285 b_rot = new Button[3]; 00286 b_rot[0] = controlP5.addButton("rot_x", 20, OBJ_DIM_X, OBJ_DIM_Y+55, 32, 20); 00287 b_rot[0].setId(20); 00288 b_rot[0].moveTo("global"); 00289 00290 b_rot[1] = controlP5.addButton("rot_y", 21, OBJ_DIM_X+50, OBJ_DIM_Y+55, 32, 20); 00291 b_rot[1].setId(21); 00292 b_rot[1].moveTo("global"); 00293 00294 b_rot[2] = controlP5.addButton("rot_z", 22, OBJ_DIM_X+100, OBJ_DIM_Y+55, 32, 20); 00295 b_rot[2].setId(22); 00296 b_rot[2].moveTo("global"); 00297 00298 00299 00300 00301 00302 Button parent = controlP5.addButton("select parent", 24, UPDATE_X, UPDATE_Y, 72, 20); 00303 parent.moveTo("global"); 00304 00305 t_parent = controlP5.addTextfield("parent", UPDATE_X+85, UPDATE_Y, 130, 20); 00306 t_parent.moveTo("global"); 00307 00308 00309 Button export = controlP5.addButton("export to owl", 25, UPDATE_X, UPDATE_Y+40, 72, 20); 00310 export.moveTo("global"); 00311 00312 t_filename = controlP5.addTextfield("filename", UPDATE_X+85, UPDATE_Y+40, 130, 20); 00313 t_filename.moveTo("global"); 00314 00315 00317 // TABS 00318 00319 // simple position tab 00320 Textlabel l_pos = controlP5.addTextlabel("l_pos","OBJECT POSITION",TAB_X,TAB_Y); 00321 l_pos.setWidth(200); 00322 00323 t_pos = new Textfield[3]; 00324 t_pos[0] = controlP5.addTextfield("x_pos",TAB_X, TAB_Y+15, 40, 20); 00325 t_pos[1] = controlP5.addTextfield("y_pos",TAB_X+50, TAB_Y+15, 40, 20); 00326 t_pos[2] = controlP5.addTextfield("z_pos",TAB_X+100,TAB_Y+15, 40, 20); 00327 00328 for(Textfield t : t_pos) { // for using the tab key 00329 t.setAutoClear(false); 00330 t_all_simple.add(t); 00331 } 00332 00333 00334 // pose matrix tab 00335 Textlabel l_matrix = controlP5.addTextlabel("l_matrix","POSE MATRIX ",TAB_X,TAB_Y); 00336 l_matrix.setWidth(200); 00337 l_matrix.moveTo("matrix"); 00338 00339 t_matrix = new Textfield[16]; 00340 for(int i=0;i<4;i++) { 00341 for(int j=0;j<4;j++) { 00342 00343 t_matrix[i*4+j] = controlP5.addTextfield("m"+i+j, TAB_X+j*50, TAB_Y+15 + 40*i, 40, 20); 00344 t_matrix[i*4+j].moveTo("matrix"); 00345 //t_matrix[i*4+j].setColorBackground(color(255,60)); 00346 t_all_matrix.add(t_matrix[i*4+j]); 00347 } 00348 } 00349 00350 00351 // quaternion pose tab 00352 Textlabel l_quat = controlP5.addTextlabel("l_qpos","POSE QUATERNION",TAB_X,TAB_Y); 00353 l_quat.setWidth(200); 00354 l_quat.moveTo("quaternion"); 00355 00356 t_qpos = new Textfield[3]; 00357 t_qpos[0] = controlP5.addTextfield("x_qpos",TAB_X, TAB_Y+15, 40,20); 00358 t_qpos[0].setLabel("x_pos"); 00359 t_qpos[1] = controlP5.addTextfield("y_qpos",TAB_X+50, TAB_Y+15, 40,20); 00360 t_qpos[1].setLabel("y_pos"); 00361 t_qpos[2] = controlP5.addTextfield("z_qpos",TAB_X+100,TAB_Y+15, 40,20); 00362 t_qpos[2].setLabel("z_pos"); 00363 00364 for(Textfield t : t_qpos) { // for using the tab key 00365 t.moveTo("quaternion"); 00366 t.setAutoClear(false); 00367 t_all_quat.add(t); 00368 } 00369 00370 t_quat = new Textfield[4]; 00371 t_quat[0] = controlP5.addTextfield("w",TAB_X, TAB_Y+55, 40,20); 00372 t_quat[1] = controlP5.addTextfield("x",TAB_X+50, TAB_Y+55,40,20); 00373 t_quat[2] = controlP5.addTextfield("y",TAB_X+100, TAB_Y+55,40,20); 00374 t_quat[3] = controlP5.addTextfield("z",TAB_X+150, TAB_Y+55,40,20); 00375 00376 for(Textfield t : t_quat) { // for using the tab key 00377 t.moveTo("quaternion"); 00378 t.setAutoClear(false); 00379 t_all_quat.add(t); 00380 } 00381 00382 00383 // joint properties tab 00384 l_jointdir = controlP5.addTextlabel("l_joint","DIRECTION (PRISMATIC ONLY)",TAB_X,TAB_Y); 00385 l_jointdir.setWidth(200); 00386 l_jointdir.moveTo("joint properties"); 00387 00388 t_jointdir = new Textfield[3]; 00389 t_jointdir[0] = controlP5.addTextfield("dir_x",TAB_X, TAB_Y+15, 40,20); 00390 t_jointdir[0].setLabel("dir_x"); 00391 t_jointdir[1] = controlP5.addTextfield("dir_y",TAB_X+50, TAB_Y+15, 40,20); 00392 t_jointdir[1].setLabel("dir_y"); 00393 t_jointdir[2] = controlP5.addTextfield("dir_z",TAB_X+100,TAB_Y+15, 40,20); 00394 t_jointdir[2].setLabel("dir_z"); 00395 00396 for(Textfield t : t_jointdir) { // for using the tab key 00397 t.moveTo("joint properties"); 00398 t.setAutoClear(false); 00399 t_all_joint.add(t); 00400 } 00401 00402 00403 l_jointlim = controlP5.addTextlabel("l_jointlim","JOINT LIMITS",TAB_X,TAB_Y+60); 00404 l_jointlim.setWidth(200); 00405 l_jointlim.moveTo("joint properties"); 00406 00407 t_jointlim = new Textfield[2]; 00408 t_jointlim[0] = controlP5.addTextfield("q_min",TAB_X, TAB_Y+75, 40,20); 00409 t_jointlim[0].setLabel("q_min"); 00410 t_jointlim[1] = controlP5.addTextfield("q_max",TAB_X+50, TAB_Y+75, 40,20); 00411 t_jointlim[1].setLabel("q_max"); 00412 00413 for(Textfield t : t_jointlim) { // for using the tab key 00414 t.moveTo("joint properties"); 00415 t.setAutoClear(false); 00416 t_all_joint.add(t); 00417 } 00418 00419 00420 l_radius = controlP5.addTextlabel("l_radius","RADIUS",TAB_X+100,TAB_Y+60); 00421 l_radius.setWidth(200); 00422 l_radius.moveTo("joint properties"); 00423 00424 t_radius = controlP5.addTextfield("radius",TAB_X+100, TAB_Y+75, 40,20); 00425 t_radius.setLabel("radius"); 00426 t_radius.moveTo("joint properties"); 00427 00428 00429 b_child = controlP5.addButton("select child", 26, UPDATE_X, UPDATE_Y-40, 72, 20); 00430 b_child.moveTo("joint properties"); 00431 00432 t_child = controlP5.addTextfield("child", UPDATE_X+85, UPDATE_Y-40, 130, 20); 00433 t_child.moveTo("joint properties"); 00434 00435 00436 00437 // settings tab 00438 Textlabel l_settings = controlP5.addTextlabel("l_namespace","GLOBAL SETTINGS",OBJ_ID_X,OBJ_ID_Y); 00439 l_settings.setWidth(200); 00440 l_settings.moveTo("settings"); 00441 00442 t_namespace = controlP5.addTextfield("OWL NAMESPACE",OBJ_ID_X, OBJ_ID_Y+15, 250, 20); 00443 t_namespace.setText("http://ias.cs.tum.edu/kb/ias_semantic_map.owl#"); 00444 t_namespace.moveTo("settings"); 00445 00446 00447 00448 } 00449 00450 00452 // 00453 // 00454 // HANDLE USER EVENTS 00455 // 00456 // 00458 00463 public void controlEvent(controlP5.ControlEvent theControlEvent) { 00464 00465 00466 System.err.println("in controlEvent"); 00467 if(theControlEvent.isController()) { 00468 00469 // update button 00470 if(theControlEvent.name().equals("add to map")) { 00471 00472 // read information from the forms, create/update objects[] entry 00473 readFormData(); 00474 00475 // create visualization item 00476 updateVisualization(); 00477 00478 } 00479 00480 00481 if(theControlEvent.name().equals("new")) { 00482 00483 clearFormFields(); // new object is implicitly created when a new identifier is used 00484 } 00485 00486 00487 if(theControlEvent.name().equals("delete")) { 00488 00489 if(t_id.getText() != null) { 00490 objects.remove(t_id.getText()); 00491 clearFormFields(); // reset interface 00492 updateVisualization(); 00493 } 00494 } 00495 00496 00497 if(theControlEvent.name().equals("rot_x")) { 00498 MapObject cur = objects.get(t_id.getText()); 00499 cur.pose_matrix.mul(new Matrix4d( 00500 1, 0, 0, 0, 00501 0, 0, -1, 0, 00502 0, 1, 0, 0, 00503 0, 0, 0, 1)); 00504 updateVisualization(); 00505 writeFormData(cur); 00506 } 00507 00508 if(theControlEvent.name().equals("rot_y")) { 00509 MapObject cur = objects.get(t_id.getText()); 00510 cur.pose_matrix.mul(new Matrix4d( 00511 0, 0, 1, 0, 00512 0, 1, 0, 0, 00513 -1, 0, 0, 0, 00514 0, 0, 0, 1)); 00515 updateVisualization(); 00516 writeFormData(cur); 00517 } 00518 00519 if(theControlEvent.name().equals("rot_z")) { 00520 MapObject cur = objects.get(t_id.getText()); 00521 cur.pose_matrix.mul(new Matrix4d( 00522 0,-1, 0, 0, 00523 1, 0, 0, 0, 00524 0, 0, 1, 0, 00525 0, 0, 0, 1)); 00526 updateVisualization(); 00527 writeFormData(cur); 00528 } 00529 00530 00531 if(theControlEvent.name().equals("export to owl")) { 00532 00533 // first get the current form content 00534 readFormData(); 00535 updateVisualization(); 00536 00537 OWLImportExport exp = new OWLImportExport(); 00538 00539 RDFXMLOntologyFormat format = new RDFXMLOntologyFormat(); 00540 format.setPrefix("knowrob:", "http://ias.cs.tum.edu/kb/knowrob.owl#"); 00541 format.setPrefix("owl:", "http://www.w3.org/2002/07/owl#"); 00542 format.setPrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#"); 00543 format.setPrefix("map:", t_namespace.getText()); 00544 00545 OWLOntology ont = exp.createOWLMapDescription(t_namespace.getText(), new ArrayList<MapObject>(this.objects.values())); 00546 00547 OWLFileUtils.saveOntologyToFile(ont, format, t_filename.getText()); 00548 00549 } 00550 00551 if(theControlEvent.name().equals("select parent")) { 00552 00553 selectParentObj=true; 00554 cursor(HAND); 00555 this.prologVisCanvas.getKitchenVisApplet().cursor(HAND); 00556 00557 } 00558 00559 if(theControlEvent.name().equals("select child")) { 00560 00561 selectChildObj=true; 00562 cursor(HAND); 00563 this.prologVisCanvas.getKitchenVisApplet().cursor(HAND); 00564 00565 } 00566 00567 00568 00569 // switch tabs (update information in the tabs) 00570 } else if (theControlEvent.isTab()) { 00571 00572 if(theControlEvent.name().equals("default")) { 00573 this.tab = Tab.SIMPLE; 00574 showObjSpecificElements(); 00575 00576 } else if (theControlEvent.name().equals("matrix")) { 00577 this.tab = Tab.MATRIX; 00578 showObjSpecificElements(); 00579 00580 } else if (theControlEvent.name().equals("quaternion")) { 00581 this.tab = Tab.QUATERNION; 00582 showObjSpecificElements(); 00583 00584 } else if (theControlEvent.name().equals("settings")) { 00585 this.tab = Tab.SETTINGS; 00586 hideObjSpecificElements(); 00587 00588 } else if (theControlEvent.name().equals("joint properties")) { 00589 this.tab = Tab.JOINTS; 00590 showObjSpecificElements(); 00591 00592 // deactivate fields that are not available for the current object type 00593 showJointSpecificFormFields(); 00594 00595 } 00596 00597 00598 } else if (theControlEvent.isGroup()) { 00599 00600 // handle listbox events 00601 if(theControlEvent.group().id()==42) { 00602 t_types.captionLabel().set( objClasses.get( (int) theControlEvent.group().value()) ); 00603 00604 } 00605 } 00606 redraw(); 00607 } 00608 00609 00610 private void hideObjSpecificElements() { 00611 00612 00613 b_new_obj.hide(); 00614 b_del_obj.hide(); 00615 b_update.hide(); 00616 t_id.hide(); 00617 t_types.hide(); 00618 00619 l_dim.hide(); 00620 for(Textfield t : t_dim) 00621 t.hide(); 00622 00623 for(Button b : b_rot) 00624 b.hide(); 00625 00626 } 00627 00628 private void showObjSpecificElements() { 00629 00630 b_new_obj.show(); 00631 b_del_obj.show(); 00632 b_update.show(); 00633 t_id.show(); 00634 t_types.show(); 00635 00636 l_dim.show(); 00637 for(Textfield t : t_dim) 00638 t.show(); 00639 00640 for(Button b : b_rot) 00641 b.show(); 00642 } 00643 00644 00645 private void showJointSpecificFormFields() { 00646 // draw joint limits and child selection for all kinds of joints 00647 if(t_types.captionLabel().getText().equals("PrismaticJoint") || 00648 t_types.captionLabel().getText().equals("HingedJoint")) { 00649 l_jointlim.show(); 00650 for(Textfield t : t_jointlim) { 00651 t.show(); 00652 } 00653 t_child.show(); 00654 b_child.show(); 00655 } else { 00656 l_jointlim.hide(); 00657 for(Textfield t : t_jointlim) { 00658 t.hide(); 00659 } 00660 t_child.hide(); 00661 b_child.hide(); 00662 } 00663 00664 // draw direction fields only for prismatic joints 00665 if(t_types.captionLabel().getText().equals("PrismaticJoint")) { 00666 l_jointdir.show(); 00667 for(Textfield t : t_jointdir) { 00668 t.show(); 00669 } 00670 } else { 00671 l_jointdir.hide(); 00672 for(Textfield t : t_jointdir) { 00673 t.hide(); 00674 } 00675 } 00676 00677 00678 // draw direction fields only for rotational joints 00679 if(t_types.captionLabel().getText().equals("HingedJoint")) { 00680 l_radius.show(); 00681 t_radius.show(); 00682 } else { 00683 l_radius.hide(); 00684 t_radius.hide(); 00685 } 00686 } 00687 00688 00698 public void keyPressed() { 00699 00700 keys[keyCode] = true; 00701 00702 // ENTER key updates visualization 00703 if (key == ENTER || key == RETURN) { 00704 readFormData(); 00705 updateVisualization(); 00706 } 00707 00708 00709 // switch through the text fields using TAB 00710 if (keyCode == KeyEvent.VK_TAB) { 00711 00712 boolean fwd = true; // direction to skip through the fields 00713 if(checkKey(KeyEvent.VK_SHIFT)) { 00714 fwd=false; 00715 } 00716 00717 if(this.tab==Tab.SIMPLE) { 00718 switchFocus(t_all_simple, fwd); 00719 } else if(this.tab==Tab.MATRIX) { 00720 switchFocus(t_all_matrix, fwd); 00721 } else if(this.tab==Tab.QUATERNION) { 00722 switchFocus(t_all_quat, fwd); 00723 } else if(this.tab==Tab.JOINTS) { 00724 switchFocus(t_all_joint, fwd); 00725 } 00726 00727 } 00728 00729 if (keyCode == KeyEvent.VK_PAGE_UP) { 00730 00731 if(this.tab==Tab.SIMPLE) { 00732 incTextfieldValue(t_all_simple, 0.05f); 00733 } else if(this.tab==Tab.MATRIX) { 00734 incTextfieldValue(t_all_matrix, 0.05f); 00735 } else if(this.tab==Tab.QUATERNION) { 00736 incTextfieldValue(t_all_quat, 0.05f); 00737 } else if(this.tab==Tab.JOINTS) { 00738 incTextfieldValue(t_all_joint, 0.05f); 00739 } 00740 readFormData(); 00741 updateVisualization(); 00742 } 00743 00744 if (keyCode == KeyEvent.VK_PAGE_DOWN) { 00745 00746 if(this.tab==Tab.SIMPLE) { 00747 incTextfieldValue(t_all_simple, -0.05f); 00748 } else if(this.tab==Tab.MATRIX) { 00749 incTextfieldValue(t_all_matrix, -0.05f); 00750 } else if(this.tab==Tab.QUATERNION) { 00751 incTextfieldValue(t_all_quat, -0.05f); 00752 } else if(this.tab==Tab.JOINTS) { 00753 incTextfieldValue(t_all_joint, -0.05f); 00754 } 00755 readFormData(); 00756 updateVisualization(); 00757 } 00758 00759 } 00760 00761 00762 00767 public void keyReleased() { 00768 keys[keyCode] = false; 00769 } 00770 00771 00778 boolean checkKey(int k) { 00779 return keys[k]; 00780 } 00781 00782 00791 protected void switchFocus(ArrayList<Textfield> t_all, boolean forward) { 00792 00793 for(int i=0;i<t_all.size();i++) { 00794 if(t_all.get(i).isFocus()){ 00795 00796 if(forward) { 00797 t_all.get(i).setFocus(false); 00798 t_all.get((i+1)%t_all.size()).setFocus(true); 00799 } else { 00800 t_all.get(i).setFocus(false); 00801 00802 if(i>0) 00803 t_all.get(i-1).setFocus(true); 00804 else 00805 t_all.get(t_all.size()-1).setFocus(true); 00806 } 00807 break; 00808 } 00809 } 00810 } 00811 00812 00819 protected void incTextfieldValue(ArrayList<Textfield> t_all, float inc) { 00820 00821 for(int i=0;i<t_all.size();i++) { 00822 if(t_all.get(i).isFocus()){ 00823 00824 try{ 00825 float val = Float.valueOf(t_all.get(i).getText()); 00826 t_all.get(i).setText((val+inc)+""); 00827 } catch(NumberFormatException e) {} 00828 00829 } 00830 } 00831 } 00832 00833 00834 00835 00837 // 00838 // 00839 // READ AND WRITE FORM DATA 00840 // 00841 // 00843 00844 00845 00849 void readFormData() { 00850 00851 // check if the object already exists or if we should create a new one 00852 00853 MapObject cur; 00854 String id = t_id.getText(); 00855 00856 // skip this if the ID or class are not set 00857 if(t_id.equals("") || t_types.captionLabel().getText().equals("object class")){ 00858 return; 00859 } 00860 00861 if(objects.containsKey(id)) { 00862 cur = objects.get(id); 00863 } else { 00864 00865 if(t_types.captionLabel().getText().equals("HingedJoint") || 00866 t_types.captionLabel().getText().equals("PrismaticJoint")) { 00867 00868 cur = new MapJoint(); 00869 00870 } else { 00871 cur = new MapObject(); 00872 } 00873 objects.put(id, cur); 00874 } 00875 00876 00877 // set global values 00878 cur.id = id; 00879 00880 cur.types.clear(); // only one type for now 00881 cur.types.add(t_types.captionLabel().getText()); 00882 00883 00884 double xdim=0.0, ydim=0.0, zdim=0.0; 00885 try{xdim = Double.valueOf(t_dim[0].getText());} catch(NumberFormatException e) {} 00886 try{ydim = Double.valueOf(t_dim[1].getText());} catch(NumberFormatException e) {} 00887 try{zdim = Double.valueOf(t_dim[2].getText()); } catch(NumberFormatException e) {} 00888 cur.setDimensions(new Vector3d(xdim, ydim, zdim)); 00889 00890 00891 00892 // set per-tab values 00893 switch(tab) { 00894 00895 case SIMPLE: 00896 // set only position 00897 double x=0.0, y=0.0, z=0.0; 00898 try{x = Double.valueOf(t_pos[0].getText());} catch(NumberFormatException e) {} 00899 try{y = Double.valueOf(t_pos[1].getText());} catch(NumberFormatException e) {} 00900 try{z = Double.valueOf(t_pos[2].getText());} catch(NumberFormatException e) {} 00901 00902 cur.setPosition(new Vector3d(x, y, z )); 00903 updateQuaternionForm(cur.getPosition(), cur.getPoseQuat()); 00904 updateMatrixForm(cur.getPoseMatrix()); 00905 break; 00906 00907 case MATRIX: 00908 00909 double[] m = new double[16]; 00910 00911 try{m[0] = Double.valueOf(t_matrix[0].getText());} catch(NumberFormatException e) {m[0]=0.0;} 00912 try{m[1] = Double.valueOf(t_matrix[1].getText());} catch(NumberFormatException e) {m[1]=0.0;} 00913 try{m[2] = Double.valueOf(t_matrix[2].getText());} catch(NumberFormatException e) {m[2]=0.0;} 00914 try{m[3] = Double.valueOf(t_matrix[3].getText());} catch(NumberFormatException e) {m[3]=0.0;} 00915 00916 try{m[4] = Double.valueOf(t_matrix[4].getText());} catch(NumberFormatException e) {m[4]=0.0;} 00917 try{m[5] = Double.valueOf(t_matrix[5].getText());} catch(NumberFormatException e) {m[5]=0.0;} 00918 try{m[6] = Double.valueOf(t_matrix[6].getText());} catch(NumberFormatException e) {m[6]=0.0;} 00919 try{m[7] = Double.valueOf(t_matrix[7].getText());} catch(NumberFormatException e) {m[7]=0.0;} 00920 00921 try{m[8] = Double.valueOf(t_matrix[8].getText());} catch(NumberFormatException e) {m[8]=0.0;} 00922 try{m[9] = Double.valueOf(t_matrix[9].getText());} catch(NumberFormatException e) {m[9]=0.0;} 00923 try{m[10] = Double.valueOf(t_matrix[10].getText());} catch(NumberFormatException e) {m[10]=0.0;} 00924 try{m[11] = Double.valueOf(t_matrix[11].getText());} catch(NumberFormatException e) {m[11]=0.0;} 00925 00926 try{m[12] = Double.valueOf(t_matrix[12].getText());} catch(NumberFormatException e) {m[12]=0.0;} 00927 try{m[13] = Double.valueOf(t_matrix[13].getText());} catch(NumberFormatException e) {m[13]=0.0;} 00928 try{m[14] = Double.valueOf(t_matrix[14].getText());} catch(NumberFormatException e) {m[14]=0.0;} 00929 try{m[15] = Double.valueOf(t_matrix[15].getText());} catch(NumberFormatException e) {m[15]=0.0;} 00930 00931 cur.setPoseMatrix(new Matrix4d(m)); 00932 updateQuaternionForm(cur.getPosition(), cur.getPoseQuat()); 00933 updatePositionForm(cur.getPosition()); 00934 break; 00935 00936 case QUATERNION: 00937 00938 try{x = Double.valueOf(t_qpos[0].getText());} catch(NumberFormatException e) {x=0.0;} 00939 try{y = Double.valueOf(t_qpos[1].getText());} catch(NumberFormatException e) {y=0.0;} 00940 try{z = Double.valueOf(t_qpos[2].getText());} catch(NumberFormatException e) {z=0.0;} 00941 00942 double qx=0.0, qy=0.0, qz=0.0, qw=1.0; 00943 try{qw = Double.valueOf(t_quat[0].getText());} catch(NumberFormatException e) {} 00944 try{qy = Double.valueOf(t_quat[1].getText());} catch(NumberFormatException e) {} 00945 try{qz = Double.valueOf(t_quat[2].getText());} catch(NumberFormatException e) {} 00946 try{qz = Double.valueOf(t_quat[3].getText());} catch(NumberFormatException e) {} 00947 00948 cur.setPoseQuat(new Vector3d(x,y,z), 00949 new Quat4d(qx,qy,qz,qw),1.0); 00950 00951 updateMatrixForm(cur.getPoseMatrix()); 00952 updatePositionForm(cur.getPosition()); 00953 break; 00954 00955 case JOINTS: 00956 00957 00958 if(t_types.captionLabel().getText().equals("HingedJoint") || 00959 t_types.captionLabel().getText().equals("PrismaticJoint")) { 00960 00961 // set direction of prismatic joints 00962 try{x = Double.valueOf(t_jointdir[0].getText());} catch(NumberFormatException e) {x=0.0;} 00963 try{y = Double.valueOf(t_jointdir[1].getText());} catch(NumberFormatException e) {y=0.0;} 00964 try{z = Double.valueOf(t_jointdir[2].getText());} catch(NumberFormatException e) {z=0.0;} 00965 00966 ((MapJoint) cur).setDirection(new Vector3d(x,y,z)); 00967 00968 // set joint limits 00969 double q_min=0.0, q_max=0.0; 00970 try{q_min = Double.valueOf(t_jointlim[0].getText());} catch(NumberFormatException e) {} 00971 try{q_max = Double.valueOf(t_jointlim[1].getText());} catch(NumberFormatException e) {} 00972 00973 ((MapJoint) cur).setQ_min(q_min); 00974 ((MapJoint) cur).setQ_max(q_max); 00975 00976 double radius=0.0; 00977 try{ 00978 radius = Double.valueOf(t_radius.getText());} 00979 catch(NumberFormatException e) { 00980 e.printStackTrace(); 00981 } 00982 ((MapJoint) cur).setRadius(radius); 00983 00984 00985 // set child/parent fields (hinges have only one each) 00986 if(t_child.getText() != null) { 00987 if(objects.get(t_child.getText())!=null) 00988 ((MapJoint) cur).setChild(objects.get(t_child.getText())); 00989 } 00990 00991 if(t_parent.getText() != null) { 00992 if(objects.get(t_parent.getText())!=null) 00993 ((MapJoint) cur).setParent(objects.get(t_parent.getText())); 00994 } 00995 00996 } 00997 updateMatrixForm(cur.getPoseMatrix()); 00998 updateQuaternionForm(cur.getPosition(), cur.getPoseQuat()); 00999 updatePositionForm(cur.getPosition()); 01000 break; 01001 } 01002 01003 // set object as physicalPart of parent object 01004 if(t_parent.getText() != null) 01005 if(objects.get(t_parent.getText())!=null) 01006 objects.get(t_parent.getText()).physicalParts.add(cur); 01007 01008 01009 } 01010 01016 void writeFormData(MapObject cur) { 01017 01018 t_id.setText(cur.id); 01019 01020 01021 // find object that has this object as physical part 01022 for(MapObject o : objects.values()) { 01023 01024 if(o.physicalParts.contains(cur)) { 01025 t_parent.setText(o.getId()); 01026 break; 01027 } else { 01028 t_parent.setText(""); 01029 } 01030 } 01031 01032 t_types.captionLabel().set(cur.types.get(0)); 01033 01034 t_dim[0].setText(""+cur.dimensions.x); 01035 t_dim[1].setText(""+cur.dimensions.y); 01036 t_dim[2].setText(""+cur.dimensions.z); 01037 01038 updateQuaternionForm(cur.getPosition(), cur.getPoseQuat()); 01039 updateMatrixForm(cur.getPoseMatrix()); 01040 updatePositionForm(cur.getPosition()); 01041 updateJointForm(cur); 01042 } 01043 01044 01050 void updateMatrixForm(Matrix4d m) { 01051 01052 t_matrix[0].setText(""+m.m00); 01053 t_matrix[1].setText(""+m.m01); 01054 t_matrix[2].setText(""+m.m02); 01055 t_matrix[3].setText(""+m.m03); 01056 01057 t_matrix[4].setText(""+m.m10); 01058 t_matrix[5].setText(""+m.m11); 01059 t_matrix[6].setText(""+m.m12); 01060 t_matrix[7].setText(""+m.m13); 01061 01062 t_matrix[8].setText(""+m.m20); 01063 t_matrix[9].setText(""+m.m21); 01064 t_matrix[10].setText(""+m.m22); 01065 t_matrix[11].setText(""+m.m23); 01066 01067 t_matrix[12].setText(""+m.m30); 01068 t_matrix[13].setText(""+m.m31); 01069 t_matrix[14].setText(""+m.m32); 01070 t_matrix[15].setText(""+m.m33); 01071 } 01072 01078 void updatePositionForm(Vector3d pos) { 01079 01080 t_pos[0].setText(""+pos.x); 01081 t_pos[1].setText(""+pos.y); 01082 t_pos[2].setText(""+pos.z); 01083 } 01084 01085 01092 void updateQuaternionForm(Vector3d pos, Quat4d q) { 01093 01094 t_qpos[0].setText(""+pos.x); 01095 t_qpos[1].setText(""+pos.y); 01096 t_qpos[2].setText(""+pos.z); 01097 01098 t_quat[0].setText(""+q.w); 01099 t_quat[1].setText(""+q.x); 01100 t_quat[2].setText(""+q.y); 01101 t_quat[3].setText(""+q.z); 01102 } 01103 01109 void updateJointForm(MapObject cur) { 01110 01111 showJointSpecificFormFields(); 01112 01113 if(cur instanceof MapJoint) { 01114 t_jointlim[0].setText(((MapJoint)cur).q_min+""); 01115 t_jointlim[1].setText(((MapJoint)cur).q_max+""); 01116 01117 t_jointdir[0].setText(((MapJoint)cur).direction.x+""); 01118 t_jointdir[1].setText(((MapJoint)cur).direction.y+""); 01119 t_jointdir[2].setText(((MapJoint)cur).direction.z+""); 01120 01121 if(((MapJoint)cur).child.id != null) 01122 t_child.setText(((MapJoint)cur).child.id); 01123 01124 if(((MapJoint)cur).parent.id != null) 01125 t_parent.setText(((MapJoint)cur).parent.id); 01126 01127 t_radius.setText(((MapJoint)cur).radius+""); 01128 } 01129 01130 } 01131 01132 void clearFormFields(){ 01133 01134 for(Textfield t : t_all_simple) { 01135 t.setText(""); 01136 } 01137 for(Textfield t : t_all_matrix) { 01138 t.setText(""); 01139 } 01140 for(Textfield t : t_all_quat) { 01141 t.setText(""); 01142 } 01143 01144 } 01145 01146 01148 // 01149 // 01150 // MANAGE OBJECT INSTANCES 01151 // 01152 // 01154 01158 protected void updateVisualization() { 01159 01160 prologVisCanvas.getKitchenVisApplet().clear(); 01161 01162 for(MapObject o : objects.values()) { 01163 01164 ItemBase item = createItem(o); 01165 01166 if(item!=null) { 01167 item.name=o.id; 01168 01169 prologVisCanvas.getKitchenVisApplet().addItem(item); 01170 01171 } else { 01172 System.err.println("Object "+o.id+" not found."); 01173 } 01174 } 01175 prologVisCanvas.getKitchenVisApplet().redraw(); 01176 01177 } 01178 01179 01180 01189 Item createItem(MapObject obj) { 01190 01191 String type = obj.types.get(0); 01192 01193 int col = grayValues[(++grayLevelCounter) % grayValues.length]; 01194 01195 01197 // tableware 01198 01199 if(type.endsWith("Cup")) { 01200 return new Cup(obj.pose_matrix, obj.dimensions); 01201 01202 } else if(type.endsWith("DinnerPlate")) { 01203 return new Plate(obj.pose_matrix, obj.dimensions); 01204 01205 } else if(type.endsWith("Saucer")) { 01206 return new Plate(obj.pose_matrix, obj.dimensions); 01207 01208 } else if (type.endsWith("DrinkingGlass")) { 01209 return new DrinkingGlass(obj.pose_matrix, obj.dimensions); 01210 01211 } else if (type.endsWith("Bowl-Eating")) { 01212 return new BowlEating(obj.pose_matrix, obj.dimensions); 01213 01214 } else if (type.endsWith("DrinkingBottle")) { 01215 return new Sphere(obj.pose_matrix, new Vector3d(0.05f,0.05f,0.15f)); 01216 01217 01218 01220 // silverware 01221 01222 } else if(type.endsWith("DinnerFork")) { 01223 return new Fork(obj.pose_matrix, obj.dimensions); 01224 01225 } else if(type.endsWith("TableKnife")) { 01226 return new Knife(obj.pose_matrix, obj.dimensions); 01227 01228 } else if(type.endsWith("SoupSpoon")) { 01229 return new Spoon(obj.pose_matrix, obj.dimensions); 01230 01231 01233 // serving and cooking 01234 01235 } else if(type.endsWith("Napkin")) { 01236 return new Napkin(obj.pose_matrix, obj.dimensions); 01237 01238 } else if(type.endsWith("PlaceMat")) { 01239 return new PlaceMat(obj.pose_matrix, obj.dimensions); 01240 01241 } else if (type.endsWith("Platter")) { 01242 return new Platter(obj.pose_matrix, obj.dimensions); 01243 01244 } else if(type.endsWith("CookingPot")) { 01245 return new CookingPot(obj.pose_matrix, obj.dimensions); 01246 01247 } else if(type.endsWith("Spatula")) { 01248 return new Spatula(obj.pose_matrix, obj.dimensions); 01249 01250 } else if(type.endsWith("PancakeMaker")) { 01251 return new PancakeMaker(obj.pose_matrix, obj.dimensions); 01252 01253 01255 // breakfast consumables 01256 01257 } else if (type.endsWith("Bread")) { 01258 return new Bread(obj.pose_matrix, obj.dimensions); 01259 01260 } else if (type.endsWith("Cheese")) { 01261 return new Cheese(obj.pose_matrix, obj.dimensions); 01262 01263 } else if (type.endsWith("Butter")) { 01264 return new Cheese(obj.pose_matrix, obj.dimensions); 01265 01266 } else if (type.endsWith("Sausage")) { 01267 return new Sausage(obj.pose_matrix, obj.dimensions); 01268 01269 } else if (type.endsWith("Cake")) { 01270 return new Cake(obj.pose_matrix, obj.dimensions); 01271 01272 } else if (type.endsWith("BreakfastCereal")) { 01273 return new CerealBox(obj.pose_matrix, obj.dimensions); 01274 01275 } else if (type.endsWith("PancakeMix")) { 01276 return new PancakeMix(obj.pose_matrix, obj.dimensions); 01277 01278 } else if (type.endsWith("Pancake")) { 01279 return new Pancake(obj.pose_matrix, obj.dimensions); 01280 01281 } else if (type.endsWith("Yogurt")) { 01282 return new DrinkingGlass(obj.pose_matrix, obj.dimensions); 01283 01284 01286 // lunch/dinner consumables 01287 01288 } else if (type.endsWith("Pizza")) { 01289 return new Pizza(obj.pose_matrix, obj.dimensions); 01290 01291 } else if (type.endsWith("Salad")) { 01292 return new SaladBowl(obj.pose_matrix, obj.dimensions); 01293 01294 } else if (type.endsWith("Pasta")) { 01295 return new SaladBowl(obj.pose_matrix, obj.dimensions); 01296 01297 } else if (type.endsWith("Soup")) { 01298 return new SoupPlate(obj.pose_matrix, obj.dimensions); 01299 01300 01301 01303 // drinks 01304 01305 } else if (type.endsWith("Water")) { 01306 return new Bottle(obj.pose_matrix, obj.dimensions); 01307 01308 } else if (type.endsWith("Pitcher")) { 01309 return new Thermos(obj.pose_matrix, obj.dimensions); 01310 01311 } else if (type.endsWith("Tea-Beverage")) { 01312 return new Bread(obj.pose_matrix, obj.dimensions); 01313 01314 } else if (type.endsWith("Coffee-Beverage")) { 01315 return new Thermos(obj.pose_matrix, obj.dimensions); 01316 01317 } else if (type.endsWith("Juice")) { 01318 return new Tetrapak(obj.pose_matrix, obj.dimensions); 01319 01320 } else if (type.endsWith("Tea-Iced")) { 01321 return new Tetrapak(obj.pose_matrix, obj.dimensions); 01322 01323 } else if(type.endsWith("Tetrapak")) { 01324 return new Tetrapak(obj.pose_matrix, obj.dimensions); 01325 01326 } else if (type.endsWith("CardboardBox")) { 01327 return new Bread(obj.pose_matrix, obj.dimensions); 01328 01329 } else if (type.endsWith("CowsMilk-Product")) { 01330 return new Tetrapak(obj.pose_matrix, obj.dimensions); 01331 01332 } else if (type.endsWith("Buttermilk")) { 01333 return new Tetrapak(obj.pose_matrix, obj.dimensions); 01334 01335 01337 // furniture 01338 01339 } else if(type.endsWith("Bed-PieceOfFurniture")) { 01340 Box c = new Box(obj.pose_matrix, obj.dimensions); 01341 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01342 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01343 return c; 01344 01345 } else if(type.endsWith("Chair-PieceOfFurniture")) { 01346 Chair c = new Chair(obj.pose_matrix, obj.dimensions); 01347 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01348 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01349 return c; 01350 01351 } else if(type.endsWith("Cupboard")) { 01352 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01353 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01354 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01355 return c; 01356 01357 } else if(type.endsWith("Cabinet-PieceOfFurniture")) { 01358 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01359 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01360 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01361 return c; 01362 01363 } else if(type.endsWith("Drawer")) { 01364 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01365 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01366 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01367 return c; 01368 01369 } else if(type.endsWith("Dishwasher")) { 01370 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01371 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01372 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01373 return c; 01374 01375 } else if(type.endsWith("Oven")) { 01376 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01377 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01378 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01379 return c; 01380 01381 } else if(type.endsWith("Refrigerator")) { 01382 Cupboard c = new Cupboard(obj.pose_matrix, obj.dimensions); 01383 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01384 c.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01385 return c; 01386 01387 } else if(type.endsWith("Handle")) { 01388 BoxHandle b = new BoxHandle(obj.pose_matrix, obj.dimensions); 01389 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01390 b.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 170)); 01391 return b; 01392 01393 } else if(type.endsWith("ControlKnob")) { 01394 Sphere s = new Sphere(obj.pose_matrix, obj.dimensions); 01395 col = grayValues[(++grayLevelCounter) % grayValues.length]; 01396 s.setColor(StandaloneKitchenVisApplet.convertColor(col, col, col, 255)); 01397 return s; 01398 01399 } else if(type.endsWith("Door")) { 01400 Door d = new Door(obj.pose_matrix, obj.dimensions); 01401 d.setColor(StandaloneKitchenVisApplet.convertColor(255, 175, 0, 255)); 01402 return d; 01403 01404 } else if(type.endsWith("HingedJoint")) { 01405 HingedJoint h = new HingedJoint(obj.pose_matrix, obj.dimensions); 01406 h.setColor(StandaloneKitchenVisApplet.convertColor(70, 120, 255, 255)); 01407 return h; 01408 01409 } else if(type.endsWith("PrismaticJoint")) { 01410 PrismaticJoint h = new PrismaticJoint(obj.pose_matrix, new Vector3d(0.02f, 0.02f, 0.02f)); 01411 h.setColor(StandaloneKitchenVisApplet.convertColor(70, 255, 120, 255)); 01412 return h; 01413 01415 // dummies 01416 01417 } else if(type.endsWith("SpatialThing-Localized")) { 01418 return new Ellipse(obj.pose_matrix, obj.dimensions); 01419 01420 } else if(type.endsWith("Place")) { 01421 return new Ellipse(obj.pose_matrix, obj.dimensions); 01422 01423 } else if(type.endsWith("Point3D")) { 01424 return new Sphere(obj.pose_matrix, new Vector3d(0.03f,0.03f,0.03f)); 01425 01426 } else { 01427 return new Sphere(obj.pose_matrix, new Vector3d(0.02f,0.02f,0.02f)); 01428 } 01429 01430 } 01431 01432 01433 01434 01436 // 01437 // 01438 // INTERFACE WITH PROLOG CANVAS 01439 // 01440 // 01442 01447 public PrologVisualizationCanvas getPrologVisCanvas() { 01448 return prologVisCanvas; 01449 } 01450 01451 01457 public void setPrologVisCanvas(PrologVisualizationCanvas prologVisCanvas) { 01458 this.prologVisCanvas = prologVisCanvas; 01459 } 01460 01461 01472 void editObject(String identifier) { 01473 01474 // special mode: select the parent object for the currently edited object 01475 if(selectParentObj) { 01476 01477 MapObject cur = objects.get(t_id.getText()); 01478 01479 // clear previous parent objects 01480 for(MapObject o : objects.values()) { 01481 if(o.physicalParts.contains(cur)) { 01482 o.physicalParts.remove(cur); 01483 } 01484 } 01485 01486 objects.get(identifier).physicalParts.add(cur); 01487 01488 if(cur instanceof MapJoint) 01489 ((MapJoint) cur).parent = objects.get(identifier); 01490 01491 this.t_parent.setText(identifier); 01492 01493 selectParentObj=false; 01494 cursor(ARROW); 01495 this.prologVisCanvas.getKitchenVisApplet().cursor(ARROW); 01496 01497 01498 01499 } else if(selectChildObj) { 01500 01501 MapObject cur = objects.get(t_id.getText()); 01502 01503 // clear previous parent objects 01504 for(MapObject o : objects.values()) { 01505 if(o.physicalParts.contains(cur)) { 01506 o.physicalParts.remove(cur); 01507 } 01508 } 01509 01510 if(cur instanceof MapJoint) 01511 ((MapJoint) cur).child = objects.get(identifier); 01512 01513 this.t_child.setText(identifier); 01514 01515 selectChildObj=false; 01516 cursor(ARROW); 01517 this.prologVisCanvas.getKitchenVisApplet().cursor(ARROW); 01518 01519 01520 01521 } else { 01522 // normal mode: load information about the object the user clicked on into the form fields 01523 writeFormData(objects.get(identifier)); 01524 } 01525 } 01526 01527 }