diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index 44981e52..f1b9d668 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -573,6 +573,10 @@ namespace Volian.Controls.Library btnInsAftH.Enabled = btnInsBefH.Enabled = btnInsAfter.Enabled = btnInsBefore.Enabled = btnCpyStp.Enabled = value; } } + public void SetCopyStepButton(bool val) + { + btnCpyStp.Enabled = val; + } void _MyEditItem_Enter(object sender, EventArgs e) { // The following two lines were replaced by the third line so that the Ribbon KeyTips will work properly. @@ -1115,17 +1119,35 @@ namespace Volian.Controls.Library btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false; // don't replace itself return; } - // THE FOLLOWING NEEDS TO BE ADDED IN - CODE HAD TO BE CHECKED IN BEFORE THIS COULD BE TESTED BY SOFTWARE ENGINEER (KBR) but is needed. // for now (Jan 2016 - initial implementation of enhanced document support) do NOT paste any step (MyCopyStep) that has enhanced data associated // with it unless pasting within a enhanced source document. The reason is that code would need to handle clearing the pasted enhanced config // data if it is pasted into a non-enhanced location. - //if ((!MyItemInfo.IsEnhancedSection && !!!MyItemInfo.IsEnhancedStep) && tmp.MyDisplayTabControl.MyCopyStep.IsEnhancedStep) - //{ - // btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false; - // btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false; - // btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false; - // return; - //} + if ((!MyItemInfo.IsEnhancedSection && !MyItemInfo.IsEnhancedStep) && tmp.MyDisplayTabControl.MyCopyStep.IsEnhancedStep) + { + btnPasteBefore.Enabled = btnCMPasteBefore.Enabled = false; + btnPasteAfter.Enabled = btnCMPasteAfter.Enabled = false; + btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false; + return; + } + // enhanced: if 'from' step is not enhanced, only allow paste before/after + if (MyItemInfo.IsHigh && !MyItemInfo.IsEnhancedStep) + { + StepConfig stepToCfg = MyItemInfo.MyConfig as StepConfig; + if (stepToCfg.MyEnhancedDocuments != null && stepToCfg.MyEnhancedDocuments.Count>0 && stepToCfg.MyEnhancedDocuments[0].Type != 0) + { + // Current selected step is source (i.e. has enhanced links to enhanced steps) + // check if 'from' step is non. If so, allow paste before/after but not replace + if (tmp.MyDisplayTabControl.MyCopyStep.IsHigh) + { + StepConfig fromCfg = tmp.MyDisplayTabControl.MyCopyStep.MyConfig as StepConfig; + if (fromCfg != null && (fromCfg.MyEnhancedDocuments==null || fromCfg.MyEnhancedDocuments.Count==0)) + { + btnPasteReplace.Enabled = btnCMPasteReplace.Enabled = false; + return; + } + } + } + } //copy item is high level step // Allow a High Level step to be pasted to a sub-step, but not to a table, figure, section or procedure type if (tmp.MyDisplayTabControl.MyCopyStep.IsHigh && (MyItemInfo.IsTable || MyItemInfo.IsFigure || MyItemInfo.IsSection || MyItemInfo.IsProcedure)) @@ -2293,7 +2315,7 @@ namespace Volian.Controls.Library bool surpressMessageBox = (e == null); SectionInfo si = MyEditItem.MyItemInfo as SectionInfo; - if (si != null) // KBR What if linked to an enhanced section? + if (si != null) { string msg = si.HasChildren ? "Are you sure you want to delete this section and its steps?" : "Are you sure you want to delete this section?"; DialogResult result = MessageBox.Show(msg, "Verify Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index 2a397b68..3178bba2 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -878,10 +878,15 @@ namespace Volian.Controls.Library if (tn.VEObject as ItemInfo != null) { ItemInfo i = tn.VEObject as ItemInfo; - if (ui.IsAdministrator() || ui.IsSetAdministrator(i.MyProcedure.MyDocVersion) || ui.IsWriter(i.MyProcedure.MyDocVersion)) + // in the following, 'Copy' is not allowed for any procedure/section/step that is enhanced. Note that this may be + // changed later, but for the initial enhanced development it was decided to not allow copy of enhanced since paste would + // require clearing of all enhanced config data or mapping it to existing data (quite complicated) + Console.WriteLine("EnhancedStep: {0}, EnhancedSection: {1}, EnhancedProcedure: {2}", i.IsEnhancedStep, i.IsEnhancedSection, i.IsEnhancedProcedure); + if ((ui.IsAdministrator() || ui.IsSetAdministrator(i.MyProcedure.MyDocVersion) || ui.IsWriter(i.MyProcedure.MyDocVersion)) && (!i.IsEnhancedStep && !i.IsEnhancedProcedure && !i.IsEnhancedSection)) cm.MenuItems.Add("Copy", new EventHandler(mi_Click)); } #endregion + #region Menu_Paste bool ok = false; if (tn.VEObject is FolderInfo && (ui.IsAdministrator() || ui.IsSetAdministrator(tn.VEObject as FolderInfo))) ok = true; @@ -891,8 +896,9 @@ namespace Volian.Controls.Library ok = true; if(ok) Menu_Paste(tn, cm); + #endregion #region Menu_Delete - if (ok) + if (ok) { // Add delete to the menu unless at the very 'top' node, on a grouping (partinfo) // node (RNOs, Steps, Cautions, Notes) or Folder/DocVersion that contains any items. @@ -1198,15 +1204,50 @@ namespace Volian.Controls.Library } private void Menu_Paste(VETreeNode tn, ContextMenu cm) { - #region MenuPaste + #region Menu_Paste method // Find what's in paste buffer & determine whether the paste can occur for the selected node. ItemInfo iiClipboard = OnClipboardStatus(this, new vlnTreeEventArgs(tn)); if (iiClipboard != null) { // can it be pasted at current node. + + // for now (Jan 2016 - initial implementation of enhanced document support) do NOT paste + // any items that have enhanced data associated with it unless pasting within an enhanced source item. + // The reason is that code would need to handle clearing/setting the pasted enhanced config which + // becomes very complicated. + + // For all enhanced comments in code use the following: + // 'source' is Procedures, for example EOP procedures (that has config's myenhanceddocuments pointing to enhanced, i.e. not source) + // 'enhanced' is enhanced procedures, for example Background/deviation (that has config's myenhanceddocuments pointing back to source) + // 'non' or 'not enhanced', anything other than 'source' or 'enhanced' (has no myenhanceddocuments on config) + // 'from' is object copied + // 'to' is object where paste was selected from + #region Menu_Paste_ToDocVersion if (tn.VEObject as DocVersionInfo != null) // paste item must be a proc { - if (iiClipboard.IsProcedure) cm.MenuItems.Add("Paste Procedure", new EventHandler(mi_Click)); + if (iiClipboard.IsProcedure) + { + // In order to paste a procedure into a docVersion: NOTE that an 'enhanced' procedure cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // 2) 'to' docVersion is 'source' and 'from' procedure is 'non' (has no MyEnhancedDocuments) + // 3) 'to' docversion is 'source' and 'from' procedure is within this docversion + // 4) 'to' docVersion is 'enhanced' and 'from' procedure is not + bool canPaste = false; + + DocVersionInfo dvi = tn.VEObject as DocVersionInfo; + DocVersionConfig dvc = dvi.DocVersionConfig; + bool docVersionIsEnhanced = dvc.MyEnhancedDocuments != null && dvc.MyEnhancedDocuments.Count > 0 && dvc.MyEnhancedDocuments[0].Type == 0; + bool docVersionIsSource = dvc.MyEnhancedDocuments != null && dvc.MyEnhancedDocuments.Count > 0 && dvc.MyEnhancedDocuments[0].Type != 0; + ProcedureInfo pi = iiClipboard as ProcedureInfo; + ProcedureConfig pcfg = pi.MyConfig as ProcedureConfig; + bool procIsSource = pcfg.MyEnhancedDocuments != null && pcfg.MyEnhancedDocuments.Count > 0 && pcfg.MyEnhancedDocuments[0].Type != 0; + if (!docVersionIsEnhanced && !docVersionIsSource && !procIsSource) canPaste = true; + else if (docVersionIsSource && !procIsSource) canPaste = true; + else if (docVersionIsSource) canPaste = (!procIsSource || (iiClipboard.MyDocVersion.ItemID == dvi.ItemID)); + else if (docVersionIsEnhanced) canPaste = !procIsSource; + if (canPaste) cm.MenuItems.Add("Paste Procedure", new EventHandler(mi_Click)); + } + #endregion } else { @@ -1216,19 +1257,97 @@ namespace Volian.Controls.Library if (iiPasteHere != null) { SectionInfo si = (tn.VEObject as SectionInfo != null) ? tn.VEObject as SectionInfo : null; + #region Menu_Paste_ToFromProcedure if (iiPasteHere.IsProcedure && iiClipboard.IsProcedure) // procedure can be pasted before/replace/after { - cm.MenuItems.Add("Paste Procedure Before", new EventHandler(mi_Click)); - if (okToReplace) cm.MenuItems.Add("Replace Existing Procedure", new EventHandler(mi_Click)); - cm.MenuItems.Add("Paste Procedure After", new EventHandler(mi_Click)); + // Enhanced considerations, in order to paste a procedure around another procedure: NOTE that an 'enhanced' procedure cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // can do Before/After/Replace + // 2) 'to' is 'non', 'from' is 'source' + // cannot do any + // 3) 'to' procedure is 'source' and 'from' procedure is 'non' (has no MyEnhancedDocuments) + // can do Before/After - no links exist in pasted procedure. + // cannot do Replace + // 4) 'to' procedure is 'source' and 'from' procedure is same docversion 'source' + // can do Before/After/Replace + // 5) 'to' procedure is 'source' and 'from' procedure is different docversion 'source' + // cannot do any + // 6) 'to' procedure is 'enhanced' and 'from' procedure is 'source' + // cannot do any + ProcedureConfig pcToCfg = iiPasteHere.MyConfig as ProcedureConfig; + ProcedureConfig pcFromCfg = iiClipboard.MyConfig as ProcedureConfig; + + bool prToIsEnhanced = iiPasteHere.IsEnhancedProcedure; + bool prToIsSource = pcToCfg.MyEnhancedDocuments != null && pcToCfg.MyEnhancedDocuments.Count > 0 && pcToCfg.MyEnhancedDocuments[0].Type != 0; + bool prFromIsEnhanced = iiClipboard.IsEnhancedProcedure; + bool prFromIsSource = pcFromCfg.MyEnhancedDocuments != null && pcFromCfg.MyEnhancedDocuments.Count > 0 && pcFromCfg.MyEnhancedDocuments[0].Type != 0; + bool prCanPaste = false; + if (!prToIsEnhanced && !prToIsSource && !prFromIsEnhanced && !prFromIsSource) prCanPaste = true; // 1) + // else if ((!prToIsEnhanced && !prToIsSource) && prFromIsSource) prCanPaste = false; // 2) commented out because already set to false + else if (prToIsSource && !prFromIsEnhanced && !prFromIsSource) // 3) + { + prCanPaste = true; + okToReplace = false; + } + else if (prToIsSource && iiPasteHere.MyDocVersion.VersionID == iiClipboard.MyDocVersion.VersionID) prCanPaste = true; // 4) + //else if (prToIsSource && iiPasteHere.MyDocVersion.VersionID != iiClipboard.MyDocVersion.VersionID) prCanPaste = false; // 5) commented out because already set to false + //else if (prToIsEnhanced && prFromIsSource) prCanPaste = false; // 6)commented out because already set to false + if (prCanPaste) cm.MenuItems.Add("Paste Procedure Before", new EventHandler(mi_Click)); + if (okToReplace && prCanPaste) cm.MenuItems.Add("Replace Existing Procedure", new EventHandler(mi_Click)); + if (prCanPaste) cm.MenuItems.Add("Paste Procedure After", new EventHandler(mi_Click)); } + #endregion + #region Menu_Paste_ToProcedureFromSection else if (iiPasteHere.IsProcedure && iiClipboard.IsSection) // procedure must have sections only - cm.MenuItems.Add("Paste Section", new EventHandler(mi_Click)); + { + // In order to paste a section into a procedure: NOTE that an 'enhanced' section cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // can do + // 2) 'to' procedure is 'source' and 'from' section is 'non' (has no MyEnhancedDocuments) + // can do + // 3) 'to' procedure is 'source' and 'from' section is same source + ProcedureConfig pccToCfg = iiPasteHere.MyConfig as ProcedureConfig; + SectionConfig scFromCfg = iiClipboard.MyConfig as SectionConfig; + bool prToIsEnhanced = iiPasteHere.IsEnhancedProcedure; + bool prToIsSource = pccToCfg.MyEnhancedDocuments != null && pccToCfg.MyEnhancedDocuments.Count > 0 && pccToCfg.MyEnhancedDocuments[0].Type != 0; + bool scFromIsEnhanced = iiClipboard.IsEnhancedSection; + bool scFromIsSource = scFromCfg.MyEnhancedDocuments != null && scFromCfg.MyEnhancedDocuments.Count > 0 && scFromCfg.MyEnhancedDocuments[0].Type != 0; + bool scCanPaste = false; + if (!prToIsEnhanced && !prToIsSource && !scFromIsEnhanced && !scFromIsSource) scCanPaste = true; // 1) + else if (prToIsSource && !scFromIsEnhanced && !scFromIsSource) scCanPaste = true; + else if (prToIsSource && iiPasteHere.MyDocVersion.VersionID == iiClipboard.MyDocVersion.VersionID) scCanPaste = true; // 3) + if (scCanPaste) cm.MenuItems.Add("Paste Section", new EventHandler(mi_Click)); + } + #endregion + #region Menu_Paste_ToSectionFromSection else if (iiPasteHere.IsSection && iiClipboard.IsSection) { - cm.MenuItems.Add("Paste Section Before", new EventHandler(mi_Click)); - if (okToReplace) cm.MenuItems.Add("Replace Existing Section", new EventHandler(mi_Click)); - cm.MenuItems.Add("Paste Section After", new EventHandler(mi_Click)); + // Enhanced considerations, in order to paste a section around another section: NOTE that an 'enhanced' section cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // can do Before/After/Replace + // 2) 'to' section is 'source' and 'from' section is 'non' (has no MyEnhancedDocuments) + // can do Before/After - no links exist in pasted section. + // cannot do Replace + // 3) 'to' section is 'source' and 'from' section is same docversion 'source' + // can do Before/After/Replace + SectionConfig secToCfg = iiPasteHere.MyConfig as SectionConfig; + SectionConfig secFromCfg = iiClipboard.MyConfig as SectionConfig; + + bool secToIsEnhanced = iiPasteHere.IsEnhancedSection; + bool secToIsSource = secToCfg.MyEnhancedDocuments != null && secToCfg.MyEnhancedDocuments.Count > 0 && secToCfg.MyEnhancedDocuments[0].Type != 0; + bool secFromIsEnhanced = iiClipboard.IsEnhancedSection; + bool secFromIsSource = secFromCfg.MyEnhancedDocuments != null && secFromCfg.MyEnhancedDocuments.Count > 0 && secFromCfg.MyEnhancedDocuments[0].Type != 0; + bool secCanPaste = false; + if (!secToIsEnhanced && !secToIsSource && !secFromIsEnhanced && !secFromIsSource) secCanPaste = true; // 1) + else if (secToIsSource && !secFromIsEnhanced && !secFromIsSource) // 2) + { + secCanPaste = true; + okToReplace = false; + } + else if (secToIsSource && iiPasteHere.MyDocVersion.VersionID == iiClipboard.MyDocVersion.VersionID) secCanPaste = true; // 3) + if (secCanPaste) cm.MenuItems.Add("Paste Section Before", new EventHandler(mi_Click)); + if (okToReplace && secCanPaste) cm.MenuItems.Add("Replace Existing Section", new EventHandler(mi_Click)); + if (secCanPaste) cm.MenuItems.Add("Paste Section After", new EventHandler(mi_Click)); if (si.ActiveFormat.PlantFormat.FormatData.SectData.UseMetaSections && iiPasteHere.IsStepSection && iiClipboard.IsStepSection) { // only paste a subsection if the paste here is an empty section or has @@ -1237,14 +1356,60 @@ namespace Volian.Controls.Library cm.MenuItems.Add("Paste Subsection", new EventHandler(mi_Click)); } } + #endregion + #region Menu_Paste_ToSectionFromStep else if (iiPasteHere.IsStepSection && iiClipboard.IsStep) - cm.MenuItems.Add("Paste Step", new EventHandler(mi_Click)); + { + // In order to paste a step into a section: NOTE that an 'enhanced' step cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // can do + // 2) 'to' section is 'source' and 'from' step is 'non' (has no MyEnhancedDocuments) + // can do + // 3) 'to' section is 'source' and 'from' section is same source + SectionConfig secToCfg = iiPasteHere.MyConfig as SectionConfig; + StepConfig stpFromCfg = iiClipboard.MyConfig as StepConfig; + bool secToIsEnhanced = iiPasteHere.IsEnhancedSection; + bool secToIsSource = secToCfg.MyEnhancedDocuments != null && secToCfg.MyEnhancedDocuments.Count > 0 && secToCfg.MyEnhancedDocuments[0].Type != 0; + bool stpFromIsEnhanced = iiClipboard.IsEnhancedStep; + bool stpFromIsSource = stpFromCfg.MyEnhancedDocuments != null && stpFromCfg.MyEnhancedDocuments.Count > 0 && stpFromCfg.MyEnhancedDocuments[0].Type != 0; + bool stpCanPaste = false; + if (!secToIsEnhanced && !secToIsSource && !stpFromIsEnhanced && !stpFromIsSource) stpCanPaste = true; // 1) + else if (secToIsSource && !stpFromIsEnhanced && !stpFromIsSource) stpCanPaste = true; // 2) + else if (secToIsSource && iiPasteHere.MyDocVersion.VersionID == iiClipboard.MyDocVersion.VersionID) stpCanPaste = true; // 3) + if (stpCanPaste) cm.MenuItems.Add("Paste Step", new EventHandler(mi_Click)); + } + #endregion + #region Menu_Paste_ToStepFromStep else if (iiPasteHere.IsStep && iiClipboard.IsStep) { - if (AddToInsertMenu(iiPasteHere, 0)) cm.MenuItems.Add("Paste Step Before", new EventHandler(mi_Click)); - if (okToReplace) cm.MenuItems.Add("Replace Existing Step", new EventHandler(mi_Click)); - if (AddToInsertMenu(iiPasteHere, 1)) cm.MenuItems.Add("Paste Step After", new EventHandler(mi_Click)); + // Enhanced considerations, in order to paste a step around another step: NOTE that an 'enhanced' section cannot be in paste buffer! + // 1) 'to' & 'from' both 'non', i.e. Neither can have enhanced config data (be source or enhanced) + // can do Before/After/Replace + // 2) 'to' step is 'source' and 'from' step is 'non' (has no MyEnhancedDocuments) + // can do Before/After - no links exist in pasted step, treat like an insert.. + // cannot do Replace + // 3) 'to' step is 'source' and 'from' step is same docversion 'source' + // can do Before/After/Replace + StepConfig stpToCfg = iiPasteHere.MyConfig as StepConfig; + StepConfig stpFromCfg = iiClipboard.MyConfig as StepConfig; + + bool stpToIsEnhanced = iiPasteHere.IsEnhancedStep; + bool stpToIsSource = stpToCfg.MyEnhancedDocuments != null && stpToCfg.MyEnhancedDocuments.Count > 0 && stpToCfg.MyEnhancedDocuments[0].Type != 0; + bool stpFromIsEnhanced = iiClipboard.IsEnhancedStep; + bool stpFromIsSource = stpFromCfg.MyEnhancedDocuments != null && stpFromCfg.MyEnhancedDocuments.Count > 0 && stpFromCfg.MyEnhancedDocuments[0].Type != 0; + bool stpCanPaste = false; + if (!stpToIsEnhanced && !stpToIsSource && !stpFromIsEnhanced && !stpFromIsSource) stpCanPaste = true; // 1) + else if (stpToIsSource && !stpFromIsEnhanced && !stpFromIsSource) // 2) + { + stpCanPaste = true; + okToReplace = false; + } + else if (stpToIsSource && iiPasteHere.MyDocVersion.VersionID == iiClipboard.MyDocVersion.VersionID) stpCanPaste = true; // 3) + if (stpCanPaste && AddToInsertMenu(iiPasteHere, 0)) cm.MenuItems.Add("Paste Step Before", new EventHandler(mi_Click)); + if (stpCanPaste && okToReplace) cm.MenuItems.Add("Replace Existing Step", new EventHandler(mi_Click)); + if (stpCanPaste && AddToInsertMenu(iiPasteHere, 1)) cm.MenuItems.Add("Paste Step After", new EventHandler(mi_Click)); } + #endregion } } } @@ -2006,6 +2171,7 @@ namespace Volian.Controls.Library { ShowBrokenRules(procedure.BrokenRulesCollection); SetLastValues(ProcedureInfo.Get(procedure.ItemID)); + procedure.ProcedureConfig.CreatingNew = true; if (OnNodeOpenProperty(this, new vlnTreePropertyEventArgs("New Procedure", procedure.ProcedureConfig)) == DialogResult.OK) { procedure.Save();