private bool removeFlashStr() { //remove the structures used to generate flash in the plan StructureSet ss = vmatPlan.StructureSet; //check to see if this structure set is used in any other calculated plans that are NOT the _VMAT TBI plan or any of the AP/PA legs plans string message = ""; List <ExternalPlanSetup> otherPlans = new List <ExternalPlanSetup> { }; foreach (Course c in vmatPlan.Course.Patient.Courses) { foreach (ExternalPlanSetup p in c.ExternalPlanSetups) { if ((p != vmatPlan && !appaPlan.Where(x => x == p).Any()) && p.IsDoseValid && p.StructureSet == ss) { message += String.Format("Course: {0}, Plan: {1}", c.Id, p.Id) + System.Environment.NewLine; otherPlans.Add(p); } } } //photon dose calculation model type string calcModel = vmatPlan.GetCalculationModel(CalculationType.PhotonVolumeDose); if (otherPlans.Count > 0) { //if some plans were found that use this structure set and have dose calculated, inform the user and ask if they want to continue WITHOUT removing flash. message = "The following plans have dose calculated and use the same structure set:" + System.Environment.NewLine + message + System.Environment.NewLine; message += "I need to remove the calculated dose from these plans before removing the flash structures." + System.Environment.NewLine; message += "Continue?"; confirmUI CUI = new VMATTBIautoPlan.confirmUI(); CUI.message.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); CUI.message.Text = message; CUI.ShowDialog(); //need to return from this function regardless of what the user decides if (!CUI.confirm) { return(true); } foreach (ExternalPlanSetup p in otherPlans) { p.ClearCalculationModel(CalculationType.PhotonVolumeDose); p.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel); } } //dumbass way around the issue of modifying structures in a plan that already has dose calculated... reset the calculation model, make the changes you need, then reset the calculation model vmatPlan.ClearCalculationModel(CalculationType.PhotonVolumeDose); vmatPlan.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel); foreach (ExternalPlanSetup p in appaPlan) { p.ClearCalculationModel(CalculationType.PhotonVolumeDose); p.SetCalculationModel(CalculationType.PhotonVolumeDose, calcModel); } IEnumerable <Structure> flashStr = ss.Structures.Where(x => x.Id.ToLower().Contains("flash")); List <Structure> removeMe = new List <Structure> { }; //can't remove directly from flashStr because the vector size would change on each loop iteration foreach (Structure s in flashStr) { if (!s.IsEmpty) { if (ss.CanRemoveStructure(s)) { removeMe.Add(s); } } } foreach (Structure s in removeMe) { ss.RemoveStructure(s); } //from the generateTS class, the human_body structure was a copy of the body structure BEFORE flash was added. Therefore, if this structure still exists, we can just copy it back onto the body Structure bodyCopy = ss.Structures.FirstOrDefault(x => x.Id.ToLower() == "human_body"); if (bodyCopy != null && !bodyCopy.IsEmpty) { Structure body = ss.Structures.First(x => x.Id.ToLower() == "body"); body.SegmentVolume = bodyCopy.Margin(0.0); if (ss.CanRemoveStructure(bodyCopy)) { ss.RemoveStructure(bodyCopy); } } else { MessageBox.Show("WARNING 'HUMAN_BODY' STRUCTURE NOT FOUND! BE SURE TO RE-CONTOUR THE BODY STRUCTURE!"); } flashRemoved = true; return(false); }