コード例 #1
0
ファイル: elemmakepkg.go プロジェクト: fwachs/go-xsd
func (me *Documentation) makePkg(bag *PkgBag) {
	me.elemBase.beforeMakePkg(bag)
	if len(me.CDATA) > 0 {
		var s, ln string
		for _, ln = range ustr.Split(me.CDATA, "\n") {
			if s = strings.Trim(ln, " \t\r\n"); len(s) > 0 {
				bag.appendFmt(false, "//\t%s", s)
			}
		}
	}
	me.elemBase.afterMakePkg(bag)
}
コード例 #2
0
ファイル: elemmakepkg.go プロジェクト: fwachs/go-xsd
func (me *Union) makePkg(bag *PkgBag) {
	var memberTypes []string
	var rtn, rtnSafeName, safeName string
	me.elemBase.beforeMakePkg(bag)
	me.hasElemsSimpleType.makePkg(bag)
	memberTypes = ustr.Split(me.MemberTypes, " ")
	for _, st := range me.SimpleTypes {
		memberTypes = append(memberTypes, st.Name.String())
	}
	for _, mt := range memberTypes {
		rtn = bag.resolveQnameRef(mt, "T", nil)
		safeName, rtnSafeName = bag.safeName(ustr.PrependIf(bag.Stacks.CurSimpleType().Name.String(), "T")), bag.safeName(rtn)
		bag.ctd.addMethod(me, safeName, "To"+rtnSafeName, rtn, sfmt(ustr.Ifs(bag.isParseType(rtn), "var x = new(%v); x.Set(me.String()); return *x", "return %v(me)"), rtn), sfmt("%v is an XSD union-type of several types. This is a simple type conversion to %v, but keep in mind the actual value may or may not be a valid %v value.", safeName, rtnSafeName, rtnSafeName), me.Annotation)
	}
	me.elemBase.afterMakePkg(bag)
}
コード例 #3
0
ファイル: convert.go プロジェクト: go3d/go-collada
func processNode(xn *xmlx.Node) {
	if (!Force) && (xn.Name.Local == "COLLADA") {
		if _, ver := ugo.ParseVersion(attVal(xn, "version")); ver >= 1.5 {
			skipped = true
			return
		}
	}
	xn.Name.Space = ""
	for _, att := range xn.Attributes {
		att.Name.Space = ""
	}
	switch xn.Name.Local {
	case "COLLADA":
		setAttr(xn, "version", "1.5", false)
		setAttr(xn, "xmlns", "http://www.collada.org/2008/03/COLLADASchema", false)
	case "array":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "array", "newparam", "setparam") {
			delNode(xn)
		}
	case "argument", "texenv":
		delAttr(xn, "unit")
	case "cg_value_type", "connect_param", "generator", "tapered_capsule", "tapered_cylinder", "texture_unit":
		delNode(xn)
	case "code", "include":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "profile_CG", "profile_GLES2", "profile_GLSL") {
			delNode(xn)
		}
	case "color_target", "depth_target", "stencil_target":
		if val := surfaceImages[xn.Value]; len(val) == 0 {
			setAttr(ensureChild(xn, "param"), "ref", xn.Value, false)
		} else {
			setAttr(ensureChild(xn, "instance_image"), "url", "#"+val, false)
		}
		xn.Value = ""
	case "float_array":
		restrictAttr(xn, "digits", 1, 17)
		restrictAttr(xn, "magnitude", -324, 308)
	case "image":
		convertImage(xn)
	case "instance_effect":
		if xn.Parent.Name.Local == "render" {
			id := fmt.Sprintf("render_%v", time.Now().UnixNano())
			matNode := xmlx.NewNode(xn.Type)
			matNode.Name.Local = "material"
			setAttr(matNode, "id", id, false)
			matsLibNode := ensureChild(srcDoc.Root.Children[0], "library_materials")
			matsLibNode.AddChild(matNode)
			oldParent := xn.Parent
			_, pos := moveNode(xn, matNode, "")
			instNode := xmlx.NewNode(xn.Type)
			instNode.Name.Local = "instance_material"
			setAttr(instNode, "url", "#"+id, false)
			instNode.Parent = oldParent
			oldParent.Children[pos] = instNode
		}
	case "magfilter", "minfilter", "mipfilter":
		if (xn.Value == "NONE") && (xn.Name.Local != "mipfilter") {
			xn.Value = "NEAREST"
		} else {
			switch xn.Value {
			case "NEAREST_MIPMAP_NEAREST":
				ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "NEAREST"})
			case "LINEAR_MIPMAP_NEAREST":
				ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "NEAREST"})
			case "NEAREST_MIPMAP_LINEAR":
				ensureSiblings(xn, map[string]string{"minfilter": "NEAREST", "mipfilter": "LINEAR"})
			case "LINEAR_MIPMAP_LINEAR":
				ensureSiblings(xn, map[string]string{"minfilter": "LINEAR", "mipfilter": "LINEAR"})
			}
		}
	case "mipmap_bias":
		renameNode(xn, "mip_bias")
	case "mipmap_maxlevel":
		renameNode(xn, "mip_max_level")
	case "newparam":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "effect", "profile_CG", "profile_COMMON", "profile_GLSL", "profile_GLES", "profile_GLES2") {
			delNode(xn)
		}
	case "radius":
		if vals := ustr.Split(xn.Value, " "); (xn.Parent.Name.Local == "capsule") && (len(vals) > 0) && (len(vals) < 3) {
			for len(vals) < 3 {
				vals = append(vals, "1.0")
			}
			xn.Value = strings.Join(vals, " ")
		}
	case "setparam":
		if !ustr.IsOneOf(xn.Parent.Name.Local, "instance_effect", "usertype") {
			delNode(xn)
		}
	case "shader":
		convertShader(xn)
	case "surface":
		convertSurface(xn)
	case "texture_pipeline":
		if xn.Parent.Name.Local != "states" {
			delNode(xn)
		}
	case "transparent":
		setAttr(xn, "opaque", "A_ONE", true)
	case "usertype":
		renameAttr(xn, "name", "typename")
		if !ustr.IsOneOf(xn.Parent.Name.Local, "newparam", "setparam", "array", "bind_uniform") {
			delNode(xn)
		} else {
			for _, sn := range xn.Children {
				if sn.Name.Local != "setparam" {
					delNode(sn)
				}
			}
		}
	default:
		if (xn.Parent != nil) && (xn.Parent.Name.Local == "pass") {
			switch xn.Name.Local {
			case "annotate", "extra", "evaluate", "states", "program":
				break
			case "color_target", "depth_target", "stencil_target", "color_clear", "depth_clear", "stencil_clear", "draw":
				moveNode(xn, ensureChild(xn.Parent, "evaluate"), "")
			case "shader":
				moveNode(xn, ensureChild(xn.Parent, "program"), "")
			default:
				moveNode(xn, ensureChild(xn.Parent, "states"), "")
			}
		}
		if strings.HasPrefix(xn.Name.Local, "wrap_") && (xn.Value == "NONE") {
			xn.Value = "BORDER"
		}
		if (xn.Name.Local != "sampler") && strings.HasPrefix(xn.Name.Local, "sampler") && !strings.HasPrefix(xn.Name.Local, "sampler_") {
			if sn := subNode(xn, "source"); sn != nil {
				sn.Name.Local = "instance_image"
				setAttr(sn, "url", "#"+surfaceImages[sn.Value], false)
				sn.Value = ""
			}
		}
	}
	for _, sn := range xn.Children {
		processNode(sn)
	}
}
コード例 #4
0
ファイル: convert.go プロジェクト: go3d/go-collada
func convertSurface(xn *xmlx.Node) {
	var (
		imgNode, imgCreateNode, imgCreateFormatNode, rn, sn, tn *xmlx.Node
		ensureCreateNode                                        = func() *xmlx.Node {
			if imgCreateNode == nil {
				if rn = subNode(imgNode, "init_from"); rn != nil {
					imgNode.RemoveChild(rn)
				}
				imgCreateNode = ensureChild(imgNode, "create_"+strings.ToLower(attVal(xn, "type")))
				if rn != nil {
					imgCreateNode.AddChild(rn)
				}
			}
			return imgCreateNode
		}
		ensureCreateFormatNode = func(exact, hint bool) *xmlx.Node {
			imgCreateFormatNode = ensureChild(ensureCreateNode(), "format")
			if hint {
				ensureChild(imgCreateFormatNode, "hint")
			}
			if exact {
				ensureChild(imgCreateFormatNode, "exact")
			}
			return imgCreateFormatNode
		}
	)
	surfaceNodes = append(surfaceNodes, xn)
	myID, imgID, initNode := attVal(xn.Parent, "sid"), "", subNode(xn, "init_as_target")
	if len(myID) == 0 {
		myID = attVal(xn.Parent, "ref")
	}
	if myID = ustr.StripPrefix(myID, "#"); len(myID) > 0 {
		if initNode != nil {
			imgID = fmt.Sprintf("img_target_%v", time.Now().UnixNano())
			imgNode, rn = xmlx.NewNode(xn.Type), xmlx.NewNode(xn.Type)
			imgNode.Name.Local, rn.Name.Local = "image", "renderable"
			setAttr(imgNode, "id", imgID, false)
			setAttr(rn, "share", "true", false)
			imgNode.AddChild(rn)
			moveNode(imgNode, nil, "library_images")
		} else if initNode = subNode(xn, "init_from"); initNode != nil {
			imgID = initNode.Value
		} else {
			for _, sn = range xn.Children {
				if strings.HasPrefix(sn.Name.Local, "init_") {
					initNode = sn
					break
				}
			}
			if initNode != nil {
				for _, sn = range initNode.Children {
					if imgID = attVal(sn, "ref"); len(imgID) > 0 {
						break
					}
				}
			}
		}
		if imgID = ustr.StripPrefix(imgID, "#"); len(imgID) > 0 {
			surfaceImages[myID] = imgID
			if imgNode == nil {
				for _, sn = range subNode(srcDoc.Root.Children[0], "library_images").Children {
					if attVal(sn, "id") == imgID {
						imgNode = sn
						break
					}
				}
			}
		}
		if imgNode != nil {
			if tn = subNode(xn, "format"); tn != nil {
				subNode(ensureCreateFormatNode(true, false), "exact").Value = tn.Value
			}
			if tn = subNode(xn, "format_hint"); tn != nil {
				rn = subNode(ensureCreateFormatNode(false, true), "hint")
				if sn = subNode(tn, "channels"); sn != nil {
					setAttr(rn, "channels", sn.Value, false)
				}
				if sn = subNode(tn, "range"); sn != nil {
					setAttr(rn, "range", sn.Value, false)
				}
				if sn = subNode(tn, "precision"); sn != nil {
					setAttr(rn, "precision", sn.Value, false)
				}
				if sn = subNode(tn, "option"); sn != nil {
					setAttr(rn, "space", sn.Value, false)
				}
			}
			if tn = subNode(xn, "size"); tn != nil {
				vals := ustr.Split(tn.Value, " ")
				rn = ensureChild(ensureCreateNode(), "size_exact")
				if len(vals) > 0 {
					setAttr(rn, "width", vals[0], false)
				}
				if len(vals) > 1 {
					setAttr(rn, "height", vals[1], false)
				}
				if len(vals) > 2 {
					setAttr(rn, "depth", vals[2], false)
				}
			}
			if tn = subNode(xn, "viewport_ratio"); tn != nil {
				vals := ustr.Split(tn.Value, " ")
				rn = ensureChild(ensureCreateNode(), "size_ratio")
				setAttr(rn, "width", vals[0], false)
				setAttr(rn, "height", vals[1], false)
			}
			if tn = subNode(xn, "mip_levels"); tn != nil {
				setAttr(ensureChild(ensureCreateNode(), "mips"), "levels", tn.Value, false)
			}
			if tn = subNode(xn, "mipmap_generate"); tn != nil {
				setAttr(ensureChild(ensureCreateNode(), "mips"), "auto_generate", tn.Value, false)
			}
		}
	}
}