IRasterFunctionVariable myWatermarkImagePathVar; // Variable for WatermarkImagePath property. #endregion public WatermarkFunctionUIClass() { myForm = new WatermarkFunctionUIForm(); myArgs = null; myPriority = 100; myPageSite = null; myHelpFile = ""; mySupportedID = new UIDClass(); mySupportedID.Value = "{" + "168721E7-7010-4a36-B886-F644437B164D" + "}"; templateMode = false; isFormReadOnly = false; myRasterVar = null; myBlendPercentageVar = null; myWatermarkLocationVar = null; myWatermarkImagePathVar = null; }
IRasterFunctionVariable myWatermarkImagePathVar; // Variable for WatermarkImagePath property. #endregion public WatermarkFunctionUIClass() { myForm = new WatermarkFunctionUIForm(); myArgs = null; myPriority = 100; myPageSite = null; myHelpFile = ""; mySupportedID = new UIDClass(); mySupportedID.Value = "{" + "168721E7-7010-4a36-B886-F644437B164D" + "}"; templateMode = false; isFormReadOnly = false; myRasterVar = null; myBlendPercentageVar = null; myWatermarkLocationVar = null; myWatermarkImagePathVar = null; }
public WatermarkFunctionUIClass() { myForm = new WatermarkFunctionUIForm(); myArgs = null; myPriority = 100; myPageSite = null; myHelpFile = ""; mySupportedID = new UIDClass(); mySupportedID.Value = "{" + "25BE29A6-AAF9-496E-AE73-130D5947682D" + "}"; templateMode = false; isFormReadOnly = false; myRasterVar = null; myBlendPercentageVar = null; myWatermarkImagePathVar = null; myXGapVar = null; myYGapVar = null; }
bool templateMode; // Flag to specify template mode. #endregion Fields #region Constructors public WatermarkFunctionUIClass() { myForm = new WatermarkFunctionUIForm(); myArgs = null; myPriority = 100; myPageSite = null; myHelpFile = ""; mySupportedID = new UIDClass(); mySupportedID.Value = "{" + "25BE29A6-AAF9-496E-AE73-130D5947682D" + "}"; templateMode = false; isFormReadOnly = false; myRasterVar = null; myBlendPercentageVar = null; myWatermarkImagePathVar = null; myXGapVar = null; myYGapVar = null; }
/// <summary> /// Initialize the Raster function using the argument object. This is one of the two /// main functions to implement for a custom Raster function. The raster object is /// dereferenced if required and given to the RasterFuntionHelper object to bind. /// </summary> /// <param name="pArguments">Arguments object used for initialization</param> public void Bind(object pArguments) { try { // Check if the Arguments object is of the correct type. IWatermarkFunctionArguments watermarkFuncArgs = null; if (pArguments is IWatermarkFunctionArguments) { watermarkFuncArgs = (IWatermarkFunctionArguments)pArguments; myBlendPercentage = watermarkFuncArgs.BlendPercentage; myWatermarkImagePath = watermarkFuncArgs.WatermarkImagePath; xgap = watermarkFuncArgs.XGap; ygap = watermarkFuncArgs.YGap; object inputRaster = watermarkFuncArgs.Raster; if (watermarkFuncArgs.Raster is IRasterFunctionVariable) { IRasterFunctionVariable rasterFunctionVariable = (IRasterFunctionVariable)watermarkFuncArgs.Raster; inputRaster = rasterFunctionVariable.Value; } // Call the Bind method of the Raster Function Helper object. myFunctionHelper.Bind(inputRaster); } else { // Throw an error if incorrect arguments object is passed. throw new System.Exception( "Incorrect arguments object. Expected: IWatermarkFunctionArguments"); } // Get the raster info and Pixel Type from the RasterFunctionHelper object. myRasterInfo = myFunctionHelper.RasterInfo; myPixeltype = myRasterInfo.PixelType; // Convert blending percentage to blending value. if (myBlendPercentage >= 0.0 && myBlendPercentage <= 100.0) { blendValue = myBlendPercentage / 100.0; } else /// A value of 50% is used as default. { blendValue = 0.50; } if (myWatermarkImagePath != "") { // Load the watermark image from the path provided myWatermarkImage = new Bitmap(myWatermarkImagePath); // and check the pixel type of the loaded image to see if its compatible. if (myWatermarkImage.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb && myWatermarkImage.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb) { // Throw error if the image is not compatible. throw new System.Exception( "Invalid watermark image. Please provide one with 8 bits per band in ARGB or RGB format."); } // Cleanup myWatermarkImage.Dispose(); myWatermarkImage = null; } } catch (Exception exc) { #region Cleanup if (myWatermarkImage != null) { myWatermarkImage.Dispose(); } myWatermarkImage = null; #endregion System.Exception myExc = new System.Exception( "Exception caught in Bind method of Watermark Function. " + exc.Message, exc); throw myExc; } }
/// <summary> /// Set the necessary objects required for the form. In this case /// the form is given an arguments object in edit mode, or is required /// to create one in create mode. After getting or creating the arguments /// object, template mode is checked for and handled. The template mode /// requires all parameters of the arguments object to converted to variables. /// </summary> /// <param name="objects">Set of objects required for the form.</param> public void SetObjects(ESRI.ArcGIS.esriSystem.ISet objects) { try { // Recurse through the objects objects.Reset(); for (int i = 0; i < objects.Count; i++) { object currObject = objects.Next(); // Find the properties to be set. if (currObject is IPropertySet) { IPropertySet uiParameters = (IPropertySet)currObject; object names, values; uiParameters.GetAllProperties(out names, out values); bool disableForm = false; try { disableForm = Convert.ToBoolean(uiParameters.GetProperty("RFxPropPageIsReadOnly")); } catch (Exception) { } if (disableForm) { isFormReadOnly = true; } else { isFormReadOnly = false; } // Check if the arguments object exists in the property set. object functionArgument = null; try{ functionArgument = uiParameters.GetProperty("RFxArgument"); } catch (Exception) {} // If not, the form is in create mode. if (functionArgument == null) { #region Create Mode // Create a new arguments object. myArgs = new WatermarkFunctionArguments(); // Create a new property and set the arguments object on it. uiParameters.SetProperty("RFxArgument", myArgs); // Check if a default raster is supplied. object defaultRaster = null; try { defaultRaster = uiParameters.GetProperty("RFxDefaultInputRaster"); } catch (Exception) { } if (defaultRaster != null) // If it is, set it to the raster property. { myArgs.Raster = defaultRaster; } // Check if the form is in template mode. templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode"); if (templateMode) { // Since we are in create mode already, new variables have to be // created for each property of the arguments object. #region Create Variables if (defaultRaster != null) { // If a default raster is supplied and it is a variable, // there is no need to create one. if (defaultRaster is IRasterFunctionVariable) { myRasterVar = (IRasterFunctionVariable)defaultRaster; } else { // Create variable object for the InputRaster property. myRasterVar = new RasterFunctionVariableClass(); myRasterVar.Value = defaultRaster; myRasterVar.Name = "InputRaster"; myRasterVar.IsDataset = true; } } // Create a variable for the BlendPercentage property. myBlendPercentageVar = new RasterFunctionVariableClass(); myBlendPercentageVar.Name = "BlendPercentage"; // Use the default value from the arguments object myBlendPercentageVar.Value = myArgs.BlendPercentage; myXGapVar = new RasterFunctionVariableClass(); myXGapVar.Name = "XGap"; myXGapVar.Value = myArgs.XGap; myYGapVar = new RasterFunctionVariableClass(); myYGapVar.Name = "YGap"; myYGapVar.Value = myArgs.YGap; // Create a variable for the WatermarkImagePath property. myWatermarkImagePathVar = new RasterFunctionVariableClass(); myWatermarkImagePathVar.Name = "WatermarkImagePath"; // Use the default value from the arguments object myWatermarkImagePathVar.Value = myArgs.WatermarkImagePath; // Set the variables created as properties on the arguments object. IRasterFunctionArguments rasterFunctionArgs = (IRasterFunctionArguments)myArgs; rasterFunctionArgs.PutValue("Raster", myRasterVar); rasterFunctionArgs.PutValue("BlendPercentage", myBlendPercentageVar); rasterFunctionArgs.PutValue("XGap", myXGapVar); rasterFunctionArgs.PutValue("YGap", myYGapVar); #endregion } #endregion } else { #region Edit Mode // Get the arguments object from the property set. myArgs = (IWatermarkFunctionArguments)functionArgument; // Check if the form is in template mode. templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode"); if (templateMode) { #region Edit Template // In template edit mode, the variables from the arguments object // are extracted. IRasterFunctionArguments rasterFunctionArgs = (IRasterFunctionArguments)myArgs; object raster = rasterFunctionArgs.GetValue("Raster"); object blendPercentage = rasterFunctionArgs.GetValue("BlendPercentage"); object watermarkLocation = rasterFunctionArgs.GetValue("WatermarkLocation"); object watermarkPath = rasterFunctionArgs.GetValue("WatermarkImagePath"); object xGap = rasterFunctionArgs.GetValue("XGap"); object yGap = rasterFunctionArgs.GetValue("YGap"); // Create or Open the Raster variable. if (raster is IRasterFunctionVariable) { myRasterVar = (IRasterFunctionVariable)raster; } else { myRasterVar = new RasterFunctionVariableClass(); myRasterVar.Name = "InputRaster"; myRasterVar.Value = raster; } // Create or Open the BlendPercentage variable. if (blendPercentage is IRasterFunctionVariable) { myBlendPercentageVar = (IRasterFunctionVariable)blendPercentage; } else { myBlendPercentageVar = new RasterFunctionVariableClass(); myBlendPercentageVar.Name = "BlendPercentage"; myBlendPercentageVar.Value = blendPercentage; } if (xGap is IRasterFunctionVariable) { myXGapVar = (IRasterFunctionVariable)xGap; } else { myXGapVar = new RasterFunctionVariableClass(); myXGapVar.Name = "XGap"; myXGapVar.Value = xGap; } if (yGap is IRasterFunctionVariable) { myYGapVar = (IRasterFunctionVariable)yGap; } else { myYGapVar = new RasterFunctionVariableClass(); myYGapVar.Name = "YGap"; myYGapVar.Value = yGap; } // Create or Open the WatermarkImagePath variable. if (watermarkPath is IRasterFunctionVariable) { myWatermarkImagePathVar = (IRasterFunctionVariable)watermarkPath; } else { myWatermarkImagePathVar = new RasterFunctionVariableClass(); myWatermarkImagePathVar.Name = "WatermarkImagePath"; myWatermarkImagePathVar.Value = watermarkPath; } #endregion } #endregion } } } } catch (Exception exc) { string errorMsg = exc.Message; } }
/// <summary> /// Set the necessary objects required for the form. In this case /// the form is given an arguments object in edit mode, or is required /// to create one in create mode. After getting or creating the arguments /// object, template mode is checked for and handled. The template mode /// requires all parameters of the arguments object to converted to variables. /// </summary> /// <param name="objects">Set of objects required for the form.</param> public void SetObjects(ESRI.ArcGIS.esriSystem.ISet objects) { try { // Recurse through the objects objects.Reset(); for (int i = 0; i < objects.Count; i++) { object currObject = objects.Next(); // Find the properties to be set. if (currObject is IPropertySet) { IPropertySet uiParameters = (IPropertySet)currObject; object names, values; uiParameters.GetAllProperties(out names, out values); bool disableForm = false; try { disableForm = Convert.ToBoolean(uiParameters.GetProperty("RFxPropPageIsReadOnly")); } catch (Exception) { } if (disableForm) isFormReadOnly = true; else isFormReadOnly = false; // Check if the arguments object exists in the property set. object functionArgument = null; try{ functionArgument = uiParameters.GetProperty("RFxArgument"); } catch (Exception) {} // If not, the form is in create mode. if (functionArgument == null) { #region Create Mode // Create a new arguments object. myArgs = new WatermarkFunctionArguments(); // Create a new property and set the arguments object on it. uiParameters.SetProperty("RFxArgument", myArgs); // Check if a default raster is supplied. object defaultRaster = null; try { defaultRaster = uiParameters.GetProperty("RFxDefaultInputRaster"); } catch (Exception) { } if (defaultRaster != null) // If it is, set it to the raster property. myArgs.Raster = defaultRaster; // Check if the form is in template mode. templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode"); if (templateMode) { // Since we are in create mode already, new variables have to be // created for each property of the arguments object. #region Create Variables if (defaultRaster != null) { // If a default raster is supplied and it is a variable, // there is no need to create one. if (defaultRaster is IRasterFunctionVariable) myRasterVar = (IRasterFunctionVariable)defaultRaster; else { // Create variable object for the InputRaster property. myRasterVar = new RasterFunctionVariableClass(); myRasterVar.Value = defaultRaster; myRasterVar.Name = "InputRaster"; myRasterVar.IsDataset = true; } } // Create a variable for the BlendPercentage property. myBlendPercentageVar = new RasterFunctionVariableClass(); myBlendPercentageVar.Name = "BlendPercentage"; // Use the default value from the arguments object myBlendPercentageVar.Value = myArgs.BlendPercentage; myXGapVar = new RasterFunctionVariableClass(); myXGapVar.Name = "XGap"; myXGapVar.Value = myArgs.XGap; myYGapVar = new RasterFunctionVariableClass(); myYGapVar.Name = "YGap"; myYGapVar.Value = myArgs.YGap; // Create a variable for the WatermarkImagePath property. myWatermarkImagePathVar = new RasterFunctionVariableClass(); myWatermarkImagePathVar.Name = "WatermarkImagePath"; // Use the default value from the arguments object myWatermarkImagePathVar.Value = myArgs.WatermarkImagePath; // Set the variables created as properties on the arguments object. IRasterFunctionArguments rasterFunctionArgs = (IRasterFunctionArguments)myArgs; rasterFunctionArgs.PutValue("Raster", myRasterVar); rasterFunctionArgs.PutValue("BlendPercentage", myBlendPercentageVar); rasterFunctionArgs.PutValue("XGap", myXGapVar); rasterFunctionArgs.PutValue("YGap", myYGapVar); #endregion } #endregion } else { #region Edit Mode // Get the arguments object from the property set. myArgs = (IWatermarkFunctionArguments)functionArgument; // Check if the form is in template mode. templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode"); if (templateMode) { #region Edit Template // In template edit mode, the variables from the arguments object // are extracted. IRasterFunctionArguments rasterFunctionArgs = (IRasterFunctionArguments)myArgs; object raster = rasterFunctionArgs.GetValue("Raster"); object blendPercentage = rasterFunctionArgs.GetValue("BlendPercentage"); object watermarkLocation = rasterFunctionArgs.GetValue("WatermarkLocation"); object watermarkPath = rasterFunctionArgs.GetValue("WatermarkImagePath"); object xGap = rasterFunctionArgs.GetValue("XGap"); object yGap = rasterFunctionArgs.GetValue("YGap"); // Create or Open the Raster variable. if (raster is IRasterFunctionVariable) myRasterVar = (IRasterFunctionVariable)raster; else { myRasterVar = new RasterFunctionVariableClass(); myRasterVar.Name = "InputRaster"; myRasterVar.Value = raster; } // Create or Open the BlendPercentage variable. if (blendPercentage is IRasterFunctionVariable) myBlendPercentageVar = (IRasterFunctionVariable)blendPercentage; else { myBlendPercentageVar = new RasterFunctionVariableClass(); myBlendPercentageVar.Name = "BlendPercentage"; myBlendPercentageVar.Value = blendPercentage; } if (xGap is IRasterFunctionVariable) myXGapVar = (IRasterFunctionVariable)xGap; else { myXGapVar = new RasterFunctionVariableClass(); myXGapVar.Name = "XGap"; myXGapVar.Value = xGap; } if (yGap is IRasterFunctionVariable) myYGapVar = (IRasterFunctionVariable)yGap; else { myYGapVar = new RasterFunctionVariableClass(); myYGapVar.Name = "YGap"; myYGapVar.Value = yGap; } // Create or Open the WatermarkImagePath variable. if (watermarkPath is IRasterFunctionVariable) myWatermarkImagePathVar = (IRasterFunctionVariable)watermarkPath; else { myWatermarkImagePathVar = new RasterFunctionVariableClass(); myWatermarkImagePathVar.Name = "WatermarkImagePath"; myWatermarkImagePathVar.Value = watermarkPath; } #endregion } #endregion } } } } catch (Exception exc) { string errorMsg = exc.Message; } }