Beispiel #1
0
        private void LoadButtons(ITaskpaneView taskPaneView, ISldWorks app)
        {
            if (Spec.Buttons?.Any() == true)
            {
                using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>())
                {
                    foreach (var btn in Spec.Buttons)
                    {
                        var tooltip = btn.Tooltip;

                        if (string.IsNullOrEmpty(tooltip))
                        {
                            tooltip = btn.Title;
                        }

                        if (btn.StandardIcon.HasValue)
                        {
                            if (!taskPaneView.AddStandardButton((int)btn.StandardIcon, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to add standard button for '{tooltip}'");
                            }
                        }
                        else
                        {
                            var icon = btn.Icon;

                            if (icon == null)
                            {
                                icon = Defaults.Icon;
                            }

                            //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands
                            if (app.SupportsHighResIcons(CompatibilityUtils.HighResIconsScope_e.TaskPane))
                            {
                                var imageList = iconsConv.ConvertIcon(new CommandGroupHighResIcon(icon));
                                if (!taskPaneView.AddCustomButton2(imageList, tooltip))
                                {
                                    throw new InvalidOperationException($"Failed to create task pane button for '{tooltip}' with highres icon");
                                }
                            }
                            else
                            {
                                var imagePath = iconsConv.ConvertIcon(new CommandGroupIcon(icon)).First();
                                if (!taskPaneView.AddCustomButton(imagePath, tooltip))
                                {
                                    throw new InvalidOperationException($"Failed to create task pane button for {tooltip}");
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public bool ProvideNetControl(ITaskpaneView taskPaneView, Control ctrl)
        {
            var genCtrl = (GeneralControlHost)ProvideComControl(taskPaneView, GeneralControlHost.ProgId);

            if (genCtrl != null)
            {
                ctrl.Dock = DockStyle.Fill;
                genCtrl.Controls.Add(ctrl);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <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());
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
 public object ProvideComControl(ITaskpaneView taskPaneView, string progId)
 => taskPaneView.AddControl(progId, "");
Beispiel #7
0
 public bool ProvideNetControl(ITaskpaneView taskPaneView, Control ctrl)
 => taskPaneView.DisplayWindowFromHandle(ctrl.Handle.ToInt32());
Beispiel #8
0
 public ITaskpaneViewObject(ITaskpaneView ITaskpaneViewinstance)
 {
     ITaskpaneViewInstance = ITaskpaneViewinstance;
 }
Beispiel #9
0
        internal TaskPaneHandler(ISldWorks app, ITaskpaneView taskPaneView,
                                 Action <TCmdEnum> cmdHandler, IIconsConverter iconsConv, ILogger logger)
        {
            m_Logger = logger;

            m_TaskPaneView = taskPaneView;
            m_CmdHandler   = cmdHandler;

            if (!typeof(TCmdEnum).IsEnum)
            {
                throw new ArgumentException($"{typeof(TCmdEnum)} must be an enumeration");
            }

            if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e) && cmdHandler != null)
            {
                var enumValues = Enum.GetValues(typeof(TCmdEnum));

                m_Commands = enumValues.Cast <TCmdEnum>().ToArray();

                foreach (Enum cmdEnum in enumValues)
                {
                    //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands
                    var icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>(
                        cmdEnum,
                        i => new MasterIcon(i),
                        a => a.Icon);

                    var tooltip = "";

                    if (!cmdEnum.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName))
                    {
                        cmdEnum.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description);
                    }

                    if (!cmdEnum.TryGetAttribute <TaskPaneStandardButtonAttribute>(a =>
                    {
                        if (!m_TaskPaneView.AddStandardButton((int)a.Icon, tooltip))
                        {
                            throw new InvalidOperationException($"Failed to add standard button for {cmdEnum}");
                        }
                    }))
                    {
                        if (app.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane))
                        {
                            var imageList = iconsConv.ConvertIcon(icon, true);
                            if (!m_TaskPaneView.AddCustomButton2(imageList, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum} with highres icon");
                            }
                        }
                        else
                        {
                            var imagePath = iconsConv.ConvertIcon(icon, false)[0];
                            if (!m_TaskPaneView.AddCustomButton(imagePath, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum}");
                            }
                        }
                    }
                }

                (m_TaskPaneView as TaskpaneView).TaskPaneToolbarButtonClicked += OnTaskPaneToolbarButtonClicked;
            }

            (m_TaskPaneView as TaskpaneView).TaskPaneDestroyNotify += OnTaskPaneDestroyNotify;
        }