processing.data.XML Java Examples

The following examples show how to use processing.data.XML. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PloadShape.java    From warp10-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
  
  String xml = String.valueOf(stack.pop());
  
  Reader reader = new StringReader(xml);
  
  try {
    PShapeJava2D shape = new PShapeJava2D(new XML(reader, null));
  
    stack.push(shape);
  } catch (Exception e) {
    throw new WarpScriptException(getName() + " caught an exception while loading SVG.", e);
  }
      
  return stack;
}
 
Example #2
Source File: PlaneCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void loadFrom(PApplet parent, String fileName) {
    XML root = parent.loadXML(fileName);
    XML planeNode = root.getChild(PLANE_XML_NAME);
    XML posNode = planeNode.getChild(PLANE_POS_XML_NAME);
    XML normalNode = planeNode.getChild(PLANE_NORMAL_XML_NAME);
    XML heightNode = planeNode.getChild(PLANE_HEIGHT_XML_NAME);

    Vec3D position = getVectorFrom(posNode);
    Vec3D normal = getVectorFrom(normalNode);
    float h = heightNode.getFloat(PLANE_HEIGHT_XML_NAME);

    this.plane = new Plane();
    plane.set(position);
    plane.normal.set(normal);
    setHeight(h);
}
 
Example #3
Source File: PlanarTouchCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void setIn(XML xml) {
    xml.setFloat(MAX_DIST_XML_NAME, maximumDistance);
    xml.setFloat(MAX_DIST_INIT_XML_NAME, maximumDistanceInit);
    xml.setFloat(MIN_HEIGHT_XML_NAME, minimumHeight);
    xml.setFloat(NORMAL_FILTER_XML_NAME, normalFilter);

    xml.setInt(MIN_COPO_SIZE_XML_NAME, minimumComponentSize);
    xml.setInt(MAX_RECURSION_XML_NAME, maximumRecursion);
    xml.setInt(SEARCH_DEPTH_XML_NAME, searchDepth);
    xml.setInt(PRECISION_XML_NAME, precision);

    xml.setInt(TRACKING_FORGET_TIME_XML_NAME, trackingForgetTime);
    xml.setFloat(TRACKING_MAX_DIST_TIME_XML_NAME, trackingMaxDistance);

    xml.setFloat(TEST1_XML_NAME, test1);
    xml.setFloat(TEST2_XML_NAME, test2);
    xml.setFloat(TEST3_XML_NAME, test3);
    xml.setFloat(TEST4_XML_NAME, test4);
    xml.setFloat(TEST5_XML_NAME, test5);
}
 
Example #4
Source File: PlanarTouchCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void getFrom(XML xml) {
    maximumDistance = xml.getFloat(MAX_DIST_XML_NAME);
    maximumDistanceInit = xml.getFloat(MAX_DIST_INIT_XML_NAME);
    minimumComponentSize = xml.getInt(MIN_COPO_SIZE_XML_NAME);
    minimumHeight = xml.getFloat(MIN_HEIGHT_XML_NAME);
    maximumRecursion = xml.getInt(MAX_RECURSION_XML_NAME);

    searchDepth = xml.getInt(SEARCH_DEPTH_XML_NAME);
    precision = xml.getInt(PRECISION_XML_NAME);

    normalFilter = xml.getFloat(NORMAL_FILTER_XML_NAME);
    trackingForgetTime = xml.getInt(TRACKING_FORGET_TIME_XML_NAME);
    trackingMaxDistance = xml.getFloat(TRACKING_MAX_DIST_TIME_XML_NAME);

    test1 = xml.getFloat(TEST1_XML_NAME);
    test2 = xml.getFloat(TEST2_XML_NAME);
    test3 = xml.getFloat(TEST3_XML_NAME);
    test4 = xml.getFloat(TEST4_XML_NAME);
    test5 = xml.getFloat(TEST5_XML_NAME);
}
 
