public static IEnumerable <long> AsEnumerable(this ILongArray longArray)
 {
     for (int i = 0; i < longArray.Count; i++)
     {
         yield return(longArray.get_Element(i));
     }
 }
        public void TestPofUniformSparseArray()
        {
            // perform the test twice, once with references disable, once with them enabled
            for (bool isRefEnabled = false; ;)
            {
                TestValue tv   = CreateTestValue(isRefEnabled);
                Binary    bin  = Serialize(tv, isRefEnabled);
                IPofValue root = PofValueParser.Parse(bin, GetPofContext(isRefEnabled));

                IPofValue pv = root.GetChild(5);
                Assert.IsTrue(pv is PofUniformSparseArray);
                Assert.AreEqual(pv.GetChild(2).GetValue(), "two");
                Assert.AreEqual(pv.GetChild(4).GetValue(), "four");

                if (isRefEnabled)
                {
                    break;
                }

                pv.GetChild(1).SetValue("jedan");
                pv.GetChild(3).SetValue("tri");
                pv.GetChild(4).SetValue("cetiri");
                pv.GetChild(5).SetValue("pet");
                Binary binModified = root.ApplyChanges();

                TestValue  tvModified = (TestValue)Deserialize(binModified);
                ILongArray arr        = tvModified.m_uniformSparseArray;
                Assert.AreEqual(arr[1], "jedan");
                Assert.AreEqual(arr[2], "two");
                Assert.AreEqual(arr[3], "tri");
                Assert.AreEqual(arr[4], "cetiri");
                Assert.AreEqual(arr[5], "pet");
                isRefEnabled = true;
            }
        }
Beispiel #3
0
        private void FindTerminusForSequence(ref IGSForwardStar FwdStar, int StartNodeId,
                                             ref int TerminusPoint, int iInfinityChecker)
        {
            if (TerminusPoint > -1)
            {
                return;
            }

            //iInfinityChecker++;
            if (iInfinityChecker++ > 5000)
            {
                return;
            }

            ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
            int        iCnt2   = 0;

            iCnt2 = iLngArr.Count;
            IGSLine pGSLine = null;

            for (int i = 0; i < iCnt2; i++)
            {
                int  i2          = iLngArr.get_Element(i);
                bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);

                if (iCnt2 == 1) //this is a terminus/end-line
                {
                    TerminusPoint = StartNodeId;
                }

                FindTerminusForSequence(ref FwdStar, i2, ref TerminusPoint, iInfinityChecker);
            }
        }
Beispiel #4
0
        private bool TestForEditLocks(ICadastralFabric Fabric, string NewJobName, ILongArray ParcelsToLock)
        {
            ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)Fabric;

            pFabLocks.LockingJob = NewJobName;

            ILongArray pLocksInConflict    = null;
            ILongArray pSoftLcksInConflict = null;

            try
            {
                pFabLocks.AcquireLocks(ParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                return(true);
            }
            catch (COMException pCOMEx)
            {
                if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS ||
                    pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED)
                {
                    MessageBox.Show("Edit Locks could not be acquired on all parcels of selected lines.");
                    // since the operation is being aborted, release any locks that were acquired
                    pFabLocks.UndoLastAcquiredLocks();
                }
                else
                {
                    MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode));
                }

                return(false);
            }
        }
Beispiel #5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DifferenceRow" /> struct.
 /// </summary>
 /// <param name="differenceType">Type of the difference.</param>
 /// <param name="oid">The object id of the row.</param>
 /// <param name="differenceRow">The read-only row reference, which can be null if it was deleted.</param>
 public DifferenceRow(esriDifferenceType differenceType, int oid, IRow differenceRow)
 {
     this.DifferenceType = differenceType;
     this.OID            = oid;
     this.Changed        = differenceRow;
     this.Original       = null;
     this.FieldIndices   = null;
 }
Beispiel #6
0
        public void TestReadInt32Array()
        {
            la      = new LongSortedList();
            la[1L]  = 0;
            la[3L]  = 1;
            la[30L] = Int32.MaxValue;
            la[31L] = Int32.MinValue;

            LongSortedList la1 = new LongSortedList();

            la1[1L]  = (Single)1.0;
            la1[10L] = (Single)10.0;
            la1[11L] = (Single)11.0;

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            // writting ILongArray
            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            // writting uniform ILongArray
            pofWriter.WriteLongArray(0, la, typeof(Int32));
            pofWriter.WriteLongArray(0, la1, typeof(Single));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            // reading ILongArray
            Int32[] resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la[1L], resInt32Array[1]);
            Assert.AreEqual(la[3L], resInt32Array[3]);
            Assert.AreEqual(la[30L], resInt32Array[30]);
            Assert.AreEqual(la[31L], resInt32Array[31]);

            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(0, resInt32Array.Length);

            // reading  uniform ILongArray
            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la[1L], resInt32Array[1]);
            Assert.AreEqual(la[3L], resInt32Array[3]);
            Assert.AreEqual(la[30L], resInt32Array[30]);
            Assert.AreEqual(la[31L], resInt32Array[31]);

            resInt32Array = pofReader.ReadInt32Array(0);
            Assert.AreEqual(la1.LastIndex + 1, resInt32Array.Length);

            Assert.AreEqual(la1[1L], resInt32Array[1]);
            Assert.AreEqual(la1[10L], resInt32Array[10]);
            Assert.AreEqual(la1[11L], resInt32Array[11]);
        }
Beispiel #7
0
 /// <summary>
 ///     Creates an <see cref="IEnumerable{T}" /> from an <see cref="ILongArray" />
 /// </summary>
 /// <param name="source">An <see cref="IArray" /> to create an <see cref="IEnumerable{T}" /> from.</param>
 /// <returns>
 ///     An <see cref="IEnumerable{T}" /> that contains the values from the input source.
 /// </returns>
 public static IEnumerable <int> AsEnumerable(this ILongArray source)
 {
     if (source != null)
     {
         for (int i = 0; i < source.Count; i++)
         {
             yield return(source.Element[i]);
         }
     }
 }
 public TestValue(Object[] oArray, String[] sArray,
                  IList col, IList colUniform,
                  ILongArray oSparseArray, ILongArray oUniformSparseArray)
 {
     m_oArray             = oArray;
     m_sArray             = sArray;
     m_col                = col;
     m_colUniform         = colUniform;
     m_sparseArray        = oSparseArray;
     m_uniformSparseArray = oUniformSparseArray;
 }
        /// <summary>
        /// Look up the specified identity and return the object to which it
        /// refers.
        /// </summary>
        /// <param name="id">
        /// The identity.
        /// </param>
        /// <returns>
        /// The object registered under that identity.
        /// </returns>
        /// <exception cref="IOException">
        /// If the requested identity is not registered.
        /// </exception>
        protected internal IPofValue LookupIdentity(int id)
        {
            ILongArray map = EnsureReferenceRegistry();

            if (!map.Exists(id))
            {
                throw new IOException("missing identity: " + id);
            }

            return((IPofValue)map[id]);
        }
 public MapGraphicKeyframe()
 {
     activeProps = new LongArrayClass();
     activeProps.Add(0);
     activeProps.Add(1);
     animType = new AnimationTypeMapGraphic();
     name = "";
     bObjectsNeedRefresh = false;
     Position = new PointClass();
     Rotation = 0.0;
     timeStamp = 0.0;
 }
        /// <summary>
        /// Obtain the registry for identity-reference pairs, creating it if
        /// necessary.
        /// </summary>
        /// <returns>
        /// The identity-reference registry, never <c>null</c>.
        /// </returns>
        protected virtual ILongArray EnsureReferenceRegistry()
        {
            ILongArray array = m_arrayRefs;

            if (array == null)
            {
                var root = (AbstractPofValue)Root;
                m_arrayRefs = array = root == this ? new LongSortedList() : root.EnsureReferenceRegistry();
            }

            return(array);
        }
            /// <summary>
            /// Look up the specified identity and return the object to which it
            /// refers.
            /// </summary>
            /// <param name="id">
            /// The identity.
            /// </param>
            /// <returns>
            /// The object registered under that identity.
            /// </returns>
            /// <exception cref="IOException">
            /// If the requested identity is not registered.
            /// </exception>
            protected internal override object LookupIdentity(int id)
            {
                object     o     = null;
                ILongArray array = m_referenceMap;

                if (array != null)
                {
                    o = array[id];
                }

                return(o == null?m_value.LookupIdentity(id).GetValue() : o);
            }
 public MapLayerEffectsKeyframe()
 {
     activeProps = new LongArrayClass();
     activeProps.Add(0);
     activeProps.Add(1);
     animType = new AnimationTypeLayerEffects();
     name = "";
     bObjectsNeedRefresh = false;
     brightness = 0;
     contrast = 0;
     timeStamp = 0;
 }
 public MapGraphicKeyframe()
 {
     activeProps = new LongArrayClass();
     activeProps.Add(0);
     activeProps.Add(1);
     animType            = new AnimationTypeMapGraphic();
     name                = "";
     bObjectsNeedRefresh = false;
     Position            = new PointClass();
     Rotation            = 0.0;
     timeStamp           = 0.0;
 }
 public MapLayerEffectsKeyframe()
 {
     activeProps = new LongArrayClass();
     activeProps.Add(0);
     activeProps.Add(1);
     animType            = new AnimationTypeLayerEffects();
     name                = "";
     bObjectsNeedRefresh = false;
     brightness          = 0;
     contrast            = 0;
     timeStamp           = 0;
 }
