Beispiel #1
0
        public static SelectType_e[] GetDefaultFilters(IAttributeSet atts, out ISelectionCustomFilter customFilter)
        {
            var filters = new List <SelectType_e>();

            customFilter = null;

            if (atts == null)
            {
                throw new ArgumentNullException(nameof(atts));
            }

            var type = atts.BoundType;

            if (type.IsAssignableToGenericType(typeof(IEnumerable <>)))
            {
                type = type.GetArgumentsOfGenericType(typeof(IEnumerable <>)).First();
            }

            if (IsOfType <IXEdge>(type))
            {
                filters.Add(SelectType_e.Edges);
            }
            else if (IsOfType <IXFace>(type))
            {
                filters.Add(SelectType_e.Faces);
            }
            else if (IsOfType <IXSketchBase>(type))
            {
                filters.Add(SelectType_e.Sketches);
            }
            else if (IsOfType <IXSketchPoint>(type))
            {
                filters.Add(SelectType_e.SketchPoints);
            }
            else if (IsOfType <IXSketchSegment>(type))
            {
                filters.Add(SelectType_e.SketchSegments);
            }
            else if (IsOfType <IXComponent>(type))
            {
                filters.Add(SelectType_e.Components);
            }
            else if (IsOfType <IXBody>(type))
            {
                filters.Add(SelectType_e.SolidBodies);
                filters.Add(SelectType_e.SurfaceBodies);
            }

            if (!filters.Any())
            {
                filters.Add(SelectType_e.Everything);
            }

            if (customFilter == null)
            {
                customFilter = new TypeSelectionCustomFilter(type);
            }

            return(filters.ToArray());
        }
        protected override PropertyManagerPageSelectionBoxControl CreateControl(
            IPropertyManagerPageSelectionbox swCtrl, IAttributeSet atts, IMetadata metadata,
            SwPropertyManagerPageHandler handler, short height)
        {
            swCtrl.SingleEntityOnly = !(typeof(IList).IsAssignableFrom(atts.ContextType));

            if (height == -1)
            {
                height = 20;
            }

            swCtrl.Height = height;

            ISelectionCustomFilter customFilter = null;

            var filters = SelectionBoxConstructorHelper.GetDefaultFilters(atts);

            bool focusOnOpen = false;

            if (atts.Has <SelectionBoxOptionsAttribute>())
            {
                var selAtt = atts.Get <SelectionBoxOptionsAttribute>();

                if (selAtt.Style != 0)
                {
                    swCtrl.Style = (int)selAtt.Style;
                }

                if (selAtt.SelectionColor != 0)
                {
                    swCtrl.SetSelectionColor(true, (int)selAtt.SelectionColor);
                }

                if (selAtt.Filters?.Any() == true)
                {
                    filters = selAtt.Filters;
                }

                swCtrl.Mark = selAtt.SelectionMark;

                focusOnOpen = selAtt.Focused;

                if (selAtt.CustomFilter != null)
                {
                    customFilter = Activator.CreateInstance(selAtt.CustomFilter) as ISelectionCustomFilter;

                    if (customFilter == null)
                    {
                        throw new InvalidCastException(
                                  $"Specified custom filter of type {selAtt.CustomFilter.FullName} cannot be cast to {typeof(ISelectionCustomFilter).FullName}");
                    }
                }
            }

            swCtrl.SetSelectionFilters(filters.Select(f => (swSelectType_e)f).ToArray());

            return(new PropertyManagerPageSelectionBoxControl(m_SwApp, atts.Id, atts.Tag,
                                                              swCtrl, handler, atts.ContextType, customFilter, focusOnOpen));
        }
        protected override PropertyManagerPageSelectionBoxControl CreateControl(
            IPropertyManagerPageSelectionbox swCtrl, IAttributeSet atts, SwPropertyManagerPageHandler handler, short height)
        {
            swCtrl.SingleEntityOnly = !(typeof(IList).IsAssignableFrom(atts.BoundType));

            if (height == -1)
            {
                height = 20;
            }

            swCtrl.Height = height;

            ISelectionCustomFilter customFilter = null;

            SelectType_e[] filters = null;

            if (atts.Has <SelectionBoxOptionsAttribute>())
            {
                var selAtt = atts.Get <SelectionBoxOptionsAttribute>();

                if (selAtt.Style != 0)
                {
                    swCtrl.Style = (int)selAtt.Style;
                }

                if (selAtt.SelectionColor != 0)
                {
                    swCtrl.SetSelectionColor(true, ConvertColor(selAtt.SelectionColor));
                }

                if (selAtt.Filters != null)
                {
                    filters = selAtt.Filters;
                }

                swCtrl.Mark = selAtt.SelectionMark;

                if (selAtt.CustomFilter != null)
                {
                    customFilter = Activator.CreateInstance(selAtt.CustomFilter) as ISelectionCustomFilter;

                    if (customFilter == null)
                    {
                        throw new InvalidCastException(
                                  $"Specified custom filter of type {selAtt.CustomFilter.FullName} cannot be cast to {typeof(ISelectionCustomFilter).FullName}");
                    }
                }
            }
            else
            {
                filters = GetDefaultFilters(atts, out customFilter);
            }

            swCtrl.SetSelectionFilters(filters);

            return(new PropertyManagerPageSelectionBoxControl(m_SwApp, atts.Id, atts.Tag,
                                                              swCtrl, handler, atts.BoundType, customFilter));
        }
Beispiel #4
0
        public PropertyManagerPageSelectionBoxEx(ISldWorks app, int id, object tag,
                                                 IPropertyManagerPageSelectionbox selBox,
                                                 PropertyManagerPageHandlerEx handler, Type objType, ISelectionCustomFilter customFilter = null)
            : base(selBox, id, tag, handler)
        {
            m_App          = app;
            m_ObjType      = objType;
            m_CustomFilter = customFilter;

            m_Handler.SelectionChanged += OnSelectionChanged;

            if (m_CustomFilter != null)
            {
                m_Handler.SubmitSelection += OnSubmitSelection;
            }
        }
Beispiel #5
0
        public PropertyManagerPageSelectionBoxControl(ISwApplication app, int id, object tag,
                                                      IPropertyManagerPageSelectionbox selBox,
                                                      SwPropertyManagerPageHandler handler, Type objType, ISelectionCustomFilter customFilter, bool defaultFocus)
            : base(selBox, id, tag, handler)
        {
            m_App          = app;
            m_ObjType      = objType;
            m_ElementType  = SelectionBoxConstructorHelper.GetElementType(m_ObjType);
            m_CustomFilter = customFilter;

            m_DefaultFocus = defaultFocus;

            m_Handler.SelectionChanged += OnSelectionChanged;

            if (m_DefaultFocus)
            {
                m_Handler.Opened += OnPageOpened;
            }

            m_Handler.SubmitSelection += OnSubmitSelection;
        }
 protected virtual SelectType_e[] GetDefaultFilters(IAttributeSet atts, out ISelectionCustomFilter customFilter)
 {
     return(SelectionBoxConstructorHelper.GetDefaultFilters(atts, out customFilter));
 }