private void SearchForTopBlocks(string blkName, int targetCount)
        {
            List <ObjectId> blkIds = new List <ObjectId>();

            try
            {
                if (ProcessingStarted != null)
                {
                    string msg = string.Format(
                        "Searching first {0} block refeences: \"{1}\"",
                        targetCount, blkName);
                    LongProcessStartedEventArgs e =
                        new LongProcessStartedEventArgs(msg);

                    ProcessingStarted(this, e);
                }

                using (var tran = _dwg.TransactionManager.StartTransaction())
                {
                    //Get all entities' ID in ModelSpace
                    BlockTableRecord model = (BlockTableRecord)tran.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(
                            _dwg.Database), OpenMode.ForRead);

                    foreach (ObjectId id in model)
                    {
                        if (ProcessingProgressed != null)
                        {
                            string progMsg = string.Format(
                                "{0} found\n" +
                                "Processing entity: {1}",
                                blkIds.Count, id.ObjectClass.DxfName);
                            LongProcessingProgressEventArgs e =
                                new LongProcessingProgressEventArgs(progMsg);
                            ProcessingProgressed(this, e);
                        }

                        if (IsTargetBlock(id, blkName, tran))
                        {
                            blkIds.Add(id);
                            if (blkIds.Count == targetCount)
                            {
                                break;
                            }
                        }
                    }

                    tran.Commit();
                }

                ProcessingEnded?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                //Make sure the CloseProgressUIRequested event always fires,
                //so that the progress dialog box gets closed because of
                //this event
                CloseProgressUIRequested?.Invoke(this, EventArgs.Empty);
            }
        }
        private void LoopThroughModelSpace()
        {
            try
            {
                //run 2 long processing loops
                for (int n = 0; n < 2; n++)
                {
                    using (var tran =
                               _dwg.TransactionManager.StartTransaction())
                    {
                        //Get all entities' ID in ModelSpace
                        BlockTableRecord model = (BlockTableRecord)
                                                 tran.GetObject(
                            SymbolUtilityServices.GetBlockModelSpaceId(
                                _dwg.Database), OpenMode.ForRead);

                        ObjectId[] entIds = model.Cast <ObjectId>().ToArray();

                        if (ProcessingStarted != null)
                        {
                            string process = n == 0 ?
                                             "Searching ModelSpace for AAAA" :
                                             "Search ModelSpace for BBBB";
                            LongProcessStartedEventArgs e =
                                new LongProcessStartedEventArgs(
                                    process, entIds.Length, true);

                            ProcessingStarted(this, e);
                        }

                        int count = 0;
                        foreach (var entId in entIds)
                        {
                            count++;

                            if (ProcessingProgressed != null)
                            {
                                string progMsg = string.Format(
                                    "{0} out of {1}. {2} remaining...\n" +
                                    "Processing entity: {3}",
                                    count,
                                    entIds.Length,
                                    entIds.Length - count,
                                    entId.ObjectClass.DxfName);

                                LongProcessingProgressEventArgs e =
                                    new LongProcessingProgressEventArgs(progMsg);
                                ProcessingProgressed(this, e);

                                //Since this processing is cancellable, we
                                //test if user clicked the "Stop" button in the
                                //progressing dialog box
                                if (e.Cancel)
                                {
                                    break;
                                }
                            }

                            //Do something with the entity
                            Entity ent = (Entity)tran.GetObject(
                                entId, OpenMode.ForRead);
                            long s = 0;
                            for (int i = 0; i < 1000000; i++)
                            {
                                s += i * i;
                            }
                        }

                        ProcessingEnded?.Invoke(this, EventArgs.Empty);
                        tran.Commit();
                    }
                }
            }
            finally
            {
                //Make sure the CloseProgressUIRequested event always fires, so
                //that the progress dialog box gets closed because of this event
                CloseProgressUIRequested?.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #3
0
 private void InvokeProcessingEnded(object sender)
 {
     ProcessingEnded?.Invoke(sender, new EventArgs());
 }
Beispiel #4
0
        //Messpunkte einfügen
        private void InsertMP()
        {
            bool bHeader  = false;
            bool bErrorIO = false;
            int  firstRow = 0;      //erste einzulesende Zeile

            string[]         arZeile = _Text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            List <Messpunkt> lsMP    = new List <Messpunkt>();

            //Header?
            if (bHeader)
            {
                firstRow = 1;
            }

            for (int i = firstRow; i < arZeile.Length; i++)
            {
                try
                {
                    string   Zeile     = arZeile[i];
                    string[] arElement = Zeile.Split(new char[] { ';' }, StringSplitOptions.None);

                    string PNum = arElement[0];
                    double X    = Convert.ToDouble(arElement[1].Replace(',', '.'), CultureInfo.InvariantCulture);
                    double Y    = Convert.ToDouble(arElement[2].Replace(',', '.'), CultureInfo.InvariantCulture);

                    //Höhe
                    string HöheText = String.Empty;;
                    double?Z        = null;
                    bool   import3d = Convert.ToBoolean(_config.GetAppSettingString("3dImport"));

                    try
                    {
                        HöheText = @arElement[3].Replace(',', '.');
                        HöheText = HöheText.Replace("\r", "");

                        if (HöheText != String.Empty)
                        {
                            Z = Convert.ToDouble(HöheText, CultureInfo.InvariantCulture);
                        }
                    }
                    catch { }

                    Messpunkt MP = null;
                    if (import3d)
                    {
                        if (Z.HasValue)
                        {
                            Point3d pos = new Point3d(X, Y, Z.Value);
                            MP = new Messpunkt(PNum, pos, HöheText);
                        }
                        else
                        {
                            Point2d pos = new Point2d(X, Y);
                            MP = new Messpunkt(PNum, pos);
                        }
                    }
                    else
                    {
                        Point2d pos = new Point2d(X, Y);

                        if (Z.HasValue)
                        {
                            MP = new Messpunkt(PNum, pos, HöheText);
                        }
                        else
                        {
                            MP = new Messpunkt(PNum, pos);
                        }
                    }

                    lsMP.Add(MP);
                }
                catch
                {
                    if (i == 0)
                    {
                        bHeader = true;
                    }
                    else
                    {
                        _lsErrorLine.Add(i);
                        bErrorIO = true;
                    }
                }
            }

            try
            {
                if (!bErrorIO)
                {
                    int Anzahl = lsMP.Count;

                    if (ProcessingStarted != null)
                    {
                        string process = "Punkte importieren";
                        LongProcessStartedEventArgs e = new LongProcessStartedEventArgs(
                            process, lsMP.Count, true);

                        ProcessingStarted(this, e);
                    }

                    for (int i = 0; i < lsMP.Count; i++)
                    {
                        Messpunkt MP = lsMP[i];

                        if (ProcessingProgressed != null)
                        {
                            string progMsg = string.Format(
                                "{0} out of {1}. {2} remaining...\n" +
                                "Processing entity: {3}",
                                i,
                                lsMP.Count,
                                lsMP.Count - i,
                                MP.PNum);

                            LongProcessingProgressEventArgs e1 =
                                new LongProcessingProgressEventArgs(progMsg);
                            ProcessingProgressed(this, e1);

                            //Since this processing is cancellable, we
                            //test if user clicked the "Stop" button in the
                            //progressing dialog box
                            if (e1.Cancel)
                            {
                                Anzahl = i;
                                break;
                            }
                        }

                        MP.Draw(_block, _basislayer);
                    }

                    ProcessingEnded?.Invoke(this, EventArgs.Empty);

                    MessageBox.Show(Anzahl.ToString() + " Messpunkte eingefügt!");
                }
                else
                {
                    dlgPtImport diaPtImport = new dlgPtImport()
                    {
                        Text = _Text
                    };
                    diaPtImport.ShowDialog();
                }
            }
            finally
            {
                //Make sure the CloseProgressUIRequested event always fires, so
                //that the progress dialog box gets closed because of this event
                CloseProgressUIRequested?.Invoke(this, EventArgs.Empty);
            }
        }