public bool IsEqual(IClone other) { //1. make sure that the 'other' object is pointing to a valid object if (null == other) { throw new COMException("Invalid object."); } //2. verify the type of 'other' if (!(other is TriangleElementClass)) { throw new COMException("Bad object type."); } TriangleElementClass otherTriangle = (TriangleElementClass)other; //test that all of the object's properties are the same. //please note the usage of IsEqual when using ArcObjects components that //supports cloning if (otherTriangle.Name == m_elementName && otherTriangle.Type == m_elementType && otherTriangle.AutoTransform == m_autoTrans && otherTriangle.ReferenceScale == m_scaleRef && otherTriangle.Angle == m_rotation && otherTriangle.Size == m_size && otherTriangle.AnchorPoint == m_anchorPointType && ((IClone)otherTriangle.Geometry).IsEqual((IClone)m_triangle) && ((IClone)otherTriangle.FillSymbol).IsEqual((IClone)m_fillSymbol) && ((IClone)otherTriangle.SpatialReference).IsEqual((IClone)m_nativeSR)) { return(true); } return(false); }
public IClone Clone() { TriangleElementClass triangle = new TriangleElementClass(); triangle.Assign((IClone)this); return((IClone)triangle); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { //set the color for the symbol's outline IColor color = (IColor)ESRI.ArcGIS.ADF.Connection.Local.Converter.ToRGBColor(Color.Black); //create the triangle outline symbol ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = color; lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; lineSymbol.Width = 2.0; //create the triangle's fill symbol color = (IColor)Converter.ToRGBColor(Color.Gold); color.Transparency = 50; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = color; simpleFillSymbol.Outline = (ILineSymbol)lineSymbol; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; //create a new triangle element ITriangleElement triangleElement = new TriangleElementClass(); triangleElement.Angle = 40.0; triangleElement.Size = 25; triangleElement.FillSymbol = simpleFillSymbol; //set the geometry of the element IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IElement element = (IElement)triangleElement; element.Geometry = (IGeometry)point; //add the graphics element to the map IGraphicsContainer graphicsContainer = (IGraphicsContainer)m_hookHelper.FocusMap; graphicsContainer.AddElement(element, 0); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void Assign(IClone src) { //1. make sure that src is pointing to a valid object if (null == src) { throw new COMException("Invalid object."); } //2. make sure that the type of src is of type 'TriangleElementClass' if (!(src is TriangleElementClass)) { throw new COMException("Bad object type."); } //3. assign the properties of src to the current instance TriangleElementClass srcTriangle = (TriangleElementClass)src; m_elementName = srcTriangle.Name; m_elementType = srcTriangle.Type; m_autoTrans = srcTriangle.AutoTransform; m_scaleRef = srcTriangle.ReferenceScale; m_rotation = srcTriangle.Angle; m_size = srcTriangle.Size; m_anchorPointType = srcTriangle.AnchorPoint; IObjectCopy objCopy = new ObjectCopyClass(); //take care of the custom property if (null != srcTriangle.CustomProperty) { if (srcTriangle.CustomProperty is IClone) { m_customProperty = (object)((IClone)srcTriangle.CustomProperty).Clone(); } else if (srcTriangle.CustomProperty is IPersistStream) { m_customProperty = objCopy.Copy((object)srcTriangle.CustomProperty); } else if (srcTriangle.CustomProperty.GetType().IsSerializable) { //serialize to a memory stream MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, srcTriangle.CustomProperty); byte[] bytes = memoryStream.ToArray(); memoryStream = new MemoryStream(bytes); m_customProperty = binaryFormatter.Deserialize(memoryStream); } } if (null != srcTriangle.SpatialReference) { m_nativeSR = objCopy.Copy(srcTriangle.SpatialReference) as ISpatialReference; } else { m_nativeSR = null; } if (null != srcTriangle.FillSymbol) { m_fillSymbol = objCopy.Copy(srcTriangle.FillSymbol) as ISimpleFillSymbol; } else { m_fillSymbol = null; } if (null != srcTriangle.Geometry) { m_triangle = objCopy.Copy(srcTriangle.Geometry) as IPolygon; m_pointGeometry = objCopy.Copy(((IArea)m_triangle).Centroid) as IPoint; } else { m_triangle = null; m_pointGeometry = null; } }
public IClone Clone() { TriangleElementClass triangle = new TriangleElementClass(); triangle.Assign((IClone)this); return (IClone)triangle; }