1   /*****************************************************************************
2    *                   Virtual Mockup for Machine Vision
3    *  Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 
4    *                         Carlos S. Santos.
5    *   Virtual Mockup for Machine Vision Project funded by SENAC-SP
6    *
7    * Permission is granted to redistribute and/or modify this
8    * software under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16   * for more details.
17   *
18   *****************************************************************************/
19  
20  package camera3d;
21  
22  /***
23   *
24   * @author Fábio Roberto de Miranda e Carlos da Silva dos Santos
25   */
26  import org.jdom.*;
27  
28  class VcLaserArrayXMLHandler extends VcObjectXMLHandler {
29  
30    private static final String xBeamAttrib = "xBeam";
31    private static final String yBeamAttrib = "yBeam";
32    private static final String xDistAttrib = "xDist";
33    private static final String yDistAttrib = "yDist";
34    private static final String gizmoScaleAttrib ="GizmoScale";
35    private static final String redAttrib = "red";
36    private static final String blueAttrib = "blue";
37    private static final String greenAttrib = "green";
38  
39  
40    public VcLaserArrayXMLHandler() {
41         super();
42         this.type = "VcLaserArray";
43    }
44  
45     Element createElement(VcObject obj){
46         if(!(obj instanceof VcLaserArray))return null;
47         element = super.createElement(obj);
48         VcLaserArray vcla = (VcLaserArray) obj;
49         element.setAttribute(xBeamAttrib,Integer.toString(vcla.getXBeams()));
50         element.setAttribute(yBeamAttrib,Integer.toString(vcla.getYBeams()));
51         element.setAttribute(xDistAttrib,Double.toString(vcla.getXDelta()));
52         element.setAttribute(yDistAttrib,Double.toString(vcla.getYDelta()));
53         element.setAttribute(gizmoScaleAttrib,Double.toString(vcla.getTargetScale()));
54         element.setAttribute(redAttrib,Double.toString(vcla.getRed()));
55         element.setAttribute(greenAttrib,Double.toString(vcla.getGreen()));
56         element.setAttribute(blueAttrib,Double.toString(vcla.getBlue()));
57  
58         return element;
59    }
60  
61  
62    VcObject createObject(Element el){
63        if(!type.equals(el.getName())){
64         //System.out.println("__VcLaserArrayXMLHandler:"+ el.getName() + " expected: "+this.type);
65         return null;
66        }
67        //System.out.println("__VcLaserArrayXMLHandler:"+ el.getName() + " expected: "+this.type);
68  
69        int xb=2,yb=2;
70        double xd=.1,yd=.1,red=1.0,green=0.0,blue=0.0,scale=1.0;
71  
72        try{
73            xb = el.getAttribute(xBeamAttrib).getIntValue();
74            yb = el.getAttribute(yBeamAttrib).getIntValue();
75            xd = el.getAttribute(xDistAttrib).getDoubleValue();
76            yd = el.getAttribute(yDistAttrib).getDoubleValue();
77            red = el.getAttribute(redAttrib).getDoubleValue();
78            green = el.getAttribute(greenAttrib).getDoubleValue();
79            blue = el.getAttribute(blueAttrib).getDoubleValue();
80            scale = el.getAttribute(gizmoScaleAttrib).getDoubleValue();
81         }catch(org.jdom.DataConversionException dce){
82            dce.printStackTrace();
83         }
84  
85        VcLaserArray array = new VcLaserArray(xb,yb,xd,yd);
86        initializeObject(el,array);
87  
88        array.setColor(red,green,blue);
89        array.setTargetScale(scale);
90  
91        return (VcObject)array;
92    }
93  
94    void addObject(VcObject vcObject, J3DBase base){
95       if(!(vcObject instanceof VcLaserArray))return;
96         VcObject obj = base.getByLabel(vcObject.getLabel());
97         if(obj!=null){
98            if(obj instanceof VcLaserArray) base.removeVcObject(obj);
99            else obj.setLabel("_"+obj.getLabel());
100        }
101 
102      base.addLaserArray((VcLaserArray)vcObject);
103 
104   }
105 
106 }
This page was automatically generated by Maven