Beispiel #16
0
        public void TestReadLongArray()
        {
            la      = new LongSortedList();
            la[1L]  = 'a';
            la[3L]  = 'b';
            la[20L] = 'c';
            byte[] bytes = new byte[] { 1, 250, 3 };

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, la, typeof(char));
            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, null);
            pofWriter.WriteArray(0, bytes);
            pofWriter.WriteArray(0, bytes, typeof(byte));
            pofWriter.WriteArray(0, new byte[0]);

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            ILongArray resLongArray = pofReader.ReadLongArray(0, null);

            Assert.AreEqual(la.Count, resLongArray.Count);
            Assert.AreEqual(la[1], resLongArray[1]);
            Assert.AreEqual(la[3], resLongArray[3]);
            Assert.AreEqual(la[20], resLongArray[20]);

            //uniform sparse array
            resLongArray = pofReader.ReadLongArray(0, null);
            Assert.AreEqual(la.Count, resLongArray.Count);
            Assert.AreEqual(la[1], resLongArray[1]);
            Assert.AreEqual(la[3], resLongArray[3]);
            Assert.AreEqual(la[20], resLongArray[20]);

            resLongArray = pofReader.ReadLongArray(0, null);
            Assert.AreEqual(0, resLongArray.Count);

            resLongArray = pofReader.ReadLongArray(0, null);
            Assert.IsTrue(resLongArray == null);

            resLongArray = pofReader.ReadLongArray(0, null);
            Assert.AreEqual(3, resLongArray.Count);

            resLongArray = pofReader.ReadLongArray(0, null);
            Assert.AreEqual(3, resLongArray.Count);

            resLongArray = pofReader.ReadLongArray(0, new LongSortedList());
            Assert.AreEqual(0, resLongArray.Count);
        }
        /// <summary>
        /// Register the passed value with the passed identity.
        /// </summary>
        /// <param name="id">
        /// The identity.
        /// </param>
        /// <param name="value">
        /// The object registerd under the passed identity.
        /// </param>
        /// <exception cref="ArgumentException">
        /// If the specified identity is already registered with a different object.
        /// </exception>
        protected internal void RegisterIdentity(int id, object value)
        {
            if (id >= 0)
            {
                ILongArray map = EnsureReferenceRegistry();
                object     o   = map[id];
                if (o != null && o != value)
                {
                    throw new ArgumentException("duplicate identity: " + id);
                }

                map[id] = value;
            }
        }
Beispiel #18
0
        public void TestReadObject()
        {
            la     = new LongSortedList();
            la[1L] = "one";
            la[2L] = "two";
            la.Add("five");
            la.Add("three");
            la[200L] = "twohundred";


            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, la, typeof(String));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            LongSortedList resLA = (LongSortedList)pofReader.ReadObject(0);

            Assert.AreEqual(la.Count, resLA.Count);

            IEnumerator e  = resLA.GetEnumerator();
            IEnumerator de = la.GetEnumerator();

            for (; e.MoveNext() && de.MoveNext();)
            {
                Assert.AreEqual(((DictionaryEntry)e.Current).Key, ((DictionaryEntry)de.Current).Key);
                Assert.AreEqual(((DictionaryEntry)e.Current).Value, ((DictionaryEntry)de.Current).Value);
            }

            resLA = (LongSortedList)pofReader.ReadObject(0);
            Assert.AreEqual(0, resLA.Count);

            //uniform sparse array
            resLA = (LongSortedList)pofReader.ReadObject(0);
            Assert.AreEqual(la.Count, resLA.Count);

            e  = resLA.GetEnumerator();
            de = la.GetEnumerator();
            for (; e.MoveNext() && de.MoveNext();)
            {
                Assert.AreEqual(((DictionaryEntry)e.Current).Key, ((DictionaryEntry)de.Current).Key);
                Assert.AreEqual(((DictionaryEntry)e.Current).Value, ((DictionaryEntry)de.Current).Value);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Return index of the last parsed child with an index lower than the
        /// specified one.
        /// </summary>
        /// <param name="nIndex">
        /// Index to find the preceding child index for.
        /// </param>
        /// <returns>
        /// Index of the last parsed child, or -1 if one does not exist.
        /// </returns>
        protected int GetLastChildIndex(int nIndex)
        {
            ILongArray aChildren = m_aChildren;
            int        nLast     = (int)aChildren.LastIndex;

            if (nIndex < nLast)
            {
                nLast = nIndex;
                while (nLast >= 0 && !aChildren.Exists(nLast))
                {
                    nLast--;
                }
            }
            return(nLast);
        }
Beispiel #20
0
        public bool TestForEditLocks(ICadastralFabric Fabric, string NewJobName, List <int> ParcelsToLock)
        {
            ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)Fabric;

            pFabLocks.LockingJob = NewJobName;
            ILongArray pLocksInConflict    = null;
            ILongArray pSoftLcksInConflict = null;

            ILongArray TheParcelsToLock = new LongArrayClass();

            foreach (int i in ParcelsToLock)
            {
                TheParcelsToLock.Add(i);
            }

            try
            {
                pFabLocks.AcquireLocks(TheParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                return(true);
            }
            catch (COMException pCOMEx)
            {
                if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS ||
                    pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED)
                {
                    string sListOfFirst10 = "";
                    for (int i = 0; i < pLocksInConflict.Count; i++)
                    {
                        if (i == 10)
                        {
                            break;
                        }
                        sListOfFirst10 += pLocksInConflict.get_Element(i).ToString() + ", ";
                    }
                    MessageBox.Show("Edit Locks could not be acquired on all parcels." + Environment.NewLine +
                                    "Parcel ids: " + sListOfFirst10.Trim().TrimEnd(','), "Move Fabric Points");
                    // since the operation is being aborted, release any locks that were acquired
                    pFabLocks.UndoLastAcquiredLocks();
                }
                else
                {
                    MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode));
                }
                return(false);
            }
        }
        private void AddTVItemForSubLayer(TreeViewItem pTVIParent, IMapLayerInfos pMLInfos, IMapLayerInfo pMLI, ref int curMLIindex)
        {
            TreeViewItem pTVIlayer = CreateTreeViewItem(pMLI); //pMLI.Name, pMLI.ID, false);

            pTVIParent.Items.Add(pTVIlayer);

            ILongArray pSubLayersIDs = pMLI.SubLayers;

            if (pSubLayersIDs == null)
            {
                return;
            }

            //when it is a group layer
            IMapLayerInfo pChildMLI = null;

            for (int i = 0; i < pSubLayersIDs.Count; i++)
            {
                pChildMLI = pMLInfos.get_Element(++curMLIindex);
                AddTVItemForSubLayer(pTVIlayer, pMLInfos, pChildMLI, ref curMLIindex);
            }
        }
Beispiel #22
0
        public void TestReadString()
        {
            la      = new LongSortedList();
            la[1L]  = 'a';
            la[3L]  = 'b';
            la[20L] = 'c';

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, la, typeof(char));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            String resCharArray = pofReader.ReadString(0);

            Assert.AreEqual(la.LastIndex + 1, resCharArray.Length);

            Assert.AreEqual(la[1L], resCharArray[1]);
            Assert.AreEqual(la[3L], resCharArray[3]);
            Assert.AreEqual(la[20L], resCharArray[20]);

            resCharArray = pofReader.ReadString(0);
            Assert.IsTrue(resCharArray.Length == 0);

            //uniform sparse array
            resCharArray = pofReader.ReadString(0);
            Assert.AreEqual(la.LastIndex + 1, resCharArray.Length);

            Assert.AreEqual(la[1L], resCharArray[1]);
            Assert.AreEqual(la[3L], resCharArray[3]);
            Assert.AreEqual(la[20L], resCharArray[20]);
        }
Beispiel #23
0
        public void TestReadByteArray()
        {
            la      = new LongSortedList();
            la[1L]  = (byte)1;
            la[3L]  = (byte)3;
            la[30L] = (byte)30;

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, la, typeof(byte));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            byte[] resByteArray = pofReader.ReadByteArray(0);
            Assert.AreEqual(la.LastIndex + 1, resByteArray.Length);

            Assert.AreEqual(la[1L], resByteArray[1]);
            Assert.AreEqual(la[3L], resByteArray[3]);
            Assert.AreEqual(la[30L], resByteArray[30]);

            resByteArray = pofReader.ReadByteArray(0);
            Assert.AreEqual(0, resByteArray.Length);

            //uniform sparse array
            resByteArray = pofReader.ReadByteArray(0);
            Assert.AreEqual(la.LastIndex + 1, resByteArray.Length);

            Assert.AreEqual(la[1L], resByteArray[1]);
            Assert.AreEqual(la[3L], resByteArray[3]);
            Assert.AreEqual(la[30L], resByteArray[30]);
        }