Example #5
Source File: MarkerBoardSvg.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
public MarkerBoardSvg(String fileName, float width, float height) {
        super(fileName, width, height);
        // Trackers not used
//        trackers = new ArrayList<>();
        this.type = MarkerType.SVG;

        try {
            // TODO: better than getting the Papart object...
            XML xml = Papart.getPapart().getApplet().loadXML(getFileName());

            markersFromSVG = (new MarkerSVGReader(xml)).getList();
//        markersFromSVG = MarkerSvg.getMarkersFromSVG(xml);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
Example #6
Source File: PlaneCalibrationTest.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void checkXML() {
    sketch = new Sketch();         String[] args = new String[]{"--present", "test.fr.inria.papart.calibration.ProjectiveCalibrationTest"};         PApplet.runSketch(args, sketch);
    instance = new PlaneCalibration();

    XML root = sketch.loadXML(Common.currentPath + Common.PlaneCalibration);
    assertTrue(root.getName() == Calibration.CALIBRATION_XML_NAME);

    XML planeNode = root.getChild(PlaneCalibration.PLANE_XML_NAME);
    assertNotNull(planeNode);

    XML posNode = planeNode.getChild(PlaneCalibration.PLANE_POS_XML_NAME);
    assertNotNull(posNode);
    XML normalNode = planeNode.getChild(PlaneCalibration.PLANE_NORMAL_XML_NAME);
    assertNotNull(normalNode);
    XML heightNode = planeNode.getChild(PlaneCalibration.PLANE_HEIGHT_XML_NAME);
    assertNotNull(heightNode);

    assertTrue(heightNode.getFloat(PlaneCalibration.PLANE_HEIGHT_XML_NAME) == DEFAULT_PLANE_HEIGHT);
}
 
Example #7
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void loadFrom(PApplet parent, String fileName) {
    XML root = parent.loadXML(fileName);
    XML resolutionNode = root.getChild(RESOLUTION_XML_NAME);
    this.width = resolutionNode.getInt(WIDTH_XML_NAME);
    this.height = resolutionNode.getInt(HEIGHT_XML_NAME);

    XML intrinsicsNode = root.getChild(INTRINSICS_XML_NAME);
    getMatFrom(intrinsicsNode, intrinsics);

    XML extrinsicsNode = root.getChild(EXTRINSICS_XML_NAME);
    if (extrinsicsNode == null) {
        this.hasExtrinsics = false;
        return;
    }
    getMatFrom(extrinsicsNode, extrinsics);

    checkExtrinsics();
}
 
Example #8
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void getMatFrom(XML node, PMatrix3D matrix) {
    matrix.m00 = node.getFloat("m00");
    matrix.m01 = node.getFloat("m01");
    matrix.m02 = node.getFloat("m02");
    matrix.m03 = node.getFloat("m03");
    matrix.m10 = node.getFloat("m10");
    matrix.m11 = node.getFloat("m11");
    matrix.m12 = node.getFloat("m12");
    matrix.m13 = node.getFloat("m13");
    matrix.m20 = node.getFloat("m20");
    matrix.m21 = node.getFloat("m21");
    matrix.m22 = node.getFloat("m22");
    matrix.m23 = node.getFloat("m23");
    matrix.m30 = node.getFloat("m30");
    matrix.m31 = node.getFloat("m31");
    matrix.m32 = node.getFloat("m32");
    matrix.m33 = node.getFloat("m33");
}
 
Example #9
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void setXmlTo(XML xml, PMatrix3D matrix) {
    xml.setFloat("m00", matrix.m00);
    xml.setFloat("m01", matrix.m01);
    xml.setFloat("m02", matrix.m02);
    xml.setFloat("m03", matrix.m03);
    xml.setFloat("m10", matrix.m10);
    xml.setFloat("m11", matrix.m11);
    xml.setFloat("m12", matrix.m12);
    xml.setFloat("m13", matrix.m13);
    xml.setFloat("m20", matrix.m20);
    xml.setFloat("m21", matrix.m21);
    xml.setFloat("m22", matrix.m22);
    xml.setFloat("m23", matrix.m23);
    xml.setFloat("m30", matrix.m30);
    xml.setFloat("m31", matrix.m31);
    xml.setFloat("m32", matrix.m32);
    xml.setFloat("m33", matrix.m33);
}
 
Example #10
Source File: QuadSurface.java    From sketch-mapper with MIT License 6 votes vote down vote up
private void setupCornerPoints(XML xml) {
    PVector[] points = new PVector[4];
    int index = 0;
    while (index < 4) {
        for (XML child : xml.getChildren()) {
            if (!"cornerpoint".equals(child.getName())) {
                continue;
            }
            float x = child.getFloat("x");
            float y = child.getFloat("y");
            points[index] = new PVector(x, y);
            index++;
        }
    }
    setCornerPoints(
            points[0].x, points[0].y,
            points[1].x, points[1].y,
            points[2].x, points[2].y,
            points[3].x, points[3].y
    );
}
 
Example #11
Source File: Manifest.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
public void setPermissions(String[] names) {
	// Check permissions from the template
	// e.g. watch face already has WAKE_LOCK
	// And don't add them if they're already there
	
	XML[] existingPermissionsXml = xml.getChildren("uses-permission");
	List<String> existingPermissions = new ArrayList<>(existingPermissionsXml.length);
	for (XML perm : existingPermissionsXml) {
		existingPermissions.add(perm.getString("android:name"));
	}
	
	for (String name : names) {
		if (!existingPermissions.contains(name)) {
			XML newbie = xml.addChild("uses-permission");
			newbie.setString("android:name", name);
		}
	}
}
 
Example #12
Source File: SurfaceMapper.java    From sketch-mapper with MIT License 5 votes vote down vote up
/**
 * Puts all projection mapping data in the XMLElement
 *
 * @param root
 */
public void save(XML root) {
    root.setName("ProjectionMap");
    // create XML elements for each surface containing the resolution
    // and control point data
    for (SuperSurface s : surfaces) {
        XML surf = new XML("surface");
        surf.setInt("type", s.getSurfaceType());
        surf.setInt("id", s.getId());
        surf.setString("name", s.getSurfaceName());
        surf.setInt("res", s.getRes());
        surf.setString("lock", String.valueOf(s.isLocked()));
        surf.setInt("horizontalForce", s.getHorizontalForce());
        surf.setInt("verticalForce", s.getVerticalForce());
        surf.setString("sketch", s.getSketch().getName());

        for (int i = 0; i < s.getCornerPoints().length; i++) {
            XML cp = new XML("cornerpoint");
            cp.setInt("i", i);
            cp.setFloat("x", s.getCornerPoint(i).x);
            cp.setFloat("y", s.getCornerPoint(i).y);
            surf.addChild(cp);

        }

        if (s.getSurfaceType() == SuperSurface.BEZIER) {
            for (int i = 0; i < 8; i++) {
                XML bp = new XML("bezierpoint");
                bp.setInt("i", i);
                bp.setFloat("x", s.getBezierPoint(i).x);
                bp.setFloat("y", s.getBezierPoint(i).y);
                surf.addChild(bp);
            }
        }
        root.addChild(surf);
    }
}
 
Example #13
Source File: SurfaceMapper.java    From sketch-mapper with MIT License 5 votes vote down vote up
/**
 * Save all projection mapping data to file
 *
 * @param file
 */
public void save(File file) {
    if (this.MODE == SurfaceMapper.MODE_CALIBRATE) {
        XML root = new XML("root");
        this.save(root);
        try {
            root.save(file);
        } catch (Exception e) {
            PApplet.println(e.getStackTrace());
        }
    }
}
 
Example #14
Source File: MarkerSVGReader.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
public MarkerSVGReader(XML in) {
        xml = in;

        // All sizes are in millimeters now in inkscape ?
        checkMmOrPixelsSizes();
//        if (!this.millimeterMode) {
        checkDPI();
//        } else {
//            System.out.println("Markerboard: Millimeter mode.");
//        }

        sheetWidthMm = computeSizeMM(xml.getString("width"));
        sheetHeightMm = computeSizeMM(xml.getString("height"));
        
//        System.out.println("Size of the markerboard: " + sheetWidthMm  + " " + sheetHeightMm);

        // Find if it uses any weird scales
        XML view = xml.getChild("sodipodi:namedview");
        if (view != null) {
            String units = view.getString("units");

            if (units == null) {
                units = view.getString("inkscape:document-units");
            }
            if (units != null && units.equals("px")) {
                String scale = view.getString("scale-x");
                if (scale == null) {
                    unitsToMM = PX_TO_MM_96_DPI; // default inkscape value...
                } else {
                    unitsToMM = Float.parseFloat(scale);
                }
            }
            if (units != null && units.equals("mm")) {
                unitsToMM = 1f;
            }
        }
    }
 
Example #15
Source File: Manifest.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
public String[] getPermissions() {
	XML[] elements = xml.getChildren("uses-permission");
	int count = elements.length;
	String[] names = new String[count];
	for (int i = 0; i < count; i ++) {
		names[i] = elements[i].getString("android:name");
	}
	return names;
}
 
Example #16
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addTo(XML xml) {
    xml.addChild(resolutionNode());
    xml.addChild(intrinsicNode());

    if (hasExtrinsics) {
        xml.addChild(extrinsicsNode());
    }
}
 
Example #17
Source File: PlaneCalibration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Vec3D getVectorFrom(XML node) {
    Vec3D v = new Vec3D();
    v.x = node.getFloat(X_XML_NAME);
    v.y = node.getFloat(Y_XML_NAME);
    v.z = node.getFloat(Z_XML_NAME);
    return v;
}
 
Example #18
Source File: PlaneCalibration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addTo(XML xml) {
    XML root = new XML(PLANE_XML_NAME);
    XML pos = createXML(PLANE_POS_XML_NAME, (Vec3D) plane);
    XML normal = createXML(PLANE_NORMAL_XML_NAME, plane.normal);
    XML height = new XML(PLANE_HEIGHT_XML_NAME);
    height.setFloat(PLANE_HEIGHT_XML_NAME, this.height);

    root.addChild(pos);
    root.addChild(normal);
    root.addChild(height);
    xml.addChild(root);
}
 
Example #19
Source File: PlaneCalibration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void replaceIn(XML xml) {
    XML planeNode = xml.getChild(PLANE_XML_NAME);
    setVectorIn(planeNode.getChild(PLANE_POS_XML_NAME), (Vec3D) plane);
    setVectorIn(planeNode.getChild(PLANE_NORMAL_XML_NAME), plane.normal);
    planeNode.getChild(PLANE_HEIGHT_XML_NAME).setFloat(PLANE_HEIGHT_XML_NAME, height);
}
 
Example #20
Source File: CameraConfiguration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
private XML createCameraNode() {
    XML cameraNode = new XML(CAMERA_XML_NAME);
    cameraNode.setString(CAMERA_NAME_XML_NAME, cameraName);
    cameraNode.setString(CAMERA_FORMAT_XML_NAME, cameraFormat);
    String type = this.cameraType.name();
    cameraNode.setString(CAMERA_TYPE_XML_NAME, type);

    return cameraNode;
}
 
Example #21
Source File: ScreenConfiguration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
private XML createScreenNode() {
    XML screenNode = new XML(SCREEN_XML_NAME);
    screenNode.setInt(SCREEN_WIDTH_XML_NAME, projectionScreenWidth);
    screenNode.setInt(SCREEN_HEIGHT_XML_NAME, projectionScreenHeight);
    screenNode.setInt(SCREEN_OFFSET_X_XML_NAME, projectionScreenOffsetX);
    screenNode.setInt(SCREEN_OFFSET_Y_XML_NAME, projectionScreenOffsetY);
    return screenNode;
}
 
Example #22
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void replaceIn(XML xml) {

    XML intrNode = xml.getChild(INTRINSICS_XML_NAME);
    xml.removeChild(intrNode);

    XML extrNode = xml.getChild(EXTRINSICS_XML_NAME);
    xml.removeChild(extrNode);

    XML resNode = xml.getChild(RESOLUTION_XML_NAME);
    xml.removeChild(resNode);

    addTo(xml);
}
 
Example #23
Source File: CameraConfiguration.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void loadFrom(PApplet parent, String fileName) {
    // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    XML root = parent.loadXML(fileName);

    XML cameraNode = root.getChild(CAMERA_XML_NAME);
    loadCameraFrom(cameraNode);
}
 
Example #24
Source File: PlanarTouchCalibration.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void replaceIn(XML xml) {
    XML element = xml.getChild(PLANAR_TOUCH_CALIBRATION_XML_NAME);
    setIn(element);
}
 
Example #25
Source File: EditorActivity.java    From APDE with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Load specified key bindings from the XML resource
 * 
 * @param xml
 */
public void loadKeyBindings(XML xml) {
	XML[] bindings = xml.getChildren();
	for(XML binding : bindings) {
		//Make sure that this is a "binding" element
		if(!binding.getName().equals("binding"))
			continue;
		
		//Parse the key binding
		String name = binding.getContent();
		int key = binding.getInt("key");
		
		//Load the list of possible key modifiers
		String modifiers = binding.getString("mod");
		String[] mods = modifiers.split("\\|"); // "|" is a REGEX keyword... need to escape it
		
		//The possible modifiers (these are available in API level 11+)
		boolean ctrl = false;
		boolean meta = false;
		boolean func = false;
		
		// (and these are available across all API levels)
		boolean alt = false;
		boolean sym = false;
		boolean shift = false;
		
		//This isn't very elegant... but it gets the job done
		for(String mod : mods) {
			if(mod.equals("ctrl")) ctrl = true;
			if(mod.equals("meta")) meta = true;
			if(mod.equals("func")) func = true;
			
			if(mod.equals("alt")) alt = true;
			if(mod.equals("sym")) sym = true;
			if(mod.equals("shift")) shift = true;
		}
		
		//Build the KeyBinding
		KeyBinding bind = new KeyBinding(name, key, ctrl, meta, func, alt, sym, shift);
		
		//Add the key binding
		keyBindings.put(name, bind);
	}
}
 
Example #26
Source File: Manifest.java    From APDE with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Save a new version of the manifest info to the build location.
 * Also fill in any missing attributes that aren't yet set properly.
 */
protected void writeCopy(File file, String className, ComponentTarget appComp) {
	// write a copy to the build location
	save(file);
	
	// load the copy from the build location and start messing with it
	try {
		XML mf = new XML(file);
		
		// package name, or default
		String p = mf.getString("package").trim();
		if (p.length() == 0) {
			mf.setString("package", SketchProperties.defaultPackageName(context.getSketchName()));
		}
		
		// app name and label, or the class name
		XML app = mf.getChild("application");
		String label = app.getString("android:label");
		if (label.length() == 0) {
			app.setString("android:label", className);
		}
		app.setString("android:debuggable", "true");
		
		// Services need the label also in the service section
		if (appComp == ComponentTarget.WALLPAPER || appComp == ComponentTarget.WATCHFACE) {
			XML serv = app.getChild("service");
			if (serv == null) {
				serv = app.addChild("service");
				serv.setString("android:label", className);
			} else {
				label = serv.getString("android:label");
				if (label.length() == 0) {
					serv.setString("android:label", className);
				}
			}
		}
		
		save(file);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #27
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
private XML resolutionNode() {
    XML node = new XML(RESOLUTION_XML_NAME);
    node.setInt(WIDTH_XML_NAME, width);
    node.setInt(HEIGHT_XML_NAME, height);
    return node;
}
 
Example #28
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
private XML intrinsicNode() {
    XML node = new XML(INTRINSICS_XML_NAME);
    setXmlTo(node, intrinsics);
    return node;
}
 
Example #29
Source File: ProjectiveDeviceCalibration.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
private XML extrinsicsNode() {
    XML node = new XML(EXTRINSICS_XML_NAME);
    setXmlTo(node, extrinsics);
    return node;
}
 
Example #30
Source File: SurfaceMapper.java    From sketch-mapper with MIT License 4 votes vote down vote up
/**
 * Load projection map from file
 *
 * @param file
 */
public void load(File file) {
    if (this.MODE == SurfaceMapper.MODE_CALIBRATE) {
        if (file.exists()) {
            this.setGrouping(false);
            selectedSurfaces.clear();
            surfaces.clear();
            try {
                XML root = new XML(file);
                for (int i = 0; i < root.getChildCount(); i++) {
                    if (root.getChild(i).getName().equals("surface")) {
                        SuperSurface loaded = null;
                        if (SuperSurface.BEZIER == root.getChild(i).getInt("type")) {
                            loaded = new BezierSurface(parent, this, root.getChild(i), root.getChild(i).getInt("id"), root.getChild(i).getString("name"));
                        } else {
                            loaded = new QuadSurface(parent, this, root.getChild(i), root.getChild(i).getInt("id"), root.getChild(i).getString("name"));
                        }
                        if (ccolor.length > 0)
                            loaded.setColor(ccolor[numAddedSurfaces % ccolor.length]);
                        loaded.setModeCalibrate();
                        final String sketch = root.getChild(i).getString("sketch");
                        if (null != sketch && sketch.trim().length() > 0) {
                            loadSketch(loaded, sketch);
                        }
                        surfaces.add(loaded);
                        numAddedSurfaces++;
                    }
                }
                if (this.getDebug())
                    PApplet.println("Projection layout loaded from " + file.getName() + ". " + surfaces.size()
                                    + " surfaces were loaded!");
            } catch (Exception e) {
                PApplet.println("Error loading configuration!!!");
                e.printStackTrace();
            }
        } else {
            if (this.getDebug())
                PApplet.println("ERROR loading XML! No projection layout exists!");
        }
    }

}