/// /// <summary> * get the sum of all matching AmountPool/PartAmount/@attName as a double PartAmounts match if all attributes /// * match those in PartAmount, i.e. mPart is a submap of the searche PartAmount elements /// * /// * </summary> /// * <param name="attName"> the Attribute name , e.g Amount, ActualAmount </param> /// * <param name="mPart"> </param> /// * <returns> double - the element </returns> /// * <exception cref="JDFException"> if the element can not be cast to double </exception> /// public static double getAmountPoolDouble(IAmountPoolContainer poolParent, string attName, JDFAttributeMap mPart) { double d = 0; int n = 0; bool bFound = false; JDFAmountPool ap = poolParent.getAmountPool(); while (true) { string w = getAmountPoolAttribute(poolParent, attName, null, mPart, n); if (isWildCard(w)) { if (ap == null || ap.getPartAmount(mPart, n) == null) { return(bFound ? d : -1); } n++; continue; } double dd = StringUtil.parseDouble(w, -1.234567); if (dd == -1.234567) { throw new JDFException("JDFResourceLink.getAmountPoolDouble: Attribute " + attName + " has an invalid value"); } d += dd; bFound = true; n++; } }
/// /// <summary> * returns the attribute occurence in PartAmount, or the default in the ResourceLink /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="vPart"> defines which part of this ResourceLink the Amount belongs to. If null get the ResourceLink root /// * attribute. </param> /// * <returns> value of attribute found, null if not available /// * @since 071103 </returns> /// public static string getAmountPoolAttribute(IAmountPoolContainer poolParent, string attrib, string nameSpaceURI, VJDFAttributeMap vPart) { // want a map but already in a partamount - snafu if (poolParent is JDFPartAmount) { if (vPart != null) { throw new JDFException("JDFResourceLink.getAmountPoolAttribute: calling method on PartAmount object"); } return(poolParent.getAttribute(attrib, nameSpaceURI, null)); } // default to attribute if no amountpool JDFAmountPool amountPool = poolParent.getAmountPool(); if (amountPool == null || vPart == null) { return(poolParent.getAttribute(attrib, nameSpaceURI, null)); } JDFPartAmount pa = amountPool.getPartAmount(vPart); if (pa != null) // we have a pa; if it has the attribute return its // value, else get the link attribute { string ret = pa.getAttribute(attrib, nameSpaceURI, null); if (ret != null) { return(ret); } } return(poolParent.getAttribute(attrib, nameSpaceURI, null)); }
public virtual void testGetPartAmountMulti() { JDFDoc d = new JDFDoc("JDF"); JDFNode n = d.getJDFRoot(); n.setType(EnumType.ConventionalPrinting); JDFComponent comp = (JDFComponent)n.addResource("Component", null, EnumUsage.Output, null, null, null, null); JDFAttributeMap map = new JDFAttributeMap(EnumPartIDKey.SignatureName, "Sig1"); JDFAttributeMap mapSig = new JDFAttributeMap(map); JDFAttributeMap map2 = new JDFAttributeMap(EnumPartIDKey.SignatureName, "Sig1"); JDFResourceLink rl = n.getLink(comp, null); map.put(EnumPartIDKey.SheetName, "Sheet"); comp.getCreatePartition(map, new VString("SignatureName SheetName", " ")); map.put(EnumPartIDKey.Side, "Front"); map2.put(EnumPartIDKey.Side, "Back"); VJDFAttributeMap vMap = new VJDFAttributeMap(); vMap.Add(map); vMap.Add(map2); JDFAmountPool aplocal = rl.appendAmountPool(); JDFPartAmount pa = aplocal.appendPartAmount(vMap); Assert.AreEqual(pa.numChildElements_JDFElement(ElementName.PART, null), 2); rl.setActualAmount(42, map); rl.setActualAmount(21, map2); Assert.AreEqual(2, pa.numChildElements_JDFElement(ElementName.PART, null)); Assert.AreEqual(42.0, rl.getActualAmount(map), 0.0); Assert.AreEqual(42.0 + 21.0, rl.getActualAmount(mapSig), 0.0); Assert.AreEqual(aplocal.getPartAmount(vMap), pa); }
public virtual void testGetPartAmountNull() { JDFAttributeMap map = new JDFAttributeMap("Separation", "Black"); VJDFAttributeMap vMap = new VJDFAttributeMap(); vMap.Add(map); JDFResourceLink rl = (JDFResourceLink) new JDFDoc("MediaLink").getRoot(); ap = rl.appendAmountPool(); Assert.IsNull(ap.getPartAmount(vMap)); Assert.IsNull(ap.getPartAmount(map)); Assert.IsNull(ap.getPartAmount(2)); Assert.IsNull(ap.getPartAmount(0)); JDFPartAmount pa = ap.appendPartAmount(); Assert.IsNull(ap.getPartAmount(vMap)); Assert.IsNull(ap.getPartAmount(map)); Assert.IsNull(ap.getPartAmount(2)); Assert.AreEqual(pa, ap.getPartAmount(0)); }