/// /// <summary> * Get a vector of PartAmounts which are supersets of the filter defined by mPart<br> /// * i.e. mPart is a submap of all returned elements /// * </summary> /// * <param name="mPart"> filter vector for the part to set the status /// * </param> /// * <returns> VElement - the vector of PartAmount elements that fit, null if nothing matches </returns> /// public virtual VElement getMatchingPartAmountVector(JDFAttributeMap mPart) { VElement vPartAmount = getChildElementVector(ElementName.PARTAMOUNT, null, null, true, 0, false); int size = vPartAmount.Count; if (size == 0) { return(null); } VElement vPA = new VElement(); for (int i = 0; i < size; i++) { JDFPartAmount ps = (JDFPartAmount)vPartAmount[i]; VJDFAttributeMap mm = ps.getPartMapVector(); for (int j = 0; j < mm.Count; j++) { JDFAttributeMap m = mm[j]; if (m.subMap(mPart)) { vPA.Add(ps); break; } } } return(vPA.Count == 0 ? null : vPA); }
/// /// <summary> * Append JDFPartAmount elements /// * </summary> /// * <param name="vPArt"> vector of partAmounts to append </param> /// public virtual JDFPartAmount appendPartAmount(VJDFAttributeMap vPart) { JDFPartAmount p = base.appendPartAmount(); p.setPartMapVector(vPart); return(p); }
/// /// <summary> * remove all partAmounts that are not specified in keepList /// * </summary> /// * <param name="keepList"> partAmounts to keep </param> /// public virtual void reducePartAmounts(VJDFAttributeMap keepList) { if (keepList == null) { return; } VElement v = getChildElementVector(ElementName.PARTAMOUNT, null, null, true, -1, true); for (int i = 0; i < v.Count; i++) { JDFPartAmount pa = (JDFPartAmount)v[i]; JDFAttributeMap map = pa.getPartMap(); bool ciao = true; for (int j = 0; j < keepList.Count; j++) { if (map.subMap(keepList[j])) { ciao = false; break; } } if (ciao) { pa.deleteNode(); } } }
/// /// <summary> * Append JDFPartAmount element /// * </summary> /// * <param name="mPart"> JDFAttributeMap to append </param> /// public virtual JDFPartAmount appendPartAmount(JDFAttributeMap mPart) { JDFPartAmount p = base.appendPartAmount(); p.setPartMap(mPart); return(p); }
/// /// <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); }
/// /// <summary> * get JDFPartAmount specified by mPart, create a new one if it doesn't exist /// * </summary> /// * <param name="vPart"> JDFPartAmount to get/create /// * @return </param> /// public virtual JDFPartAmount getCreatePartAmount(VJDFAttributeMap vPart) { JDFPartAmount p = getPartAmount(vPart); if (p == null) { p = (JDFPartAmount)appendElement(ElementName.PARTAMOUNT, null); p.setPartMapVector(vPart); } return(p); }
public virtual JDFPartAmount getPartAmount(JDFAttributeMap mPart, bool bCreate) { JDFPartAmount p = getPartAmount(mPart, 0); if (bCreate && p == null) { p = (JDFPartAmount)appendElement("PartAmount", JDFConstants.EMPTYSTRING); p.setPartMap(mPart); } return(p); }
public virtual VElement getPartAmountVector(VJDFAttributeMap vmPart, bool bCreate) { VElement vPartAmount = new VElement(); for (int i = 0; i < vmPart.Count; i++) { JDFPartAmount ps = getPartAmount(vmPart[i], bCreate); if (ps != null) { vPartAmount.Add(ps); } } return(vPartAmount); }
/// /// <summary> * Get all PartAmount from the current element /// * </summary> /// * <returns> Collection<JDFPartAmount> </returns> /// public virtual ICollection <JDFPartAmount> getAllPartAmount() { List <JDFPartAmount> v = new List <JDFPartAmount>(); JDFPartAmount kElem = (JDFPartAmount)getFirstChildElement(ElementName.PARTAMOUNT, null); while (kElem != null) { v.Add(kElem); kElem = (JDFPartAmount)kElem.getNextSiblingElement(ElementName.PARTAMOUNT, null); } return(v); }
/// /// <summary> * Get a PartAmount that fits to the filter defined by mPart /// * </summary> /// * <param name="vPart"> filter for the part to set the status </param> /// * <returns> the PartAmount that fits </returns> /// public virtual JDFPartAmount getPartAmount(VJDFAttributeMap vPart) { VElement vPartAmount = getChildElementVector(ElementName.PARTAMOUNT, null, null, true, 0, false); for (int i = vPartAmount.Count - 1; i >= 0; i--) { JDFPartAmount partAmount = (JDFPartAmount)vPartAmount[i]; VJDFAttributeMap vMapPart = partAmount.getPartMapVector(); if (ContainerUtil.Equals(vMapPart, vPart)) { return(partAmount); // exact match } } return(null); }
/// /// <summary> * sets the attribute occurence in the appropriate PartAmount when called for a resourceLink and creates the /// * AmountPool and/or PartAmount(s) if they are not yet there /// * </summary> /// * <param name="attrib"> the attribute name </param> /// * <param name="value"> value to set in string form. </param> /// * <param name="nameSpaceURI"> the XML-namespace </param> /// * <param name="vPart"> defines which part of this ResourceLink the Amount belongs to, if empty set the ResourceLink /// * root attribute. </param> /// * <exception cref="JDFException"> when called directly on a PartAmount /// * @since 060630 </exception> /// public static void setAmountPoolAttribute(IAmountPoolContainer poolParent, string attrib, string @value, string nameSpaceURI, VJDFAttributeMap vPart) { // ideally the method would be hidden in PartAmount if ((vPart == null) || (vPart.IsEmpty()) || vPart.Count == 1 && vPart[0].Count == 0) { poolParent.setAttribute(attrib, @value, nameSpaceURI); return; } poolParent.removeAttribute(attrib, nameSpaceURI); // either in the // pool or the // link, not both JDFAmountPool ap = poolParent.getCreateAmountPool(); JDFPartAmount pa0 = ap.getCreatePartAmount(vPart); pa0.setAttribute(attrib, @value, nameSpaceURI); }
/// /// <summary> * Get a PartAmount that fits to the filter defined by mPart /// * </summary> /// * <param name="mPart"> filter for the part to set the status </param> /// * <param name="iSkip"> the iSkip'th element to get </param> /// * <returns> the PartAmount that fits </returns> /// public virtual JDFPartAmount getPartAmount(JDFAttributeMap mPart, int iSkip) { VElement vPartAmount = getChildElementVector(ElementName.PARTAMOUNT, null, null, true, 0, false); int n = 0; for (int i = vPartAmount.Count - 1; i >= 0; i--) { JDFPartAmount partAmount = (JDFPartAmount)vPartAmount[i]; VJDFAttributeMap vMapPart = partAmount.getPartMapVector(); if (vMapPart.subMap(mPart) && ++n > iSkip) { return(partAmount); // exact match } } return(null); }
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)); }
public virtual void testGetCreatePartAmount() { JDFAttributeMap map = new JDFAttributeMap("Separation", "Black"); JDFAttributeMap map2 = new JDFAttributeMap("Separation", "Cyan"); VJDFAttributeMap vMap = new VJDFAttributeMap(); vMap.Add(map); vMap.Add(map2); JDFPartAmount pa1 = ap.getCreatePartAmount(map); Assert.AreEqual(map, pa1.getPartMap()); JDFPartAmount pa3 = ap.getCreatePartAmount(vMap); Assert.AreEqual(vMap, pa3.getPartMapVector()); JDFPartAmount pa4 = ap.getCreatePartAmount(vMap); Assert.AreEqual(pa3, pa4); JDFPartAmount pa2 = ap.getCreatePartAmount(map2); Assert.AreEqual(map2, pa2.getPartMap()); }
/// /// /// <summary> * gets the sum of all matching tags, with the assumpzion that no condition defaults to good /// * </summary> /// * <param name="poolParent"> </param> /// * <param name="attName"> </param> /// * <param name="vPart"> </param> /// * <returns> the sum /// * </returns> /// public static double getAmountPoolSumDouble(IAmountPoolContainer poolParent, string attName, VJDFAttributeMap vPart) { VJDFAttributeMap vPartLocal = vPart; if (vPartLocal == null) { vPartLocal = poolParent.getPartMapVector(); } if (poolParent.hasAttribute(attName)) { return(poolParent.getRealAttribute(attName, null, 0)); } VJDFAttributeMap vm = vPartLocal == null ? null : new VJDFAttributeMap(vPartLocal); JDFResource linkRoot = poolParent.getLinkRoot(); if (linkRoot != null && vm != null) { SupportClass.SetSupport <string> @set = linkRoot.getPartIDKeys().getSet(); @set.Add(AttributeName.CONDITION); // retain good / waste vm.reduceMap(@set); } if (vm == null) { vm = new VJDFAttributeMap(); vm.Add((JDFAttributeMap)null); } double dd = 0; JDFAmountPool ap = poolParent.getAmountPool(); if (ap == null) { return(poolParent.getRealAttribute(attName, null, 0.0)); } VElement vParts = ap.getChildElementVector(ElementName.PARTAMOUNT, null); if (vParts.IsEmpty()) { return(poolParent.getRealAttribute(attName, null, 0.0)); } bool isWaste = vPartLocal != null && vPartLocal.subMap(new JDFAttributeMap(AttributeName.CONDITION, "Waste")); if (!isWaste && (vPartLocal == null || !vPartLocal.subMap(new JDFAttributeMap(AttributeName.CONDITION, "*")))) { vPartLocal = new VJDFAttributeMap(vPartLocal); vPartLocal.Add(new JDFAttributeMap(AttributeName.CONDITION, "Good")); } for (int j = 0; j < vParts.Count; j++) { JDFPartAmount pa = (JDFPartAmount)vParts[j]; VJDFAttributeMap partMapVector = pa.getPartMapVector(); if (isWaste) { bool hasCondition = partMapVector.subMap(new JDFAttributeMap(AttributeName.CONDITION, "*")); if (!hasCondition) { continue; } } if (!partMapVector.overlapsMap(vm)) { continue; } string ret = null; ret = pa.getAttribute(attName, null, null); if (ret == null) { ret = poolParent.getAttribute(attName, null, null); } dd += StringUtil.parseDouble(ret, 0.0); } return(dd); }