Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: emc/animation/emcAnimation.java


1   package emc.animation;
2   
3   import java.util.*;
4   import java.awt.*;
5   import java.applet.*;
6   import rcs.posemath.*;
7   import rcs.nml.*;
8   import rcs.utils.*;
9   
10  import emc.nml.*;
11  
12  class emcAnimationShape
13  {
14    static final int BOX_TYPE = 1;
15    static final int CYL_TYPE = 2;
16  
17  
18    boolean invisibleFromTop = false;
19    boolean invisibleFromFront = false;
20    boolean invisibleFromSide = false;
21  
22    int type;
23    Color c = Color.blue;
24    PM_POSE pose = new PM_POSE();
25  }
26  
27  
28  
29  class emcAnimationBox extends emcAnimationShape
30  {
31    double length;
32    double width;
33    double height;
34    
35    public emcAnimationBox()
36    {
37      type = BOX_TYPE;
38    }
39  
40    public String toString()
41    {
42      return "{ length="+length+", width="+width+", height="+height+", pose="+pose+" } ";
43    }
44  }
45  
46  class emcAnimationCyl extends emcAnimationShape
47  {
48    double length;
49    double radius;
50    int axis;
51  
52    public emcAnimationCyl()
53    {
54      type = CYL_TYPE;
55    }
56  
57    public String toString()
58    {
59      return "{ length="+length+", radius="+radius+", axis="+axis+", pose="+pose+" } ";
60    }
61  }
62  
63  public class emcAnimation extends Applet implements Runnable
64  {
65    EMC_STAT emcStatus = null;
66    NMLConnection emcStatusConnection = null;
67    Vector ShapeList = null;
68    Vector SortedTopShapeList = null;
69    Vector SortedFrontShapeList = null;
70    Vector SortedSideShapeList = null;
71    static public boolean debug_on = false;
72  
73    emcAnimationBox XAxisBox = null;
74    emcAnimationBox StockBox = null;
75    emcAnimationBox SpindleBox = null;
76    emcAnimationCyl Spindle = null;
77  
78   
79    public void InitializeShapeList()
80    {
81      ShapeList = new Vector();
82  
83  
84      emcAnimationBox box = new emcAnimationBox();
85      
86      // Grey tray at the base of minimill
87      box = new emcAnimationBox();
88      box.length = 10.0;
89      box.width = 10.0;
90      box.height = 2.0;
91      box.pose.tran.x = 2.0;
92      box.pose.tran.y = 2.0;
93      box.pose.tran.z = 2.0;
94      box.c = Color.gray;
95      ShapeList.addElement(box);
96  
97     // Blue tower
98      box = new emcAnimationBox();
99      box.length = 2.0;
100     box.width = 3.0;
101     box.height = 10.0;
102     box.pose.tran.x = 5.5;
103     box.pose.tran.y = 11.0;
104     box.pose.tran.z = 4.0;
105     box.c = Color.blue;
106     ShapeList.addElement(box); 
107     
108     // Black Y axis
109     box = new emcAnimationBox();
110     box.length = 10.0;
111     box.width = 3.0;
112     box.height = 1.0;
113     box.pose.tran.x = 5.5;
114     box.pose.tran.y = 1.0;
115     box.pose.tran.z = 4.0;
116     box.c = Color.darkGray;
117     ShapeList.addElement(box); 
118 
119     // Black X axis
120     box = new emcAnimationBox();
121     box.length = 3.0;
122     box.width = 12.0;
123     box.height = 1.0;
124     box.pose.tran.x = 1.0;
125     box.pose.tran.y = 6.0;
126     box.pose.tran.z = 5.0;
127     box.c = Color.darkGray;
128     XAxisBox = box;
129     ShapeList.addElement(box); 
130 
131     // Blue Wax Stock
132     box = new emcAnimationBox();
133     box.length = 3.0;
134     box.width =  3.0;
135     box.height = 1.0;
136     box.pose.tran.x = 5.5;
137     box.pose.tran.y = 6.0;
138     box.pose.tran.z = 6.0;
139     box.c = Color.blue;
140     StockBox = box;
141     ShapeList.addElement(box); 
142 
143 
144     // Black Z axis
145     box = new emcAnimationBox();
146     box.length = 1.0;
147     box.width = 3.0;
148     box.height = 9.0;
149     box.pose.tran.x = 5.5;
150     box.pose.tran.y = 10.0;
151     box.pose.tran.z = 5.0;
152     box.c = Color.darkGray;
153     ShapeList.addElement(box); 
154 
155 
156     // Blue Spindle Box
157     box = new emcAnimationBox();
158     box.length = 3.0;
159     box.width = 3.0;
160     box.height = 3.0;
161     box.pose.tran.x = 5.5;
162     box.pose.tran.y = 7.0;
163     box.pose.tran.z = 9.0;
164     box.c = Color.blue;
165     box.invisibleFromTop = true;
166     SpindleBox = box;
167     ShapeList.addElement(box); 
168 
169     // Spindle 
170     emcAnimationCyl cyl = new emcAnimationCyl();
171     cyl.length = 2.0;
172     cyl.radius = 0.25;
173     cyl.axis = 3;
174     cyl.pose.tran.x = 6.75;
175     cyl.pose.tran.y = 8.25;
176     cyl.pose.tran.z = 7.0;
177     cyl.c = Color.lightGray;
178     Spindle = cyl;
179     ShapeList.addElement(cyl);
180   }
181     
182   public void init()
183   {
184     try
185       {
186   emcStatusConnection = new NMLConnection(new emcStatDict(), "emcStatus", "emcAnimation", "emc.nml");
187 
188       }
189     catch(Exception e)
190       {
191   e.printStackTrace();
192       }
193     InitializeShapeList();
194   }
195 
196   Thread updatePositionThread = null;
197 
198   public void start()
199   {
200     if(null == updatePositionThread)
201       {
202   updatePositionThread = new Thread(this);
203   updatePositionThread.start();
204       }
205   }
206   
207   public void stop()
208   {
209     if(null != updatePositionThread)
210       {
211   updatePositionThread.stop();
212   updatePositionThread = null;
213       }
214   }
215 
216   public void run()
217   {
218     try
219       {
220   while(true)
221     {
222       UpdatePosition();
223       Thread.sleep(100);
224     }
225       }
226     catch(Exception e)
227       {
228   e.printStackTrace();
229       }
230   }
231 
232   double scale_x = 15.0;
233   double scale_y = 15.0;
234   double scale_z = 15.0;
235   
236   static final int SHOW_ALL = 0;
237   static final int SHOW_TOP = 1;
238   static final int SHOW_FRONT = 2;
239   static final int SHOW_SIDE = 3;
240   
241   int side_to_show = SHOW_ALL;
242   
243   public boolean mouseDown(Event evt, int x, int y)
244   {
245     if(side_to_show != SHOW_ALL)
246       {
247   side_to_show = SHOW_ALL;
248    scale_x = 15.0;
249    scale_y = 15.0;
250    scale_z = 15.0;
251   return true;
252       }
253 
254     if(x < size().width / 2)
255       {
256   if( y < size().height /2)
257     {
258       side_to_show = SHOW_TOP;
259       scale_x = 30.0;
260       scale_y = 30.0;
261       scale_z = 30.0;
262       return true;
263     }
264   else
265     {
266       side_to_show = SHOW_FRONT;
267       scale_x = 30.0;
268       scale_y = 30.0;
269       scale_z = 30.0;
270       return true;
271     }
272       }
273     else
274       {
275   side_to_show = SHOW_SIDE;
276   scale_x = 30.0;
277   scale_y = 30.0;
278   scale_z = 30.0;
279   return true;
280       }
281 
282   }
283 
284   public void paintTop(Graphics g)
285   {
286     try
287       {
288   Dimension d = size();
289   int viewx_offset = 0;
290   int viewy_offset = d.height/2;
291   if(side_to_show != SHOW_ALL)
292     {
293       viewy_offset = d.height;
294     }
295   for(int i = 0; i < SortedTopShapeList.size(); i++)
296     {
297       emcAnimationShape shape= (emcAnimationShape) SortedTopShapeList.elementAt(i);
298       if(shape.invisibleFromTop)
299         {
300     continue;
301         }
302        int x=0,y=0,height=0,width=0;
303       switch(shape.type)
304         {
305         case emcAnimationShape.BOX_TYPE:
306     emcAnimationBox box = (emcAnimationBox) shape;
307     if(debug_on)
308       {
309         System.out.println("PaintTop box="+box);
310       }
311     x = (int) (viewx_offset + (shape.pose.tran.x *scale_x));
312     y = (int) (viewy_offset - (shape.pose.tran.y *scale_y) - (box.length * scale_y) );
313     height = (int) (box.length * scale_y);
314     width = (int) (box.width * scale_x);
315     g.setColor(shape.c);
316     g.fillRect(x,y,width, height);
317     g.setColor(Color.black);
318     g.drawRect(x,y,width,height);
319     break;
320     
321         case emcAnimationShape.CYL_TYPE:
322     emcAnimationCyl cyl = (emcAnimationCyl) shape;
323     if(debug_on)
324       {
325         System.out.println("PaintTop cyl="+cyl);
326       }
327     switch(cyl.axis)
328       {
329       case 1: // X axis
330         x = (int) (viewx_offset+ (shape.pose.tran.x *scale_x));
331         y = (int) (viewy_offset - (shape.pose.tran.y *scale_y) - (cyl.radius*2 * scale_y) );
332         height = (int) (cyl.radius*2 * scale_y);
333         width = (int) (cyl.length * scale_x);
334         g.setColor(shape.c);
335         g.fillRect(x,y,width, height);
336         g.setColor(Color.black);
337         g.drawRect(x,y,width,height);
338         break;
339   
340       case 2: // Y axis
341         x = (int) (viewx_offset+ (shape.pose.tran.x *scale_x));
342         y = (int) (viewy_offset - (shape.pose.tran.y *scale_y) - (cyl.length * scale_y) );
343         height = (int) (cyl.length * scale_y);
344         width = (int) (cyl.radius*2 * scale_x);
345         g.setColor(shape.c);
346         g.fillRect(x,y,width, height);
347         g.setColor(Color.black);
348         g.drawRect(x,y,width,height);
349         break;
350 
351       case 3: // Z axis
352         x = (int) (viewx_offset+ (shape.pose.tran.x *scale_x));
353         y = (int) (viewy_offset - (shape.pose.tran.y *scale_y) - (cyl.radius*2 * scale_y) );
354         height = (int) (cyl.radius*2 * scale_y);
355         width = (int) (cyl.radius*2 * scale_x);
356 
357         g.setColor(shape.c);
358         g.fillOval(x,y,width, height);
359         g.setColor(Color.black);
360         g.drawOval(x,y,width,height);
361         break;
362       }
363     break;
364     
365         default:
366     break;
367         }
368       if(debug_on)
369         {
370     System.out.println("PaintTop x="+x+", y="+y+", height="+height+", width="+width);
371         }
372     }
373       }
374     catch(Exception e)
375       {
376   e.printStackTrace();
377       }
378   }
379 
380   public void paintFront(Graphics g)
381   {
382     try
383       {
384   Dimension d = size();
385   for(int i = 0; i < SortedFrontShapeList.size(); i++)
386     {
387       emcAnimationShape shape= (emcAnimationShape) SortedFrontShapeList.elementAt(i);
388       if(shape.invisibleFromFront)
389         {
390     continue;
391         }
392       int x=0,y=0,height=0,width=0;
393       switch(shape.type)
394         {
395         case emcAnimationShape.BOX_TYPE:
396     emcAnimationBox box = (emcAnimationBox) shape;
397     if(debug_on)
398       {
399         System.out.println("PaintFront box="+box);
400       }
401     x = (int) (shape.pose.tran.x *scale_x);
402     y = (int) ((d.height) - (shape.pose.tran.z *scale_z) - (box.height * scale_z));
403     height = (int) (box.height * scale_z);
404     width = (int) (box.width * scale_x);
405     g.setColor(shape.c);
406     g.fillRect(x,y,width, height);
407     g.setColor(Color.black);
408     g.drawRect(x,y,width,height);
409     break;
410     
411         case emcAnimationShape.CYL_TYPE:
412     emcAnimationCyl cyl = (emcAnimationCyl) shape;
413     if(debug_on)
414       {
415         System.out.println("PaintFront cyl="+cyl);
416       }
417     switch(cyl.axis)
418       {
419       case 1: // X axis
420         x = (int) (shape.pose.tran.x *scale_x);
421         y = (int) ((d.height) - (shape.pose.tran.z *scale_z) - (cyl.radius*2 * scale_z) );
422         height = (int) (cyl.radius*2 * scale_y);
423         width = (int) (cyl.length * scale_x);
424         g.setColor(shape.c);
425         g.fillRect(x,y,width, height);
426         g.setColor(Color.black);
427         g.drawRect(x,y,width,height);
428         break;
429   
430       case 2: // Y axis
431         x = (int) (shape.pose.tran.x *scale_x);
432         y = (int) ((d.height) - (shape.pose.tran.z *scale_z) - (cyl.radius*2 * scale_z) );
433         height = (int) (cyl.radius*2 * scale_z);
434         width = (int) (cyl.radius*2 * scale_x);
435         g.setColor(shape.c);
436         g.fillOval(x,y,width, height);
437         g.setColor(Color.black);
438         g.drawOval(x,y,width,height);
439         break;
440 
441       case 3: // Z axis
442         x = (int) (shape.pose.tran.x *scale_x);
443         y = (int) ((d.height) - (shape.pose.tran.z *scale_z) - (cyl.length * scale_z) );
444         height = (int) (cyl.length * scale_z);
445         width = (int) (cyl.radius*2 * scale_x);
446         g.setColor(shape.c);
447         g.fillRect(x,y,width, height);
448         g.setColor(Color.black);
449         g.drawRect(x,y,width,height);
450         break;
451       }
452     break;
453     
454         default:
455     break;
456         }
457       if(debug_on)
458         {
459     System.out.println("PaintFront x="+x+", y="+y+", height="+height+", width="+width);
460         }
461     }
462       }
463     catch(Exception e)
464       {
465   e.printStackTrace();
466       }
467   }
468 
469   public void paintSide(Graphics g)
470   {
471     try
472       {
473   Dimension d = size();
474   int viewx_offset = d.width/2;
475   int viewy_offset = d.height;
476   if(side_to_show != SHOW_ALL)
477     {
478       viewx_offset = 0;
479     }
480   for(int i = 0; i < SortedSideShapeList.size(); i++)
481     {
482       emcAnimationShape shape= (emcAnimationShape) SortedSideShapeList.elementAt(i);
483       if(shape.invisibleFromSide)
484         {
485     continue;
486         }
487       int x=0,y=0,height=0,width=0;
488       switch(shape.type)
489         {
490         case emcAnimationShape.BOX_TYPE:
491     emcAnimationBox box = (emcAnimationBox) shape;
492     if(debug_on)
493       {
494         System.out.println("PaintFront box="+box);
495       }
496     x = (int) (viewx_offset + (shape.pose.tran.y *scale_y));
497     y = (int) (viewy_offset - (shape.pose.tran.z *scale_z) - (box.height * scale_z));
498     height = (int) (box.height * scale_z);
499     width = (int) (box.length * scale_y);
500     g.setColor(shape.c);
501     g.fillRect(x,y,width, height);
502     g.setColor(Color.black);
503     g.drawRect(x,y,width,height);
504     break;
505     
506         case emcAnimationShape.CYL_TYPE:
507     emcAnimationCyl cyl = (emcAnimationCyl) shape;
508     if(debug_on)
509       {
510         System.out.println("PaintSide cyl="+cyl);
511       }
512     switch(cyl.axis)
513       {
514       case 1: // X axis
515         x = (int) (viewx_offset + (shape.pose.tran.y *scale_y));
516         y = (int) (viewy_offset - (shape.pose.tran.z *scale_z) - (cyl.radius*2 * scale_z) );
517         height = (int) (cyl.radius*2 * scale_y);
518         width = (int) (cyl.radius*2 * scale_x);
519         g.setColor(shape.c);
520         g.fillOval(x,y,width, height);
521         g.setColor(Color.black);
522         g.drawOval(x,y,width,height);
523         break;
524   
525       case 2: // Y axis
526         x = (int) (viewx_offset + (shape.pose.tran.y *scale_y));
527         y = (int) (viewy_offset - (shape.pose.tran.z *scale_z) - (cyl.radius*2 * scale_z) );
528         height = (int) (cyl.radius*2 * scale_z);
529         width = (int) (cyl.length * scale_x);
530         g.setColor(shape.c);
531         g.fillRect(x,y,width, height);
532         g.setColor(Color.black);
533         g.drawRect(x,y,width,height);
534         break;
535 
536       case 3: // Z axis
537         x = (int) (viewx_offset + (shape.pose.tran.y *scale_y));
538         y = (int) (viewy_offset - (shape.pose.tran.z *scale_z) - (cyl.length * scale_z) );
539         height = (int) (cyl.length * scale_z);
540         width = (int) (cyl.radius*2 * scale_y);
541         g.setColor(shape.c);
542         g.fillRect(x,y,width, height);
543         g.setColor(Color.black);
544         g.drawRect(x,y,width,height);
545         break;
546     
547       default:
548         break;
549       }
550     break;
551         }
552       if(debug_on)
553         {
554     System.out.println("PaintSide x="+x+", y="+y+", height="+height+", width="+width);
555         }
556     }
557       }
558     catch(Exception e)
559       {
560   e.printStackTrace();
561       }
562   }
563   
564   public void paintCross(Graphics g)
565   {
566     try
567       {
568   Dimension d = size();
569   g.setColor(Color.black);
570   g.drawLine(0,d.height/2, d.width, d.height/2);
571   g.drawLine(d.width/2,0, d.width/2, d.height);
572       }
573     catch(Exception e)
574       {
575   e.printStackTrace();
576       }
577   }
578 
579   public void paint(Graphics g)
580   {
581     setBackground(Color.white);
582     switch(side_to_show)
583       {
584       case SHOW_ALL:
585   paintTop(g); 
586   paintFront(g);
587   paintSide(g);
588   paintCross(g);
589   break;
590   
591       case SHOW_TOP:
592   paintTop(g);
593   break;
594 
595       case SHOW_FRONT:
596   paintFront(g);
597   break;
598 
599       case SHOW_SIDE:
600   paintSide(g);
601   break;
602       }
603   }
604 
605 
606   public void SortTopShapeList()
607   {
608     SortedTopShapeList = new Vector();
609     
610     for(int i = 0; i < ShapeList.size(); i++)
611       {
612   emcAnimationShape shape = (emcAnimationShape) ShapeList.elementAt(i);
613   
614   SortedTopShapeList.addElement(shape);
615       }
616     
617     for(int i = 0; i < SortedTopShapeList.size(); i++)
618       {
619   emcAnimationShape first_shape = (emcAnimationShape) SortedTopShapeList.elementAt(i);
620   double first_shape_top = 0;
621   switch(first_shape.type)
622     {
623     case emcAnimationShape.BOX_TYPE:
624       emcAnimationBox box = (emcAnimationBox) first_shape;
625       first_shape_top = box.pose.tran.z + box.height;
626       break;
627    
628     case emcAnimationShape.CYL_TYPE:
629     emcAnimationCyl cyl = (emcAnimationCyl) first_shape;
630     if(cyl.axis == 3)
631       {
632         first_shape_top = cyl.pose.tran.z + cyl.length;
633       }
634     else
635       {
636         first_shape_top = cyl.pose.tran.z + cyl.radius*2;
637       }
638     
639     break;
640           
641     default:
642       break;
643     }
644   for(int j = i+1; j < SortedTopShapeList.size(); j++)
645     {
646       emcAnimationShape last_shape = (emcAnimationShape) SortedTopShapeList.elementAt(j);
647       double last_shape_top = 0;
648       switch(last_shape.type)
649         {
650         case emcAnimationShape.BOX_TYPE:
651     emcAnimationBox box = (emcAnimationBox) last_shape;
652     last_shape_top = box.pose.tran.z + box.height;
653     break;
654 
655         case emcAnimationShape.CYL_TYPE:
656     emcAnimationCyl cyl = (emcAnimationCyl) last_shape;
657     if(cyl.axis == 3)
658       {
659         last_shape_top = cyl.pose.tran.z + cyl.length;
660       }
661     else
662       {
663         last_shape_top = cyl.pose.tran.z + cyl.radius*2;
664       }
665     if(cyl.axis == 3)
666       {
667         last_shape_top = cyl.pose.tran.z + cyl.length;
668       }
669     else
670       {
671         last_shape_top = cyl.pose.tran.z + cyl.radius*2;
672       }
673     break;
674       
675         default:
676     break;
677         }
678       if(last_shape_top < first_shape_top)
679         {
680     SortedTopShapeList.setElementAt(first_shape, j);
681     SortedTopShapeList.setElementAt(last_shape, i);
682     first_shape = last_shape;
683     first_shape_top = last_shape_top;
684         }
685     }
686       }
687   }
688 
689   public void SortFrontShapeList()
690   {
691     SortedFrontShapeList = new Vector();
692     
693     for(int i = 0; i < ShapeList.size(); i++)
694       {
695   emcAnimationShape shape = (emcAnimationShape) ShapeList.elementAt(i);
696   
697   SortedFrontShapeList.addElement(shape);
698       }
699     
700     for(int i = 0; i < SortedFrontShapeList.size(); i++)
701       {
702   emcAnimationShape first_shape = (emcAnimationShape) SortedFrontShapeList.elementAt(i);
703   double first_shape_front = 0;
704   switch(first_shape.type)
705     {
706     case emcAnimationShape.BOX_TYPE:
707       emcAnimationBox box = (emcAnimationBox) first_shape;
708       first_shape_front = box.pose.tran.y;
709       break;
710 
711     case emcAnimationShape.CYL_TYPE:
712       emcAnimationCyl cyl = (emcAnimationCyl) first_shape;
713       if(cyl.axis == 2)
714         {
715     first_shape_front = cyl.pose.tran.y + cyl.length;
716         }
717       else
718         {
719     first_shape_front = cyl.pose.tran.y + cyl.radius*2;
720         }
721       break;
722 
723     default:
724       break;
725     }
726   for(int j = i+1; j < SortedFrontShapeList.size(); j++)
727     {
728       emcAnimationShape last_shape = (emcAnimationShape) SortedFrontShapeList.elementAt(j);
729       double last_shape_front = 0;
730       switch(last_shape.type)
731         {
732         case emcAnimationShape.BOX_TYPE:
733     emcAnimationBox box = (emcAnimationBox) last_shape;
734     last_shape_front = box.pose.tran.y;
735     break;
736   
737     
738         case emcAnimationShape.CYL_TYPE:
739     emcAnimationCyl cyl = (emcAnimationCyl) last_shape;
740     if(cyl.axis == 2)
741       {
742         last_shape_front = cyl.pose.tran.y + cyl.length;
743       }
744     else
745       {
746         last_shape_front = cyl.pose.tran.y + cyl.radius*2;
747       }
748     break;
749 
750         default:
751     break;
752         }
753       if(last_shape_front > first_shape_front)
754         {
755     SortedFrontShapeList.setElementAt(first_shape, j);
756     SortedFrontShapeList.setElementAt(last_shape, i);
757     first_shape = last_shape;
758     first_shape_front = last_shape_front;
759         }
760     }
761       }
762   }
763 
764   public void SortSideShapeList()
765   {
766     SortedSideShapeList = new Vector();
767     
768     for(int i = 0; i < ShapeList.size(); i++)
769       {
770   emcAnimationShape shape = (emcAnimationShape) ShapeList.elementAt(i);
771   
772   SortedSideShapeList.addElement(shape);
773       }
774     
775     for(int i = 0; i < SortedSideShapeList.size(); i++)
776       {
777   emcAnimationShape first_shape = (emcAnimationShape) SortedSideShapeList.elementAt(i);
778   double first_shape_side =0;
779   switch(first_shape.type)
780     {
781     case emcAnimationShape.BOX_TYPE:
782       emcAnimationBox box = (emcAnimationBox) first_shape;
783       first_shape_side = box.pose.tran.x + box.width;
784       break;
785       
786     case emcAnimationShape.CYL_TYPE:
787       emcAnimationCyl cyl = (emcAnimationCyl) first_shape;
788       if(cyl.axis == 1)
789         {
790     first_shape_side = cyl.pose.tran.x + cyl.length;
791         }
792       else
793         {
794     first_shape_side = cyl.pose.tran.x + cyl.radius*2;
795         }
796       break;
797     default:
798       break;
799     }
800   for(int j = i+1; j < SortedSideShapeList.size(); j++)
801     {
802       emcAnimationShape last_shape = (emcAnimationShape) SortedSideShapeList.elementAt(j);
803       double last_shape_side = 0;
804       switch(last_shape.type)
805         {
806         case emcAnimationShape.BOX_TYPE:
807     emcAnimationBox box = (emcAnimationBox) last_shape;
808     last_shape_side = box.pose.tran.x + box.width;
809     break;
810       
811         case emcAnimationShape.CYL_TYPE:
812     emcAnimationCyl cyl = (emcAnimationCyl) last_shape;
813     if(cyl.axis == 1)
814       {
815         last_shape_side = cyl.pose.tran.x + cyl.length;
816       }
817     else
818       {
819         last_shape_side = cyl.pose.tran.x + cyl.radius*2;
820       }
821     break;
822 
823         default:
824     break;
825         }
826       if(last_shape_side < first_shape_side)
827         {
828     SortedSideShapeList.setElementAt(first_shape, j);
829     SortedSideShapeList.setElementAt(last_shape, i);
830     first_shape = last_shape;
831     first_shape_side = last_shape_side;
832         }
833     }
834       }
835   }
836       
837   
838   public boolean first_time = true;
839   public void UpdatePosition()
840   {
841     try
842       {
843   EMC_STAT emcStatusTemp = null;
844   emcStatusTemp = (EMC_STAT) emcStatusConnection.read();
845   if(null != emcStatusTemp || first_time)
846     {
847       emcStatus = emcStatusTemp;
848       if(null != emcStatus)
849         {
850     double x, y, z;
851     x = emcStatus.motion.traj.position.tran.x/emcStatus.motion.traj.linearUnits; // X Position in Millimeters.
852     y = emcStatus.motion.traj.position.tran.y/emcStatus.motion.traj.linearUnits; // Y Position in Millimeters.
853     z = emcStatus.motion.traj.position.tran.z/emcStatus.motion.traj.linearUnits; // Z Position in Millimeters.
854 
855     XAxisBox.pose.tran.y = 2.0 - y /60;
856     StockBox.pose.tran.y = 2.0 - y /60;
857     StockBox.pose.tran.x = 2.0 - x /50;
858     SpindleBox.pose.tran.z = 11.0 + z /82;
859     Spindle.pose.tran.z = 9.0 + z /82;
860         }
861       SortTopShapeList();
862       SortFrontShapeList();
863       SortSideShapeList();
864       first_time = false;
865       repaint();
866     }
867       }
868     catch(Exception e)
869       {
870   e.printStackTrace();
871       }
872   }
873 
874   public static  void main(String args[])
875   {
876     emcAnimation animation = new emcAnimation();
877     emcAnimationFrame f = new emcAnimationFrame("EMC Animation",animation);
878     f.resize(750,550);
879     
880     animation.init();
881     animation.start();
882     animation.show();
883 
884     f.add(animation);
885     f.show();
886   }
887 }
888