예제 #1
0
        /// <summary>
        /// Returns an instance of <see cref="Image"/> based on the provided <see cref="ClassKind"/>
        /// </summary>
        /// <param name="classKind">
        /// the subject <see cref="ClassKind"/>
        /// </param>
        /// <param name="getsmallicon">
        /// Indicates whether a small or large icon should be returned.
        /// </param>
        /// <returns>
        /// An of <see cref="Image"/> that corresponds to the subject <see cref="ClassKind"/>
        /// </returns>
        public Image GetImage(ClassKind classKind, bool getsmallicon = true)
        {
            Uri imageUri;

            if (IconUtilities.ImageUri(classKind, getsmallicon) is string convertedstring)
            {
                imageUri = new Uri(convertedstring);
                var image  = new BitmapImage(imageUri);
                var bitmap = IconUtilities.BitmapImage2Bitmap(image);
                return(bitmap);
            }

            if (IconUtilities.ImageUri(classKind, getsmallicon) is DXImageExtension convertedDXImageExtension)
            {
                var image = new BitmapImage();
                image.BeginInit();
                image.UriSource = convertedDXImageExtension.Image.MakeUri();
                image.EndInit();

                var bitmap = IconUtilities.BitmapImage2Bitmap(image);
                return(bitmap);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Returns an GetImage (icon) based on the <see cref="Thing"/> that is provided
        /// </summary>
        /// <param name="value">An instance of <see cref="Thing"/> for which an Icon needs to be returned</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The parameter is not used.</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>
        /// A <see cref="Uri"/> to an GetImage
        /// </returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var rowStatus   = value.OfType <RowStatusKind>().SingleOrDefault();
            var thing       = value.OfType <Thing>().SingleOrDefault();
            var thingStatus = value.OfType <ThingStatus>().SingleOrDefault();

            Uri uri;

            if (thing == null && thingStatus == null)
            {
                return(null);
            }

            var classKind = thing != null ? thing.ClassKind : thingStatus.Thing.ClassKind;

            switch (rowStatus)
            {
            case RowStatusKind.Active:
                uri = new Uri(IconUtilities.ImageUri(classKind).ToString());
                break;

            case RowStatusKind.Inactive:
                uri = new Uri(this.GrayScaleImageUri(classKind).ToString());
                break;

            default:
                uri = new Uri(IconUtilities.ImageUri(classKind).ToString());
                break;
            }

            if (thing != null)
            {
                if (thing.ValidationErrors.Any())
                {
                    return(this.QueryIIconCacheService().QueryErrorOverlayBitmapSource(uri));
                }
                else
                {
                    return(this.QueryIIconCacheService().QueryBitmapImage(uri));
                }
            }

            if (thingStatus.HasError)
            {
                return(this.QueryIIconCacheService().QueryErrorOverlayBitmapSource(uri));
            }

            if (thingStatus.HasRelationship)
            {
                return(this.QueryIIconCacheService().QueryOverlayBitmapSource(uri, IconUtilities.RelationshipOverlayUri, OverlayPositionKind.TopRight));
            }

            return(this.QueryIIconCacheService().QueryBitmapImage(uri));
        }
예제 #3
0
        /// <summary>
        /// Returns an GetImage (icon) based on the <see cref="ClassKind"/> that is provided
        /// </summary>
        /// <param name="value">A <see cref="ClassKind"/> for which an Icon needs to be returned</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The <see cref="ClassKind"/> of the overlay to use</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>
        /// A <see cref="Uri"/> to an GetImage
        /// </returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            var classKind = value.OfType <ClassKind?>().SingleOrDefault();

            if (classKind == null)
            {
                return(null);
            }

            var baseUri = new Uri(IconUtilities.ImageUri(classKind.Value).ToString());

            return(this.QueryIIconCacheService().QueryBitmapImage(baseUri));
        }
        /// <summary>
        /// Returns an GetImage (icon) based on the <see cref="Thing" /> that is provided
        /// </summary>
        /// <param name="value">An instance of <see cref="Thing" /> for which an Icon needs to be returned</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The <see cref="ClassKind" /> of the overlay to use</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>
        /// A <see cref="Uri" /> to an GetImage
        /// </returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            var genericConverter = new ThingToIconUriConverter();
            var thingStatus      = value.SingleOrDefault() as ThingStatus;

            var parameterBase = thingStatus?.Thing as ParameterBase;

            ClassKind valuesetRowType;

            if (parameterBase == null || parameter == null || !Enum.TryParse(parameter.ToString(), out valuesetRowType))
            {
                return(genericConverter.Convert(value, targetType, parameter, culture));
            }

            var isCompound = parameterBase.ParameterType is CompoundParameterType;

            // Value set row
            // row representing an option
            if (valuesetRowType == ClassKind.Option)
            {
                var optionUri = new Uri(IconUtilities.ImageUri(valuesetRowType).ToString());

                if (parameterBase.StateDependence != null || isCompound)
                {
                    return(new BitmapImage(optionUri));
                }

                var uri = new Uri(IconUtilities.ImageUri(parameterBase.ClassKind).ToString());
                return(IconUtilities.WithOverlay(uri, optionUri));
            }

            // row representing a component
            if (valuesetRowType == ClassKind.ParameterTypeComponent)
            {
                var componentUri = new Uri(IconUtilities.ImageUri(valuesetRowType).ToString());
                return(new BitmapImage(componentUri));
            }

            // Row representing state
            var stateUri = new Uri(IconUtilities.ImageUri(ClassKind.ActualFiniteState).ToString());

            if (isCompound)
            {
                return(new BitmapImage(stateUri));
            }

            var baseUri = new Uri(IconUtilities.ImageUri(parameterBase.ClassKind).ToString());

            return(IconUtilities.WithOverlay(baseUri, stateUri));
        }
예제 #5
0
        /// <summary>
        /// Returns an GetImage (icon) based on the <see cref="Thing"/> that is provided
        /// </summary>
        /// <param name="value">An instance of <see cref="Thing"/> for which an Icon needs to be returned</param>
        /// <param name="targetType">The parameter is not used.</param>
        /// <param name="parameter">The <see cref="ClassKind"/> of the overlay to use</param>
        /// <param name="culture">The parameter is not used.</param>
        /// <returns>
        /// A <see cref="Uri"/> to an GetImage
        /// </returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (value.Length == 0)
            {
                return(null);
            }

            var file = value[0] as File;

            if (file != null)
            {
                var fileIconUri = new Uri(IconUtilities.ImageUri(file.ClassKind).ToString());
                return(new BitmapImage(fileIconUri));
            }

            var thing = value[0] as Thing;

            if (thing != null)
            {
                var fileIconUri = new Uri(IconUtilities.ImageUri(thing.ClassKind).ToString());
                return(new BitmapImage(fileIconUri));
            }

            var isLocked = value[0] as bool?;

            if (isLocked != null && isLocked.Value)
            {
                var lockedUri = new Uri("pack://application:,,,/CDP4Composition;component/Resources/Images/Thing/lock.png", UriKind.RelativeOrAbsolute);
                return(new BitmapImage(lockedUri));
            }

            return(null);
        }