/// <summary> /// remove the checked curtain grids from the curtain system /// Note: curtain system must have at least one curtain grid /// so sample users can't remove all the curtain grids away /// </summary> /// <param name="sender"> /// object who sent this event /// </param> /// <param name="e"> /// event args /// </param> private void removeCGButton_Click(object sender, EventArgs e) { // step 1: get the curtain system List <CurtainSystem.SystemInfo> csInfos = m_mydocument.SystemData.CurtainSystemInfos; // no curtain system available, ask sample user to create some curtain systems first if (null == csInfos || 0 == csInfos.Count) { string hint = Properties.Resources.HINT_CreateCSFirst; m_mydocument.Message = new KeyValuePair <string, bool>(hint, true); return; } CurtainSystem.SystemInfo csInfo = csInfos[csListBox.SelectedIndex]; // if the curtain system is created by face array, it's forbidden to make other operations on it if (true == csInfo.ByFaceArray) { return; } // step 2: find out the curtain grids to be removed List <int> faceIndices = new List <int>(); for (int i = 0; i < cgCheckedListBox.Items.Count; i++) { bool itemChecked = cgCheckedListBox.GetItemChecked(i); if (true == itemChecked) { CurtainSystem.GridFaceInfo info = cgCheckedListBox.Items[i] as CurtainSystem.GridFaceInfo; faceIndices.Add(info.FaceIndex); } } // no curtain grids selected, warn the sample user if (null == faceIndices || 0 == faceIndices.Count) { string hint = Properties.Resources.HINT_SelectCGFirst; m_mydocument.Message = new KeyValuePair <string, bool>(hint, true); return; } // step 3: remove the selected curtain grids csInfo.RemoveCurtainGrids(faceIndices); // step 4: update the UI list boxes csListBox_SelectedIndexChanged(null, null); }
/// <summary> /// the selected curtain system changed, update the "Curtain grid" and /// "Uncovered faces" list boxes of the selected curtain system /// </summary> /// <param name="sender"> /// object who sent this event /// </param> /// <param name="e"> /// event args /// </param> private void csListBox_SelectedIndexChanged(object sender, EventArgs e) { List <CurtainSystem.SystemInfo> csInfos = m_mydocument.SystemData.CurtainSystemInfos; // data verification if (null == csInfos || 0 == csInfos.Count) { return; } // // step 1: activate the selected one // CurtainSystem.SystemInfo csInfo = csInfos[csListBox.SelectedIndex]; // update the curtain grid list box cgCheckedListBox.Items.Clear(); foreach (int index in csInfo.GridFacesIndices) { CurtainSystem.GridFaceInfo gridFaceInfo = new CurtainSystem.GridFaceInfo(index); cgCheckedListBox.Items.Add(gridFaceInfo); } // update the uncovered face list box facesCheckedListBox.Items.Clear(); foreach (int index in csInfo.UncoverFacesIndices) { CurtainSystem.UncoverFaceInfo uncoverFaceInfo = new CurtainSystem.UncoverFaceInfo(index); facesCheckedListBox.Items.Add(uncoverFaceInfo); } // // step 2: enable/disable some buttons and refresh the status hints // // the selected curtain system is created by face array // it's not allowed to modify its curtain grids data if (true == csInfo.ByFaceArray) { // disable the buttons this.addCGButton.Enabled = false; this.removeCGButton.Enabled = false; this.facesCheckedListBox.Enabled = false; this.cgCheckedListBox.Enabled = false; // update the status hints string hint = Properties.Resources.HINT_CSIsByFaceArray; m_mydocument.Message = new KeyValuePair <string, bool>(hint, false); } // the selected curtain system is created by references of the faces // it's allowed to modify its curtain grids data else { // enable the buttons if (null == facesCheckedListBox.Items || 0 == facesCheckedListBox.Items.Count) { this.addCGButton.Enabled = false; } else { this.addCGButton.Enabled = true; } // at least one curtain grid must be kept if (null == cgCheckedListBox.Items || 2 > cgCheckedListBox.Items.Count) { this.removeCGButton.Enabled = false; } else { this.removeCGButton.Enabled = true; } this.facesCheckedListBox.Enabled = true; this.cgCheckedListBox.Enabled = true; // update the status hints string hint = ""; m_mydocument.Message = new KeyValuePair <string, bool>(hint, false); } }
/// <summary> /// the selected curtain system changed, update the "Curtain grid" and /// "Uncovered faces" list boxes of the selected curtain system /// </summary> /// <param name="sender"> /// object who sent this event /// </param> /// <param name="e"> /// event args /// </param> private void csListBox_SelectedIndexChanged(object sender, EventArgs e) { List<CurtainSystem.SystemInfo> csInfos = m_mydocument.SystemData.CurtainSystemInfos; // data verification if (null == csInfos || 0 == csInfos.Count) { return; } // // step 1: activate the selected one // CurtainSystem.SystemInfo csInfo = csInfos[csListBox.SelectedIndex]; // update the curtain grid list box cgCheckedListBox.Items.Clear(); foreach (int index in csInfo.GridFacesIndices) { CurtainSystem.GridFaceInfo gridFaceInfo = new CurtainSystem.GridFaceInfo(index); cgCheckedListBox.Items.Add(gridFaceInfo); } // update the uncovered face list box facesCheckedListBox.Items.Clear(); foreach (int index in csInfo.UncoverFacesIndices) { CurtainSystem.UncoverFaceInfo uncoverFaceInfo = new CurtainSystem.UncoverFaceInfo(index); facesCheckedListBox.Items.Add(uncoverFaceInfo); } // // step 2: enable/disable some buttons and refresh the status hints // // the selected curtain system is created by face array // it's not allowed to modify its curtain grids data if (true == csInfo.ByFaceArray) { // disable the buttons this.addCGButton.Enabled = false; this.removeCGButton.Enabled = false; this.facesCheckedListBox.Enabled = false; this.cgCheckedListBox.Enabled = false; // update the status hints string hint = Properties.Resources.HINT_CSIsByFaceArray; m_mydocument.Message = new KeyValuePair<string, bool>(hint, false); } // the selected curtain system is created by references of the faces // it's allowed to modify its curtain grids data else { // enable the buttons if (null == facesCheckedListBox.Items || 0 == facesCheckedListBox.Items.Count) { this.addCGButton.Enabled = false; } else { this.addCGButton.Enabled = true; } // at least one curtain grid must be kept if (null == cgCheckedListBox.Items || 2 > cgCheckedListBox.Items.Count) { this.removeCGButton.Enabled = false; } else { this.removeCGButton.Enabled = true; } this.facesCheckedListBox.Enabled = true; this.cgCheckedListBox.Enabled = true; // update the status hints string hint = ""; m_mydocument.Message = new KeyValuePair<string, bool>(hint, false); } }