Beispiel #24
0
        public void TestReadDoubleArray()
        {
            la      = new LongSortedList();
            la[1L]  = 1.0;
            la[3L]  = 3.0;
            la[20L] = 20.0;

            DataWriter      writer    = new DataWriter(stream);
            PofStreamWriter pofWriter = new PofStreamWriter(writer, ctx);

            pofWriter.WriteLongArray(0, new LongSortedList());
            pofWriter.WriteLongArray(0, la);
            pofWriter.WriteLongArray(0, la, typeof(double));

            stream.Position = 0;
            DataReader      reader    = new DataReader(stream);
            PofStreamReader pofReader = new PofStreamReader(reader, ctx);

            double[] resFloatArray = pofReader.ReadDoubleArray(0);
            Assert.AreEqual(0, resFloatArray.Length);

            resFloatArray = pofReader.ReadDoubleArray(0);
            Assert.AreEqual(la.LastIndex + 1, resFloatArray.Length);

            Assert.AreEqual(la[1L], resFloatArray[1]);
            Assert.AreEqual(la[3L], resFloatArray[3]);
            Assert.AreEqual(la[20L], resFloatArray[20]);

            //uniform sparse array
            resFloatArray = pofReader.ReadDoubleArray(0);
            Assert.AreEqual(la.LastIndex + 1, resFloatArray.Length);

            Assert.AreEqual(la[1L], resFloatArray[1]);
            Assert.AreEqual(la[3L], resFloatArray[3]);
            Assert.AreEqual(la[20L], resFloatArray[20]);
        }
 public IFunctionRasterDataset getBands(object inRaster, ILongArray lArr)
 {
     string tempAr = funcDir + "\\" + FuncCnt + ".afr";
     IFunctionRasterDataset frDset = new FunctionRasterDatasetClass();
     IFunctionRasterDatasetName frDsetName = new FunctionRasterDatasetNameClass();
     frDsetName.FullName = tempAr;
     frDset.FullName = (IName)frDsetName;
     IRasterFunction rsFunc = new ExtractBandFunctionClass();
     IExtractBandFunctionArguments args = new ExtractBandFunctionArgumentsClass(); //IExtractBandFunctionArguments2 args = new ExtractBandFunctionArgumentsClass();
     args.Raster = createIdentityRaster(inRaster);
     //args.MissingBandAction = esriMissingBandAction.esriMissingBandActionFindBestMatch;
     args.BandIDs = lArr;
     frDset.Init(rsFunc, args);
     return frDset;
 }
