// Linking two modules with Multiple attribute values - Modified by Janet Ma 12 Dec 2003 // /* This program links two modules based on a common attribute. */ pragma runLim, 0 //****** GLOBAL VARIABLES ****************// Object objSource, objTarget int inGetPos = 0 int inStart = 0 int CountLinks = 0 string strAttrib_Src = null string strAttrib_Trg = null string strAttrName = null string strTargAttrName = null string strSMod = null string SelectedTarget = null Module srcMod Module trgMod string sourceList[] = {} string targetList[] = {} string AttribList[] = {} const string charMatchComma = ", " const char charFindComma = ',' const string charMatchRT = "\n" const char charFindRT = '\n' const string charMatchSP = " " const char charFindSP = ' ' string sLabelHead = "Instructions" string sLabelText = "This program will link modules only on the {\\b following conditions}:\n 1) The attributes for both the target and source modules should be of compatible types (although not necessarily having the same name) 2) The source module must have a mandatory linkset defined to the target module. 3) The program assumes the source module have multiple values that may be separated by: 1 space, a hard return, or a comma A target module has to be selected or you will get a DXL error" bool chkTarg = false Module m = current string sCurrent = m."Name" if (!isEdit(m)) { ack "You must be in exclusive edit mode to do global linking!" halt } else { //***************** Dialog Box Elements *************// DB SourceModDB = create "Link Two Modules by Attribute" DBE lblDBE = label(SourceModDB, sCurrent) DBE rch = richText(SourceModDB, sLabelHead, sLabelText, 500, 170, true) DBE AttributePick = list (SourceModDB, "Pick an Attribute from the Source Module", 500, 5, AttribList) DBE fieldMod = field(SourceModDB, "Type in a module keyword, e.g. 680005 or BUDS and hit ENTER ", "", 10) DBE moduleNameDBE = list (SourceModDB, "Pick Target Module", 500, 5, targetList) DBE AttributePickTarg = list (SourceModDB, "Pick an attribute from the Target Module", 500, 5, AttribList) //****************** FUNCTIONS SECTION **************// //function to filter both modules void FilterBPR (Module modIn, string MyAttrName) { current = modIn if (!exists attribute MyAttrName) { ack "Your target does not have this attribute name!" halt } else { Filter f1, f2, f f2 = notNull(attribute(MyAttrName)) f = f2 set (f) filtering on ancestors off refresh modIn } } // end of FilterBPR void initWindow() { AttrDef ad //open the module srcMod = current Module for ad in srcMod do { if (!ad.system) then { insert (AttributePick, noElems(AttributePick), ad.name) } } }// end of initWindow void PopMod (DBE dbe) { Item itemRef string sModName = get(fieldMod) Regexp ModMatch = regexp sModName empty moduleNameDBE for itemRef in current Project do { if (type(itemRef) == "Formal") { string sItemName = name(itemRef)"" if (ModMatch sItemName) then insert (moduleNameDBE, noElems(moduleNameDBE), fullName(itemRef)) } }//end for } //PopMod //set(AttributePickTarg, ShowAttribTarg) void ShowAttribTarg (DBE dbe) { AttrDef ad Item iRef string stName string stPath SelectedTarget = get(moduleNameDBE) for iRef in current Project do { stName = fullName iRef if (stName==SelectedTarget) { //stPath = fullName (iRef) //open the module trgMod = edit(SelectedTarget, false) for ad in trgMod do { // if (!ad.system) then { strTargAttrName = ad.name insert (AttributePickTarg, noElems(AttributePickTarg), strTargAttrName) //} }//inner for break }//equal name } //of for }// ShowAttribTarg void PickTargAttrib (DBE dbe) { strTargAttrName = get(AttributePickTarg) } void LinkTargObj (Module modTrg) { for objTarget in modTrg do { strAttrib_Trg = objTarget.strTargAttrName if (strAttrib_Trg != "") then { if (strAttrib_Src == strAttrib_Trg) then { objSource -> objTarget CountLinks++ break } else { // go to next target object objTarget = next(objTarget) }// of equal BPRs }// of if not null } //of target for } // of LinkTargObj void LinkBPR(Module modSrc, Module modTrg) { bool Found = false for objSource in modSrc do { string stCheckLength = objSource.strAttrName // find multi-BPRs if (matches (charMatchComma, stCheckLength)) { int intLen = length(stCheckLength) for (i=0; i