/// <summary> /// Add form to taskpanel /// </summary> public void Routing(IModelDoc2 doc, ISldWorks swApp, List <string> routingIds) { ITaskpaneView pTaskPanView = null; if (GlobalCache.Instance.PTaskPanView == null) { pTaskPanView = iSwApp.CreateTaskpaneView2("", "关联工艺路线"); GlobalCache.Instance.PTaskPanView = pTaskPanView; } else { pTaskPanView = GlobalCache.Instance.PTaskPanView; } frm = new ProcessLine(doc, swApp, routingIds); pTaskPanView.DisplayWindowFromHandle(frm.Handle.ToInt32()); }
/// <inheritdoc/> public ITaskpaneView CreateTaskPane <TControl, TCmdEnum>(Action <TCmdEnum> cmdHandler, out TControl ctrl) where TControl : UserControl, new() where TCmdEnum : IComparable, IFormattable, IConvertible { var tooltip = ""; CommandGroupIcon taskPaneIcon = null; var getTaskPaneDisplayData = new Action <Type, bool>((t, d) => { if (taskPaneIcon == null) { taskPaneIcon = DisplayInfoExtractor.ExtractCommandDisplayIcon <TaskPaneIconAttribute, CommandGroupIcon>( t, i => new TaskPaneMasterIcon(i), a => a.Icon, d); } if (string.IsNullOrEmpty(tooltip)) { if (!t.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName)) { t.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description); } } }); if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e)) { getTaskPaneDisplayData.Invoke(typeof(TCmdEnum), false); } getTaskPaneDisplayData.Invoke(typeof(TControl), true); ITaskpaneView taskPaneView = null; ITaskPaneHandler taskPaneHandler = null; m_Logger.Log($"Creating task pane for {typeof(TControl).FullName} type"); using (var iconConv = new IconsConverter()) { if (App.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane)) { var taskPaneIconImages = iconConv.ConvertIcon(taskPaneIcon, true); taskPaneView = App.CreateTaskpaneView3(taskPaneIconImages, tooltip); } else { var taskPaneIconImage = iconConv.ConvertIcon(taskPaneIcon, false)[0]; taskPaneView = App.CreateTaskpaneView2(taskPaneIconImage, tooltip); } taskPaneHandler = new TaskPaneHandler <TCmdEnum>(App, taskPaneView, cmdHandler, iconConv, m_Logger); } if (typeof(TControl).IsComVisible()) { var progId = typeof(TControl).GetProgId(); ctrl = taskPaneView.AddControl(progId, "") as TControl; if (ctrl == null) { throw new NullReferenceException( $"Failed to create COM control from {progId}. Make sure that COM component is properly registered"); } } else { ctrl = new TControl(); ctrl.CreateControl(); var handle = ctrl.Handle; if (!taskPaneView.DisplayWindowFromHandle(handle.ToInt32())) { throw new NullReferenceException($"Failed to host .NET control (handle {handle}) in task pane"); } } taskPaneHandler.Disposed += OnTaskPaneHandlerDisposed; m_TaskPanes.Add(taskPaneHandler); return(taskPaneView); }
private void btnComfirm_Click(object sender, EventArgs e) { var routings = from p in rcontext.ProcessFileRoutinges where p.ProcessFileName == GlobalCache.Instance.ComponetName && p.RoutingId == cbxProcessLine.SelectedValue.ToString() select p; if (routings.Count() > 0) { MessageBox.Show("该零件已和选中的工艺路线进行了关联!"); return; } ProcessFileRouting processFileRouting = new ProcessFileRouting(); processFileRouting.RoutingId = cbxProcessLine.SelectedValue.ToString(); processFileRouting.ProcessFileRoutingId = Guid.NewGuid().ToString(); processFileRouting.ProcessFileName = _processFilePath; processFileRouting.ProcessFilePath = _processFilePath; processFileRouting.OperId = ""; try { rcontext.ProcessFileRoutinges.InsertOnSubmit(processFileRouting); rcontext.SubmitChanges(); MessageBox.Show("关联零件到工艺路线成功!"); ITaskpaneView pTaskPanView = null; if (GlobalCache.Instance.PTaskPanView == null) { pTaskPanView = _swApp.CreateTaskpaneView2("", "关联工艺路线"); GlobalCache.Instance.PTaskPanView = pTaskPanView; } else { pTaskPanView = GlobalCache.Instance.PTaskPanView; } ProcessLine frm = null; if (ProcessLine.CurrentProcessLine == null) { frm = new ProcessLine( _doc, _swApp, new List <string>() { processFileRouting.RoutingId }); pTaskPanView.DisplayWindowFromHandle(frm.Handle.ToInt32()); } else { ///show in task plane ProcessLine.CurrentProcessLine.AddProcessLine( null, new RoutingEventArgs() { RoutingId = processFileRouting.RoutingId, RoutingName = ((Routing)cbxProcessLine.SelectedItem).Name }); } } catch { MessageBox.Show("关联零件到工艺路线出错!"); } this.Dispose(); GC.Collect(); }
public bool ProvideNetControl(ITaskpaneView taskPaneView, Control ctrl) => taskPaneView.DisplayWindowFromHandle(ctrl.Handle.ToInt32());