Beispiel #26
0
        protected override void OnClick()
        {
            IMouseCursor pMouseCursor = new MouseCursorClass();

            pMouseCursor.SetCursor(2);

            //first get the selected parcel features
            UID pUID = new UIDClass();

            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralEditor            pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);

            Marshal.ReleaseComObject(pUID);

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            IFeatureLayer CFPointLayer = null; IFeatureLayer CFLineLayer = null;
            IFeatureLayer CFControlLayer   = null;
            IFeatureLayer CFLinePointLayer = null;

            IActiveView      pActiveView       = ArcMap.Document.ActiveView;
            IMap             pMap              = pActiveView.FocusMap;
            ICadastralFabric pCadFabric        = null;
            IProgressDialog2 pProgressorDialog = null;

            clsFabricUtils UTILS = new clsFabricUtils();

            //if we're in an edit session then grab the target fabric
            if (pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }

            if (pCadFabric == null)
            {//find the first fabric in the map
                if (!UTILS.GetFabricFromMap(pMap, out pCadFabric))
                {
                    MessageBox.Show
                        ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again.");
                    return;
                }
            }

            IArray CFParcelLayers = new ArrayClass();

            if (!(UTILS.GetFabricSubLayersFromFabric(pMap, pCadFabric, out CFPointLayer, out CFLineLayer,
                                                     out CFParcelLayers, out CFControlLayer, out CFLinePointLayer)))
            {
                return; //no fabric sublayers available for the targeted fabric
            }
            bool       bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersioned = false;
            IWorkspace pWS = null;

            try
            {
                //Get the selection of parcels
                IFeatureLayer pFL = (IFeatureLayer)CFParcelLayers.get_Element(0);
                IDataset      pDS = (IDataset)pFL.FeatureClass;
                pWS = pDS.Workspace;

                if (!UTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB,
                                                out bIsUnVersioned, out bUseNonVersioned))
                {
                    return;
                }

                if (bUseNonVersioned)
                {
                    ICadastralFabricLayer pCFLayer = new CadastralFabricLayerClass();
                    pCFLayer.CadastralFabric    = pCadFabric;
                    pCadEd.CadastralFabricLayer = pCFLayer;//NOTE: Need to set this back to NULL when done.
                }

                Hashtable   FabLyrToFieldMap   = new Hashtable();
                DateChanger pDateChangerDialog = new DateChanger();
                pDateChangerDialog.cboBoxFabricClasses.Items.Clear();
                string[] FieldStrArr = new string[CFParcelLayers.Count];
                for (int i = 0; i < CFParcelLayers.Count; i++)
                {
                    FieldStrArr[i] = "";
                    IFeatureLayer lyr = (IFeatureLayer)CFParcelLayers.get_Element(i);
                    //   ICadastralFabricLayer cflyr = CFParcelLayers.get_Element(i);

                    pDateChangerDialog.cboBoxFabricClasses.Items.Add(lyr.Name);
                    IFields pFlds = lyr.FeatureClass.Fields;
                    for (int j = 0; j < lyr.FeatureClass.Fields.FieldCount; j++)
                    {
                        IField pFld = lyr.FeatureClass.Fields.get_Field(j);
                        if (pFld.Type == esriFieldType.esriFieldTypeDate)
                        {
                            if (FieldStrArr[i].Trim() == "")
                            {
                                FieldStrArr[i] = pFld.Name;
                            }
                            else
                            {
                                FieldStrArr[i] += "," + pFld.Name;
                            }
                        }
                    }
                    FabLyrToFieldMap.Add(i, FieldStrArr[i]);
                }
                pDateChangerDialog.FieldMap = FabLyrToFieldMap;
                pDateChangerDialog.cboBoxFabricClasses.SelectedIndex = 0;



                // ********  Display the dialog  *********
                DialogResult pDialogResult = pDateChangerDialog.ShowDialog();
                if (pDialogResult != DialogResult.OK)
                {
                    return;
                }
                //************************

                //*** get the choices from the dialog
                IFeatureLayer flyr     = (IFeatureLayer)CFParcelLayers.get_Element(pDateChangerDialog.cboBoxFabricClasses.SelectedIndex);
                int           iDateFld = flyr.FeatureClass.Fields.FindField(pDateChangerDialog.cboBoxFields.Text);

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    IField pFld = flyr.FeatureClass.Fields.get_Field(iDateFld);
                    if (!pFld.IsNullable)
                    {
                        MessageBox.Show("The field you selected does not allow NULL values, and must have a date." + Environment.NewLine +
                                        "Please try again using the date option, or using a different date field.", "Field does not Allow Null", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }

                ICadastralFabricSubLayer pSubLyr = (ICadastralFabricSubLayer)flyr;
                bool bLines   = false;
                bool bParcels = false;
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTLines)
                {
                    bLines = true;
                }
                if (pSubLyr.CadastralTableType == esriCadastralFabricTable.esriCFTParcels)
                {
                    bParcels = true;
                }

                //find out if there is a selection for the chosen layer
                bool ChosenLayerHasSelection = false;

                IFeatureSelection   pFeatSel       = null;
                ISelectionSet2      pSelSet        = null;
                ICadastralSelection pCadaSel       = null;
                IEnumGSParcels      pEnumGSParcels = null;

                int iFeatureCnt = 0;
                pFeatSel = (IFeatureSelection)flyr;
                if (pFeatSel != null)
                {
                    pSelSet = (ISelectionSet2)pFeatSel.SelectionSet;
                    ChosenLayerHasSelection = (pSelSet.Count > 0);
                    iFeatureCnt             = pSelSet.Count;
                }
                //****

                if (iFeatureCnt == 0)
                {
                    if (MessageBox.Show("There are no features selected in the " + flyr.Name + " layer." + Environment.NewLine + "Click OK to Change dates for ALL features in the layer.", "No Selection",
                                        MessageBoxButtons.OKCancel) != DialogResult.OK)
                    {
                        return;
                    }
                }
                else
                {
                    pCadaSel = (ICadastralSelection)pCadEd;
                    //** TODO: this enum should be based on the selected points, lines, or line-points
                    pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround
                    //***
                }

                if (iFeatureCnt == 0)
                {
                    m_pCursor = (ICursor)flyr.FeatureClass.Search(null, false);
                    ITable pTable = (ITable)flyr.FeatureClass;
                    iFeatureCnt = pTable.RowCount(null);
                }

                m_bShowProgressor = (iFeatureCnt > 10);
                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = iFeatureCnt;
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }
                m_pQF = new QueryFilterClass();
                string sPref; string sSuff;

                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                //====== need to do this for all the parcel sublayers in the map that are part of the target fabric
                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Collecting data...";
                }

                bool bCont = true;
                m_pFIDSetParcels = new FIDSetClass();

                if (ChosenLayerHasSelection && bParcels && !bIsUnVersioned)
                {
                    //if there is a selection add the OIDs of all the selected parcels into a new feature IDSet
                    pEnumGSParcels.Reset();
                    IGSParcel pGSParcel = pEnumGSParcels.Next();

                    while (pGSParcel != null)
                    {
                        //Check if the cancel button was pressed. If so, stop process
                        if (m_bShowProgressor)
                        {
                            bCont = m_pTrackCancel.Continue();
                            if (!bCont)
                            {
                                break;
                            }
                        }
                        m_pFIDSetParcels.Add(pGSParcel.DatabaseId);
                        Marshal.ReleaseComObject(pGSParcel); //garbage collection
                        pGSParcel = pEnumGSParcels.Next();
                        //}
                        if (m_bShowProgressor)
                        {
                            if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                            {
                                m_pStepProgressor.Step();
                            }
                        }
                    }
                }

                if ((!ChosenLayerHasSelection && bParcels && !bIsUnVersioned) ||
                    (!ChosenLayerHasSelection && bLines && !bIsUnVersioned))
                {
                    IRow pRow = m_pCursor.NextRow();
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add(pRow.OID);
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                if (bLines && ChosenLayerHasSelection && !bIsUnVersioned)
                {
                    pSelSet.Search(null, false, out m_pCursor);
                    IRow pRow = m_pCursor.NextRow();
                    int  iFld = m_pCursor.FindField("PARCELID");
                    while (pRow != null)
                    {
                        m_pFIDSetParcels.Add((int)pRow.get_Value(iFld));
                        Marshal.ReleaseComObject(pRow);
                        pRow = m_pCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(m_pCursor);
                }

                //=========================================================
                if (!bCont)
                {
                    //Since I'm using update cursor need to clear the cadastral selection
                    pCadaSel.SelectedParcels = null;
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly
                    return;
                }

                string sTime = "";
                if (!bIsUnVersioned)
                {
                    //see if parcel locks can be obtained on the selected parcels. First create a job.
                    DateTime localNow = DateTime.Now;
                    sTime = Convert.ToString(localNow);
                    ICadastralJob pJob = new CadastralJobClass();
                    pJob.Name        = sTime;
                    pJob.Owner       = System.Windows.Forms.SystemInformation.UserName;
                    pJob.Description = "Change Date on selected parcels";
                    try
                    {
                        Int32 jobId = pCadFabric.CreateJob(pJob);
                    }
                    catch (COMException ex)
                    {
                        if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Job named: '" + pJob.Name + "', already exists");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                        m_pStepProgressor = null;
                        if (!(pProgressorDialog == null))
                        {
                            pProgressorDialog.HideDialog();
                        }
                        pProgressorDialog = null;
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //if we're in an enterprise then test for edit locks
                ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric;
                if (!bIsUnVersioned)
                {
                    pFabLocks.LockingJob = sTime;
                    ILongArray pLocksInConflict    = null;
                    ILongArray pSoftLcksInConflict = null;

                    ILongArray pParcelsToLock = new LongArrayClass();

                    UTILS.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, m_pStepProgressor);
                    if (m_pStepProgressor != null && !bIsFileBasedGDB)
                    {
                        m_pStepProgressor.Message = "Testing for edit locks on parcels...";
                    }

                    try
                    {
                        pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                    }
                    catch (COMException pCOMEx)
                    {
                        if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Edit Locks could not be acquired on all selected parcels.");
                            // since the operation is being aborted, release any locks that were acquired
                            pFabLocks.UndoLastAcquiredLocks();
                            //clear selection, to make sure the parcel explorer is updated and refreshed properly
                            RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);
                        }
                        else
                        {
                            MessageBox.Show(Convert.ToString(pCOMEx.ErrorCode));
                        }

                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Now... start the edit. Start an edit operation.
                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StartOperation();
                }

                if (bUseNonVersioned)
                {
                    if (!UTILS.StartEditing(pWS, bUseNonVersioned))
                    {
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                }

                //Change all the date records
                if (m_pStepProgressor != null)
                {
                    m_pStepProgressor.Message = "Changing dates...";
                }

                bool bSuccess = true;

                ITable      Table2Edit = (ITable)flyr.FeatureClass;
                ITableWrite pTableWr   = (ITableWrite)Table2Edit;

                if (ChosenLayerHasSelection)
                {
                    //TODO: Selection based update does not work on unversioned tables
                    //need to change this code to create an update cursor from the selection,
                    //including code for tokens > 995
                    pSelSet.Update(null, false, out m_pCursor);
                }
                else
                {
                    if (bUseNonVersioned)
                    {
                        m_pCursor = pTableWr.UpdateRows(null, false);
                    }
                    else
                    {
                        m_pCursor = Table2Edit.Update(null, false);
                    }
                }
                ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                if (bLines)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLines); //release safety-catch
                }
                else if (bParcels)
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTParcels); //release safety-catch
                }
                else
                {
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ReleaseReadOnlyFields(Table2Edit,
                                                    esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }

                if (pDateChangerDialog.radioButton2.Checked)
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text, "",
                                                        bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }
                else
                {
                    bSuccess = UTILS.ChangeDatesOnTable(m_pCursor, pDateChangerDialog.cboBoxFields.Text,
                                                        pDateChangerDialog.dateTimePicker1.Text, bUseNonVersioned, m_pStepProgressor, m_pTrackCancel);
                }

                if (!bSuccess)
                {
                    if (!bIsUnVersioned)
                    {
                        pFabLocks.UndoLastAcquiredLocks();
                    }
                    if (bUseNonVersioned)
                    {
                        UTILS.AbortEditing(pWS);
                    }
                    else
                    {
                        pEd.AbortOperation();
                    }
                    //clear selection, to make sure the parcel explorer is updated and refreshed properly

                    return;
                }

                if (pEd.EditState == esriEditState.esriStateEditing)
                {
                    pEd.StopOperation("Change Date");
                }

                if (bUseNonVersioned)
                {
                    UTILS.StopEditing(pWS);
                }

                if (bParcels)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels);
                }
                else if (bLines)
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLines);
                }
                else
                {
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints);     //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);    //release safety-catch
                    pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLinePoints); //release safety-catch
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + ex.Message);
                if (bUseNonVersioned)
                {
                    UTILS.AbortEditing(pWS);
                }
                else
                {
                    pEd.AbortOperation();
                }
            }
            finally
            {
                RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);

                if (bUseNonVersioned)
                {
                    pCadEd.CadastralFabricLayer = null;
                    CFParcelLayers   = null;
                    CFPointLayer     = null;
                    CFLineLayer      = null;
                    CFControlLayer   = null;
                    CFLinePointLayer = null;
                }

                m_pStepProgressor = null;
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pProgressorDialog = null;
            }
        }
