Beispiel #1
0
        private void AddGridRow([NotNull] IItemTemplate template, [NotNull] GridPanel panel)
        {
            string itemType = null;
            Image  image    = null;

            if (template is IEntityTemplate entityTemplate)
            {
                itemType = entityTemplate.EntityType.GetEnumLabel();
                entityTemplate.ImageChanged += OnImageChanged;
            }
            else if (template is IFlowTemplate)
            {
                itemType = "Flow";
            }
            else if (template is ITrustBoundaryTemplate)
            {
                itemType = "Trust Boundary";
            }

            var row = new GridRow(template.Name, itemType);

            ((INotifyPropertyChanged)template).PropertyChanged += OnTemplatePropertyChanged;
            row.Tag = template;
            row.Cells[0].CellStyles.Default.Image = template.GetImage(ImageSize.Small);
            for (int i = 0; i < row.Cells.Count; i++)
            {
                row.Cells[i].PropertyChanged += OnPropertyChanged;
            }
            panel.Rows.Add(row);
        }
    public ItemIconPickUpImplementor CreateIIPUImplementor(int transferableQuantity, int itemQuantity, int pickUpStepQuantity, out IItemIcon ii, out IItemIconTransactionManager iiTAM, out IPickUpSystemUIElementFactory uieFactory)
    {
        IItemIcon thisII = Substitute.For <IItemIcon>();

        thisII.GetUIImage().Returns(Substitute.For <IUIImage>());
        IItemTemplate itemTemp = Substitute.For <IItemTemplate>();

        itemTemp.GetPickUpStepQuantity().Returns(pickUpStepQuantity);
        // thisII.GetItemTemplate().Returns(itemTemp);
        IUIItem item = Substitute.For <IUIItem>();

        item.GetItemTemplate().Returns(itemTemp);
        thisII.GetUIItem().Returns(item);
        thisII.GetTransferableQuantity().Returns(transferableQuantity);
        thisII.GetItemQuantity().Returns(itemQuantity);
        thisII.GetIconGroup().Returns(Substitute.For <IIconGroup>());
        IItemIconTransactionManager   thisIITAM      = Substitute.For <IItemIconTransactionManager>();
        IPickUpSystemUIElementFactory thisUIEFactory = Substitute.For <IPickUpSystemUIElementFactory>();
        ItemIconPickUpImplementor     implementor    = new ItemIconPickUpImplementor(thisIITAM, thisUIEFactory);

        implementor.SetItemIcon(thisII);
        ii         = thisII;
        iiTAM      = thisIITAM;
        uieFactory = thisUIEFactory;
        return(implementor);
    }
        private static void InitializeBaseSchema([NotNull] IItemTemplate template, [NotNull] IPropertySchema baseSchema)
        {
            var propertyTypes = baseSchema.PropertyTypes?.ToArray();

            if (propertyTypes?.Any() ?? false)
            {
                foreach (var propertyType in propertyTypes)
                {
                    string value = null;
                    if (propertyType is IListPropertyType listPropertyType)
                    {
                        value = listPropertyType.Values.FirstOrDefault()?.Id;
                    }

                    var containerProperty = template.GetProperty(propertyType);
                    if (containerProperty == null)
                    {
                        template.AddProperty(propertyType, value);
                    }
                    else
                    {
                        containerProperty.StringValue = value;
                    }
                }
            }
        }
Beispiel #4
0
        public override void OnEnter()
        {
            IItemTemplate eqpItemTemp = thisEqpII.GetItemTemplate();

            thisEqpTool.TrySwitchItemMode(eqpItemTemp);
            if (thisEqpII.IsInEqpIG())
            {
                thisEqpTool.TrySwitchItemFilter(eqpItemTemp);
            }
            base.OnEnter();
        }
    public void GetAllItemIconWithItemTemplate_NoMatch_ReturnsEmptyList(int[] quantities, int[] sameAt)
    {
        IIconGroupConstArg arg;
        TestIG             testIG         = CreateTestIG(quantities.Length, quantities.Length, out arg);
        IItemTemplate      sourceItemTemp = Substitute.For <IItemTemplate>();
        List <IItemIcon>   iis            = CreateStubItemIconsWithItemTempsMatchingAt(quantities, sameAt, sourceItemTemp);

        testIG.SetItemIcons(iis);

        List <IItemIcon> actualIIs = testIG.GetAllItemIconWithItemTemplate(sourceItemTemp);

        Assert.That(actualIIs, Is.Empty);
    }
