public static CvtValuePath FromTemplateDefinition(DocTemplateDefinition dtd, DocProject docProject) { if (dtd.Rules.Count > 0 && dtd.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)dtd.Rules[0]; DocEntity docEnt = docProject.GetDefinition(dtd.Type) as DocEntity; if (docEnt != null) { CvtValuePath pathInner = null; if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { pathInner = FromModelRule((DocModelRuleEntity)docRuleAtt.Rules[0], docProject); } DocAttribute docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); string identifier = null; if (docRuleAtt.Name.Equals("IsDefinedBy")) { // hack for compat docRuleAtt.ToString(); // look for identifier if (docRuleAtt.Rules.Count > 0) { try { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleAtt.Rules[0].Rules[0].Rules[0].Rules[1].Rules[0].Rules[0]; if (docRuleIndexCon != null) { if (docRuleIndexCon.Expression is DocOpStatement) { DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression; if (docOpStatement.Value != null) { identifier = docOpStatement.Value.ToString(); if (identifier.StartsWith("'") && identifier.EndsWith("'")) { identifier = identifier.Substring(1, identifier.Length - 2); } } } } } catch { } } } CvtValuePath pathRoot = new CvtValuePath(docEnt, docAtt, identifier, pathInner); return(pathRoot); } } return(null); }
private static CvtValuePath FromModelRule(DocModelRuleEntity docRuleEntity, DocProject docProject) { DocDefinition docDef = docProject.GetDefinition(docRuleEntity.Name); DocAttribute docAtt = null; string identifier = null; CvtValuePath pathInner = null; if (docDef is DocEntity && docRuleEntity.Rules.Count > 0 && docRuleEntity.Rules[0] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)docRuleEntity.Rules[0]; DocEntity docEnt = (DocEntity)docDef; docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject); if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity) { DocModelRuleEntity docRuleInner = (DocModelRuleEntity)docRuleAtt.Rules[0]; pathInner = FromModelRule(docRuleInner, docProject); // look for identifier if (docRuleInner.Rules.Count > 1 && docRuleInner.Rules[1] is DocModelRuleAttribute) { DocModelRuleAttribute docRuleIndexAtt = (DocModelRuleAttribute)docRuleInner.Rules[1]; if (docRuleIndexAtt.Rules.Count > 0) { DocModelRuleEntity docRuleIndexEnt = (DocModelRuleEntity)docRuleIndexAtt.Rules[0]; if (docRuleIndexEnt.Rules.Count > 0 && docRuleIndexEnt.Rules[0] is DocModelRuleConstraint) { DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleIndexEnt.Rules[0]; if (docRuleIndexCon.Expression is DocOpStatement) { DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression; if (docOpStatement.Value != null) { identifier = docOpStatement.Value.ToString(); if (identifier.StartsWith("'") && identifier.EndsWith("'")) { identifier = identifier.Substring(1, identifier.Length - 2); } } } } } } } } CvtValuePath pathOuter = new CvtValuePath(docDef, docAtt, identifier, pathInner); return(pathOuter); }
/// <summary> /// Parses a value path from string in ISO-10303-11 (EXPRESS) format. /// </summary> /// <param name="value"></param> /// <returns></returns> public static CvtValuePath Parse(string value, Dictionary <string, DocObject> map) { if (value == null) { return(null); } string[] tokens = value.Split(new char[] { '\\' }); //???// don't remove empty entries -- if it ends in backslash, then indicates type identifier CvtValuePath rootpath = null; CvtValuePath outerpath = null; foreach (string token in tokens) { CvtValuePath valuepath = new CvtValuePath(); string[] parts = token.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length >= 1 && map.ContainsKey(parts[0])) { valuepath.Type = map[parts[0]] as DocDefinition; if (valuepath.Type != null && parts.Length == 2) { string propname = parts[1]; int bracket = propname.IndexOf('['); if (bracket >= 0) { string content = propname.Substring(bracket + 1, propname.Length - bracket - 2); if (content.StartsWith("'") && content.EndsWith("'")) { // indexed by name valuepath.Identifier = content.Substring(1, content.Length - 2); } else if (content.StartsWith("@")) { // indexed by parameter for each line, e.g. value identifies column by name when importing/exporting spreadsheet valuepath.Identifier = content; } else if (content.Length == 0) { valuepath.Vector = true; } propname = propname.Substring(0, bracket); } if (valuepath.Type is DocEntity) { DocEntity docEntity = (DocEntity)valuepath.Type; valuepath.Property = docEntity.ResolveAttribute(propname, map); } } } // chain if (outerpath != null) { outerpath.InnerPath = valuepath; } else { rootpath = valuepath; } outerpath = valuepath; } // avoid empty head link if (rootpath.Type == null && rootpath.Property == null && rootpath.InnerPath != null) { rootpath = rootpath.InnerPath; } return(rootpath); }