///// <summary> ///// Получение экземпляра средства записи EC-свойств в dgn-элемент. ///// Может быть NULL. ///// </summary> //public static ECPropertyReader TryGet( // Element element, ECClassTypeEnum instType) //{ // var reader = new ECPropertyReader(element, instType); // return reader.ecInst != null ? reader : null; //} public IECPropertyValue Get(string propName) { IECPropertyValue propVal = ecInst.GetPropertyValue(propName); if (propVal == null || propVal.IsNull) { //throw new SPDSException(string.Format( // "Element doesn't have property", propName)); return(null); } return(propVal); }
public void FindInstances() { DgnECManager manager = DgnECManager.Manager; FindInstancesScope scope = FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.Element, true)); ECQuery query = new ECQuery(Extension.Utilities.GetActiveModelAllClasses()); query.SelectClause.SelectAllProperties = true; manager.FindInstances(scope, query); //每次寻找实例不对啊,需要打开Property窗口后才能正确显示 using (DgnECInstanceCollection ecInstances = manager.FindInstances(scope, query)) { foreach (var ecin in ecInstances) { foreach (IECProperty itemProp in ecin.ClassDefinition.Properties(false)) { var instanceitem = new Instance(); instanceitem.ClassName = ecin.ClassDefinition.DisplayLabel; instanceitem.PropertyName = itemProp.Name; string type = itemProp.Type.Name.ToLower(); instanceitem.TypeName = type; IECPropertyValue propvalue = ecin.GetPropertyValue(itemProp.Name); switch (type) { case "string": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "boolean": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "int": instanceitem.PropertyValue = (propvalue != null) ? propvalue.IntValue.ToString() : ""; break; case "double": instanceitem.PropertyValue = (propvalue != null) ? propvalue.DoubleValue.ToString() : ""; break; } Instances.Add(instanceitem); } } } }
/*------------------------------------------------------------------------------------**/ /// <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 void UpdateWBSParts(ArrayList assocItems, IECInstance selectedECInstance) { if (assocItems == null || assocItems.Count == 0 || selectedECInstance == null) { return; } //set cache of WBS items (classname, relationship name) IDictionary <string, string> aitems = new Dictionary <string, string> (); foreach (string item in assocItems) { string[] part = item.Split(new char[] { '|' }); if (part.Length < 1) { continue; } string className = part[0]; string relClassName = part[1]; if (!aitems.ContainsKey(className)) { aitems.Add(className, relClassName); } } DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECRelationshipInstanceCollection ecList = selectedECInstance.GetRelationshipInstances(); if (ecList == null || ecList.Count == 0) { return; } bool needWBS = false; string msg = string.Empty; //iterate thru relationship instances IEnumerator en = ecList.GetEnumerator(); while (en.MoveNext()) { IECRelationshipInstance rel = en.Current as IECRelationshipInstance; if (rel == null) { continue; } string wbsRelationshipName = rel.ClassDefinition.Name; IECInstance wbsSource = rel.Source; if (wbsSource == null) { continue; } string wbsSourceClassName = wbsSource.ClassDefinition.Name; //match wbs type and pass to UpdateWBSComboxValue() if (!aitems.ContainsKey(wbsSourceClassName)) { continue; } if (UpdateWBSComboxValue(wbsSource, wbsRelationshipName) == WBSUpdateType.NeedToCreate) { IECPropertyValue sourceVal = wbsSource.FindPropertyValue(s_WBSName, false, false, false); string val = string.Empty; if (sourceVal != null && !sourceVal.IsNull) { val = sourceVal.StringValue; } msg = msg + "\n" + string.Format(LocalizableStrings.MissingWbs, wbsSourceClassName, val); needWBS = true; } } if (needWBS && !string.IsNullOrEmpty(msg)) { string val = WorkspaceUtilities.GetMSConfigVariable("AllowPlacementOnMissingWBSItems"); if (string.IsNullOrEmpty(val) || val != "1") { dgnUtil.RunKeyin("BMECH DEFERDEFAULTCMD"); } //this value is used in consistency manager placement. //setting to false allows CM to display instances correctly dgnUtil.ConsistencyPlacementValidState = false; string message = string.Format(LocalizableStrings.AlertMissingWbs, msg); dgnUtil.ConsistencyPlacementErrorMessage = message; MessageBox.Show(message, LocalizableStrings.WBSAlert, MessageBoxButtons.OK, MessageBoxIcon.Warning); WorkspaceUtilities.DisplayWarningMessage(LocalizableStrings.WBSAlert, message); } }
private void OnCellValueChanged ( object sender, DataGridViewCellEventArgs e ) { if (e.ColumnIndex != 1) { return; } if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } IECClass ecClass = getECClassInformationForCurrentSelection(e.RowIndex); //this[ClassColumn, e.RowIndex].Tag as IECClass; IECRelationshipClass ecRelClass = getECRelationshipClassInformationForCurrentSelection(e.RowIndex); //this[ClassColumn, e.RowIndex].Tag as IECRelationshipClass; string strVal = LocalizableStrings.None; if (null != this[ComboBoxColumn, e.RowIndex].Value) { strVal = this[ComboBoxColumn, e.RowIndex].Value.ToString(); } if (strVal == _cstr_Varies) { return; } DgnUtilities dgnUtil = DgnUtilities.GetInstance(); IECInstance newECIsnt = getInstanceForCurrentSelection(e.RowIndex, strVal); // get from Tag //dgnUtil.GetSourceInstance (ecClass, strVal); foreach (IECInstance ecInstance in _instList) { IECRelationshipInstanceCollection ecRelCol = ecInstance.GetRelationshipInstances(); IEnumerator <IECRelationshipInstance> ecRelInstEnum = ecRelCol.GetEnumerator(); bool newSourceSet = false; while (ecRelInstEnum.MoveNext()) { IECRelationshipInstance ecRelInst = ecRelInstEnum.Current; if (!ecRelInst.ClassDefinition.Is(ecRelClass)) { continue; } if (strVal == LocalizableStrings.None || string.IsNullOrEmpty(strVal)) { ecRelCol.Remove(ecRelInst); } else { ecRelInst.Source = newECIsnt; } newSourceSet = true; break; } if (!newSourceSet && newECIsnt != null) { IECRelationshipInstance temporaryRelInst = ecRelClass.CreateInstance() as IECRelationshipInstance; temporaryRelInst.Source = newECIsnt; temporaryRelInst.Target = ecInstance; ecInstance.GetRelationshipInstances().Add(temporaryRelInst); } IECInstance ecInst = newECIsnt; if (ecInst != null) { if ((dgnUtil.IsECInstanceFromReferenceFile(ecInst) || dgnUtil.IsECInstanceReferencedOut(ecInst) || ecInst.IsReadOnly)) { ecInst = null; } } DataGridViewImageCell tempImageCell = this["optionEdit", e.RowIndex] as DataGridViewImageCell; tempImageCell.Tag = ecInst; tempImageCell = this["optionDelete", e.RowIndex] as DataGridViewImageCell; tempImageCell.Tag = ecInst; //Mark the property (having business key CA/or NAME property if no Business key is defined) as changed and set the event which will reset the property pane. //This is required to update UNIT and SERVICE property listed in property pane on the fly whenever user changes the UNIT or SERVICE in ASSOCIATIONS pane. IECPropertyValue propVal = BusinessKeyUtility.GetPropertyValue(ecInstance); if (propVal != null) { ecInstance.OnECPropertyValueChanged(propVal); } } SaveSettings(); }
//update the WBS specific item based on the wbs ecinstance and relationship name private WBSUpdateType UpdateWBSComboxValue(IECInstance sourceWBS, string WBSRrelationshipName) { //set source WBS values //these values will be matched against values in existing datagrid combo box string sourceName = sourceWBS.ClassDefinition.Name; IECPropertyValue sourceVal = sourceWBS.FindPropertyValue(s_WBSName, false, false, false); if (sourceVal == null || sourceVal.IsNull) { return(WBSUpdateType.Error); } string sourceWbsValue = sourceVal.StringValue; DataGridViewCell dataGridClassCell = null; DataGridViewCell dataGridInstanceCell = null; //iterate items and try match passed in value against associated datagrid combox items for (int i = 0; i < this.Rows.Count; i++) { ECClass ecClass = this[s_WBSClassKey, i].Tag as ECClass; if (!ecClass.Name.Equals(WBSRrelationshipName)) { continue; } string currentValue = this[s_WBSInstanceKey, i].Value as string; //values are the same no need to update if (currentValue.Equals(sourceWbsValue)) { return(WBSUpdateType.ExistingFoundInDgn); } //list of existing WBS items are stored in tag Dictionary <string, IECInstance> cachedInstances = this[s_WBSInstanceKey, i].Tag as Dictionary <string, IECInstance>; if (cachedInstances == null || cachedInstances.Count == 0) { continue; } foreach (IECInstance wbsInst in cachedInstances.Values) { IECPropertyValue wbsPropval = wbsInst.FindPropertyValue(s_WBSName, false, false, false); if (wbsPropval == null || wbsPropval.IsNull) { return(WBSUpdateType.Error); } //if match is found set datagrid values if (wbsPropval.StringValue.Equals(sourceWbsValue)) { dataGridClassCell = this[s_WBSClassKey, i]; dataGridInstanceCell = this[s_WBSInstanceKey, i]; break; } } if (dataGridInstanceCell != null && dataGridClassCell != null) { break; } } //if all those values are found, set datagrid values if (dataGridInstanceCell != null && dataGridClassCell != null) { dataGridClassCell.Selected = true; dataGridInstanceCell.Selected = true; dataGridInstanceCell.Value = sourceWbsValue; return(WBSUpdateType.ExistingFoundInDgn); } return(WBSUpdateType.NeedToCreate); }