// Copy Atts v1.3 /* This script allows the user to copy the attributes from the current to multiple others. */ /* Revision History version developed on date by notes 1.0.0 DOORS 5.2 PC 02/07/02 Telelogic NA 1.0.1 04-Jul-07 Modified by Landale: Folder or Project (not DB) modules; does ad.module attributes as well. 1.2 05-Aug-02 Graceful handling modules that cannot be opened. Tweaked messages. 1.3 06-May-14 Copies the DXL for attribute DXL, even if the attribute already exists. Wider Attr Window */ // Constants const string srcDest[] = {"Source", "Destination", "Cancel"} const string dummy[] = {} const int modListWidth = 600 const int modWidth = 200 const int pathWidth = modListWidth - 2 * modWidth - 20 const int attWidth = modWidth - 20 const int listLength = 12 // Variables Module srcMod, destMod int dataRow DB copyDB DBE modListDBE, attListDBE, splitDBE, scopeDBE, modFrameDBE, attFrameDBE, okBtnDBE, applyBtnDBE int modSelected, attSelected, i bool closeSrc, firstMsg Buffer msgBuffer // Functions //================================================================================================= // Stores messages for display at the end // // Called by: copyAtts // // Calls: none // void storeMsg(string input) { if(firstMsg) { msgBuffer = create msgBuffer = input firstMsg = false } else { msgBuffer += "\n" msgBuffer += input } } // storeMsg //================================================================================================= // If messages were collected in the buffer, display the text in a dialog box. // // Called by: copyAttsCB // // Calls: none // void displayMessages() { if(! firstMsg) { DB msgBox=create("CopyAtts.dxl Report:") text(msgBox, "", stringOf(msgBuffer), 500, 300, true) realize(msgBox, 200, 200) msgBox=null delete(msgBuffer) firstMsg = true raise(copyDB) } } // displayMessages //================================================================================================= // Creates types for use by attributes yet to be created in the target module. // // Called by: copyAtts // // Calls: none // bool createType(Module srcMod, Module destMod, string nameOfType) { bool boundSet, passed = false string errMsg = null AttrType destAttType AttrType attType = find(srcMod, nameOfType) string baseType = attType.type "" current = destMod if (baseType == "Real") { destAttType = create(attType.name, attrReal, errMsg) boundSet = attType.minValue if (boundSet) { real minVal = attType.minValue setMinValue(destAttType, minVal, true) } boundSet = attType.maxValue if (boundSet) { real maxVal = attType.maxValue setMaxValue(destAttType, maxVal, true) } } else if (baseType == "Integer") { destAttType = create(attType.name, attrInteger, errMsg) boundSet = attType.minValue if (boundSet) { int minVal = attType.minValue setMinValue(destAttType, minVal, true) } boundSet = attType.maxValue if (boundSet) { int maxVal = attType.maxValue setMaxValue(destAttType, maxVal, true) } } else if (baseType == "Date") { destAttType = create(attType.name, attrDate, errMsg) boundSet = attType.minValue if (boundSet) { Date minVal = attType.minValue setMinValue(destAttType, minVal, true) } boundSet = attType.maxValue if (boundSet) { Date maxVal = attType.maxValue setMaxValue(destAttType, maxVal, true) } } else if (baseType == "String") { create(attType.name, attrString, errMsg) } else if (baseType == "Text") { create(attType.name, attrText, errMsg) } else if (baseType == "Enumeration") { string options[attType.size] int vals[attType.size] int cols[attType.size] bool keepVals = false for (i = 0; i < attType.size; i++) { options[i] = attType.strings[i] vals[i] = attType.values[i] cols[i] = attType.colors[i] if (i != vals[i]) { keepVals = true } } if (keepVals) { create(attType.name, options, vals, cols, errMsg) } else { create(attType.name, options, errMsg) } } else { storeMsg("xx Unable to create type '" attType.name "' due to unknown base type '" baseType "'") } if (null errMsg) { passed = true } else { storeMsg("xx Unable to create type:\n" errMsg) } return passed } // createType //================================================================================================= // Creates an attribute definition in the to module based on // the attribute definition in the from module // // Called by: copyAtts // // Calls: none // bool createAtt(Module destMod, AttrDef ad) { AttrDef destAttDef current = destMod bool passed = false AttrDef__ destAd = attribute ad.name if (ad.object) destAd = destAd object if (ad.module) destAd = destAd module destAd = destAd type ad.typeName if (ad.nohistory) destAd = destAd history false if (ad.nochanges) destAd = destAd date false if (ad.nobars) destAd = destAd changeBars false if (ad.multi) destAd = destAd multi true if (ad.inherit) destAd = destAd inherit true if (ad.hidden) destAd = destAd hidden true if (ad.dxl) destAd = destAd dxl ad.dxl if (ad.defval) destAd = destAd (default ad.defval) destAttDef = create destAd if (! null(destAttDef)) { passed = true } return passed } // createAtt //================================================================================================= // Ensures that all the attributes from the source module exist in the target module. // // Called by: updateMod // // Calls: createType // createAtt // void copyAtts(Module srcMod, Module toMod) { AttrDef destAttDef, attDef string attName int pos current = toMod bool typePass storeMsg("... Copying atts in module '" toMod."Name" "'...") for pos in attListDBE do { attName = getColumnValue(attListDBE, pos, 0) attDef = find(srcMod, attName) destAttDef = find(toMod, attName) if (null(destAttDef)) { string typeNm = attDef.typeName AttrType attType = find(toMod, typeNm) if (null(attType)) { typePass = createType(srcMod, toMod, typeNm) } else { typePass = true } if (typePass) { if (! createAtt(toMod, attDef)) { storeMsg(" xx Unable to create attribute '" attName "' in module '" toMod."Name" "'") } } else { storeMsg(" xx Unable to create type '" typeNm "' in module '" toMod."Name" "'") } } else { bool IsDXLDst = destAttDef.dxl bool IsDXLSrc = attDef.dxl if (IsDXLDst and IsDXLSrc) { // Both are Attr DXL. Update it string NewDXL = attDef.dxl modify(destAttDef, setDXL, NewDXL) storeMsg(" !! DXL for attr '" attName "' update in module '" toMod."Name" "'") } else storeMsg(" !! The attribute '" attName "' already exists in module '" toMod."Name" "'") } } storeMsg(">>>> Attributes copied to '" fullName(toMod) "'") } // copyAtts //================================================================================================= // Called by both of the execution buttons (OK, apply) to copy attributes. Loops through the // // Called by: // // Calls: // void copyAttsCB(DB box) { int pos bool closeIt for pos in modListDBE do { string modName = getColumnValue(modListDBE, pos, 2) "/" getColumnValue(modListDBE, pos, 0) if (open(module(modName))) { closeIt = false } else { closeIt = true } destMod = edit(modName, false) if (null destMod) storeMsg ("xx Cannot open at all " modName) elseif(!isEdit(destMod)) storeMsg ("xx Cannot open for Edit " modName) else { if (destMod != srcMod) { copyAtts(srcMod, destMod) save(destMod) } } if (!null destMod and closeIt) close(destMod) } displayMessages } // copyAttsCB //================================================================================================= // Called when an attribute list item is selected. // // Called by: getDest callback // // Calls: none // void attSelectionMade(DBE lstv, int sel) { int modSel = get(modListDBE) if (modSel >= 0) { active(okBtnDBE) active(applyBtnDBE) } attSelected++ } // attSelectionMade //================================================================================================= // Called when an attribute list item is deselected. // // Called by: getDest callback // // Calls: none // void attDeselected(DBE lstv, int sel) { int attSel = get(lstv) if (attSel < 0) { inactive(okBtnDBE) inactive(applyBtnDBE) } } // attDeselected //================================================================================================= // Called when an attribute list item is double-clicked. // // Called by: getDest callback // // Calls: none // void attActivated(DBE lstv, int sel) { } // attActivated //================================================================================================= // Fills the attribute list in the dialog box. // // Called by: getDest // // Calls: none // void listAtts() { empty(attListDBE) AttrDef attDef dataRow = 0 attSelected-- inactive(okBtnDBE) inactive(applyBtnDBE) for attDef in srcMod do { // if (! attDef.system and attDef.object) { if (! attDef.system) {// Landale insert(attListDBE, dataRow++, attDef.name) } } } // listAtts //================================================================================================= // Called when a module list item is selected. // // Called by: getDest callback // // Calls: none // void modSelectionMade(DBE lstv, int sel) { string srcModName int attSel = get(attListDBE) if (attSel >= 0) { active(okBtnDBE) active(applyBtnDBE) } } // modSelectionMade //================================================================================================= // Called when a module list item is deselected. // // Called by: getDest callback // // Calls: none // void modDeselected(DBE lstv, int sel) { int modSel = get(lstv) if (modSel < 0) { inactive(okBtnDBE) inactive(applyBtnDBE) } } // modDeselected //================================================================================================= // Called when a module list item is double-clicked. // // Called by: getDest callback // // Calls: none // void modActivated(DBE lstv, int sel) { } // modActivated //================================================================================================= // Builds the module list for the dialog box. // // Called by: getDest callback // // Calls: none // void getModules(DBE tgl) { empty(modListDBE) dataRow = 0 bool onlyCurrent = get(tgl) void goRecurse(Folder f) { Skip modSkip = createString Item itm for itm in all f do { if (type itm == "Project" or type itm == "Folder") { // if (name(itm) == "Change Proposal System") { // continue // } goRecurse(folder(itm)) } else if (type itm == "Formal") { if (!isDeleted itm){ put(modSkip, fullName(itm), itm) } } } for itm in modSkip do { insert(modListDBE, dataRow, name(itm)) Project p = getParentProject(itm) string projName if (null(p)) { projName = "" } else { projName = name(p) } set(modListDBE, dataRow, 1, projName) set(modListDBE, dataRow++, 2, path(itm)) } delete(modSkip) } Folder fCurr = current if (onlyCurrent) { goRecurse(fCurr) } else { // Landale Project pCurr = current if (null pCurr) { infoBox("No current Project") set(tgl, true) goRecurse(current Folder) } else goRecurse(folder "/" name(pCurr)) } } // getModules //================================================================================================= // Builds the dialog box for capturing the attributes and modules the user wished to use for the // copy. // // Called by: main // // Calls: attSelectionMade // attDeselected // attActivated // modSelectionMade // modDeselected // modActivated // getModules // copyAttsCB // listAtts // void getDest() { copyDB = create("Copy Attributes from '" fullName(srcMod) "' to Other Modules", styleCentered) attFrameDBE = frame(copyDB, "Select attributes", modWidth + 20, listLength * 20 + 60) attFrameDBE -> "right" -> "unattached" attListDBE = listView(copyDB, listViewOptionMultiselect, modWidth, listLength, dummy) attListDBE -> "top" -> "inside" -> attFrameDBE attListDBE -> "left" -> "inside" -> attFrameDBE attListDBE -> "right" -> "inside" -> attFrameDBE attListDBE -> "bottom" -> "inside" -> attFrameDBE set(attListDBE, attSelectionMade, attDeselected, attActivated) modFrameDBE = frame(copyDB, "Select destination module(s)", modListWidth + 20, listLength * 20 + 60) modFrameDBE -> "left" -> "unattached" modFrameDBE -> "top" -> "aligned" -> attFrameDBE modListDBE = listView(copyDB, listViewOptionMultiselect, modListWidth, listLength, dummy) modListDBE -> "top" -> "inside" -> modFrameDBE modListDBE -> "left" -> "inside" -> modFrameDBE modListDBE -> "right" -> "inside" -> modFrameDBE set(modListDBE, modSelectionMade, modDeselected, modActivated) scopeDBE = toggle(copyDB, "Current folder only", true) scopeDBE -> "top" -> "flush" -> modListDBE scopeDBE -> "left" -> "inside" -> modFrameDBE scopeDBE -> "right" -> "inside" -> modFrameDBE scopeDBE -> "bottom" -> "inside" -> modFrameDBE set(scopeDBE, getModules) splitDBE = splitter(copyDB, attFrameDBE, modFrameDBE, 5) splitDBE -> "top" -> "form" splitDBE -> "left" -> "unattached" splitDBE -> "right" -> "unattached" splitDBE -> "bottom" -> "form" okBtnDBE = ok(copyDB, "OK", copyAttsCB) applyBtnDBE = apply(copyDB, "Apply", copyAttsCB) inactive(okBtnDBE) inactive(applyBtnDBE) realize(copyDB) insertColumn(attListDBE, 0, "Attribute", attWidth, iconNone) insertColumn(modListDBE, 0, "Module", modWidth, iconNone) insertColumn(modListDBE, 1, "from Project", modWidth, iconNone) insertColumn(modListDBE, 2, "Path", pathWidth, iconNone) listAtts getModules(scopeDBE) show(copyDB) } // getDest // Initializations srcMod = current if (null srcMod) {infoBox("Run from open (source) module"); halt} modSelected = 0 attSelected = 0 firstMsg = true // Main getDest // ---- end file CopyAtts.dxl ---- // ---- end file CopyAtts.dx