Beispiel #27
0
 public void SetUp()
 {
     ctx    = new SimplePofContext();
     stream = new MemoryStream();
     la     = new LongSortedList();
 }
        private static Dictionary <string, List <int> > GetEIDListsBySourceName(INetworkAnalystExtension nax, object searchObject, string baseName)
        {
            if (nax == null)
            {
                return(null);
            }

            bool             naxEnabled = false;
            IExtensionConfig naxConfig  = nax as IExtensionConfig;

            naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled;

            if (!naxEnabled)
            {
                return(null);
            }

            INAWindow       naWindow  = nax.NAWindow;
            INALayer        naLayer   = null;
            INAContext      naContext = null;
            INetworkDataset nds       = null;

            naLayer = naWindow.ActiveAnalysis;
            if (naLayer != null)
            {
                naContext = naLayer.Context;
            }

            if (naContext != null)
            {
                nds = naContext.NetworkDataset;
            }

            INetworkQuery netQuery = nds as INetworkQuery;

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

            bool oidSearch      = false;
            bool geometrySearch = false;

            if (searchObject == null)
            {
                return(null);
            }
            else if (searchObject is Dictionary <string, ILongArray> )
            {
                oidSearch = true;
            }
            else if (searchObject is IGeometry)
            {
                geometrySearch = true;
            }
            else
            {
                return(null);
            }

            VarType       vt          = GetEIDArrayParameterType();
            List <string> sourceNames = FindParameterizedSourceNames(nds, baseName, vt);
            Dictionary <string, List <int> > eidsBySourceName = new Dictionary <string, List <int> >();

            foreach (string sourceName in sourceNames)
            {
                INetworkSource netSource = nds.get_SourceByName(sourceName);
                int            sourceID  = netSource.ID;
                List <int>     eids      = new List <int>();

                if (oidSearch)
                {
                    Dictionary <string, ILongArray> oidArraysBySourceName = (Dictionary <string, ILongArray>)searchObject;
                    ILongArray          oids = null;
                    IEnumNetworkElement enumNetElement;
                    INetworkElement     netElement;

                    if (oidArraysBySourceName.TryGetValue(sourceName, out oids))
                    {
                        enumNetElement = netQuery.get_ElementsByOIDs(sourceID, oids);
                        enumNetElement.Reset();
                        netElement = enumNetElement.Next();
                        while (netElement != null)
                        {
                            eids.Add(netElement.EID);
                            netElement = enumNetElement.Next();
                        }
                    }
                }
                else if (geometrySearch)
                {
                    IGeometry searchGeometry = (IGeometry)searchObject;
                    if (searchGeometry != null && !searchGeometry.IsEmpty)
                    {
                        IGeometry elementGeometry          = null;
                        esriNetworkElementType elementType = esriNetworkElementType.esriNETEdge;
                        int eid = -1;

                        // Search for the network dataset layer associated with the active analysis layer or create one using the
                        // network dataset if matching one not found.
                        // If, for example, multiple network dataset layers are added to the map, the active analysis layer
                        // might not reference the current network dataset layer (nax.CurrentNetworkLayer).

                        INetworkLayer ndsLayer = new NetworkLayerClass();
                        ndsLayer.NetworkDataset = nds;

                        int count = nax.NetworkLayerCount;
                        for (int i = 0; i < count; ++i)
                        {
                            ndsLayer = nax.get_NetworkLayer(i);
                            if (ndsLayer.NetworkDataset == nds)
                            {
                                break;
                            }
                            else
                            {
                                ndsLayer = null;
                            }
                        }

                        if (ndsLayer == null)
                        {
                            ndsLayer = new NetworkLayerClass();
                            ndsLayer.NetworkDataset = nds;
                        }

                        IEnumLocatedNetworkElement enumLocatedNetElement = null;
                        if (ndsLayer != null)
                        {
                            enumLocatedNetElement = ndsLayer.SearchLocatedNetworkElements(sourceName, searchGeometry);
                            enumLocatedNetElement.Reset();
                            eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType);
                            while (eid != -1)
                            {
                                eids.Add(eid);
                                eid = enumLocatedNetElement.Next(ref elementGeometry, ref elementType);
                            }
                        }
                    }
                }

                eidsBySourceName.Add(sourceName, eids);
            }

            return(eidsBySourceName);
        }
        protected override void OnClick()
        {
            #region Prepare for editing
            IMouseCursor pMouseCursor = new MouseCursorClass();
            pMouseCursor.SetCursor(2);

            UID pUID = new UIDClass();
            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralEditor            pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);

            //check if there is a Manual Mode "modify" job active ===========
            ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan;
            if (pCadPacMan.PacketOpen)
            {
                MessageBox.Show("This command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.",
                                "Delete Selected Parcels");
                return;
            }

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            IActiveView      pActiveView       = ArcMap.Document.ActiveView;
            IMap             pMap              = pActiveView.FocusMap;
            ICadastralFabric pCadFabric        = null;
            clsFabricUtils   FabricUTILS       = new clsFabricUtils();
            IProgressDialog2 pProgressorDialog = null;

            //if we're in an edit session then grab the target fabric
            if (pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }
            else
            {
                MessageBox.Show("Please start editing and try again.");
                return;
            }

            if (pCadFabric == null)
            {//find the first fabric in the map
                if (!FabricUTILS.GetFabricFromMap(pMap, out pCadFabric))
                {
                    MessageBox.Show
                        ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again.");
                    return;
                }
            }

            IArray CFParcelLayers = new ArrayClass();

            if (!(FabricUTILS.GetFabricSubLayersFromFabric(pMap, pCadFabric, out CFPointLayer, out CFLineLayer,
                                                           out CFParcelLayers, out CFControlLayer, out CFLinePointLayer)))
            {
                return; //no fabric sublayers available for the targeted fabric
            }

            //bool bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false;
            //ICadastralFabricLayer pCFLayer = null;

            IWorkspace pWS           = null;
            ITable     pParcelsTable = null;
            ITable     pLinesTable   = null;
            ITable     pLinePtsTable = null;
            ITable     pPointsTable  = null;
            pParcelsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);
            pLinesTable   = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLines);
            pLinePtsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLinePoints);
            pPointsTable  = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints);
            #endregion

            dlgChangeParcelHistory pChangeHistoryDialog = new dlgChangeParcelHistory();
            // ********  Display the dialog  *********
            DialogResult pDialogResult = pChangeHistoryDialog.ShowDialog();
            if (pDialogResult != DialogResult.OK)
            {
                return;
            }
            //************************

            #region Get Selection
            //Get the selection of parcels
            IFeatureLayer pFL = (IFeatureLayer)CFParcelLayers.get_Element(0);

            IDataset pDS = (IDataset)pFL.FeatureClass;
            pWS = pDS.Workspace;

            ICadastralSelection pCadaSel       = (ICadastralSelection)pCadEd;
            IEnumGSParcels      pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround

            IFeatureSelection           pFeatSel  = (IFeatureSelection)pFL;
            ISelectionSet2              pSelSet   = (ISelectionSet2)pFeatSel.SelectionSet;
            ICadastralFabricSchemaEdit2 pSchemaEd = null;
            try
            {
                int  iParcelCount      = pCadaSel.SelectedParcelCount;
                bool m_bShowProgressor = (iParcelCount > 10);

                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = iParcelCount * 14; //(estimate 7 lines per parcel, 4 pts per parcel)
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Initializing...";
                }

                #endregion

                #region Get Parcel History Fields
                //Get the parcel table history fields
                //SystemStart, SystemEnd, LegalStart, LegalEnd, Historic
                int iParcSysStartDate   = pParcelsTable.FindField("systemstartdate");
                int iParcSysEndDate     = pParcelsTable.FindField("systemenddate");
                int iParcLegalStartDate = pParcelsTable.FindField("legalstartdate");
                int iParcLegalEndDate   = pParcelsTable.FindField("legalenddate");
                int iParcHistorical     = pParcelsTable.FindField("historical");

                //Add the OIDs of all the selected parcels into a new feature IDSet
                //Need a Lookup for the History information
                Dictionary <int, string> ParcelToHistory_DICT = new Dictionary <int, string>();
                List <string>            sOIDList             = new List <string>();
                sOIDList.Add("");
                int  tokenLimit = 995;
                bool bCont      = true;
                int  j          = 0;
                int  iCounter   = 0;

                m_pFIDSetParcels = new FIDSetClass();

                pEnumGSParcels.Reset();
                IGSParcel pGSParcel = pEnumGSParcels.Next();
                while (pGSParcel != null)
                {
                    //Check if the cancel button was pressed. If so, stop process
                    if (m_bShowProgressor)
                    {
                        bCont = m_pTrackCancel.Continue();
                        if (!bCont)
                        {
                            break;
                        }
                    }
                    m_pFIDSetParcels.Add(pGSParcel.DatabaseId);

                    if (iCounter <= tokenLimit)
                    {
                        if (sOIDList[j].Trim() == "")
                        {
                            sOIDList[j] = Convert.ToString(pGSParcel.DatabaseId);
                        }
                        else
                        {
                            sOIDList[j] = sOIDList[j] + "," + Convert.ToString(pGSParcel.DatabaseId);
                        }
                        iCounter++;
                    }
                    else
                    {//maximum tokens reached
                        iCounter = 0;
                        //set up the next OIDList
                        j++;
                        sOIDList.Add("");
                        sOIDList[j] = Convert.ToString(pGSParcel.DatabaseId);
                    }

                    //add to the lookup
                    IGSAttributes pGSParcelAttributes = (IGSAttributes)pGSParcel;
                    object        pObj = pGSParcelAttributes.GetProperty("systemstartdate");
                    string        sSystemStartParcel = "";
                    if (pObj != null)
                    {
                        sSystemStartParcel = pObj.ToString();
                    }

                    pObj = pGSParcelAttributes.GetProperty("systemenddate");
                    string sSystemEndParcel = "";
                    if (pObj != null)
                    {
                        sSystemEndParcel = pObj.ToString();
                    }

                    string sLegalStartParcel = pGSParcel.LegalStartDate.ToString();
                    string sLegalEndParcel   = pGSParcel.LegalEndDate.ToString();
                    string sHistorical       = pGSParcel.Historical.ToString();

                    ParcelToHistory_DICT.Add(pGSParcel.DatabaseId, sSystemStartParcel + "," +
                                             sSystemEndParcel + "," + sLegalStartParcel + "," + sLegalEndParcel + "," +
                                             sHistorical);

                    Marshal.ReleaseComObject(pGSParcel); //garbage collection
                    pGSParcel = pEnumGSParcels.Next();
                    if (m_bShowProgressor)
                    {
                        if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                        {
                            m_pStepProgressor.Step();
                        }
                    }
                }
                Marshal.ReleaseComObject(pEnumGSParcels); //garbage collection

                #endregion

                #region Confirm Edit Locks
                bool bIsFileBasedGDB  = false;
                bool bIsUnVersioned   = false;
                bool bUseNonVersioned = false;

                if (!FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB,
                                                      out bIsUnVersioned, out bUseNonVersioned))
                {
                    return;
                }
                //if we're in an enterprise then test for edit locks
                string sTime = "";
                if (!bIsUnVersioned && !bIsFileBasedGDB)
                {
                    //see if parcel locks can be obtained on the selected parcels. First create a job.
                    DateTime localNow = DateTime.Now;
                    sTime = Convert.ToString(localNow);
                    ICadastralJob pJob = new CadastralJobClass();
                    pJob.Name        = sTime;
                    pJob.Owner       = System.Windows.Forms.SystemInformation.UserName;
                    pJob.Description = "Delete selected parcels";
                    try
                    {
                        Int32 jobId = pCadFabric.CreateJob(pJob);
                    }
                    catch (COMException ex)
                    {
                        if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Job named: '" + pJob.Name + "', already exists");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                        m_pStepProgressor = null;
                        if (!(pProgressorDialog == null))
                        {
                            pProgressorDialog.HideDialog();
                        }
                        pProgressorDialog = null;
                        Marshal.ReleaseComObject(pJob);
                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                    Marshal.ReleaseComObject(pJob);
                }
                ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric;
                if (!bIsUnVersioned && !bIsFileBasedGDB)
                {
                    pFabLocks.LockingJob = sTime;
                    ILongArray pLocksInConflict    = null;
                    ILongArray pSoftLcksInConflict = null;

                    ILongArray pParcelsToLock = new LongArrayClass();

                    FabricUTILS.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, m_pStepProgressor);
                    if (m_bShowProgressor && !bIsFileBasedGDB)
                    {
                        m_pStepProgressor.Message = "Testing for edit locks on parcels...";
                    }

                    try
                    {
                        pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                    }
                    catch (COMException pCOMEx)
                    {
                        if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS ||
                            pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED)
                        {
                            MessageBox.Show("Edit Locks could not be acquired on all selected parcels.");
                            // since the operation is being aborted, release any locks that were acquired
                            pFabLocks.UndoLastAcquiredLocks();
                        }
                        else
                        {
                            MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode));
                        }

                        if (bUseNonVersioned)
                        {
                            pCadEd.CadastralFabricLayer = null;
                        }
                        return;
                    }
                    Marshal.ReleaseComObject(pSoftLcksInConflict);
                    Marshal.ReleaseComObject(pParcelsToLock);
                    Marshal.ReleaseComObject(pLocksInConflict);
                }
                #endregion

                string sParcelSysEndDate     = pParcelsTable.Fields.get_Field(iParcSysEndDate).Name;
                string sParcelLegalStartDate = pParcelsTable.Fields.get_Field(iParcLegalStartDate).Name;
                string sParcelLegalEndDate   = pParcelsTable.Fields.get_Field(iParcLegalEndDate).Name;
                string sParcelHistoric       = pParcelsTable.Fields.get_Field(iParcHistorical).Name;

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Updating parcel history...";
                }

                pEd.StartOperation();

                #region The Edit

                //make change to parcels
                bool         bSuccess  = false;
                ICursor      pCurs     = null;
                IQueryFilter pQuFilter = new QueryFilterClass();
                pQuFilter.SubFields = pParcelsTable.OIDFieldName + "," + sParcelLegalEndDate + "," + sParcelLegalStartDate
                                      + "," + sParcelSysEndDate + "," + sParcelHistoric;

                bool bSystemEndDate_Clear = pChangeHistoryDialog.chkSystemEndDate.Checked &&
                                            pChangeHistoryDialog.optClearSEDate.Checked;
                bool bLegalStDate_Clear = pChangeHistoryDialog.chkLegalStartDate.Checked &&
                                          pChangeHistoryDialog.optClearLSDate.Checked;
                bool bLegalEndDate_Clear = pChangeHistoryDialog.chkLegalEndDate.Checked &&
                                           pChangeHistoryDialog.optClearLEDate.Checked;

                bool bSystemEndDate_Set = pChangeHistoryDialog.chkSystemEndDate.Checked &&
                                          pChangeHistoryDialog.optChooseSEDate.Checked;
                bool bLegalStDate_Set = pChangeHistoryDialog.chkLegalStartDate.Checked &&
                                        pChangeHistoryDialog.optChooseLSDate.Checked;
                bool bLegalEndDate_Set = pChangeHistoryDialog.chkLegalEndDate.Checked &&
                                         pChangeHistoryDialog.optChooseLEDate.Checked;

                List <bool> bHistory = new List <bool>();
                bHistory.Add(bSystemEndDate_Clear);
                bHistory.Add(bLegalStDate_Clear);
                bHistory.Add(bLegalEndDate_Clear);
                bHistory.Add(bSystemEndDate_Set);
                bHistory.Add(bLegalStDate_Set);
                bHistory.Add(bLegalEndDate_Set);

                List <string> sDates = new List <string>();
                sDates.Add(pChangeHistoryDialog.dtSEDatePicker.Text);
                sDates.Add(pChangeHistoryDialog.dtLSDatePicker.Text);
                sDates.Add(pChangeHistoryDialog.dtLEDatePicker.Text);

                pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                pSchemaEd.ReleaseReadOnlyFields(pLinesTable, esriCadastralFabricTable.esriCFTLines);     //release safety-catch
                pSchemaEd.ReleaseReadOnlyFields(pParcelsTable, esriCadastralFabricTable.esriCFTParcels); //release safety-catch
                pSchemaEd.ReleaseReadOnlyFields(pPointsTable, esriCadastralFabricTable.esriCFTPoints);   //release safety-catch

                foreach (string sInClause in sOIDList)
                {
                    if (sInClause.Trim() == "")
                    {
                        continue;
                    }
                    pQuFilter.WhereClause = pParcelsTable.OIDFieldName + " IN (" + sInClause + ")";
                    pCurs    = pParcelsTable.Update(pQuFilter, false);
                    bSuccess = FabricUTILS.ChangeDatesOnTableMulti(pCurs, bHistory, sDates, bUseNonVersioned,
                                                                   ParcelToHistory_DICT, m_pStepProgressor, m_pTrackCancel);

                    if (!bSuccess)
                    {
                        if (!bIsUnVersioned)
                        {
                            pFabLocks.UndoLastAcquiredLocks();
                        }
                        if (bUseNonVersioned)
                        {
                            FabricUTILS.AbortEditing(pWS);
                        }
                        else
                        {
                            pEd.AbortOperation();
                        }
                        //clear selection, to make sure the parcel explorer is updated and refreshed properly

                        return;
                    }
                }

                //make change to points and lines
                if (!FabricUTILS.UpdateHistoryOnLines(pLinesTable, pPointsTable, iParcelCount,
                                                      pCadFabric, sOIDList, ParcelToHistory_DICT, m_pStepProgressor, m_pTrackCancel))
                {
                    if (!bIsUnVersioned)
                    {
                        pFabLocks.UndoLastAcquiredLocks();
                    }
                    if (bUseNonVersioned)
                    {
                        FabricUTILS.AbortEditing(pWS);
                    }
                    else
                    {
                        pEd.AbortOperation();
                    }
                }
                else
                {
                    pEd.StopOperation("Change Parcel History");
                }

                #endregion

                //now refresh the map layers
                RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer);
            }

            catch (Exception ex)
            {
                pEd.AbortOperation();
                MessageBox.Show("Error:" + ex.Message);
            }
            finally
            {
                if (!(pProgressorDialog == null))
                {
                    pProgressorDialog.HideDialog();
                }
                pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints);  //set safety back on
                pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLines);   //set safety back on
                pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels); //set safety back on
            }
        }
