/// <summary> /// Reads the ECInstance data from an element /// </summary> /// <param name="element">The element from which to read ECInstances from</param> /// <param name="recursive">Processes complex elements recursivly if true</param> /// <returns></returns> internal ECInstanceList ReadInstancesFromElement(Element element, bool recursive = false) { var elementRefP = (IntPtr)element.MdlElementRef(); var modelRefP = (IntPtr)element.ModelReference.MdlModelRefP(); var instances = new ECInstanceList(); var aSet = ReadInstancesFromElement(elementRefP, modelRefP); if (aSet.Count > 0) { instances.AddRange(aSet); } if (element.IsComplexElement() && recursive) { var ee = element.AsComplexElement().GetSubElements(); while (ee.MoveNext()) { aSet = ReadInstancesFromElement(ee.Current, true); if (aSet.Count > 0) { instances.AddRange(aSet); } } } return(instances); }
private void RefillItems ( int rowIndex, string className ) { DgnUtilities dgnUtil = DgnUtilities.GetInstance(); //ArrayList arr = dgnUtil.GetECInstanceDisplayLabelsFromDgn (className); ECInstanceList arr = DgnUtilities.GetInstance().GetAllInstancesFromDgn(className); DataGridViewComboBoxCell itemInstanceCell = this[s_WBSInstanceKey, rowIndex] as DataGridViewComboBoxCell; itemInstanceCell.Items.Clear(); itemInstanceCell.Tag = SchemaUtilities.PlantSchema.GetClass(className); itemInstanceCell.Value = null; if (_bMultiInst) { itemInstanceCell.Items.Add(_cstr_Varies); } itemInstanceCell.Items.Add(LocalizableStrings.None); Dictionary <string, IECInstance> dropDownCache = new Dictionary <string, IECInstance> (); foreach (IECInstance returnedInstance in arr) //for (int j = 0; j < arr.Count; j++) { string key = SchemaUtilities.GetDisplayNameForECInstance(returnedInstance, true); if (dropDownCache.ContainsKey(key)) { dropDownCache[key] = returnedInstance; } else { // insert dropDownCache.Add(key, returnedInstance); itemInstanceCell.Items.Add(key); } } if (dropDownCache.Count > 0) { itemInstanceCell.Tag = dropDownCache; } //for (int j = 0; j < arr.Count; j++) // itemInstanceCell.Items.Add (arr[j]); if (arr.Count > 0) { itemInstanceCell.Value = SchemaUtilities.GetDisplayNameForECInstance(arr[0], true); } else { itemInstanceCell.Value = LocalizableStrings.None; } }
/*------------------------------------------------------------------------------------**/ /// <summary> /// CheckConnectivity /// </summary> /// <param name="unparsed"></param> /*--------------+---------------+---------------+---------------+---------------+------*/ public static void CheckConnectivity ( string unparsed ) { BMECApi MechnanicalAPI = BMECApi.Instance; ECInstanceList ComponentList = null; DgnUtilities dgnUtil = DgnUtilities.GetInstance(); if (unparsed.ToUpper() == "HVAC") { PipelineManagerMode.Mode = PipelineManagerAvailableModes.HVAC; ComponentList = dgnUtil.GetAllInstancesFromDgn("HVAC_COMPONENT", true); } else if (unparsed.ToUpper() == "TRAY") { PipelineManagerMode.Mode = PipelineManagerAvailableModes.CableTray; ComponentList = dgnUtil.GetAllInstancesFromDgn("CABLETRAY_COMPONENT", true); } else { PipelineManagerMode.Mode = PipelineManagerAvailableModes.Piping; ComponentList = dgnUtil.GetAllInstancesFromDgn("PIPING_COMPONENT", true); } if (unparsed.ToUpper() == "FIXDISCONNECTS") { if (ComponentList.Count == 0) { return; } s_ConnectivityLog = new LogConnectivityReport(); s_ConnectivityLog.AutoConnectivityCheck(); s_ConnectivityLog.AutoDisconnectFix(); PipelineUtilities.IsConnectivityCheckerRunning = false; } else { if (ComponentList.Count == 0) { MechnanicalAPI.SendToMessageCenterD(DgnPlatformNET.OutputMessagePriority.Information, LocalizableStrings.NoComponentinDgn); } if (s_ConnectivityDialog != null) { s_ConnectivityDialog.ExamineAndShow(true); } if (s_ConnectivityDialog == null) { s_ConnectivityDialog = new DlgConnetivtyReport(); s_ConnectivityDialog.FormClosed += new FormClosedEventHandler(ConnectivityDialog_FormClosed); } s_ConnectivityDialog.Show(); } }
//WS: keyin Command public static void ListTags(string unparsed) { GeoTagList oListForm = new GeoTagList(); BCOM.ElementScanCriteria oScanCriteria = new BCOM.ElementScanCriteriaClass(); oScanCriteria.ExcludeAllTypes(); oScanCriteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.Scan(oScanCriteria); while (oEnum.MoveNext()) { BCOM.CellElement oCel = null; if (oEnum.Current.IsCellElement()) { if (oEnum.Current.AsCellElement().Name == "Embankment" || oEnum.Current.AsCellElement().Name == "RetainWall" || oEnum.Current.AsCellElement().Name == "Pond" || oEnum.Current.AsCellElement().Name == "Road" || oEnum.Current.AsCellElement().Name == "OpenChannel" || oEnum.Current.AsCellElement().Name == "Dike") { oCel = oEnum.Current.AsCellElement(); ECInstanceList oECInstancelist = GeoTagList.oECAdaptor.ReadInstancesFromElement(oCel, false); foreach (ECInstance oEC in oECInstancelist) { if (oEC.ClassDefinition.Name == "Embankment" || oEC.ClassDefinition.Name == "RetainWall" || oEC.ClassDefinition.Name == "Pond" || oEC.ClassDefinition.Name == "Road" || oEC.ClassDefinition.Name == "OpenChannel" || oEC.ClassDefinition.Name == "Dike") { //WS: loop through each class instance, get properties enumerator. IEnumerator <IECProperty> pFields = oEC.ClassDefinition.GetEnumerator(true); //WS: get properties values enumberator.. IEnumerator <IECPropertyValue> pVals = oEC.GetEnumerator(true); while (pFields.MoveNext()) { pVals.MoveNext(); if (pFields.Current.Name == "Tag_Number") { oListForm.WriteLine("Tag: " + pVals.Current.XmlStringValue + "; ElementId: " + oCel.ID.ToString()); } } } } } } } oListForm.ShowDialog(); }
private IECInstance GetAssociatedItemFromInstance ( IECInstance ecInstance, IECRelationshipClass ecRelClass, IECClass ecParentClass ) { DgnUtilities dgnUtil = DgnUtilities.GetInstance(); if (ecInstance.InstanceId == "mechanical") { return(null); } ECInstanceList ecList = dgnUtil.GetParentInstances(ecInstance, ecRelClass, ecParentClass, dgnUtil.GetDGNConnection()); return((ecList.Count > 0) ? ecList[0] : null); }
//WS: click "Select" button private void btnSelect_Click(object sender, EventArgs e) { BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.GetSelectedElements(); BCOM.Element[] oEleSet = oEnum.BuildArrayFromContents(); if (oEleSet.Length != 1) { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new LocateEle()); } else //WS: check if a correct cell with tag is already selected. { if (oEleSet[0].IsCellElement()) { if (oEleSet[0].AsCellElement().Name == "Embankment" || oEleSet[0].AsCellElement().Name == "Dike" || oEleSet[0].AsCellElement().Name == "Pond" || oEleSet[0].AsCellElement().Name == "Road" || oEleSet[0].AsCellElement().Name == "OpenChannel" || oEleSet[0].AsCellElement().Name == "RetainWall") { BCOM.Element oEle = oEleSet[0]; ECInstanceList oECInstancelist = GeoTag.Tag.oECAdaptor.ReadInstancesFromElement(oEle, false); foreach (ECInstance oEC in oECInstancelist) { if (oEC.ClassDefinition.Name == "Embankment" || oEC.ClassDefinition.Name == "RetainWall" || oEC.ClassDefinition.Name == "Pond" || oEC.ClassDefinition.Name == "Road" || oEC.ClassDefinition.Name == "OpenChannel" || oEC.ClassDefinition.Name == "Dike") { Commons.PopulateGeoTagForm(GeoTag.Tag.s_current, oEC); AddInMain.ComApp.ShowPrompt("Old Tag Data Retrived."); return; //Not necessary, but good practice. } } } else { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new LocateEle()); } } } }
public void Accept(BCOM.Element Element, ref BCOM.Point3d Point, BCOM.View View) { BCOM.Element oEle = Element; ECInstanceList oECInstancelist = Tag.oECAdaptor.ReadInstancesFromElement(oEle, false); foreach (ECInstance oEC in oECInstancelist) { if (oEC.ClassDefinition.Name == "Embankment" || oEC.ClassDefinition.Name == "RetainWall" || oEC.ClassDefinition.Name == "Pond" || oEC.ClassDefinition.Name == "Road" || oEC.ClassDefinition.Name == "OpenChannel" || oEC.ClassDefinition.Name == "Dike") { Commons.UpdateUIBasedOnFunctionCode(Tag.s_current, oEC.ClassDefinition.Name); Commons.PopulateGeoTagForm(Tag.s_current, oEC); //WS: select the element. AddInMain.ComApp.ActiveModelReference.SelectElement(oEle, true); AddInMain.ComApp.ShowCommand(""); AddInMain.ComApp.ShowPrompt("Old Tag Data Retrived."); break; } } }
/*------------------------------------------------------------------------------------**/ /// <summary> /// ReplaceComponents /// </summary> /// <param name="unparsed"></param> /*--------------+---------------+---------------+---------------+---------------+------*/ public static void ReplaceComponents ( string unparsed ) { if (PipelineUtilities.IsReplaceDialogRunning) { return; } BMECApi MechnanicalAPI = BMECApi.Instance; // Don't proceed for readonly files if (MechnanicalAPI.IsActiveModelReadOnly()) { MechnanicalAPI.SendToMessageCenterD(Bentley.DgnPlatformNET.OutputMessagePriority.Information, LocalizableStrings.DgnReadonly); return; } ECInstanceList ecList = MechnanicalAPI.GetSelectedInstances(); int count = 0; for (int i = 0; i < ecList.Count; i++) { IECInstance ecInstanceTemp = ecList[i] as IECInstance; if (ecInstanceTemp == null) { continue; } // Skip anything other than piping components or valve operators if (!(SchemaUtilities.IsPipingComponent(ecInstanceTemp) || SchemaUtilities.IsComponentOfType(ecInstanceTemp, ClassNames.VALVE_OPERATING_DEVICE))) { continue; } //You can't replace fasteners if (SchemaUtilities.IsComponentOfType(ecInstanceTemp, ClassNames.FASTENER)) { continue; } //You can't replace seals if (SchemaUtilities.IsComponentOfType(ecInstanceTemp, ClassNames.SEAL)) { continue; } count++; } ECInstanceList nozzleList = new ECInstanceList(); bool bHasFreeformNozzle = false; if (count == 0) { for (int i = 0; i < ecList.Count; i++) { IECInstance ecInstanceTemp = ecList[i] as IECInstance; if (ecInstanceTemp.ClassDefinition.Name == "NOZZLE") { IECPropertyValue propVal = ecInstanceTemp["TYPE_FOR_DATUM"]; if (propVal != null && propVal.StringValue == "Freeform") { bHasFreeformNozzle = true; nozzleList.Add(ecInstanceTemp); } } } } if (count == 0 && !bHasFreeformNozzle) { MechnanicalAPI.SendToMessageCenterD(DgnPlatformNET.OutputMessagePriority.Information, LocalizableStrings.NoComponentsSelectedinDgn); return; } for (int i = 0; i < ecList.Count; i++) { DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECInstance ecInst = ecList[i]; if (dgnUtil.IsECInstanceFromReferenceFile(ecInst) || dgnUtil.IsECInstanceReferencedOut(ecInst)) { MechnanicalAPI.SendToMessageCenterD(DgnPlatformNET.OutputMessagePriority.Information, LocalizableStrings.ReadonlyComps); return; } } if (s_ReplaceCompDialog == null) { if (nozzleList.Count <= 0) { s_ReplaceCompDialog = new DlgReplaceComponent(ecList, ReplaceDialogMode.SimpleReplace, true); s_ReplaceCompDialog.FormClosed += new FormClosedEventHandler(ReplaceCompDialog_FormClosed); } else { s_ReplaceCompDialog = new DlgReplaceComponent(nozzleList, ReplaceDialogMode.ChangeSpecSize, false); s_ReplaceCompDialog.FormClosed += new FormClosedEventHandler(ReplaceCompDialog_FormClosed); } } s_ReplaceCompDialog.Show(); }
public bool FillAssociatedItems(bool isModifyTool) { ArrayList classRelationshipStrs = SchemaUtilities.GetAssociatedItems(_ClassDef); if (classRelationshipStrs.Count == 0) { return(false); } if (_bMultiInst) {//when editing associations of multiple instances, edit and delete options should not be available. this.optionDelete.Visible = false; this.optionEdit.Visible = false; //refresh/redraw the grid this.OnResize(new EventArgs()); } for (int i = 0; i < classRelationshipStrs.Count; i++) { string strData = classRelationshipStrs[i] as string; string[] strArr = strData.Split(new char[] { '|' }); IECClass ecAssociatedClass = SchemaUtilities.PlantSchema.GetClass(strArr[0]); int rowIndex = this.Rows.Add(); DataGridViewTextBoxCell itemTypeCell = this[s_WBSClassKey, rowIndex] as DataGridViewTextBoxCell; itemTypeCell.Value = ecAssociatedClass.DisplayLabel; //itemTypeCell.Tag = ecAssociatedClass; DataGridViewComboBoxCell itemInstanceCell = this[s_WBSInstanceKey, rowIndex] as DataGridViewComboBoxCell; //ArrayList arr = DgnUtilities.GetInstance().GetECInstanceDisplayLabelsFromDgn (strArr[0]); ECInstanceList arr = DgnUtilities.GetInstance().GetAllInstancesFromDgn(strArr[0]); IECRelationshipClass ecAssociatedRel = SchemaUtilities.PlantSchema.GetClass(strArr[1]) as IECRelationshipClass; // move class to 1st column tag, to start with, later changed itemInstanceCell.Tag = ecAssociatedClass; itemTypeCell.Tag = ecAssociatedRel; if (_bMultiInst) { itemInstanceCell.Items.Add(_cstr_Varies); } itemInstanceCell.Items.Add(LocalizableStrings.None); Dictionary <string, IECInstance> dropDownCache = new Dictionary <string, IECInstance> (); foreach (IECInstance returnedInstance in arr) //for (int j = 0; j < arr.Count; j++) { // insert only if this is not from a referenced file if (DgnUtilities.GetInstance().IsECInstanceFromReferenceFile(returnedInstance)) { continue; } string key = SchemaUtilities.GetDisplayNameForECInstance(returnedInstance, true); if (dropDownCache.ContainsKey(key)) { dropDownCache[key] = returnedInstance; } else { // insert dropDownCache.Add(key, returnedInstance); itemInstanceCell.Items.Add(key); } } if (dropDownCache.Count > 0) { itemInstanceCell.Tag = dropDownCache; } if (isModifyTool) { string strLastInstID = null; string key = ""; for (int j = 0; j < _instList.Count; j++) { IECInstance parentInstance = GetAssociatedItemFromInstance(_instList[j], ecAssociatedRel, ecAssociatedRel.Source.GetClasses()[0].Class); string strCurrInstID = ""; // If we have a parent instance, then we must be using an existing instance. We need to make sure we select the existing values. if (null != parentInstance) { key = SchemaUtilities.GetDisplayNameForECInstance(parentInstance, true); strCurrInstID = parentInstance.InstanceId; } else { key = LocalizableStrings.None; strCurrInstID = LocalizableStrings.None; } if (String.IsNullOrEmpty(strLastInstID)) { strLastInstID = strCurrInstID; } else { if (strCurrInstID != strLastInstID) { key = _cstr_Varies; break; } } } // end for loop itemInstanceCell.Value = key; } itemInstanceCell.Sorted = true; DataGridViewImageCell tempImageCell = this["optionAdd", rowIndex] as DataGridViewImageCell; tempImageCell.Tag = ecAssociatedClass; } if (!isModifyTool) { ArrayList AssociatonList = WorkspaceUtilities.GetSettings("Associations." + _ClassDef.Name); LoadSettings(AssociatonList, false); } return(true); }
private void OnCellMouseClick ( object sender, DataGridViewCellMouseEventArgs e ) { if (e.RowIndex == -1) { return; } if (e.ColumnIndex == 1) { this.BeginEdit(true); ComboBox comboBox = (ComboBox)this.EditingControl; if (null != comboBox) { comboBox.DroppedDown = true; } } if (e.ColumnIndex < AddButtonColumn) { return; } DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECClass ecClass = getECClassInformationForCurrentSelection(e.RowIndex); //this[ClassColumn, e.RowIndex].Tag as IECClass; IECRelationshipClass ecRelClass = getECRelationshipClassInformationForCurrentSelection(e.RowIndex); //this[ComboBoxColumn, e.RowIndex].Tag as IECRelationshipClass; DataGridViewComboBoxCell itemInstanceCell = this[s_WBSInstanceKey, e.RowIndex] as DataGridViewComboBoxCell; string strVal = this[s_WBSInstanceKey, e.RowIndex].Value as string; if (strVal == LocalizableStrings.None && (e.ColumnIndex != AddButtonColumn && e.ColumnIndex != BrowseButtonColumn)) { this[e.ColumnIndex, e.RowIndex].Selected = false; return; } //ADD/////////////////////////////////////////////////////////////////////////////////////////////////////////// if (e.ColumnIndex == AddButtonColumn) { // If we are connected to iModelHub we should acquire a a new tag for WBS ECInstanceDialog ecDlg = new ECInstanceDialog(ecClass.Name); ecDlg.ShowDialog(); //User didn't save the new instance if (!ecDlg.SavePressed) { return; } //We were not able to save the new instance if (!ecDlg.SaveData()) { return; } RefillItems(e.RowIndex, ecClass.Name); if (itemInstanceCell.Items.Count > 0) { itemInstanceCell.Value = SchemaUtilities.GetDisplayNameForECInstance(ecDlg.GetECInstance(), false); } } //EDIT////////////////////////////////////////////////////////////////////////////////////////////////////////// else if (e.ColumnIndex == EditButtonColumn) { IECInstance ecInst = this[e.ColumnIndex, e.RowIndex].Tag as IECInstance; if (ecInst == null) { MessageBox.Show(LocalizableStrings.NoEditDesc, LocalizableStrings.NoEditTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { IECInstance ecInstance = EditECInstance(ecInst); if (ecInstance == null) { return; } RefillItems(e.RowIndex, ecClass.Name); if (itemInstanceCell.Items.Count > 0) { itemInstanceCell.Value = SchemaUtilities.GetDisplayNameForECInstance(ecInstance, false); } _bInstanceModified = true; } } //DELETE//////////////////////////////////////////////////////////////////////////////////////////////////////// else if (e.ColumnIndex == DeleteButtonColumn) { IECInstance ecInst = this[e.ColumnIndex, e.RowIndex].Tag as IECInstance; if (ecInst == null) { MessageBox.Show(LocalizableStrings.NoDeleteDescRefOut, LocalizableStrings.NoDeleteTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { //.GetRelationshipInstances (ecClass.Name, _instance.ClassDefinition.Name, ecRelClass.Name, dgnUtil.GetDGNConnection()); ECInstanceList ecList = dgnUtil.GetRelatedInstances(ecInst, ecRelClass, _ClassDef, dgnUtil.GetDGNConnection()); if (ecList.Count > 0) { MessageBox.Show(string.Format(LocalizableStrings.NoDeleteDescAssocCompFound, itemInstanceCell.Value), LocalizableStrings.NoDeleteTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (MessageBox.Show(String.Format(LocalizableStrings.AreYouSureDelete, SchemaUtilities.GetDisplayNameForECInstance(ecInst, true)), String.Format(LocalizableStrings.DeleteInstanceTitle, ecInst.ClassDefinition.DisplayLabel), MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.No) { return; } dgnUtil.DeleteECInstanceFromDgn(ecInst, dgnUtil.GetDGNConnection()); RefillItems(e.RowIndex, ecClass.Name); if (itemInstanceCell.Items.Count > 0) { itemInstanceCell.Value = itemInstanceCell.Items[0]; } else { itemInstanceCell.Value = null; } } _bInstanceModified = true; } //BROWSE//////////////////////////////////////////////////////////////////////////////////////////////////////// else if (e.ColumnIndex == BrowseButtonColumn) { IECInstance newEcinstance = ecClass.CreateInstance() as IECInstance; if (newEcinstance == null) { return; } object instance = dgnUtil.TagBrowser(newEcinstance, dgnUtil.AssoicatedItemsTagBrowserOverrides); if (instance == null || !(instance is IECInstance)) { return; } IECInstance selectedECInstance = instance as IECInstance; //CommonTools.BIMAdapter.BIMAdapter.ReleaseTag (newEcinstance); dgnUtil.CopyProperties(selectedECInstance, newEcinstance, false); //BusinessKeyUtility.Release (newEcinstance); BusinessKeyUtility.SetIsReserved(newEcinstance, true); dgnUtil.UpdateFunctionalGuidProperty(selectedECInstance, newEcinstance); dgnUtil.WriteECInstanceToDgn(newEcinstance, dgnUtil.GetDGNConnection()); //CommonTools.BIMAdapter //IECInstance inst = EditECInstance (ecInstance); //if(inst == null) // return; // inst = ecInstance; RefillItems(e.RowIndex, ecClass.Name); if (itemInstanceCell.Items.Count > 0) { itemInstanceCell.Value = SchemaUtilities.GetDisplayNameForECInstance(newEcinstance, false); } _bInstanceModified = true; } this[e.ColumnIndex, e.RowIndex].Selected = false; }