Beispiel #6
0
    public TestItem CreateTestItem(int quantity, int itemID, out IUIItemConstArg arg)
    {
        IUIItemConstArg thisArg  = Substitute.For <IUIItemConstArg>();
        IItemTemplate   itemTemp = Substitute.For <IItemTemplate>();

        thisArg.itemTemp.Returns(itemTemp);
        thisArg.quantity.Returns(quantity);
        thisArg.itemID.Returns(itemID);
        TestItem testItem = new TestItem(thisArg);

        arg = thisArg;
        return(testItem);
    }
 protected override bool IsEligibleForHover(IItemIcon pickedII)
 {
     if (pickedII is IEquippableItemIcon)
     {
         IEquippableItemIcon pickedEqpII    = pickedII as IEquippableItemIcon;
         IUIItem             pickedItem     = pickedEqpII.GetUIItem();
         IItemTemplate       pickedItemTemp = pickedItem.GetItemTemplate();
         if (pickedEqpII.IsBowOrWearItemIcon())               // always swapped
         {
             return(true);
         }
         else
         {
             if (pickedEqpII.IsInEqpIG())
             {
                 return(true);                 //always revertable
             }
             else                              // pickd from pool
             {
                 if (pickedEqpII.IsEquipped()) //always has the same partially picked item
                 {
                     return(true);
                 }
                 else
                 {
                     IEquipToolIG relevantEqpIG = thisEqpIITAM.GetRelevantEquipIG(pickedEqpII);
                     if (relevantEqpIG.GetSize() == 1)                            //swap target is deduced
                     {
                         return(true);
                     }
                     else
                     {
                         if (relevantEqpIG.HasSlotSpace())                               //add target is deduced
                         {
                             return(true);
                         }
                         else
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     else
     {
         throw new System.ArgumentException("pickedII must be of type IEquippableItemIcon");
     }
 }
Beispiel #8
0
    public void IsSameAs_ThisItemTempIsStackable_ThisItemTempNotRefEqualsToOtherItemTemp_ReturnsFalse()
    {
        IUIItemConstArg arg;
        TestItem        item         = CreateTestItem(1, 0, out arg);
        IItemTemplate   thisItemTemp = arg.itemTemp;

        thisItemTemp.IsStackable().Returns(true);
        IUIItem otherItem = Substitute.For <IUIItem>();

        otherItem.GetItemTemplate().Returns(Substitute.For <IItemTemplate>());

        bool actualBool = item.IsSameAs(otherItem);

        Assert.That(actualBool, Is.False);
    }
Beispiel #9
0
        public override bool HasItemSpace(IUIItem item)
        {
            CheckPassedIUIItemTypeValidity(item);
            IEquippableUIItem eqpItem  = item as IEquippableUIItem;           //safe
            IItemTemplate     itemTemp = eqpItem.GetItemTemplate();

            if (itemTemp is IBowTemplate && !eqpItem.IsEquipped())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #10
0
 IEquipToolItemMode GetModeToSwitch(IItemTemplate itemTemp)
 {
     if (itemTemp is IBowTemplate)
     {
         return(thisBowMode);
     }
     else if (itemTemp is IWearTemplate)
     {
         return(thisWearMode);
     }
     else                    /* cg */
     {
         return(thisCGMode);
     }
 }
Beispiel #11
0
 IEquipToolItemFilter GetFilterToSwitch(IItemTemplate itemTemp)
 {
     if (itemTemp is IBowTemplate)
     {
         return(this.thisBowFilter);
     }
     else if (itemTemp is IWearTemplate)
     {
         return(this.thisWearFilter);
     }
     else                    /* cg */
     {
         return(this.thisCGFilter);
     }
 }
Beispiel #12
0
    public void IsSameAs_ThisItemTempIsNotStackable_ThisItemIDEqualsToOtherItemID_ReturnsTrue()
    {
        IUIItemConstArg arg;
        const int       itemID       = 0;
        TestItem        item         = CreateTestItem(1, itemID, out arg);
        IItemTemplate   thisItemTemp = arg.itemTemp;

        thisItemTemp.IsStackable().Returns(false);
        IUIItem otherItem = Substitute.For <IUIItem>();

        otherItem.GetItemID().Returns(itemID);

        bool actualBool = item.IsSameAs(otherItem);

        Assert.That(actualBool, Is.True);
    }
        public IEquipToolEquipIG GetRelevantEquipIG(IEquippableItemIcon pickedEqpII)
        {
            IItemTemplate itemTemp = pickedEqpII.GetItemTemplate();

            if (itemTemp is IBowTemplate)
            {
                return(GetRelevantEquippedBowIG());
            }
            else if (itemTemp is IWearTemplate)
            {
                return(GetRelevantEquippedWearIG());
            }
            else
            {
                return(GetRelevantEquippedCarriedGearsIG());
            }
        }
Beispiel #14
0
        private GridRow GetRow([NotNull] IItemTemplate template)
        {
            GridRow result = null;

            var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray();

            foreach (var row in rows)
            {
                if (row.Tag == template)
                {
                    result = row;
                    break;
                }
            }

            return(result);
        }
Beispiel #15
0
 public ItemView(IItemTemplate model)
 {
     InitializeComponent();
     if (model == null)
     {
         model = this.BindingContext as IItemTemplate;
     }
     ItemObject.BindingContext = model;
     if (model.Obraz != null)
     {
         ItemImage.Source = ImageSource.FromStream(() => new MemoryStream(model.Obraz));
     }
     else
     {
         ItemImage.Source = ImageSource.FromUri(new Uri("https://via.placeholder.com/150"));
     }
 }
    public List <IItemIcon> CreateStubItemIconsWithItemTempsMatchingAt(int[] quantities, int[] sameAt, IItemTemplate sourceItemTemp)
    {
        List <IItemIcon> result = new List <IItemIcon>();
        int index = -1;

        foreach (int i in quantities)
        {
            index++;
            IItemIcon ii      = Substitute.For <IItemIcon>();
            IUIItem   tarItem = Substitute.For <IUIItem>();
            if (i == -1)
            {
                ii.IsEmpty().Returns(true);
                ii.GetUIItem().Returns((IUIItem)null);
                ii.GetItemTemplate().Returns((IItemTemplate)null);
            }
            else
            {
                ii.IsEmpty().Returns(false);
                tarItem.GetQuantity().Returns(i);
                IItemTemplate tarItemTemp = Substitute.For <IItemTemplate>();
                tarItem.GetItemTemplate().Returns(tarItemTemp);
                bool contained = false;
                foreach (int j in sameAt)
                {
                    if (j == index)
                    {
                        contained = true;
                    }
                }
                if (contained)
                {
                    tarItemTemp.IsSameAs(sourceItemTemp).Returns(true);
                }
                else
                {
                    tarItemTemp.IsSameAs(sourceItemTemp).Returns(false);
                }
                ii.GetUIItem().Returns(tarItem);
                ii.GetItemTemplate().Returns(tarItemTemp);
            }
            result.Add(ii);
        }
        return(result);
    }
Beispiel #17
0
        public void AddTemplate(IItemTemplate template)
        {
            if (template != null)
            {
                if (templateList.Items.ContainsKey(template.Name))
                    throw new InvalidOperationException("Template of specified name already exists.");

                imageList.Images.Add(template.Name, template.Icon);

                ListViewItem item = new ListViewItem(template.Name);
                item.Name = template.Name;
                item.ImageKey = template.Name;
                item.Tag = template;
                item.Group = templateList.Groups[template.Group];

                templateList.Items.Add(item);
            }
        }
Beispiel #18
0
        public override bool HasItemSpace(IUIItem item)
        {
            CheckPassedIUIItemTypeValidity(item);
            IEquippableUIItem eqpItem     = item as IEquippableUIItem;        //safe
            IItemTemplate     eqpItemTemp = eqpItem.GetItemTemplate();

            if (eqpItemTemp is ICarriedGearTemplate)
            {
                int maxEquippableQuantity = eqpItem.GetMaxEquippableQuantity();
                int equippedQuantity      = this.GetItemQuantity(eqpItem);
                int space = maxEquippableQuantity - equippedQuantity;
                return(space > 0);
            }
            else
            {
                return(false);
            }
        }
    public void GetAllItemIconWithItemTemplate_Matches_ReturnsAllMatches(int[] quantities, int[] sameAt)
    {
        IIconGroupConstArg arg;
        TestIG             testIG         = CreateTestIG(quantities.Length, quantities.Length, out arg);
        IItemTemplate      sourceItemTemp = Substitute.For <IItemTemplate>();
        List <IItemIcon>   iis            = CreateStubItemIconsWithItemTempsMatchingAt(quantities, sameAt, sourceItemTemp);

        testIG.SetItemIcons(iis);

        List <IItemIcon> actualIIs   = testIG.GetAllItemIconWithItemTemplate(sourceItemTemp);
        List <IItemIcon> expectedIIs = new List <IItemIcon>();

        foreach (int i in sameAt)
        {
            expectedIIs.Add(iis[i]);
        }

        Assert.That(actualIIs, Is.EquivalentTo(expectedIIs));
    }
Beispiel #20
0
        public void AddTemplate(IItemTemplate template)
        {
            if (template != null)
            {
                if (templateList.Items.ContainsKey(template.Name))
                {
                    throw new InvalidOperationException("Template of specified name already exists.");
                }

                imageList.Images.Add(template.Name, template.Icon);

                ListViewItem item = new ListViewItem(template.Name);
                item.Name     = template.Name;
                item.ImageKey = template.Name;
                item.Tag      = template;
                item.Group    = templateList.Groups[template.Group];

                templateList.Items.Add(item);
            }
        }
Beispiel #21
0
        public List <IItemIcon> GetAllItemIconWithItemTemplate(IItemTemplate itemTemp)
        {
            List <IItemIcon> result = new List <IItemIcon>();

            foreach (IItemIcon ii in thisItemIcons)
            {
                if (ii.IsEmpty())
                {
                    continue;
                }
                else
                {
                    IItemTemplate thisItemTemp = ii.GetItemTemplate();
                    if (thisItemTemp.IsSameAs(itemTemp))
                    {
                        result.Add(ii);
                    }
                }
            }
            return(result);
        }
        protected override int GetMaxTransferableQuantity()
        {
            IItemTemplate thisItemTemp = thisEqpItem.GetItemTemplate();
            int           thisQuantity = thisEqpII.GetItemQuantity();

            if (thisEqpII.IsBowOrWearItemIcon())
            {
                if (thisQuantity != 0)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (thisEqpII.IsInEqpIG())
                {
                    return(thisQuantity);
                }
                else
                {
                    if (thisItemTemp.IsStackable())
                    {
                        return(thisQuantity);
                    }
                    else
                    {
                        IEquipToolEquippedCarriedGearsIG relevantEqpCGIG = thisEqpIITAM.GetRelevantEquippedCarriedGearsIG();
                        int equippedQuantity = relevantEqpCGIG.GetItemQuantity(thisEqpItem);
                        int spaceInEqpIG     = thisEqpItem.GetMaxEquippableQuantity() - equippedQuantity;
                        return(Mathf.Min(spaceInEqpIG, thisQuantity));
                    }
                }
            }
        }
Beispiel #23
0
        private bool IsSelected([NotNull] IItemTemplate item, [Required] string filter)
        {
            var result = (!string.IsNullOrWhiteSpace(item.Name) &&
                          item.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) ||
                         (!string.IsNullOrWhiteSpace(item.Description) &&
                          item.Description.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0);

            if (!result && (item.Properties?.Any() ?? false))
            {
                var properties = item.Properties.ToArray();
                foreach (var property in properties)
                {
                    var stringValue = property.StringValue;
                    if ((!string.IsNullOrWhiteSpace(stringValue) &&
                         stringValue.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        result = true;
                        break;
                    }
                }
            }

            return(result);
        }
Beispiel #24
0
        public IRasterType PreparingRasterType(string rasterTypeName, string rasterTypeProductFilter, string rasterTypeProductName)
        {
            Console.WriteLine("Preparing Raster Type");
            // Create a Raster Type Name object.
            IRasterTypeName theRasterTypeName = new RasterTypeNameClass();

            // Assign the name of the Raster Type to the name object.
            // The Name field accepts a path to an .art file as well
            // the name for a built in Raster Type.
            theRasterTypeName.Name = rasterTypeName;
            // Use the Open function from the IName interface to get the Raster Type object.
            IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open());

            if (theRasterType == null)
            {
                Console.WriteLine("Raster Type not found " + rasterTypeName);
            }

            // Set the URI Filter on the loaded raster type.
            if (rasterTypeProductFilter != "")
            {
                // Get the supported URI filters from the raster type object using the
                // raster type properties interface.
                IArray         mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters;
                IItemURIFilter productFilter = null;
                for (int i = 0; i < mySuppFilters.Count; ++i)
                {
                    // Set the desired filter from the supported filters.
                    productFilter = (IItemURIFilter)mySuppFilters.get_Element(i);
                    if (productFilter.Name == rasterTypeProductFilter)
                    {
                        theRasterType.URIFilter = productFilter;
                    }
                }
            }
            // Enable the correct templates in the raster type.
            string[] rasterProductNames = rasterTypeProductName.Split(';');
            bool     enableTemplate     = false;

            if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != ""))
            {
                // Get the supported item templates from the raster type.
                IItemTemplateArray templateArray = theRasterType.ItemTemplates;
                for (int i = 0; i < templateArray.Count; ++i)
                {
                    // Go through the supported item templates and enable the ones needed.
                    IItemTemplate template = templateArray.get_Element(i);
                    enableTemplate = false;
                    for (int j = 0; j < rasterProductNames.Length; ++j)
                    {
                        if (template.Name == rasterProductNames[j])
                        {
                            enableTemplate = true;
                        }
                    }
                    if (enableTemplate)
                    {
                        template.Enabled = true;
                    }
                    else
                    {
                        template.Enabled = false;
                    }
                }
            }

            return(theRasterType);
        }
        public static void TestThumbnailBuilder(string rasterTypeName, string rasterTypeProductFilter,
                                                string rasterTypeProductName, string dataSource, string dataSourceFilter, string fgdbParentFolder,
                                                bool saveToArt, string customTypeFilePath, bool clearGdbDirectory)
        {
            try
            {
                string[] rasterProductNames = rasterTypeProductName.Split(';');
                string   nameString         = rasterTypeName.Replace(" ", "") + rasterTypeProductFilter.Replace(" ", "") +
                                              rasterProductNames[0].Replace(" ", "");

                #region Directory Declarations
                string fgdbName          = nameString + ".gdb";
                string fgdbDir           = fgdbParentFolder + "\\" + fgdbName;
                string MosaicDatasetName = nameString + "MD";
                #endregion

                #region Global Declarations
                IMosaicDataset                  theMosaicDataset          = null;
                IMosaicDatasetOperation         theMosaicDatasetOperation = null;
                IMosaicWorkspaceExtensionHelper mosaicExtHelper           = null;
                IMosaicWorkspaceExtension       mosaicExt = null;
                #endregion

                #region Create File GDB
                Console.WriteLine("Creating File GDB: " + fgdbName);
                if (clearGdbDirectory)
                {
                    try
                    {
                        Console.WriteLine("Emptying Gdb folder.");
                        System.IO.Directory.Delete(fgdbParentFolder, true);
                        System.IO.Directory.CreateDirectory(fgdbParentFolder);
                    }
                    catch (System.IO.IOException EX)
                    {
                        Console.WriteLine(EX.Message);
                        return;
                    }
                }

                // Create a File Gdb
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory FgdbFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                FgdbFactory.Create(fgdbParentFolder,
                                   fgdbName, null, 0);
                #endregion

                #region Create Mosaic Dataset
                try
                {
                    Console.WriteLine("Create Mosaic Dataset: " + MosaicDatasetName);
                    // Setup workspaces.
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    IWorkspace        fgdbWorkspace    = workspaceFactory.OpenFromFile(fgdbDir, 0);
                    // Create Srs
                    ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();
                    ISpatialReference        mosaicSrs         = spatialrefFactory.CreateProjectedCoordinateSystem(
                        (int)(esriSRProjCSType.esriSRProjCS_World_Mercator));
                    // Create the mosaic dataset creation parameters object.
                    ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass();
                    // Create the mosaic workspace extension helper class.
                    mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                    // Find the right extension from the workspace.
                    mosaicExt = mosaicExtHelper.FindExtension(fgdbWorkspace);
                    // Use the extension to create a new mosaic dataset, supplying the
                    // spatial reference and the creation parameters object created above.
                    theMosaicDataset = mosaicExt.CreateMosaicDataset(MosaicDatasetName,
                                                                     mosaicSrs, creationPars, "");
                    theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Error: Failed to create Mosaic Dataset : {0}.",
                                      MosaicDatasetName + " " + exc.Message);
                    return;
                }
                #endregion

                #region Create Custom Raster Type
                Console.WriteLine("Preparing Raster Type");
                // Create a Raster Type Name object.
                IRasterTypeName theRasterTypeName = new RasterTypeNameClass();
                // Assign the name of the Raster Type to the name object.
                // The Name field accepts a path to an .art file as well
                // the name for a built in Raster Type.
                theRasterTypeName.Name = rasterTypeName;
                // Use the Open function from the IName interface to get the Raster Type object.
                IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open());
                if (theRasterType == null)
                {
                    Console.WriteLine("Error:Raster Type not found " + rasterTypeName);
                    return;
                }
                #endregion

                #region Prepare Raster Type
                // Set the URI Filter on the loaded raster type.
                if (rasterTypeProductFilter != "")
                {
                    // Get the supported URI filters from the raster type object using the
                    // raster type properties interface.
                    IArray         mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters;
                    IItemURIFilter productFilter = null;
                    for (int i = 0; i < mySuppFilters.Count; ++i)
                    {
                        // Set the desired filter from the supported filters.
                        productFilter = (IItemURIFilter)mySuppFilters.get_Element(i);
                        if (productFilter.Name == rasterTypeProductFilter)
                        {
                            theRasterType.URIFilter = productFilter;
                        }
                    }
                }
                // Enable the correct templates in the raster type.
                bool enableTemplate = false;
                if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != ""))
                {
                    // Get the supported item templates from the raster type.
                    IItemTemplateArray templateArray = theRasterType.ItemTemplates;
                    for (int i = 0; i < templateArray.Count; ++i)
                    {
                        // Go through the supported item templates and enable the ones needed.
                        IItemTemplate template = templateArray.get_Element(i);
                        enableTemplate = false;
                        for (int j = 0; j < rasterProductNames.Length; ++j)
                        {
                            if (template.Name == rasterProductNames[j])
                            {
                                enableTemplate = true;
                            }
                        }
                        if (enableTemplate)
                        {
                            template.Enabled = true;
                        }
                        else
                        {
                            template.Enabled = false;
                        }
                    }
                }
                ((IRasterTypeProperties)theRasterType).DataSourceFilter = dataSourceFilter;
                #endregion

                #region Save Custom Raster Type
                if (saveToArt)
                {
                    IRasterTypeProperties  rasterTypeProperties = (IRasterTypeProperties)theRasterType;
                    IRasterTypeEnvironment rasterTypeHelper     = new RasterTypeEnvironmentClass();
                    rasterTypeProperties.Name = customTypeFilePath;

                    IMemoryBlobStream ipBlob = rasterTypeHelper.SaveRasterType(theRasterType);
                    ipBlob.SaveToFile(customTypeFilePath);
                }
                #endregion

                #region Preparing Data Source Crawler
                Console.WriteLine("Preparing Data Source Crawler");
                // Create a new property set to specify crawler properties.
                IPropertySet crawlerProps = new PropertySetClass();
                // Specify a file filter
                crawlerProps.SetProperty("Filter", dataSourceFilter);
                // Specify whether to search subdirectories.
                crawlerProps.SetProperty("Recurse", true);
                // Specify the source path.
                crawlerProps.SetProperty("Source", dataSource);
                // Get the recommended crawler from the raster type based on the specified
                // properties using the IRasterBuilder interface.
                // Pass on the Thumbnailtype to the crawler...
                IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps);
                #endregion

                #region Add Rasters
                try
                {
                    Console.WriteLine("Adding Rasters");
                    // Create a AddRaster parameters object.
                    IAddRastersParameters AddRastersArgs = new AddRastersParametersClass();
                    // Specify the data crawler to be used to crawl the data.
                    AddRastersArgs.Crawler = theCrawler;
                    // Specify the Thumbnail raster type to be used to add the data.
                    AddRastersArgs.RasterType = theRasterType;
                    // Use the mosaic dataset operation interface to add
                    // rasters to the mosaic dataset.
                    theMosaicDatasetOperation.AddRasters(AddRastersArgs, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Add raster Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Compute Pixel Size Ranges
                Console.WriteLine("Computing Pixel Size Ranges.");
                try
                {
                    // Create a calculate cellsize ranges parameters object.
                    ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass();
                    // Use the mosaic dataset operation interface to calculate cellsize ranges.
                    theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Compute Pixel Size Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Building Boundary
                Console.WriteLine("Building Boundary");
                try
                {
                    // Create a build boundary parameters object.
                    IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass();
                    // Set flags that control boundary generation.
                    boundaryArgs.AppendToExistingBoundary = true;
                    // Use the mosaic dataset operation interface to build boundary.
                    theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: Build Boundary Failed." + ex.Message);
                    return;
                }
                #endregion

                #region Report
                Console.WriteLine("Successfully created MD: " + MosaicDatasetName + ". ");
                #endregion
            }
            catch (Exception exc)
            {
                #region Report
                Console.WriteLine("Exception Caught in TestThumbnailBuilder: " + exc.Message);
                Console.WriteLine("Failed.");
                Console.WriteLine("Shutting down.");
                #endregion
            }
        }
Beispiel #26
0
        /* filter switch */
        public void TrySwitchItemFilter(IItemTemplate itemTemp)
        {
            IEquipToolItemFilter filterToSwitch = GetFilterToSwitch(itemTemp);

            thisFilterEngine.TrySwitchState(filterToSwitch);
        }
Beispiel #27
0
        /* mode switch */
        public void TrySwitchItemMode(IItemTemplate itemTemp)
        {
            IEquipToolItemMode modeToSwitch = GetModeToSwitch(itemTemp);

            thisModeEngine.TrySwitchState(modeToSwitch);
        }
Beispiel #28
0
        /// <summary>
        /// Create a Mosaic Dataset in the geodatabase provided using the parameters defined by MDParamaters.
        /// </summary>
        /// <param name="gdbWorkspace">Geodatabase to create the Mosaic dataser in.</param>
        public void CreateMosaicDataset(IWorkspace gdbWorkspace)
        {
            try
            {
                #region Global Declarations
                IMosaicDataset                  theMosaicDataset          = null;
                IMosaicDatasetOperation         theMosaicDatasetOperation = null;
                IMosaicWorkspaceExtensionHelper mosaicExtHelper           = null;
                IMosaicWorkspaceExtension       mosaicExt = null;
                #endregion

                #region CreateMosaicDataset
                try
                {
                    Console.WriteLine("Create Mosaic Dataset: " + MDParameters.mosaicDatasetName + ".amd");
                    /// Setup workspaces.
                    /// Create Srs
                    ISpatialReferenceFactory spatialrefFactory = new SpatialReferenceEnvironmentClass();

                    // Create the mosaic dataset creation parameters object.
                    ICreateMosaicDatasetParameters creationPars = new CreateMosaicDatasetParametersClass();
                    // Set the number of bands for the mosaic dataset.
                    // If defined as zero leave defaults
                    if (MDParameters.mosaicDatasetBands != 0)
                    {
                        creationPars.BandCount = MDParameters.mosaicDatasetBands;
                    }
                    // Set the pixel type of the mosaic dataset.
                    // If defined as unknown leave defaults
                    if (MDParameters.mosaicDatasetBits != rstPixelType.PT_UNKNOWN)
                    {
                        creationPars.PixelType = MDParameters.mosaicDatasetBits;
                    }
                    // Create the mosaic workspace extension helper class.
                    mosaicExtHelper = new MosaicWorkspaceExtensionHelperClass();
                    // Find the right extension from the workspace.
                    mosaicExt = mosaicExtHelper.FindExtension(gdbWorkspace);

                    // Default is none.
                    if (MDParameters.productDefinitionKey.ToLower() != "none")
                    {
                        // Set the product definition keyword and properties.
                        // (The property is called band definition keyword and band properties in the object).
                        ((ICreateMosaicDatasetParameters2)creationPars).BandDefinitionKeyword = MDParameters.productDefinitionKey;
                        MDParameters.productDefinitionProps = SetBandProperties(MDParameters.productDefinitionKey);
                        if (MDParameters.productDefinitionProps.Count == 0)
                        {
                            Console.WriteLine("Setting production definition properties failed.");
                            return;
                        }
                        ((ICreateMosaicDatasetParameters2)creationPars).BandProperties = MDParameters.productDefinitionProps;
                    }

                    // Use the extension to create a new mosaic dataset, supplying the
                    // spatial reference and the creation parameters object created above.
                    theMosaicDataset = mosaicExt.CreateMosaicDataset(MDParameters.mosaicDatasetName,
                                                                     MDParameters.mosaicDatasetSrs, creationPars, MDParameters.configKeyword);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Exception Caught while creating Mosaic Dataset: " + exc.Message);
                    return;
                }
                #endregion

                #region OpenMosaicDataset
                Console.WriteLine("Opening Mosaic Dataset");
                theMosaicDataset = null;
                // Use the extension to open the mosaic dataset.
                theMosaicDataset = mosaicExt.OpenMosaicDataset(MDParameters.mosaicDatasetName);
                // The mosaic dataset operation interface is used to perform operations on
                // a mosaic dataset.
                theMosaicDatasetOperation = (IMosaicDatasetOperation)(theMosaicDataset);
                #endregion

                #region Preparing Raster Type
                Console.WriteLine("Preparing Raster Type");
                // Create a Raster Type Name object.
                IRasterTypeName theRasterTypeName = new RasterTypeNameClass();
                // Assign the name of the Raster Type to the name object.
                // The Name field accepts a path to an .art file as well
                // the name for a built in Raster Type.
                theRasterTypeName.Name = MDParameters.rasterTypeName;
                // Use the Open function from the IName interface to get the Raster Type object.
                IRasterType theRasterType = (IRasterType)(((IName)theRasterTypeName).Open());
                if (theRasterType == null)
                {
                    Console.WriteLine("Raster Type not found " + MDParameters.rasterTypeName);
                }

                // Set the URI Filter on the loaded raster type.
                if (MDParameters.rasterTypeProductFilter != "")
                {
                    // Get the supported URI filters from the raster type object using the
                    // raster type properties interface.
                    IArray         mySuppFilters = ((IRasterTypeProperties)theRasterType).SupportedURIFilters;
                    IItemURIFilter productFilter = null;
                    for (int i = 0; i < mySuppFilters.Count; ++i)
                    {
                        // Set the desired filter from the supported filters.
                        productFilter = (IItemURIFilter)mySuppFilters.get_Element(i);
                        if (productFilter.Name == MDParameters.rasterTypeProductFilter)
                        {
                            theRasterType.URIFilter = productFilter;
                        }
                    }
                }
                // Enable the correct templates in the raster type.
                string[] rasterProductNames = MDParameters.rasterTypeProductName.Split(';');
                bool     enableTemplate     = false;
                if (rasterProductNames.Length >= 1 && (rasterProductNames[0] != ""))
                {
                    // Get the supported item templates from the raster type.
                    IItemTemplateArray templateArray = theRasterType.ItemTemplates;
                    for (int i = 0; i < templateArray.Count; ++i)
                    {
                        // Go through the supported item templates and enable the ones needed.
                        IItemTemplate template = templateArray.get_Element(i);
                        enableTemplate = false;
                        for (int j = 0; j < rasterProductNames.Length; ++j)
                        {
                            if (template.Name == rasterProductNames[j])
                            {
                                enableTemplate = true;
                            }
                        }
                        if (enableTemplate)
                        {
                            template.Enabled = true;
                        }
                        else
                        {
                            template.Enabled = false;
                        }
                    }
                }

                if (MDParameters.dataSourceSrs != null)
                {
                    ((IRasterTypeProperties)theRasterType).SynchronizeParameters.DefaultSpatialReference =
                        MDParameters.dataSourceSrs;
                }
                #endregion

                #region Add DEM To Raster Type
                if (MDParameters.rasterTypeAddDEM && ((IRasterTypeProperties)theRasterType).SupportsOrthorectification)
                {
                    // Open the Raster Dataset
                    Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
                    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                    IRasterWorkspace  rasterWorkspace  = (IRasterWorkspace)workspaceFactory.OpenFromFile(
                        System.IO.Path.GetDirectoryName(MDParameters.rasterTypeDemPath), 0);;
                    IRasterDataset myRasterDataset = rasterWorkspace.OpenRasterDataset(
                        System.IO.Path.GetFileName(MDParameters.rasterTypeDemPath));

                    IGeometricFunctionArguments geometricFunctionArguments =
                        new GeometricFunctionArgumentsClass();
                    geometricFunctionArguments.DEM = myRasterDataset;
                    ((IRasterTypeProperties)theRasterType).OrthorectificationParameters =
                        geometricFunctionArguments;
                }
                #endregion

                #region Preparing Data Source Crawler
                Console.WriteLine("Preparing Data Source Crawler");
                // Create a new property set to specify crawler properties.
                IPropertySet crawlerProps = new PropertySetClass();
                // Specify a file filter
                crawlerProps.SetProperty("Filter", MDParameters.dataSourceFilter);
                // Specify whether to search subdirectories.
                crawlerProps.SetProperty("Recurse", true);
                // Specify the source path.
                crawlerProps.SetProperty("Source", MDParameters.dataSource);
                // Get the recommended crawler from the raster type based on the specified
                // properties using the IRasterBuilder interface.
                IDataSourceCrawler theCrawler = ((IRasterBuilder)theRasterType).GetRecommendedCrawler(crawlerProps);
                #endregion

                #region Add Rasters
                Console.WriteLine("Adding Rasters");
                // Create a AddRaster parameters object.
                IAddRastersParameters AddRastersArgs = new AddRastersParametersClass();
                // Specify the data crawler to be used to crawl the data.
                AddRastersArgs.Crawler = theCrawler;
                // Specify the raster type to be used to add the data.
                AddRastersArgs.RasterType = theRasterType;
                // Use the mosaic dataset operation interface to add
                // rasters to the mosaic dataset.
                theMosaicDatasetOperation.AddRasters(AddRastersArgs, null);
                #endregion

                #region Compute Pixel Size Ranges
                Console.WriteLine("Computing Pixel Size Ranges");
                // Create a calculate cellsize ranges parameters object.
                ICalculateCellSizeRangesParameters computeArgs = new CalculateCellSizeRangesParametersClass();
                // Use the mosaic dataset operation interface to calculate cellsize ranges.
                theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null);
                #endregion

                #region Building Boundary
                Console.WriteLine("Building Boundary");
                // Create a build boundary parameters object.
                IBuildBoundaryParameters boundaryArgs = new BuildBoundaryParametersClass();
                // Set flags that control boundary generation.
                boundaryArgs.AppendToExistingBoundary = true;
                // Use the mosaic dataset operation interface to build boundary.
                theMosaicDatasetOperation.BuildBoundary(boundaryArgs, null);
                #endregion

                if (MDParameters.buildOverviews)
                {
                    #region Defining Overviews
                    Console.WriteLine("Defining Overviews");
                    // Create a define overview parameters object.
                    IDefineOverviewsParameters defineOvArgs = new DefineOverviewsParametersClass();
                    // Use the overview tile parameters interface to specify the overview factor
                    // used to generate overviews.
                    ((IOverviewTileParameters)defineOvArgs).OverviewFactor = 3;
                    // Use the mosaic dataset operation interface to define overviews.
                    theMosaicDatasetOperation.DefineOverviews(defineOvArgs, null);
                    #endregion

                    #region Compute Pixel Size Ranges
                    Console.WriteLine("Computing Pixel Size Ranges");
                    // Calculate cell size ranges to update the Min/Max pixel sizes.
                    theMosaicDatasetOperation.CalculateCellSizeRanges(computeArgs, null);
                    #endregion

                    #region Generating Overviews
                    Console.WriteLine("Generating Overviews");
                    // Create a generate overviews parameters object.
                    IGenerateOverviewsParameters genPars = new GenerateOverviewsParametersClass();
                    // Set properties to control overview generation.
                    IQueryFilter genQuery = new QueryFilterClass();
                    ((ISelectionParameters)genPars).QueryFilter = genQuery;
                    genPars.GenerateMissingImages = true;
                    genPars.GenerateStaleImages   = true;
                    // Use the mosaic dataset operation interface to generate overviews.
                    theMosaicDatasetOperation.GenerateOverviews(genPars, null);
                    #endregion
                }

                #region Report
                Console.WriteLine("Success.");
                #endregion
            }
            catch (Exception exc)
            {
                #region Report
                Console.WriteLine("Exception Caught in CreateMD: " + exc.Message);
                Console.WriteLine("Shutting down.");
                #endregion
            }
        }
 public bool IsSameAs(IItemTemplate other)
 {
     return(Object.ReferenceEquals(other, this));
 }