Beispiel #30
0
        private bool TraceLines(ref IGSForwardStar FwdStar, int StartNodeId, ref int BranchCount,
                                ref int TracedLinesCount, ref int LoopCount, ref int TerminusCount, ref List <string> FromToLine,
                                ref List <int> FromList, ref List <int> ToList, int iInfinityChecker)
        {
            iInfinityChecker++;
            if (iInfinityChecker > 5000)
            {
                return(false);
            }
            //(This is a self-calling function.) In this context 5000 downstream lines is like infinity,
            //so exit gracefully, and avoid probable endless loop.
            //Possible cause of endless loop? Corrupted data; example, a line with the same from and to point id
            IVector3D vect = new Vector3DClass();

            try
            {
                ILongArray iLngArr = FwdStar.get_ToNodes(StartNodeId);
                //get_ToNodes returns an array of radiated points, not "TO" points in the fabric data model sense
                int iCnt2 = 0;
                iCnt2 = iLngArr.Count;

                if (iCnt2 == 1)
                {
                    TerminusCount++;
                }

                IGSLine pGSLine = null;
                for (int i = 0; i < iCnt2; i++)
                {
                    int i2 = iLngArr.get_Element(i);

                    string sFromTo = StartNodeId.ToString() + "," + i2.ToString();
                    string sToFrom = i2.ToString() + "," + StartNodeId.ToString();

                    if (FromToLine.Contains(sFromTo) || FromToLine.Contains(sToFrom))
                    {
                        if (FromToLine.Contains(sFromTo))
                        {
                            LoopCount++;
                        }
                        continue;
                    }

                    if (iCnt2 > 2)
                    {
                        BranchCount++;
                    }

                    TracedLinesCount++;

                    FromToLine.Add(StartNodeId.ToString() + "," + i2.ToString());

                    bool bIsReversed = FwdStar.GetLine(StartNodeId, i2, ref pGSLine);
                    if (bIsReversed)
                    {
                        FromList.Add(-StartNodeId);
                        ToList.Add(-i2);
                        vect.PolarSet(pGSLine.Bearing + Math.PI, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                    }
                    else
                    {
                        FromList.Add(StartNodeId);
                        ToList.Add(i2);
                        vect.PolarSet(pGSLine.Bearing, 0, pGSLine.Distance); //Azimuth of IVector3D is north azimuth radians zero degrees north
                    }

                    if (!TraceLines(ref FwdStar, i2, ref BranchCount, ref TracedLinesCount, ref LoopCount, ref TerminusCount,
                                    ref FromToLine, ref FromList, ref ToList, iInfinityChecker))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public static Dictionary <string, ILongArray> GetOIDArraysBySourceNameFromMapSelection(IMap map, List <string> sourceNames)
        {
            UIDClass uid = new UIDClass();

            uid.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";             //IGeoFeatureLayer

            IEnumLayer searchEnumLayer = map.get_Layers(uid, true);

            searchEnumLayer.Reset();

            //create result dictionary from source names with empty oidArrays

            Dictionary <string, ILongArray> oidArraysBySourceName = new Dictionary <string, ILongArray>();
            ILongArray oidArray = null;

            foreach (string sourceName in sourceNames)
            {
                if (!oidArraysBySourceName.TryGetValue(sourceName, out oidArray))
                {
                    oidArray = new LongArrayClass();
                    oidArraysBySourceName.Add(sourceName, oidArray);
                }
            }

            ILayer layer = searchEnumLayer.Next();

            while (layer != null)
            {
                IDisplayTable displayTable = layer as IDisplayTable;
                string        sourceName   = "";
                if (layer.Valid && layer.Visible && displayTable != null)
                {
                    IDataset ds = displayTable.DisplayTable as IDataset;
                    if (ds != null)
                    {
                        sourceName = ds.Name;
                    }
                }

                if (sourceName.Length > 0)
                {
                    if (oidArraysBySourceName.TryGetValue(sourceName, out oidArray))
                    {
                        ISelectionSet selSet   = displayTable.DisplaySelectionSet;
                        IEnumIDs      enumOIDs = null;
                        if (selSet != null)
                        {
                            enumOIDs = selSet.IDs;
                        }

                        if (enumOIDs != null)
                        {
                            enumOIDs.Reset();
                            int oid = enumOIDs.Next();
                            while (oid != -1)
                            {
                                oidArray.Add(oid);
                                oid = enumOIDs.Next();
                            }
                        }
                    }
                }

                layer = searchEnumLayer.Next();
            }

            return(oidArraysBySourceName);
        }
        protected override void OnClick()
        {
            ICadastralEditor           pCadEd         = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");
            IParcelEditManager         pParcEditorMan = (IParcelEditManager)pCadEd;
            ICadastralExtensionManager pCadMan        = pCadEd as ICadastralExtensionManager;
            ICadastralPacketManager    pCadPacketMan  = (ICadastralPacketManager)pCadEd;

            //bool bStartedWithPacketOpen = pCadPacketMan.PacketOpen;

            if (!(pCadMan.ContextItem is IGSLine))
            {
                return;
            }

            IGSLine pGSLine = pCadMan.ContextItem as IGSLine;

            if (pParcEditorMan == null)
            {
                return;
            }

            IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            if (pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing and try again.");
                return;
            }

            IParcelConstruction     pConstr   = pParcEditorMan.ParcelConstruction;
            ICadastralLinePoints2Ex pCadLPsEx = pConstr as ICadastralLinePoints2Ex;

            ILongArray pLngArrBefore = pCadLPsEx.LinePoints;
            List <int> lstLPBefore   = new List <int>();

            for (int i = 0; i < pLngArrBefore.Count; i++)
            {
                lstLPBefore.Add(pLngArrBefore.get_Element(i));
            }

            //first get the current set of breakpoints
            Utilities FabUTILS = new Utilities();

            FabUTILS.ExecuteCommand("{9987F18B-8CC4-4548-8C41-7DB51F289BB3}"); //Run COTS Breakline command

            ILongArray pLngArrAfter = pCadLPsEx.LinePoints;
            List <int> lstLPAfter   = new List <int>();

            for (int i = 0; i < pLngArrAfter.Count; i++)
            {
                lstLPAfter.Add(pLngArrAfter.get_Element(i));
            }

            List <int> lstNewBreakPoints = lstLPAfter.Except(lstLPBefore).ToList();

            if (lstNewBreakPoints.Count == 0)
            {
                return;
            }

            IParcelConstruction4 pConstr4      = pConstr as IParcelConstruction4;
            ICadastralPoints     pCadastralPts = pConstr4 as ICadastralPoints;

            IEnumCELines pCELines     = new EnumCELinesClass();
            IEnumGSLines pEnumGSLines = (IEnumGSLines)pCELines;

            pCELines.Add(pGSLine);

            //check if it's a construction line or parent line
            bool         bIsParentLine            = true;
            IEnumGSLines pEnumGSConstructionLines = pConstr4.GetLines(false, false);

            IGSLine   pGSTestLine = null;
            IGSParcel pGSParc     = null;

            pEnumGSConstructionLines.Reset();
            pEnumGSConstructionLines.Next(ref pGSParc, ref pGSTestLine);
            while (pGSTestLine != null)
            {
                if ((pGSLine.FromPoint == pGSTestLine.FromPoint) && (pGSLine.ToPoint == pGSTestLine.ToPoint))
                {
                    bIsParentLine = false;
                    break;
                }
                pEnumGSConstructionLines.Next(ref pGSParc, ref pGSTestLine);
            }

            IParcelLineFunctions3 pParcLineFunctions = new ParcelFunctionsClass();
            IEnumGSLines          pNewLinesEnum      = pParcLineFunctions.BreakLinesAtLinePoints(pEnumGSLines, pCadastralPts, true, false);

            IGSParcel          pGSParcel    = null;
            IGSLine            pGSNewLine   = null;
            ICadastralUndoRedo pCadUndoRedo = pConstr as ICadastralUndoRedo;

            pCadUndoRedo.StartUndoRedoSession("Break-line");

            pNewLinesEnum.Reset();
            pNewLinesEnum.Next(ref pGSParcel, ref pGSNewLine);
            while (pGSNewLine != null)
            {
                pConstr4.InsertGridRow(-1, pGSNewLine, true);
                pNewLinesEnum.Next(ref pGSParcel, ref pGSNewLine);
            }

            ICadastralUnbuildableLines pUnbuildable = pConstr4 as ICadastralUnbuildableLines;

            if (bIsParentLine)
            {
                pUnbuildable.AddLine(pGSLine);
            }
            else
            {
                pConstr4.Planarize(0.001); //delete the original construction line
            }
            pCadUndoRedo.WriteUndoRedoSession(true);
        }
 public void FIDsetToLongArray(IFIDSet InFIDSet, ref ILongArray OutLongArray, IStepProgressor StepProgressor)
 {
     Int32 pfID = -1;
       InFIDSet.Reset();
       double dMax = InFIDSet.Count();
       int iMax = (int)(dMax);
       for (Int32 pCnt = 0; pCnt <= (InFIDSet.Count() - 1); pCnt++)
       {
     InFIDSet.Next(out pfID);
     OutLongArray.Add(pfID);
     if (StepProgressor != null)
     {
       if (StepProgressor.Position < StepProgressor.MaxRange)
     StepProgressor.Step();
     }
       }
       return;
 }
Beispiel #34
0
        protected override void OnClick()
        {
            m_bNoUpdates = false;
            m_sReport    = "Direction Inverse Report:";
            IEditor m_pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            if (m_pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing first, and try again.", "Start Editing");
                return;
            }

            UID pUID = new UIDClass();

            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralEditor            pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);

            //check if there is a Manual Mode "modify" job active ===========
            ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan;

            if (pCadPacMan.PacketOpen)
            {
                MessageBox.Show("The Delete Parcels command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.",
                                "Delete Selected Parcels");
                return;
            }

            try
            {
                IEditProperties2 pEditorProps2 = (IEditProperties2)m_pEd;

                IArray           LineLyrArr;
                IMap             pMap       = m_pEd.Map;
                ICadastralFabric pCadFabric = null;
                //ISpatialReference pSpatRef = m_pEd.Map.SpatialReference;
                //IProjectedCoordinateSystem2 pPCS = null;
                IActiveView pActiveView = ArcMap.Document.ActiveView;

                //double dMetersPerUnit = 1;

                //if (pSpatRef == null)
                //  ;
                //else if (pSpatRef is IProjectedCoordinateSystem2)
                //{
                //  pPCS = (IProjectedCoordinateSystem2)pSpatRef;
                //  string sUnit = pPCS.CoordinateUnit.Name;
                //  if (sUnit.Contains("Foot") && sUnit.Contains("US"))
                //    sUnit = "U.S. Feet";

                //  dMetersPerUnit = pPCS.CoordinateUnit.MetersPerUnit;
                //}

                IAngularConverter pAngConv = new AngularConverterClass();
                Utilities         Utils    = new Utilities();

                if (!Utils.GetFabricSubLayers(pMap, esriCadastralFabricTable.esriCFTLines, out LineLyrArr))
                {
                    return;
                }

                //if we're in an edit session then grab the target fabric
                if (m_pEd.EditState == esriEditState.esriStateEditing)
                {
                    pCadFabric = pCadEd.CadastralFabric;
                }

                if (pCadFabric == null)
                {//find the first fabric in the map
                    if (!Utils.GetFabricFromMap(pMap, out pCadFabric))
                    {
                        MessageBox.Show
                            ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again.");
                        return;
                    }
                }
                List <int> lstLineIds = new List <int>();

                IFeatureClass pFabricLinesFC = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLines);
                int           idxParcelIDFld = pFabricLinesFC.Fields.FindField("ParcelID");
                int           idxCENTERPTID  = pFabricLinesFC.Fields.FindField("CenterPointID");
                int           idxRADIUS      = pFabricLinesFC.Fields.FindField("Radius");
                bool          bFieldsPresent = true;
                if (idxParcelIDFld == -1)
                {
                    bFieldsPresent = false;
                }
                if (idxCENTERPTID == -1)
                {
                    bFieldsPresent = false;
                }
                if (idxRADIUS == -1)
                {
                    bFieldsPresent = false;
                }

                if (!bFieldsPresent)
                {
                    MessageBox.Show("Fields missing.");
                    return;
                }

                Dictionary <int, List <string> > dictLineToCurveNeighbourData = new Dictionary <int, List <string> >();
                m_pFIDSetParcels = new FIDSet();
                for (int i = 0; i < LineLyrArr.Count; i++)
                {
                    IFeatureSelection pFeatSel = LineLyrArr.Element[i] as IFeatureSelection;
                    ISelectionSet     pSelSet  = pFeatSel.SelectionSet;
                    ICursor           pCursor  = null;
                    pSelSet.Search(null, false, out pCursor);
                    IFeature pLineFeat = pCursor.NextRow() as IFeature;

                    while (pLineFeat != null)
                    {
                        if (!lstLineIds.Contains(pLineFeat.OID))
                        {
                            IGeometry          pGeom    = pLineFeat.ShapeCopy;
                            ISegmentCollection pSegColl = pGeom as ISegmentCollection;
                            ISegment           pSeg     = null;
                            if (pSegColl.SegmentCount == 1)
                            {
                                pSeg = pSegColl.get_Segment(0);
                            }
                            else
                            {
                                //todo: but for now, only deals with single segment short segments
                                Marshal.ReleaseComObject(pLineFeat);
                                pLineFeat = pCursor.NextRow() as IFeature;
                                continue;
                            }

                            //check geometry for circular arc
                            if (pSeg is ICircularArc)
                            {
                                object       dVal1    = pLineFeat.get_Value(idxRADIUS);
                                object       dVal2    = pLineFeat.get_Value(idxCENTERPTID);
                                ICircularArc pCircArc = pSeg as ICircularArc;
                                if (dVal1 != DBNull.Value && dVal2 != DBNull.Value)
                                {
                                    Marshal.ReleaseComObject(pLineFeat);
                                    pLineFeat = pCursor.NextRow() as IFeature;
                                    continue;
                                }
                            }

                            //query near lines
                            int           iFoundTangent            = 0;
                            List <string> sCurveInfoFromNeighbours = new List <string>();

                            if (Utils.HasTangentCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", 1.5, 0.033, 1, (pSeg.Length * 1.1),
                                                                   out iFoundTangent, ref sCurveInfoFromNeighbours))
                            {
                                lstLineIds.Add(pLineFeat.OID);
                                int j = (int)pLineFeat.get_Value(idxParcelIDFld);
                                m_pFIDSetParcels.Add(j);
                                dictLineToCurveNeighbourData.Add(pLineFeat.OID, sCurveInfoFromNeighbours);
                            }
                            if (iFoundTangent == 1) //if there's only one tangent look further afield
                            {
                                int iFoundLinesCount = 0;
                                int iFoundParallel   = 0;
                                if (Utils.HasParallelCurveMatchFeatures(pFabricLinesFC, (IPolycurve)pGeom, "", 1.5, 70,
                                                                        out iFoundLinesCount, out iFoundParallel, ref sCurveInfoFromNeighbours))
                                {
                                    if (!dictLineToCurveNeighbourData.ContainsKey(pLineFeat.OID))
                                    {
                                        dictLineToCurveNeighbourData.Add(pLineFeat.OID, sCurveInfoFromNeighbours);
                                    }
                                }
                            }
                        }
                        Marshal.ReleaseComObject(pLineFeat);
                        pLineFeat = pCursor.NextRow() as IFeature;
                    }
                    Marshal.ReleaseComObject(pCursor);
                }

                #region line to curve candidate analysis
                if (lstLineIds.Count == 0)
                {
                    return;
                }

                RefineToBestRadiusAndCenterPoint(dictLineToCurveNeighbourData);

                #endregion

                if (dictLineToCurveNeighbourData.Count == 0)
                {
                    return;
                }

                bool             bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false;
                IWorkspace       pWS               = m_pEd.EditWorkspace;
                IProgressDialog2 pProgressorDialog = null;
                IMouseCursor     pMouseCursor      = new MouseCursorClass();
                pMouseCursor.SetCursor(2);
                if (!Utils.SetupEditEnvironment(pWS, pCadFabric, m_pEd, out bIsFileBasedGDB,
                                                out bIsUnVersioned, out bUseNonVersionedDelete))
                {
                    return;
                }


                #region Create Cadastral Job
                string sTime = "";
                if (!bIsUnVersioned && !bIsFileBasedGDB)
                {
                    //see if parcel locks can be obtained on the selected parcels. First create a job.
                    DateTime localNow = DateTime.Now;
                    sTime = Convert.ToString(localNow);
                    ICadastralJob pJob = new CadastralJobClass();
                    pJob.Name        = sTime;
                    pJob.Owner       = System.Windows.Forms.SystemInformation.UserName;
                    pJob.Description = "Convert lines to curves";
                    try
                    {
                        Int32 jobId = pCadFabric.CreateJob(pJob);
                    }
                    catch (COMException ex)
                    {
                        if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS)
                        {
                            MessageBox.Show("Job named: '" + pJob.Name + "', already exists");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                        return;
                    }
                }
                #endregion

                #region Test for Edit Locks
                ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric;

                //only need to get locks for parcels that have lines that are to be changed


                int[]      pParcelIds     = new int[m_pFIDSetParcels.Count()];
                ILongArray pParcelsToLock = new LongArrayClass();
                Utils.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, ref pParcelIds, m_pStepProgressor);

                if (!bIsUnVersioned && !bIsFileBasedGDB)
                {
                    pFabLocks.LockingJob = sTime;
                    ILongArray pLocksInConflict    = null;
                    ILongArray pSoftLcksInConflict = null;

                    if (m_bShowProgressor && !bIsFileBasedGDB)
                    {
                        m_pStepProgressor.Message = "Testing for edit locks on parcels...";
                    }

                    try
                    {
                        pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict);
                    }
                    catch (COMException pCOMEx)
                    {
                        if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS ||
                            pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED)
                        {
                            MessageBox.Show("Edit Locks could not be acquired on all selected parcels.");
                            // since the operation is being aborted, release any locks that were acquired
                            pFabLocks.UndoLastAcquiredLocks();
                        }
                        else
                        {
                            MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode));
                        }

                        return;
                    }
                }
                #endregion

                if (m_pEd.EditState == esriEditState.esriStateEditing)
                {
                    try
                    {
                        m_pEd.StartOperation();
                    }
                    catch
                    {
                        m_pEd.AbortOperation();//abort any open edit operations and try again
                        m_pEd.StartOperation();
                    }
                }
                if (bUseNonVersionedDelete)
                {
                    if (!Utils.StartEditing(pWS, bIsUnVersioned))
                    {
                        return;
                    }
                }

                ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                pSchemaEd.ReleaseReadOnlyFields((ITable)pFabricLinesFC, esriCadastralFabricTable.esriCFTLines); //release for edits

                m_pQF = new QueryFilter();

                // m_pEd.StartOperation();

                List <string> sInClauseList = Utils.InClauseFromOIDsList(lstLineIds, 995);
                foreach (string InClause in sInClauseList)
                {
                    m_pQF.WhereClause = pFabricLinesFC.OIDFieldName + " IN (" + InClause + ")";
                    if (!UpdateCircularArcValues((ITable)pFabricLinesFC, m_pQF, bIsUnVersioned, dictLineToCurveNeighbourData))
                    {
                        ;
                    }
                }
                m_pEd.StopOperation("Insert missing circular arc information.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                m_pEd.AbortOperation();
            }
            finally
            {
            }
        }