SemanticMapEditorForms.java
Go to the documentation of this file.
00001 package edu.tum.cs.ias.knowrob.map;
00002 
00003 import java.awt.Container;
00004 import java.awt.Frame;
00005 import java.awt.event.KeyEvent;
00006 import java.text.SimpleDateFormat;
00007 import java.util.ArrayList;
00008 import java.util.Calendar;
00009 import java.util.HashMap;
00010 import java.util.Vector;
00011 
00012 import javax.vecmath.Matrix4d;
00013 import javax.vecmath.Quat4d;
00014 import javax.vecmath.Vector3d;
00015 
00016 import org.semanticweb.owlapi.io.RDFXMLOntologyFormat;
00017 import org.semanticweb.owlapi.model.*;
00018 
00019 import controlP5.Button;
00020 import controlP5.ControlP5;
00021 import controlP5.ListBox;
00022 import controlP5.ListBoxItem;
00023 import controlP5.Textfield;
00024 import controlP5.Textlabel;
00025 import edu.tum.cs.ias.knowrob.owl.JointInstance;
00026 import edu.tum.cs.ias.knowrob.owl.OWLClass;
00027 import edu.tum.cs.ias.knowrob.owl.OWLThing;
00028 import edu.tum.cs.ias.knowrob.owl.ObjectInstance;
00029 import edu.tum.cs.ias.knowrob.owl.utils.OWLFileUtils;
00030 import edu.tum.cs.ias.knowrob.owl.utils.OWLImportExport;
00031 import edu.tum.cs.ias.knowrob.prolog.PrologInterface;
00032 import edu.tum.cs.ias.knowrob.prolog.PrologQueryUtils;
00033 import edu.tum.cs.ias.knowrob.vis.applets.SemanticMapVisApplet;
00034 import edu.tum.cs.ias.knowrob.vis.themes.GreyTheme;
00035 import processing.core.PApplet;
00036 
00037 
00038 
00049 public class SemanticMapEditorForms extends PApplet {
00050 
00051         private static final long serialVersionUID = -4266603809510554926L;
00052 
00054         // visualization and user interface stuff
00055 
00056         private SemanticMapVisApplet mapVisApplet = null;
00057         public ControlP5 controlP5;
00058         boolean[] keys = new boolean[526];
00059         boolean selectParentObj = false; // switch mode from normal obj selection to parent obj selection
00060         boolean selectChildObj = false;  // switch mode from normal obj selection to child obj selection
00061         
00062         // form elements
00063         Textfield t_id;
00064         ListBox t_types;
00065         
00066         Textfield[] t_dim;
00067         Textfield[] t_matrix;
00068         Textfield[] t_quat;
00069         Textfield[] t_pos;
00070         Textfield[] t_qpos;
00071         Textfield[] t_jointdir;
00072         Textfield[] t_jointlim;
00073         public Textfield t_filename;
00074         Textfield t_namespace;
00075         Textfield t_map_id;
00076         Textfield t_parent;
00077         Textfield t_radius;
00078         Textlabel l_jointdir;
00079         Textlabel l_jointlim;
00080         Textlabel l_radius;
00081         Textlabel l_dim;
00082         Button[] b_rot;
00083         Button b_child;
00084         Button b_new_obj;
00085         Button b_del_obj;
00086         Button b_update;
00087         Textfield t_child;
00088         ArrayList<Textfield> t_all_simple; // for using the tab key
00089         ArrayList<Textfield> t_all_matrix; // for using the tab key
00090         ArrayList<Textfield> t_all_quat; // for using the tab key
00091         ArrayList<Textfield> t_all_joint; // for using the tab key
00092         
00093         public enum Tab {SIMPLE, MATRIX, QUATERNION, JOINTS, SETTINGS};
00094         Tab tab;
00095         
00097         
00098         
00099         
00103         HashMap<String, ObjectInstance> objects;
00104 
00105         boolean cp5_initialized = false;
00106         
00107         String map_id = "";
00108         String map_namespace = "";
00109         
00110         
00114         protected static final HashMap<Integer, String> objClasses = new HashMap<Integer, String>();
00115         static {
00116                 objClasses.put(1022,   "Sushi");
00117                 objClasses.put(1023,   "BentoBox");
00118                 objClasses.put(1024,   "Riceball");
00119                 objClasses.put(1025,   "Pizza");
00120                 objClasses.put(1026,   "Sandwich");
00121                 objClasses.put(1027,   "HamburgerSandwich");
00122                 objClasses.put(1028,   "Beer");
00123                 objClasses.put(1029,   "Water");
00124                 objClasses.put(1030,   "Coffee-Beverage");
00125                 objClasses.put(1031,   "ColaSoftDrink");
00126                 objClasses.put(1032,   "LemonLimeSoftDrink");
00127                 objClasses.put(1033,   "GreenTea");
00128                 objClasses.put(1034,   "EnergyDrink");
00129                 objClasses.put(1035,   "Chip-Food");
00130                 objClasses.put(1036,   "Cracker-FoodItem");
00131                 objClasses.put(1037,   "Pretzel");
00132                 objClasses.put(1038,   "InstantRamenNoodles");
00133                 objClasses.put(1039,   "Cake");
00134                 objClasses.put(1040,   "Bread");
00135                 objClasses.put(1041,   "ChocolateCandy");
00136                 objClasses.put(1042,   "CandyBar");
00137                 objClasses.put(1043,   "Caramel");
00138                 objClasses.put(1044,   "ChewingGum");
00139                 objClasses.put(1045,   "Shampoo");
00140                 objClasses.put(1046,   "BodyWash");
00141                 objClasses.put(1047,   "Toothpaste");
00142                 objClasses.put(1048,   "ShavingCream");
00143                 objClasses.put(1049,   "ToiletPaper");
00144                 objClasses.put(1050,   "Envelope");
00145                 objClasses.put(1051,   "SheetOfPaper");
00146                 objClasses.put(1052,   "Pencil");
00147                 objClasses.put(1053,   "Notepad");
00148                 objClasses.put(1054,   "Toy");
00149                 objClasses.put(1055,   "CashRegister");
00150                 objClasses.put(1056,   "ShelfInABuilding");
00151                 objClasses.put(1057,   "Robot");
00152                 
00153 //              objClasses.put(1022,   "Cupboard");
00154 //              objClasses.put(1023,   "Dishwasher");
00155 //              objClasses.put(1024,   "Drawer");
00156 //              objClasses.put(1025,   "Oven");
00157 //              objClasses.put(1026,   "Refrigerator");
00158 //              objClasses.put(1027,   "Door");
00159 //              objClasses.put(1028,   "Handle");
00160 //              objClasses.put(1029,   "ControlKnob");
00161 //              objClasses.put(1030,   "Cabinet-PieceOfFurniture");
00162 //              objClasses.put(1031,   "Bed-PieceOfFurniture");
00163 //              objClasses.put(1032,   "HingedJoint");
00164 //              objClasses.put(1033,   "PrismaticJoint");
00165 //              objClasses.put(1034,   "RoomInAConstruction");
00166 //              objClasses.put(1035,   "ShelfInABuilding");
00167 //              objClasses.put(1036,   "Sushi");
00168 //              objClasses.put(1037,   "Tea-Beverage");
00169 //              objClasses.put(1038,   "Computer");
00170 //              objClasses.put(1039,   "CashRegister");
00171 //              objClasses.put(1040,   "Whiteboard");
00172 //              objClasses.put(1041,   "Desk");
00173                 
00174         }
00175         
00176         
00180         public void setup() {
00181 
00182                 size(320, 600, P2D);
00183                 frameRate(20);
00184                 objects = new HashMap<String, ObjectInstance>();
00185                 tab=Tab.SIMPLE;
00186 
00187                 initControlP5Forms();
00188                 
00189                 frameRate(20);
00190                 
00191                 draw(); 
00192                 
00193         }
00194         
00195         public Frame findFrame() {      
00196                 Container f = this.getParent();
00197                 while (!(f instanceof Frame) && f!=null)
00198                         f = f.getParent();
00199                 return (Frame) f;
00200         }
00201         
00205         public void draw() {
00206 
00207                 background(40);
00208                 controlP5.draw();
00209                 
00210         }
00211 
00212 
00214         //
00215         //
00216         // INITIALIZE FORMS
00217         //
00218         //
00220         
00221         
00225         private void initControlP5Forms() {
00226 
00227                 // location definitions:
00228                 
00229                 int OBJ_ID_X=10;
00230                 int OBJ_ID_Y=25;
00231                 
00232                 int OBJ_DIM_X=10;
00233                 int OBJ_DIM_Y=200;
00234 
00235                 int TAB_X=10;
00236                 int TAB_Y=300;
00237                 
00238                 int UPDATE_X = 10;
00239                 int UPDATE_Y = 500;
00240 
00241                 // for using the tab key
00242                 t_all_simple = new ArrayList<Textfield>();
00243                 t_all_matrix = new ArrayList<Textfield>();
00244                 t_all_quat = new ArrayList<Textfield>();
00245                 t_all_joint = new ArrayList<Textfield>();
00246                 
00247                 
00248                 // wait till window has been created
00249                 while(findFrame()==null) {
00250                         try { Thread.sleep(50);
00251                         } catch (InterruptedException e) {
00252                                 e.printStackTrace(); } 
00253                 }
00254                 this.frame = findFrame();
00255                 
00256                 
00257                 controlP5 = new ControlP5(this);
00258                 GreyTheme.applyStyle(controlP5);
00259                 
00260                 GreyTheme.applyStyle(controlP5.getTab("default")).setLabel("simple").setWidth(35);
00261                 
00262                 GreyTheme.applyStyle(controlP5.addTab("matrix")).setWidth(35);
00263                 
00264                 GreyTheme.applyStyle(controlP5.addTab("quaternion")).setWidth(50);
00265 
00266                 GreyTheme.applyStyle(controlP5.addTab("joint properties")).setWidth(80);
00267 
00268                 GreyTheme.applyStyle(controlP5.addTab("settings")).setWidth(45);
00269                 
00270                 
00271                 // text field for object name
00272                 t_id = controlP5.addTextfield("object id",       OBJ_ID_X, OBJ_ID_Y, 200, 20);
00273                 t_id.moveTo("global");
00274                 t_all_simple.add(t_id); t_all_matrix.add(t_id); t_all_quat.add(t_id);
00275                 t_id.setAutoClear(false);
00276                 
00277 
00278                 b_new_obj = GreyTheme.applyStyle(controlP5.addButton("new",    17, OBJ_ID_X,      OBJ_ID_Y+40, 24, 20));
00279                 b_new_obj.moveTo("global");
00280 
00281                 b_del_obj = GreyTheme.applyStyle(controlP5.addButton("delete", 18, OBJ_ID_X + 30, OBJ_ID_Y+40, 34, 20));
00282                 b_del_obj.moveTo("global");
00283 
00284                 b_update = GreyTheme.applyStyle(controlP5.addButton("add to map", 23, OBJ_ID_X+70, OBJ_ID_Y+40, 55, 20));
00285                 b_update.setId(23);
00286                 b_update.moveTo("global");
00287 
00288                 
00289                 t_types = GreyTheme.applyStyle(controlP5.addListBox("object class",   OBJ_ID_X, OBJ_ID_Y+100,200,60), 15);
00290                 t_types.setId(42);
00291 
00292                 t_types.moveTo("global");
00293                 
00294                 ListBoxItem b;
00295                 OWLClass cl;
00296                 for(int i: objClasses.keySet()) {
00297                         
00298                         // add to OWLClass identifier buffer to enable later resolution by shortname
00299                         cl = OWLClass.getOWLClass("http://ias.cs.tum.edu/kb/knowrob.owl#" + objClasses.get(i));
00300                         
00301                         b = t_types.addItem(cl.getShortName(),i);
00302                         
00303                         b.setId(i);
00304                 }
00305                 
00306                 // object dimensions
00307                 l_dim = GreyTheme.applyStyle(controlP5.addTextlabel("l_dim","OBJECT DIMENSIONS",OBJ_DIM_X,OBJ_DIM_Y));
00308                 l_dim.setWidth(200);
00309                 l_dim.moveTo("global");
00310                 
00311                 t_dim = new Textfield[3];
00312                 t_dim[0] = GreyTheme.applyStyle(controlP5.addTextfield("x_dim",OBJ_DIM_X,     OBJ_DIM_Y+15, 40,20));
00313                 t_dim[1] = GreyTheme.applyStyle(controlP5.addTextfield("y_dim",OBJ_DIM_X+50,  OBJ_DIM_Y+15,40,20));
00314                 t_dim[2] = GreyTheme.applyStyle(controlP5.addTextfield("z_dim",OBJ_DIM_X+100, OBJ_DIM_Y+15,40,20));
00315                 
00316                 for(Textfield t : t_dim) {
00317                         t.moveTo("global");
00318                         t.setAutoClear(false);
00319                         t_all_simple.add(t);
00320                         t_all_matrix.add(t);
00321                         t_all_quat.add(t);
00322                 }
00323                 b_rot = new Button[3];
00324                 b_rot[0] = GreyTheme.applyStyle(controlP5.addButton("rot_x", 20, OBJ_DIM_X,    OBJ_DIM_Y+55, 32, 20));
00325                 b_rot[0].setId(20);
00326                 b_rot[0].moveTo("global");
00327 
00328                 b_rot[1] = GreyTheme.applyStyle(controlP5.addButton("rot_y", 21, OBJ_DIM_X+50, OBJ_DIM_Y+55, 32, 20));
00329                 b_rot[1].setId(21);
00330                 b_rot[1].moveTo("global");
00331 
00332                 b_rot[2] = GreyTheme.applyStyle(controlP5.addButton("rot_z", 22, OBJ_DIM_X+100, OBJ_DIM_Y+55, 32, 20));
00333                 b_rot[2].setId(22);
00334                 b_rot[2].moveTo("global");
00335                 
00336                 
00337                 
00338                 
00339                 
00340                 Button parent = GreyTheme.applyStyle(controlP5.addButton("select parent", 24, UPDATE_X, UPDATE_Y, 72, 20));
00341                 parent.moveTo("global");
00342 
00343                 t_parent = GreyTheme.applyStyle(controlP5.addTextfield("parent", UPDATE_X+85, UPDATE_Y, 130, 20));
00344                 t_parent.moveTo("global");
00345                 
00346                 
00347                 Button export = GreyTheme.applyStyle(controlP5.addButton("export to owl", 25, UPDATE_X, UPDATE_Y+40, 72, 20));
00348                 export.moveTo("global");
00349                 
00350                 t_filename = GreyTheme.applyStyle(controlP5.addTextfield("filename", UPDATE_X+85, UPDATE_Y+40, 130, 20));
00351                 t_filename.moveTo("global");
00352                 
00353                 
00355                 // TABS
00356 
00357                 // simple position tab
00358                 Textlabel l_pos = GreyTheme.applyStyle(controlP5.addTextlabel("l_pos","OBJECT POSITION",TAB_X,TAB_Y));
00359                 l_pos.setWidth(200);
00360 
00361                 t_pos = new Textfield[3];
00362                 t_pos[0] = GreyTheme.applyStyle(controlP5.addTextfield("x_pos",TAB_X,    TAB_Y+15, 40, 20));
00363                 t_pos[1] = GreyTheme.applyStyle(controlP5.addTextfield("y_pos",TAB_X+50, TAB_Y+15, 40, 20));
00364                 t_pos[2] = GreyTheme.applyStyle(controlP5.addTextfield("z_pos",TAB_X+100,TAB_Y+15, 40, 20));
00365                 
00366                 for(Textfield t : t_pos) { // for using the tab key
00367                         t.setAutoClear(false);
00368                         t_all_simple.add(t);
00369                 }
00370 
00371 
00372                 // pose matrix tab
00373                 Textlabel l_matrix = GreyTheme.applyStyle(controlP5.addTextlabel("l_matrix","POSE MATRIX ",TAB_X,TAB_Y));
00374                 l_matrix.setWidth(200);
00375                 l_matrix.moveTo("matrix");
00376 
00377                 t_matrix = new Textfield[16];
00378                 for(int i=0;i<4;i++) {
00379                         for(int j=0;j<4;j++) {
00380 
00381                                 t_matrix[i*4+j] = GreyTheme.applyStyle(controlP5.addTextfield("m"+i+j, TAB_X+j*50, TAB_Y+15 + 40*i, 40, 20));
00382                                 t_matrix[i*4+j].moveTo("matrix");
00383                                 //t_matrix[i*4+j].setColorBackground(color(255,60));
00384                                 t_all_matrix.add(t_matrix[i*4+j]);
00385                         }
00386                 }
00387 
00388 
00389                 // quaternion pose tab
00390                 Textlabel l_quat = GreyTheme.applyStyle(controlP5.addTextlabel("l_qpos","POSE QUATERNION",TAB_X,TAB_Y));
00391                 l_quat.setWidth(200);
00392                 l_quat.moveTo("quaternion");
00393 
00394                 t_qpos = new Textfield[3];
00395                 t_qpos[0] = GreyTheme.applyStyle(controlP5.addTextfield("x_qpos",TAB_X,    TAB_Y+15, 40,20)).setCaptionLabel("x_pos");
00396                 t_qpos[1] = GreyTheme.applyStyle(controlP5.addTextfield("y_qpos",TAB_X+50, TAB_Y+15, 40,20)).setCaptionLabel("y_pos");
00397                 t_qpos[2] = GreyTheme.applyStyle(controlP5.addTextfield("z_qpos",TAB_X+100,TAB_Y+15, 40,20)).setCaptionLabel("z_pos");
00398                 
00399                 for(Textfield t : t_qpos) { // for using the tab key
00400                         t.moveTo("quaternion");
00401                         t.setAutoClear(false);
00402                         t_all_quat.add(t);
00403                 }
00404                 
00405                 t_quat = new Textfield[4];
00406                 t_quat[0] = GreyTheme.applyStyle(controlP5.addTextfield("w",TAB_X,     TAB_Y+55, 40,20));
00407                 t_quat[1] = GreyTheme.applyStyle(controlP5.addTextfield("x",TAB_X+50,  TAB_Y+55,40,20));
00408                 t_quat[2] = GreyTheme.applyStyle(controlP5.addTextfield("y",TAB_X+100, TAB_Y+55,40,20));
00409                 t_quat[3] = GreyTheme.applyStyle(controlP5.addTextfield("z",TAB_X+150, TAB_Y+55,40,20));
00410 
00411                 for(Textfield t : t_quat) { // for using the tab key
00412                         t.moveTo("quaternion");
00413                         t.setAutoClear(false);
00414                         t_all_quat.add(t);
00415                 }
00416                 
00417 
00418                 // joint properties tab
00419                 l_jointdir = GreyTheme.applyStyle(controlP5.addTextlabel("l_joint","DIRECTION (PRISMATIC ONLY)",TAB_X,TAB_Y));
00420                 l_jointdir.setWidth(200);
00421                 l_jointdir.moveTo("joint properties");
00422 
00423                 t_jointdir = new Textfield[3];
00424                 t_jointdir[0] = GreyTheme.applyStyle(controlP5.addTextfield("dir_x",TAB_X,    TAB_Y+15, 40,20).setCaptionLabel("dir_x"));
00425                 t_jointdir[1] = GreyTheme.applyStyle(controlP5.addTextfield("dir_y",TAB_X+50, TAB_Y+15, 40,20).setCaptionLabel("dir_y"));
00426                 t_jointdir[2] = GreyTheme.applyStyle(controlP5.addTextfield("dir_z",TAB_X+100,TAB_Y+15, 40,20).setCaptionLabel("dir_z"));
00427                 
00428                 for(Textfield t : t_jointdir) { // for using the tab key
00429                         t.moveTo("joint properties");
00430                         t.setAutoClear(false);
00431                         t_all_joint.add(t);
00432                 }
00433 
00434                 
00435                 l_jointlim = GreyTheme.applyStyle(controlP5.addTextlabel("l_jointlim","JOINT LIMITS",TAB_X,TAB_Y+60));
00436                 l_jointlim.setWidth(200);
00437                 l_jointlim.moveTo("joint properties");
00438 
00439                 t_jointlim = new Textfield[2];
00440                 t_jointlim[0] = GreyTheme.applyStyle(controlP5.addTextfield("q_min",TAB_X,    TAB_Y+75, 40,20).setCaptionLabel("q_min"));
00441                 t_jointlim[1] = GreyTheme.applyStyle(controlP5.addTextfield("q_max",TAB_X+50, TAB_Y+75, 40,20).setCaptionLabel("q_max"));
00442                 
00443                 for(Textfield t : t_jointlim) { // for using the tab key
00444                         t.moveTo("joint properties");
00445                         t.setAutoClear(false);
00446                         t_all_joint.add(t);
00447                 }
00448                 
00449 
00450                 l_radius = GreyTheme.applyStyle(controlP5.addTextlabel("l_radius","RADIUS",TAB_X+100,TAB_Y+60));
00451                 l_radius.setWidth(200);
00452                 l_radius.moveTo("joint properties");
00453 
00454                 t_radius = GreyTheme.applyStyle(controlP5.addTextfield("radius",TAB_X+100,    TAB_Y+75, 40,20).setCaptionLabel("radius"));
00455                 t_radius.moveTo("joint properties");
00456                 
00457 
00458                 b_child = GreyTheme.applyStyle(controlP5.addButton("select child", 26, UPDATE_X, UPDATE_Y-40, 72, 20));
00459                 b_child.moveTo("joint properties");
00460 
00461                 t_child = GreyTheme.applyStyle(controlP5.addTextfield("child", UPDATE_X+85, UPDATE_Y-40, 130, 20));
00462                 t_child.moveTo("joint properties");
00463                 
00464                 
00465 
00466                 // settings tab
00467                 Textlabel l_settings = GreyTheme.applyStyle(controlP5.addTextlabel("l_settings","GLOBAL SETTINGS",OBJ_ID_X,OBJ_ID_Y));
00468                 l_settings.setWidth(200);
00469                 l_settings.moveTo("settings");
00470                 
00471                 t_namespace = GreyTheme.applyStyle(controlP5.addTextfield("OWL NAMESPACE",OBJ_ID_X, OBJ_ID_Y+15, 250, 20));
00472                 
00473                 if(map_namespace!=null && !map_namespace.equals("")) {
00474                         t_namespace.setText(map_namespace);
00475                 } else {
00476                         t_namespace.setText("http://ias.cs.tum.edu/kb/ias_semantic_map.owl#");
00477                 }
00478                 t_namespace.moveTo("settings");
00479                 
00480                 // init semantic map ID with a generated quasi-unique string
00481                 t_map_id = GreyTheme.applyStyle(controlP5.addTextfield("MAP IDENTIFIER",OBJ_ID_X, OBJ_ID_Y+55, 250, 20));
00482                 
00483                 if(map_id!=null && !map_id.equals("")) {
00484                         t_map_id.setText(map_id);
00485                 } else {
00486                         t_map_id.setText("SemanticEnvironmentMap" + 
00487                                         new SimpleDateFormat("yyyyMMddHHmmss").
00488                                         format(Calendar.getInstance().getTime()));
00489                 }
00490                 t_map_id.moveTo("settings");
00491                 
00492                 
00493                 cp5_initialized  = true;
00494                 
00495         }
00496 
00497 
00499         //
00500         //
00501         // HANDLE USER EVENTS
00502         //
00503         //
00505         
00510         public void controlEvent(controlP5.ControlEvent theControlEvent) {
00511                 
00512                 if(theControlEvent.isController()) {
00513                         
00514                         // update button
00515                         if(theControlEvent.getName().equals("add to map")) {
00516                                 
00517                                 // read information from the forms, create/update objects[] entry
00518                                 String obj = readFormData();
00519 
00520                                 if(obj!=null)
00521                                         mapVisApplet.addObject(obj);
00522                                 
00523                         }
00524                         
00525 
00526                         if(theControlEvent.getName().equals("new")) {
00527 
00528                                 clearFormFields(); // new object is implicitly created when a new identifier is used
00529                         }
00530                         
00531 
00532                         if(theControlEvent.getName().equals("delete")) {
00533 
00534                                 if(t_id.getText() != null) {
00535                                         objects.remove(t_id.getText());
00536                                         
00537                                         String id = t_id.getText();
00538                                         OWLThing rem = OWLThing.getOWLThingByShortname(id);
00539                                         ObjectInstance reminst = (ObjectInstance) rem; 
00540                                         
00541                                         for(ObjectInstance o : objects.values()) {
00542                                                 
00543                                                 if(o.hasPhysicalPart(reminst)) {
00544                                                         o.removePhysicalPart(reminst);
00545                                                 }
00546                                                 
00547                                                 Vector<String> propval = o.getObjPropValues("http://ias.cs.tum.edu/kb/knowrob.owl#connectedTo-Rigidly");
00548                                                 if(propval!=null && propval.contains(reminst.getIRI())) {
00549                                                         propval.remove(reminst.getIRI());
00550                                                 }
00551                                                 
00552                                                 propval = o.getObjPropValues("http://ias.cs.tum.edu/kb/knowrob.owl#hingedTo");
00553                                                 if(propval!=null && propval.contains(reminst.getIRI())) {
00554                                                         propval.remove(reminst.getIRI());
00555                                                 }
00556                                                 
00557                                                 propval = o.getObjPropValues("http://ias.cs.tum.edu/kb/knowrob.owl#prismaticallyConnectedTo");
00558                                                 if(propval!=null && propval.contains(reminst.getIRI())) {
00559                                                         propval.remove(reminst.getIRI());
00560                                                 }
00561                                         }
00562                                         
00563                                         PrologQueryUtils.deleteObjectInstance(reminst.getIRI());
00564                                         clearFormFields(); // reset interface
00565                                         
00566                                         mapVisApplet.removeObject(rem.getIRI());
00567                                         mapVisApplet.redraw();
00568                                 }
00569                         }
00570 
00571 
00572                         if(theControlEvent.getName().equals("rot_x")) {
00573                                 ObjectInstance cur = ((ObjectInstance) OWLThing.getOWLThingByShortname(t_id.getText())); 
00574                                 cur.getPoseMatrix().mul(new Matrix4d(
00575                                                 1, 0, 0,  0,
00576                                                 0, 0, -1, 0,
00577                                                 0, 1, 0,  0,
00578                                                 0, 0, 0,  1));
00579                                 cur.setSaveToProlog(true);
00580                                 cur.writeToProlog();
00581                                 
00582 
00583                                 mapVisApplet.removeObject(cur.getIRI());
00584                                 mapVisApplet.addObject(cur.getIRI());
00585                                 mapVisApplet.redraw();
00586                                 writeFormData(cur);
00587                         }
00588                         
00589                         if(theControlEvent.getName().equals("rot_y")) {
00590                                 ObjectInstance cur = ((ObjectInstance) OWLThing.getOWLThingByShortname(t_id.getText())); 
00591                                 cur.getPoseMatrix().mul(new Matrix4d(
00592                                                 0,      0,      1, 0,
00593                                                 0,      1,      0, 0,
00594                                            -1,  0,      0, 0,
00595                                                 0,  0,  0, 1));
00596                                 cur.setSaveToProlog(true);
00597                                 cur.writeToProlog();
00598                                 
00599 
00600                                 mapVisApplet.removeObject(cur.getIRI());
00601                                 mapVisApplet.addObject(cur.getIRI());
00602                                 mapVisApplet.redraw();
00603                                 writeFormData(cur);
00604                         }
00605                         
00606                         if(theControlEvent.getName().equals("rot_z")) {
00607                                 ObjectInstance cur = ((ObjectInstance) OWLThing.getOWLThingByShortname(t_id.getText())); 
00608                                 cur.getPoseMatrix().mul(new Matrix4d(
00609                                                 0,-1, 0,  0,
00610                                                 1, 0, 0, 0,
00611                                                 0, 0, 1,  0,
00612                                                 0, 0, 0,  1));
00613                                 cur.setSaveToProlog(true);
00614                                 cur.writeToProlog();
00615                                 
00616 
00617                                 mapVisApplet.removeObject(cur.getIRI());
00618                                 mapVisApplet.addObject(cur.getIRI());
00619                                 mapVisApplet.redraw();
00620                                 writeFormData(cur);
00621                         }
00622                         
00623 
00624                         if(theControlEvent.getName().equals("export to owl")) {
00625                                 saveMapToFile(t_filename.getText());
00626                         }
00627 
00628                         if(theControlEvent.getName().equals("select parent")) {
00629 
00630                                 selectParentObj=true;
00631                                 cursor(HAND);
00632                                 this.mapVisApplet.cursor(HAND);
00633                                 
00634                         }
00635                         
00636                         if(theControlEvent.getName().equals("select child")) {
00637 
00638                                 selectChildObj=true;
00639                                 cursor(HAND);
00640                                 this.mapVisApplet.cursor(HAND);
00641                                 
00642                         }
00643                         
00644                         
00645                         
00646                 // switch tabs (update information in the tabs)
00647                 } else if (theControlEvent.isTab()) {
00648                         
00649                         if(theControlEvent.getName().equals("default")) {
00650                                 this.tab = Tab.SIMPLE;
00651                                 showObjSpecificElements();
00652                                 
00653                         } else if (theControlEvent.getName().equals("matrix")) {
00654                                 this.tab = Tab.MATRIX;
00655                                 showObjSpecificElements();
00656                                 
00657                         } else if (theControlEvent.getName().equals("quaternion")) {
00658                                 this.tab = Tab.QUATERNION;
00659                                 showObjSpecificElements();
00660 
00661                         } else if (theControlEvent.getName().equals("settings")) {
00662                                 this.tab = Tab.SETTINGS;
00663                                 hideObjSpecificElements();
00664                                 
00665                         } else if (theControlEvent.getName().equals("joint properties")) {
00666                                 this.tab = Tab.JOINTS;
00667                                 showObjSpecificElements();
00668                                 
00669                                 // deactivate fields that are not available for the current object type
00670                                 showJointSpecificFormFields();
00671 
00672                         }
00673                         
00674                         
00675                 } else if (theControlEvent.isGroup()) {
00676                         
00677                         // handle listbox events
00678                         if(theControlEvent.getGroup().getId()==42) {
00679                                 t_types.getCaptionLabel().set( objClasses.get( (int) theControlEvent.getGroup().getValue()) );
00680                                 
00681                         }
00682                 }
00683                 redraw();
00684         }
00685 
00686 
00687         public void saveMapToFile(String filename) {
00688                 
00689                 OWLImportExport exp = new OWLImportExport();
00690                 
00691                 RDFXMLOntologyFormat format = new RDFXMLOntologyFormat();
00692                 format.setPrefix("knowrob:", "http://ias.cs.tum.edu/kb/knowrob.owl#");
00693                 format.setPrefix("owl:", "http://www.w3.org/2002/07/owl#");
00694                 format.setPrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#");
00695                 format.setPrefix("map:", t_namespace.getText());
00696                 
00697                 OWLOntology ont = exp.createOWLMapDescription(map_namespace, map_id, new ArrayList<ObjectInstance>(this.objects.values()));
00698                 
00699                 OWLFileUtils.saveOntologyToFile(ont, format, filename);
00700         }
00701 
00702 
00703         private void hideObjSpecificElements() {
00704                 
00705 
00706                 b_new_obj.hide();
00707                 b_del_obj.hide();
00708                 b_update.hide();
00709                 t_id.hide();
00710                 t_types.hide();
00711                 
00712                 l_dim.hide();
00713                 for(Textfield t : t_dim)
00714                         t.hide();
00715                                 
00716                 for(Button b : b_rot)
00717                         b.hide();
00718 
00719         }
00720         
00721         private void showObjSpecificElements() {
00722 
00723                 b_new_obj.show();
00724                 b_del_obj.show();
00725                 b_update.show();
00726                 t_id.show();
00727                 t_types.show();
00728                 
00729                 l_dim.show();
00730                 for(Textfield t : t_dim)
00731                         t.show();
00732                                 
00733                 for(Button b : b_rot)
00734                         b.show();
00735         }
00736         
00737         
00738         private void showJointSpecificFormFields() {
00739                 // draw joint limits and child selection for all kinds of joints
00740                 if(t_types.getCaptionLabel().getText().equals("PrismaticJoint") || 
00741                                 t_types.getCaptionLabel().getText().equals("HingedJoint")) {
00742                         l_jointlim.show();
00743                         for(Textfield t : t_jointlim) {
00744                                 t.show();
00745                         }
00746                         t_child.show();
00747                         b_child.show();
00748                 } else {
00749                         l_jointlim.hide();
00750                         for(Textfield t : t_jointlim) {
00751                                 t.hide();
00752                         }
00753                         t_child.hide();
00754                         b_child.hide();
00755                 }
00756 
00757                 // draw direction fields only for prismatic joints
00758                 if(t_types.getCaptionLabel().getText().equals("PrismaticJoint")) {
00759                         l_jointdir.show();
00760                         for(Textfield t : t_jointdir) {
00761                                 t.show();
00762                         }
00763                 } else {
00764                         l_jointdir.hide();
00765                         for(Textfield t : t_jointdir) {
00766                                 t.hide();
00767                         }
00768                 }
00769 
00770 
00771                 // draw direction fields only for rotational joints
00772                 if(t_types.getCaptionLabel().getText().equals("HingedJoint")) {
00773                         l_radius.show();
00774                         t_radius.show();
00775                 } else {
00776                         l_radius.hide();
00777                         t_radius.hide();
00778                 }
00779         }
00780         
00781         
00791         public void keyPressed() {
00792                 
00793                 keys[keyCode] = true;
00794                 
00795                 // ENTER key updates visualization
00796                 if (key == ENTER || key == RETURN) {
00797                         String obj = readFormData();
00798                         
00799                         if(obj!=null) {
00800                                 mapVisApplet.removeObject(obj);
00801                                 mapVisApplet.addObject(obj);
00802                         }
00803                 }
00804                 
00805                 
00806                 // switch through the text fields using TAB
00807                 if (keyCode == KeyEvent.VK_TAB) {
00808                         
00809                         boolean fwd = true; // direction to skip through the fields
00810                         if(checkKey(KeyEvent.VK_SHIFT)) {
00811                                 fwd=false;
00812                         }
00813                         
00814                         if(this.tab==Tab.SIMPLE) {
00815                                 switchFocus(t_all_simple, fwd);
00816                         } else if(this.tab==Tab.MATRIX) {
00817                                 switchFocus(t_all_matrix, fwd);
00818                         } else if(this.tab==Tab.QUATERNION) {
00819                                 switchFocus(t_all_quat, fwd);
00820                         } else if(this.tab==Tab.JOINTS) {
00821                                 switchFocus(t_all_joint, fwd);
00822                         }
00823 
00824                 }
00825                 
00826                 if (keyCode == KeyEvent.VK_PAGE_UP) {
00827                         
00828                         if(this.tab==Tab.SIMPLE) {
00829                                 incTextfieldValue(t_all_simple, 0.05f);
00830                         } else if(this.tab==Tab.MATRIX) {
00831                                 incTextfieldValue(t_all_matrix, 0.05f);
00832                         } else if(this.tab==Tab.QUATERNION) {
00833                                 incTextfieldValue(t_all_quat, 0.05f);
00834                         } else if(this.tab==Tab.JOINTS) {
00835                                 incTextfieldValue(t_all_joint, 0.05f);
00836                         }
00837                         String obj = readFormData();
00838                         
00839                         if(obj!=null) {
00840                                 mapVisApplet.removeObject(obj);
00841                                 mapVisApplet.addObject(obj);
00842                         }
00843                 }
00844                 
00845                 if (keyCode == KeyEvent.VK_PAGE_DOWN) {
00846                         
00847                         if(this.tab==Tab.SIMPLE) {
00848                                 incTextfieldValue(t_all_simple, -0.05f);
00849                         } else if(this.tab==Tab.MATRIX) {
00850                                 incTextfieldValue(t_all_matrix, -0.05f);
00851                         } else if(this.tab==Tab.QUATERNION) {
00852                                 incTextfieldValue(t_all_quat, -0.05f);
00853                         } else if(this.tab==Tab.JOINTS) {
00854                                 incTextfieldValue(t_all_joint, -0.05f);
00855                         }
00856                         String obj = readFormData();
00857                         
00858                         if(obj!=null) {
00859                                 mapVisApplet.removeObject(obj);
00860                                 mapVisApplet.addObject(obj);
00861                         }
00862                 }
00863                 
00864         }
00865 
00866         
00867         
00872         public void keyReleased() { 
00873           keys[keyCode] = false; 
00874         }
00875         
00876         
00883         boolean checkKey(int k) {
00884                 return keys[k];
00885         }
00886 
00887         
00896         protected void switchFocus(ArrayList<Textfield> t_all, boolean forward) {
00897                 
00898                 for(int i=0;i<t_all.size();i++) {
00899                         if(t_all.get(i).isActive()){
00900                                 
00901                                 if(forward) {
00902                                         t_all.get(i).setFocus(false);
00903                                         t_all.get((i+1)%t_all.size()).setFocus(true);
00904                                 } else {
00905                                         t_all.get(i).setFocus(false);
00906                                         
00907                                         if(i>0)
00908                                                 t_all.get(i-1).setFocus(true);
00909                                         else 
00910                                                 t_all.get(t_all.size()-1).setFocus(true);
00911                                 }
00912                                 break;
00913                         }
00914                 }
00915         }
00916         
00917         
00924         protected void incTextfieldValue(ArrayList<Textfield> t_all, float inc) {
00925                 
00926                 for(int i=0;i<t_all.size();i++) {
00927                         if(t_all.get(i).isActive()){
00928                                 
00929                                 try{
00930                                         float val = Float.valueOf(t_all.get(i).getText());
00931                                         t_all.get(i).setText((val+inc)+"");
00932                                 } catch(NumberFormatException e) {}
00933                                 
00934                         }
00935                 }
00936         }
00937         
00938         
00939 
00940 
00942         //
00943         //
00944         // READ AND WRITE FORM DATA
00945         //
00946         //
00948         
00949         
00950         
00954         protected String readFormData() {
00955                 
00956                 // check if the object already exists or if we should create a new one
00957                 
00958                 ObjectInstance cur;
00959                 String shortname =  t_id.getText();
00960                 String namespace = t_namespace.getText();
00961                 
00962                 // skip this if the ID or class are not set
00963                 if(t_id.equals("") || t_types.getCaptionLabel().getText().equals("object class")){
00964                         return null;
00965                 }
00966                 
00967                 if(objects.containsKey(shortname)) {
00968                         cur = objects.get(shortname);
00969                 } else {
00970                         
00971                         if(t_types.getCaptionLabel().getText().equals("HingedJoint") ||
00972                            t_types.getCaptionLabel().getText().equals("PrismaticJoint")) {
00973                                 
00974                                 cur = JointInstance.getMapJoint(namespace + shortname);
00975                                 
00976                         } else {
00977                                 cur = ObjectInstance.getObjectInstance(namespace + shortname);
00978                         }
00979                         objects.put(shortname, cur);
00980                 }
00981                 
00982                  
00983                 // get OWL class based on their shortname (which is used for display)
00984                 cur.addType((OWLClass) OWLThing.getOWLThingByShortname(t_types.getCaptionLabel().getText()));
00985 
00986                 
00987                 double xdim=0.0, ydim=0.0, zdim=0.0;
00988                 try{xdim = Double.valueOf(t_dim[0].getText());} catch(NumberFormatException e) {}
00989                 try{ydim = Double.valueOf(t_dim[1].getText());} catch(NumberFormatException e) {}
00990                 try{zdim = Double.valueOf(t_dim[2].getText()); } catch(NumberFormatException e) {}
00991                 cur.setDimensions(new Vector3d(xdim, ydim, zdim));
00992 
00993                 
00994                 
00995                 // set per-tab values
00996                 switch(tab) {
00997                 
00998                         case SIMPLE:
00999                                 // set only position
01000                                 double x=0.0, y=0.0, z=0.0;
01001                                 try{x = Double.valueOf(t_pos[0].getText());} catch(NumberFormatException e) {}
01002                                 try{y = Double.valueOf(t_pos[1].getText());} catch(NumberFormatException e) {}
01003                                 try{z = Double.valueOf(t_pos[2].getText());} catch(NumberFormatException e) {}
01004                                 
01005                                 cur.setPosition(new Vector3d(x, y, z ));
01006                                 updateQuaternionForm(cur.getPosition(), cur.getPoseQuaternion());
01007                                 updateMatrixForm(cur.getPoseMatrix());
01008                                 break;
01009                                 
01010                         case MATRIX:
01011                                 
01012                                 double[] m = new double[16];
01013                                 
01014                                 try{m[0] = Double.valueOf(t_matrix[0].getText());} catch(NumberFormatException e) {m[0]=0.0;}
01015                                 try{m[1] = Double.valueOf(t_matrix[1].getText());} catch(NumberFormatException e) {m[1]=0.0;}
01016                                 try{m[2] = Double.valueOf(t_matrix[2].getText());} catch(NumberFormatException e) {m[2]=0.0;}
01017                                 try{m[3] = Double.valueOf(t_matrix[3].getText());} catch(NumberFormatException e) {m[3]=0.0;}
01018                                 
01019                                 try{m[4] = Double.valueOf(t_matrix[4].getText());} catch(NumberFormatException e) {m[4]=0.0;}
01020                                 try{m[5] = Double.valueOf(t_matrix[5].getText());} catch(NumberFormatException e) {m[5]=0.0;}
01021                                 try{m[6] = Double.valueOf(t_matrix[6].getText());} catch(NumberFormatException e) {m[6]=0.0;}
01022                                 try{m[7] = Double.valueOf(t_matrix[7].getText());} catch(NumberFormatException e) {m[7]=0.0;}
01023                                 
01024                                 try{m[8] = Double.valueOf(t_matrix[8].getText());} catch(NumberFormatException e) {m[8]=0.0;}
01025                                 try{m[9] = Double.valueOf(t_matrix[9].getText());} catch(NumberFormatException e) {m[9]=0.0;}
01026                                 try{m[10] = Double.valueOf(t_matrix[10].getText());} catch(NumberFormatException e) {m[10]=0.0;}
01027                                 try{m[11] = Double.valueOf(t_matrix[11].getText());} catch(NumberFormatException e) {m[11]=0.0;}
01028                                 
01029                                 try{m[12] = Double.valueOf(t_matrix[12].getText());} catch(NumberFormatException e) {m[12]=0.0;}
01030                                 try{m[13] = Double.valueOf(t_matrix[13].getText());} catch(NumberFormatException e) {m[13]=0.0;}
01031                                 try{m[14] = Double.valueOf(t_matrix[14].getText());} catch(NumberFormatException e) {m[14]=0.0;}
01032                                 try{m[15] = Double.valueOf(t_matrix[15].getText());} catch(NumberFormatException e) {m[15]=0.0;}
01033                                 
01034                                 cur.setPoseMatrix(new Matrix4d(m));
01035                                 updateQuaternionForm(cur.getPosition(), cur.getPoseQuaternion());
01036                                 updatePositionForm(cur.getPosition());
01037                                 break;
01038 
01039                         case QUATERNION:
01040                                 
01041                                 try{x = Double.valueOf(t_qpos[0].getText());} catch(NumberFormatException e) {x=0.0;}
01042                                 try{y = Double.valueOf(t_qpos[1].getText());} catch(NumberFormatException e) {y=0.0;}
01043                                 try{z = Double.valueOf(t_qpos[2].getText());} catch(NumberFormatException e) {z=0.0;}
01044                                 
01045                                 double qx=0.0, qy=0.0, qz=0.0, qw=1.0;
01046                                 try{qw = Double.valueOf(t_quat[0].getText());} catch(NumberFormatException e) {}
01047                                 try{qy = Double.valueOf(t_quat[1].getText());} catch(NumberFormatException e) {}
01048                                 try{qz = Double.valueOf(t_quat[2].getText());} catch(NumberFormatException e) {}
01049                                 try{qz = Double.valueOf(t_quat[3].getText());} catch(NumberFormatException e) {}
01050                                 
01051                                 cur.setPoseQuaternion(new Vector3d(x,y,z), 
01052                                                                 new Quat4d(qx,qy,qz,qw),1.0);
01053                                 
01054                                 updateMatrixForm(cur.getPoseMatrix());
01055                                 updatePositionForm(cur.getPosition());
01056                                 break;
01057                                 
01058                         case JOINTS:
01059                                 
01060                                 
01061                                 if(t_types.getCaptionLabel().getText().equals("HingedJoint") ||
01062                                    t_types.getCaptionLabel().getText().equals("PrismaticJoint")) {
01063                                         
01064                                         // set direction of prismatic joints
01065                                         try{x = Double.valueOf(t_jointdir[0].getText());} catch(NumberFormatException e) {x=0.0;}
01066                                         try{y = Double.valueOf(t_jointdir[1].getText());} catch(NumberFormatException e) {y=0.0;}
01067                                         try{z = Double.valueOf(t_jointdir[2].getText());} catch(NumberFormatException e) {z=0.0;}
01068 
01069                                         ((JointInstance) cur).setDirection(new Vector3d(x,y,z));
01070 
01071                                         // set joint limits
01072                                         double q_min=0.0, q_max=0.0;
01073                                         try{q_min = Double.valueOf(t_jointlim[0].getText());} catch(NumberFormatException e) {}
01074                                         try{q_max = Double.valueOf(t_jointlim[1].getText());} catch(NumberFormatException e) {}
01075                                         
01076                                         ((JointInstance) cur).setQ_min(q_min);
01077                                         ((JointInstance) cur).setQ_max(q_max);
01078                                         
01079                                         double radius=0.0;
01080                                         try{
01081                                                 radius = Double.valueOf(t_radius.getText());} 
01082                                         catch(NumberFormatException e) {
01083                                                 e.printStackTrace();
01084                                         }
01085                                         ((JointInstance) cur).setRadius(radius);
01086                                         
01087                                         
01088                                         // set child/parent fields (hinges have only one each)
01089                                         if(t_child.getText() != null) {
01090                                                 if(objects.get(t_child.getText())!=null)
01091                                                         ((JointInstance) cur).setChild(objects.get(t_child.getText()));
01092                                         }
01093 
01094                                         if(t_parent.getText() != null) {
01095                                                 if(objects.get(t_parent.getText())!=null)
01096                                                         ((JointInstance) cur).setParent(objects.get(t_parent.getText()));
01097                                         }
01098 
01099                                 }
01100                                 updateMatrixForm(cur.getPoseMatrix());
01101                                 updateQuaternionForm(cur.getPosition(), cur.getPoseQuaternion());
01102                                 updatePositionForm(cur.getPosition());
01103                                 break;
01104                 }
01105 
01106                 // set object as physicalPart of parent object
01107                 if(t_parent.getText() != null && !t_parent.getText().isEmpty()) {
01108                         if(objects.get(t_parent.getText())!=null) {
01109                                 objects.get(t_parent.getText()).addPhysicalPart(cur);
01110                         }
01111                 }
01112                 
01113                 // synchronize with Prolog if initialized
01114                 if(PrologInterface.isInitialized()) {
01115                         cur.setSaveToProlog(true);
01116                         cur.writeToProlog();
01117                 }
01118                 return cur.getIRI();
01119         }
01120         
01126         void writeFormData(ObjectInstance cur) {
01127                 
01128                 t_id.setText(cur.getShortName());
01129                 
01130                 
01131                 // find object that has this object as physical part
01132                 for(ObjectInstance o : objects.values()) {
01133 
01134                         if(o.hasPhysicalPart(cur)) {
01135                                 t_parent.setText(o.getShortName());
01136                                 break;
01137                         } else {
01138                                 t_parent.setText("");
01139                         }
01140                 }
01141                 
01142                 t_types.getCaptionLabel().set(cur.getTypes().get(0).getShortName());
01143 
01144                 t_dim[0].setText(""+cur.getDimensions().x);
01145                 t_dim[1].setText(""+cur.getDimensions().y);
01146                 t_dim[2].setText(""+cur.getDimensions().z);
01147                 
01148                 updateQuaternionForm(cur.getPosition(), cur.getPoseQuaternion());
01149                 updateMatrixForm(cur.getPoseMatrix());
01150                 updatePositionForm(cur.getPosition());
01151                 updateJointForm(cur);
01152         }
01153         
01154         
01160         void updateMatrixForm(Matrix4d m) {
01161                 
01162                 t_matrix[0].setText(""+m.m00);
01163                 t_matrix[1].setText(""+m.m01);
01164                 t_matrix[2].setText(""+m.m02);
01165                 t_matrix[3].setText(""+m.m03);
01166                 
01167                 t_matrix[4].setText(""+m.m10);
01168                 t_matrix[5].setText(""+m.m11);
01169                 t_matrix[6].setText(""+m.m12);
01170                 t_matrix[7].setText(""+m.m13);
01171                 
01172                 t_matrix[8].setText(""+m.m20);
01173                 t_matrix[9].setText(""+m.m21);
01174                 t_matrix[10].setText(""+m.m22);
01175                 t_matrix[11].setText(""+m.m23);
01176                 
01177                 t_matrix[12].setText(""+m.m30);
01178                 t_matrix[13].setText(""+m.m31);
01179                 t_matrix[14].setText(""+m.m32);
01180                 t_matrix[15].setText(""+m.m33);
01181         }
01182 
01188         void updatePositionForm(Vector3d pos) {
01189                 
01190                 t_pos[0].setText(""+pos.x);
01191                 t_pos[1].setText(""+pos.y);
01192                 t_pos[2].setText(""+pos.z);
01193         }
01194         
01195         
01202         void updateQuaternionForm(Vector3d pos, Quat4d q) {
01203                 
01204                 t_qpos[0].setText(""+pos.x);
01205                 t_qpos[1].setText(""+pos.y);
01206                 t_qpos[2].setText(""+pos.z);
01207                 
01208                 t_quat[0].setText(""+q.w);
01209                 t_quat[1].setText(""+q.x);
01210                 t_quat[2].setText(""+q.y);
01211                 t_quat[3].setText(""+q.z);
01212         }
01213         
01219         void updateJointForm(ObjectInstance cur) {
01220                 
01221                 showJointSpecificFormFields();
01222                 
01223                 if(cur instanceof JointInstance) {
01224                         t_jointlim[0].setText(((JointInstance)cur).getQ_min()+"");
01225                         t_jointlim[1].setText(((JointInstance)cur).getQ_max()+"");
01226                         
01227                         t_jointdir[0].setText(((JointInstance)cur).getDirection().x+"");
01228                         t_jointdir[1].setText(((JointInstance)cur).getDirection().y+"");
01229                         t_jointdir[2].setText(((JointInstance)cur).getDirection().z+"");
01230                         
01231                         if(((JointInstance)cur).getChild()!=null && ((JointInstance)cur).getChild().getShortName() != null)
01232                                 t_child.setText(((JointInstance)cur).getChild().getShortName());
01233                         
01234                         if(((JointInstance)cur).getParent()!=null && ((JointInstance)cur).getParent().getShortName() != null)
01235                                 t_parent.setText(((JointInstance)cur).getParent().getShortName());
01236                         
01237                         t_radius.setText(((JointInstance)cur).getRadius()+"");
01238                 }
01239                 
01240         }
01241         
01242         void clearFormFields(){
01243                 
01244                 for(Textfield t : t_all_simple) {
01245                         t.setText("");
01246                 }
01247                 for(Textfield t : t_all_matrix) {
01248                         t.setText("");
01249                 }
01250                 for(Textfield t : t_all_quat) {
01251                         t.setText("");
01252                 }
01253                 
01254         }
01255         
01256 
01258         //
01259         //
01260         // MANAGE OBJECT INSTANCES
01261         //
01262         //
01264 
01268         public void selectAndLoadInputFile() {
01269 
01270                 String filename = selectInput();
01271                 if (filename != null) {
01272                         loadInputFile(filename);
01273                 }
01274         }
01275         
01281         public void loadInputFile(String filename) {
01282 
01283                 // clean up if re-loading a map
01284                 for(ObjectInstance o : objects.values()) {
01285                         OWLThing.removeOWLThing(o.getIRI());
01286                 }
01287                 this.objects.clear();
01288                 
01289                 if(map_id!=null && !map_id.equals("")) {
01290                         PrologQueryUtils.deleteObjectInstanceWithChildren(map_namespace + map_id);
01291                         mapVisApplet.clear();
01292                 }
01293                 
01294                 // load map from OWL
01295                 if (filename != null) {
01296                         this.objects = OWLImportExport.readObjectInstanceFromOWL(filename);     
01297                 }
01298                 PrologQueryUtils.parseOwlFile(filename);
01299                 
01300                 String mapInstance = PrologQueryUtils.getSemanticMapInstance(null, null, null, null);           
01301                 if(mapInstance != null) {
01302                         mapInstance = PrologInterface.removeSingleQuotes(mapInstance);
01303                         setMapIdentifier(OWLThing.getShortNameOfIRI(mapInstance));
01304                         setNamespace(OWLThing.getPrefixOfIRI(mapInstance) + "#");
01305                         
01306                         if(t_map_id!=null) {
01307                                 t_map_id.setText(map_id);
01308                         }
01309                         if(t_namespace!=null) {
01310                                 t_namespace.setText(map_namespace);
01311                         }
01312                 }
01313                 
01314                 for(ObjectInstance o : objects.values()) {
01315                         mapVisApplet.addObjectWithChildren(o.getIRI());
01316                 }
01317                 mapVisApplet.redraw();
01318         }
01319         
01320 
01322         //
01323         //
01324         // INTERFACE WITH PROLOG CANVAS
01325         //
01326         //
01328 
01329         
01335         public void setMapVisApplet(SemanticMapVisApplet app) {
01336                 this.mapVisApplet = app;
01337         }
01338 
01339         
01350         public void editObject(String identifier) {
01351 
01352                 if(identifier==null)
01353                         return;
01354                 
01355                 // special mode: select the parent object for the currently edited object
01356                 if(selectParentObj) {
01357                         
01358                         ObjectInstance cur = objects.get(t_id.getText());
01359                         
01360                         // clear previous parent objects
01361                         for(ObjectInstance o : objects.values()) {
01362                                 if(o.getPhysicalParts().contains(cur)) {
01363                                         o.removePhysicalPart(cur);
01364                                 }
01365                         }
01366                         
01367                         objects.get(identifier).addPhysicalPart(cur);
01368                         
01369                         if(cur instanceof JointInstance)
01370                                 ((JointInstance) cur).parent = objects.get(identifier);
01371                                 
01372                         this.t_parent.setText(identifier);
01373                         
01374                         selectParentObj=false;
01375                         cursor(ARROW);
01376                         mapVisApplet.cursor(ARROW);
01377                         
01378                         
01379                         
01380                 } else if(selectChildObj) {
01381                                 
01382                                 ObjectInstance cur = objects.get(t_id.getText());
01383                                 
01384                                 // clear previous parent objects
01385                                 for(ObjectInstance o : objects.values()) {
01386                                         if(o.hasPhysicalPart(cur)) {
01387                                                 o.removePhysicalPart(cur);
01388                                         }
01389                                 }
01390 
01391                                 if(cur instanceof JointInstance)
01392                                         ((JointInstance) cur).child = objects.get(identifier);
01393                                 
01394                                 this.t_child.setText(identifier);
01395                                 
01396                                 selectChildObj=false;
01397                                 cursor(ARROW);
01398                                 mapVisApplet.cursor(ARROW);
01399                         
01400 
01401                                 
01402                 } else {
01403                         // normal mode: load information about the object the user clicked on into the form fields 
01404                         writeFormData(objects.get(OWLThing.getShortNameOfIRI(identifier)));
01405                 }
01406         }
01407 
01408 
01409         public void setMapIdentifier(String mapID) {
01410                 map_id = mapID;
01411         }
01412 
01413         public void setNamespace(String namespace) {
01414                 map_namespace  = namespace;
01415         }
01416         
01417 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


mod_semantic_map
Author(s): Moritz Tenorth
autogenerated on Thu May 23 2013 08:54:30