Example #1
0
 private void pointButton_Click(object sender, EventArgs e)
 {
     foreach (var item in tasksPanels)
     {
         item.Enabled = false;
         item.Visible = false;
     }
     mode    = "point";
     figType = FigType.Point;
     point   = new Point();
 }
Example #2
0
 private void polygonButton_Click(object sender, EventArgs e)
 {
     foreach (var item in tasksPanels)
     {
         item.Enabled = false;
         item.Visible = false;
     }
     mode          = "polygon";
     figType       = FigType.Polygon;
     polygon       = new Polygon();
     polygonAngles = int.Parse(angleCount.Text);
 }
Example #3
0
        //создание новой фигуры
        public void NewFig()
        {
            Random r = new Random();

            curY = 0;
            curX = 5;

            FigType t = (FigType)r.Next(0, 7);

            fig.Create(t);

            this.Copy(); //отображение
        }
        /// <summary>
        /// Get figure type of figure text and object ids of nearby text
        /// </summary>
        /// <param name="dbtFigIn"></param>
        /// <param name="dbIn"></param>
        /// <param name="transIn"></param>
        /// <returns></returns>
        private Tuple <FigType, ObjectIdCollection, ObjectId> getFigInfo(DBText dbtFigIn, Database dbIn, Transaction transIn)
        {
            ObjectIdCollection oidc       = new ObjectIdCollection();
            FigType            figType    = FigType.fig;
            DBText             topmostDBT = dbtFigIn;

            using (BlockTableRecord btr2 = transIn.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(dbIn), OpenMode.ForRead) /*acTrans.GetObject(oid2, OpenMode.ForWrite)*/ as BlockTableRecord)
            {
                foreach (ObjectId oid in btr2)
                {
                    Entity ent = transIn.GetObject(oid, OpenMode.ForRead) as Entity;

                    if (ent.GetType() == typeof(DBText))
                    {
                        DBText dbt = ent as DBText;

                        if (dbt.IsPositionInRect(dbtFigIn.Position.X - LeftOfX, dbtFigIn.Position.Y - AboveY, dbtFigIn.Position.X + RightOfX, dbtFigIn.Position.Y + BelowY /*.006*/))
                        {
                            if (dbt.Position.Y > topmostDBT.Position.Y)
                            {
                                topmostDBT = dbt;
                            }

                            if (!oidc.Contains(dbt.ObjectId))
                            {
                                oidc.Add(dbt.ObjectId);
                            }

                            if (figsheetRegex.IsMatch(dbt.TextString))
                            {
                                figType = FigType.sheet;
                            }

                            if (figzoneRegex.IsMatch(dbt.TextString))
                            {
                                figType = FigType.zone;
                            }
                        }
                    }
                }
            }
            return(new Tuple <FigType, ObjectIdCollection, ObjectId>(figType, oidc, topmostDBT.Id));
        }
Example #5
0
        //создание фигуры
        public void Create(FigType figtype)
        {
            Clear(matrix); //стираем фигуру
            this.type = figtype;
            this.position = 1;
            switch (figtype) //анализируем переданную в функцию фигуру
            {
                case FigType.line: //линия
                    {
                        for (int i = 0; i < 4; i++)
                            matrix[0, i] = true;
                        break;
                    }

                case FigType.square: //квадрат
                    {
                        for (int i = 0; i < 2; i++)
                            for (int j = 0; j < 2; j++)
                                matrix[i, j] = true;
                        break;
                    }

                case FigType.leftL:
                    {
                        for (int i = 0; i < 3; i++)
                            matrix[0, i] = true;
                        matrix[1, 2] = true;
                        break;
                    }

                case FigType.rightL:
                    {
                        for (int i = 0; i < 3; i++)
                            matrix[0, i] = true;
                        matrix[1, 0] = true;
                        break;
                    }

                case FigType.pyramide:
                    {
                        for (int i = 0; i < 3; i++)
                            matrix[1, i] = true;
                        matrix[0, 1] = true;
                        break;
                    }

                case FigType.leftZ:
                    {
                        matrix[0, 0] = true; matrix[1, 0] = true;
                        matrix[1, 1] = true; matrix[2, 1] = true;
                        break;
                    }

                case FigType.rightZ:
                    {
                        matrix[0, 1] = true; matrix[1, 0] = true;
                        matrix[1, 1] = true; matrix[2, 0] = true;
                        break;
                    }
            }

        }
Example #6
0
        //создание фигуры
        public void Create(FigType figtype)
        {
            Clear(matrix); //стираем фигуру
            this.type     = figtype;
            this.position = 1;
            switch (figtype)   //анализируем переданную в функцию фигуру
            {
            case FigType.line: //линия
            {
                for (int i = 0; i < 4; i++)
                {
                    matrix[0, i] = true;
                }
                break;
            }

            case FigType.square:     //квадрат
            {
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        matrix[i, j] = true;
                    }
                }
                break;
            }

            case FigType.leftL:
            {
                for (int i = 0; i < 3; i++)
                {
                    matrix[0, i] = true;
                }
                matrix[1, 2] = true;
                break;
            }

            case FigType.rightL:
            {
                for (int i = 0; i < 3; i++)
                {
                    matrix[0, i] = true;
                }
                matrix[1, 0] = true;
                break;
            }

            case FigType.pyramide:
            {
                for (int i = 0; i < 3; i++)
                {
                    matrix[1, i] = true;
                }
                matrix[0, 1] = true;
                break;
            }

            case FigType.leftZ:
            {
                matrix[0, 0] = true; matrix[1, 0] = true;
                matrix[1, 1] = true; matrix[2, 1] = true;
                break;
            }

            case FigType.rightZ:
            {
                matrix[0, 1] = true; matrix[1, 0] = true;
                matrix[1, 1] = true; matrix[2, 0] = true;
                break;
            }
            }
        }
Example #7
0
 bool PatronNear(byte x, byte y, FigType fig, byte p)
 {
     FigType patron;
     switch (fig)
     {
         case FigType.Mn:
             patron = FigType.Es;
             break;
         case FigType.Sm:
             patron = FigType.Av;
             break;
         case FigType.Rk:
             patron = FigType.KrPl;
             break;
         case FigType.T:
             patron = FigType.Tk;
             break;
         default:
             return true;
     }
     return FindSquare(x, y, patron, p) || FindSquare(x, y, FigType.Tp, p);
 }
Example #8
0
        private bool IsBlock(byte[] x, byte[] y, byte str, FigType type, byte p, byte nx, byte ny)
        {
            if (str < 1 || str > 3)
                return false;
            if ((byte)type < 0 || (byte)type > 19)
                return false;
            if (x.Length != str || y.Length != str)
                return false;
            bool Rd = false;
            bool target_in_block = false;
            bool has_enforsed_St = false;
            for (int i = 0; i < str; i++)
            {
                if (x[i] == nx && y[i] == ny)
                    target_in_block = true;
                FigType fig = field[x[i], y[i]].fig;
                if ((byte)fig < 0 || (byte)fig > 19)
                    return false;
                if (field[x[i], y[i]].player != p)
                    return false;
                Rd = Rd || fig == FigType.Rd;
            }
            if (!target_in_block)
                return false;
            for (int i = 0; i < str; i++)
            {
                bool is_near = false;
                FigType fig = field[x[i], y[i]].fig;
                if (type != fig)
                {
                    if (fig == FigType.St && Rd && type == FigType.Es && !has_enforsed_St)
                        has_enforsed_St = true;
                    else if (fig == FigType.Rd && (type == FigType.Es || type == FigType.St || type == FigType.Tk || type == FigType.Tr))
                        Rd = true;
                    else
                        return false;

                }
                for (int j = 0; j < str; j++)
                {
                    if (Math.Abs(x[i] - x[j])+Math.Abs(y[i] - y[j]) == 1)
                    {
                        is_near = true;
                        break;
                    }
                }
                if (!is_near && str != 1)
                    return false;
            }
            return true;
        }
Example #9
0
 bool FindSquare(byte x, byte y, FigType f, byte p)
 {
     for (int i = Math.Max(0, x - 1); i < Math.Min(14, x + 2); i++)
     {
         for (int j = Math.Max(0, y - 1); j < Math.Min(14, y + 2); j++)
         {
             if (field[i, j].player == p && field[i, j].fig == f)
                 return true;
         }
     }
     return false;
 }
Example #10
0
 private void EventBattle(byte x, byte y, byte nx, byte ny, FigType a, FigType t, byte a_s, byte t_s, bool w, byte p)
 {
     Log(new Event
     {
         type = EventType.Battle,
         from = new Cord(x, y),
         to = new Cord(nx, ny),
         agr = a,
         tar = t,
         agr_str = a_s,
         tar_str = t_s,
         player = p,
         win = w
     });
 }
Example #11
0
 private void AttackAnswering(byte str, FigType type, byte[] b_x, byte[] b_y, byte p)
 {
     if (blocks[p-1] == null && IsBlock(b_x, b_y, str, type, p, inask[p-1].x, inask[p-1].y))
     {
         blocks[p - 1] = new Block(str, type, b_x, b_y);
         if (p != player)
         {
             Cord agr = inask[player - 1];
             Cord tar = inask[Opponent(player) - 1];
             FigType fig = field[agr.x, agr.y].fig;
             FigType oppfig = field[tar.x, tar.y].fig;
             if (fig == FigType.Pl || fig == FigType.Tp || fig == FigType.KrPl)
             {
                 if (fig == FigType.Tp || (fig == FigType.Pl && oppfig != FigType.Lk) || (fig == FigType.KrPl && (oppfig == FigType.Kr || oppfig == FigType.Es || oppfig == FigType.Rd)))
                 {
                     EventBattle(agr.x, agr.y, tar.x, tar.y, fig, type, 1, str, false, player);
                     Destroy(agr.x, agr.y);
                     PhaseChange(PhaseType.Move, Opponent(player));
                 }
                 else
                 {
                     EventBattle(agr.x, agr.y, tar.x, tar.y, 0, type, 0, str, true, player);
                     Destroy(tar.x, tar.y);
                     PhaseChange(PhaseType.Move, player);
                 }
                 blocks[0] = null;
                 blocks[1] = null;
             }
             else
             {
                 Log(new Event
                 {
                     type = EventType.Answer,
                     player = p,
                     agr = type,
                     agr_str = str
                 });
             }
         }
         if (blocks[0] != null && blocks[1] != null)
         {
             AttackBattle();
         }
     }
     else
     {
         throw new IllegalActionException("Неверный блок");
     }
 }
Example #12
0
 public Block(byte str, FigType type, byte[] xs, byte[] ys)
 {
     this.str = str;
     this.type = type;
     this.xs = xs;
     this.ys = ys;
 }
Example #13
0
 public Fig(FigType f, byte p)
 {
     fig = f;
     player = p;
 }
        // Use map from XML file to replace old values with new values
        public void Convert()
        {
            HashSet <ObjectId> changedFigIds  = new HashSet <ObjectId>();
            HashSet <ObjectId> placedTopWpIds = new HashSet <ObjectId>();

            String newWP = "";

            // Get the new wp
            // Key doesn't matter because dwg can only have one WP
            if (map["wp"].Values.Count > 0)
            {
                if (!map["wp"].TryGetValue(map["wp"].Keys.FirstOrDefault(), out newWP))
                {
                    logger.Log("New WP could not be found");
                }
            }

            using (Database db = new Database(false, true))
            {
                try
                {
                    db.ReadDwgFile(oldfname, FileOpenMode.OpenForReadAndWriteNoShare, true, String.Empty);
                    db.CloseInput(true);
                }
                catch (Autodesk.AutoCAD.Runtime.Exception e)
                {
                    throw new System.IO.IOException(String.Concat("Error reading DWG: ", e.Message));
                }

                try
                {
                    using (Transaction acTrans = db.TransactionManager.StartTransaction())
                    {
                        using (BlockTable bt = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable)
                        {
                            foreach (ObjectId oidOuter in bt)
                            {
                                using (BlockTableRecord btr = acTrans.GetObject(oidOuter, OpenMode.ForWrite) as BlockTableRecord)
                                {
                                    foreach (ObjectId oidInner in btr)
                                    {
                                        using (Entity ent = acTrans.GetObject(oidInner, OpenMode.ForWrite) as Entity)
                                        {
                                            if (ent.GetType() == typeof(DBText))
                                            {
                                                using (DBText dbt = ent as DBText)
                                                {
                                                    String dbtText = dbt.TextString.Trim().ToUpper();

                                                    String        oldValue  = String.Empty;
                                                    List <String> oldValues = new List <String>();

                                                    String newValue = String.Empty;

                                                    DBText         NearbyValue = new DBText();
                                                    System.Boolean changeNV    = false;

                                                    #region APPENDIX
                                                    if (appendixRegex.IsMatch(dbtText))
                                                    {
                                                        oldValue = appendixRegex.Match(dbtText).Value.Trim().Replace("APPENDIX", "").Trim();

                                                        // Look up new value and replace old value
                                                        if (map["appendix"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            try { dbt.TextString = dbtText.Replace(oldValue, newValue); }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New APPENDIX value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                        continue;
                                                    }
                                                    #endregion

                                                    #region CHAPTER
                                                    if (chapterRegex.IsMatch(dbtText))
                                                    {
                                                        oldValue = chapterRegex.Match(dbtText).Value.Trim().Replace("CHAPTER", "").Trim();

                                                        // Look up new value and replace old value
                                                        if (map["chapter"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            try { dbt.TextString = dbtText.Replace(oldValue, newValue); }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New CHAPTER value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                        continue;
                                                    }
                                                    #endregion

                                                    #region PARA0
                                                    if (para0Regex.IsMatch(dbtText))
                                                    {
                                                        oldValue = para0Regex.Match(dbtText).Value.Trim().Replace("PARAGRAPH", "").Trim();

                                                        // Look up new value and replace old value
                                                        if (map["para0"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            try { dbt.TextString = dbtText.Replace(oldValue, newValue); }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New PARA0 value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                        continue;
                                                    }
                                                    #endregion

                                                    #region TABLE
                                                    if (dbtText.Contains("TEST POINT") || dbtText.Contains("TABLE"))
                                                    {
                                                        if (String.Equals("TABLE", dbtText))
                                                        {
                                                            BlockTableRecord btrF = acTrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;
                                                            // Look nearby for #
                                                            using (BlockTableRecord btr2 = acTrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) /*acTrans.GetObject(oid2, OpenMode.ForWrite)*/ as BlockTableRecord)
                                                            {
                                                                foreach (ObjectId oid2Inner in btr2)
                                                                {
                                                                    Entity ent2 = acTrans.GetObject(oid2Inner, OpenMode.ForWrite) as Entity;
                                                                    if (ent2.GetType() == typeof(DBText))
                                                                    {
                                                                        NearbyValue = ent2 as DBText;
                                                                        if ((NearbyValue.Position.X == dbt.Position.X) &&
                                                                            (NearbyValue.ObjectId != dbt.ObjectId) &&
                                                                            (((NearbyValue.Position.Y - dbt.Position.Y) < 1) || ((dbt.Position.Y - NearbyValue.Position.Y) < 1)))
                                                                        {
                                                                            oldValue = NearbyValue.TextString.Trim();
                                                                            changeNV = true;
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else if (tableRegex.IsMatch(dbtText))
                                                        {
                                                            oldValue = tableRegex.Match(dbtText).Value.Trim();
                                                        }
                                                        else if (String.Equals(dbtText, "TEST POINT"))
                                                        {
                                                            continue;
                                                        }
                                                        else
                                                        {
                                                            logger.Log("possible TABLE found in incorrect form: " + dbtText + " in DWG: " + oldfname);
                                                            continue;
                                                        }

                                                        if (map["table"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            try
                                                            {
                                                                if (changeNV)
                                                                {
                                                                    NearbyValue.TextString = NearbyValue.TextString.Replace(oldValue, newValue);
                                                                }
                                                                else
                                                                {
                                                                    dbt.TextString = dbtText.Replace(oldValue, newValue);
                                                                }
                                                            }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New TABLE value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                        continue;
                                                    }
                                                    #endregion

                                                    #region SECTION

                                                    if (dbtText.Contains("SECTION"))
                                                    {
                                                        if (sectionRegex.IsMatch(dbtText))
                                                        {
                                                            oldValue = sectionRegex.Match(dbtText).Value.Trim().Replace("SECTION", "").Trim();
                                                        }
                                                        else
                                                        {
                                                            logger.Log("possible SECTION found in incorrect form: " + dbtText + " in DWG: " + oldfname);
                                                            continue;
                                                        }
                                                        if (map["section"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            try { dbt.TextString = dbt.TextString.Replace(oldValue, newValue); }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New SECTION value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                        continue;
                                                    }

                                                    #endregion

                                                    #region TM

                                                    if (tmRegex.IsMatch(dbtText))
                                                    {
                                                        if (tmNumRegex.IsMatch(dbtText))
                                                        {
                                                            //String is tm and #, get just tm#. String can have more than one tm#
                                                            //oldValue = tmNumRegex.Match(dbtText).Value .Trim();
                                                            foreach (Match match in tmNumRegex.Matches(dbtText))
                                                            {
                                                                oldValues.Add(match.Value.Replace(".", "").Trim());
                                                            }
                                                        }
                                                        else
                                                        {
                                                            // check if # is below tm
                                                            using (BlockTableRecord btr2 = acTrans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) /*acTrans.GetObject(oid2, OpenMode.ForWrite)*/ as BlockTableRecord)
                                                            {
                                                                foreach (ObjectId oid2Inner in btr2)
                                                                {
                                                                    Entity ent2 = acTrans.GetObject(oid2Inner, OpenMode.ForWrite) as Entity;
                                                                    if (ent2.GetType() == typeof(DBText))
                                                                    {
                                                                        NearbyValue = ent2 as DBText;

                                                                        if ((tmNumRegex.IsMatch(NearbyValue.TextString)) &&
                                                                            (NearbyValue.ObjectId != dbt.ObjectId) &&
                                                                            (((dbt.Position.Y - NearbyValue.Position.Y) < .14) && (dbt.Position.Y - NearbyValue.Position.Y) > 0))
                                                                        {
                                                                            oldValue = tmNumRegex.Match(NearbyValue.TextString).Value.Trim();
                                                                            changeNV = true;
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        if (changeNV)
                                                        {
                                                            // # is below tm
                                                            if (map["tm"].TryGetValue(oldValue, out newValue))
                                                            {
                                                                NearbyValue.TextString = NearbyValue.TextString.Replace(oldValue, newValue);
                                                            }
                                                            else
                                                            {
                                                                logger.Log("New TM value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            //String newString = dbt.TextString;
                                                            // # is same line as tm, but there might be more than one tm#
                                                            foreach (String ov in oldValues)
                                                            {
                                                                if (map["tm"].TryGetValue(ov, out newValue))
                                                                {
                                                                    //newString = newString.Replace(ov, newValue);
                                                                    try { dbt.TextString = dbt.TextString.Replace(ov, newValue); }
                                                                    catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                                }
                                                                else
                                                                {
                                                                    logger.Log("New TM value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                                }
                                                            }
                                                            //try { dbt.TextString = newString; }
                                                            //catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                        }
                                                        continue;//?
                                                    }
                                                    #endregion

                                                    #region FIG
                                                    if (figureRegex.IsMatch(dbtText))
                                                    {
                                                        Tuple <FigType, ObjectIdCollection, ObjectId> figInfo = getFigInfo(dbt, db, acTrans);

                                                        ObjectId           topMostID = figInfo.Item3;
                                                        ObjectIdCollection oidcSet   = figInfo.Item2;
                                                        FigType            figType   = figInfo.Item1;

                                                        switch (figType)
                                                        {
                                                        case FigType.sheet:

                                                            foreach (ObjectId oid in oidcSet)
                                                            {
                                                                DBText line = acTrans.GetObject(oid, OpenMode.ForWrite) as DBText;

                                                                if (oid == topMostID)
                                                                {
                                                                    // Add Work Package above text
                                                                    DBText wp = new DBText();
                                                                    wp.TextString = newWP;
                                                                    wp.Position   = new Point3d(line.Position.X, line.Position.Y + .1, line.Position.Z);
                                                                    btr.AppendEntity(wp);
                                                                    acTrans.AddNewlyCreatedDBObject(wp, true);
                                                                    placedTopWpIds.Add(wp.Id);
                                                                }

                                                                // get and replace only old fig value in this line
                                                                if (figValRegex.IsMatch(line.TextString))
                                                                {
                                                                    if (changedFigIds.Contains(line.ObjectId))
                                                                    {
                                                                        continue;
                                                                    }

                                                                    oldValue = figValRegex.Match(line.TextString).Value.Trim();

                                                                    // BUG: Sometimes sheet # can look like figure number
                                                                    if (map["figsheet"].TryGetValue(oldValue, out newValue))
                                                                    {
                                                                        try
                                                                        {
                                                                            line.TextString = line.TextString.Replace(oldValue, newValue);
                                                                            changedFigIds.Add(line.ObjectId);
                                                                        }
                                                                        catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                                    }
                                                                    else
                                                                    {
                                                                        logger.Log("New FIGSHEET value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                                    }
                                                                }
                                                            }
                                                            break;

                                                        case FigType.fig:

                                                            foreach (ObjectId oid in oidcSet)
                                                            {
                                                                DBText line = acTrans.GetObject(oid, OpenMode.ForWrite) as DBText;

                                                                if (oid == topMostID)
                                                                {
                                                                    // Add Work Package above text
                                                                    DBText wp = new DBText();
                                                                    wp.TextString = newWP;
                                                                    wp.Position   = new Point3d(line.Position.X, line.Position.Y + .1, line.Position.Z);
                                                                    btr.AppendEntity(wp);
                                                                    acTrans.AddNewlyCreatedDBObject(wp, true);
                                                                    placedTopWpIds.Add(wp.Id);
                                                                }

                                                                // get and replace only old fig value in this line

                                                                if (figValRegex.IsMatch(line.TextString))
                                                                {
                                                                    if (changedFigIds.Contains(line.ObjectId))
                                                                    {
                                                                        continue;
                                                                    }

                                                                    foreach (Match match in figValRegex.Matches(line.TextString))
                                                                    {
                                                                        //newValue = String.Empty;
                                                                        if (map["figure"].TryGetValue(match.Value, out newValue))
                                                                        {
                                                                            try
                                                                            {
                                                                                line.TextString = line.TextString.Replace(match.Value, newValue);
                                                                                changedFigIds.Add(line.ObjectId);
                                                                            }
                                                                            catch { logger.Log(match.Value + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                                        }
                                                                        else
                                                                        {
                                                                            logger.Log("New FIG value not found in XML file for old value: " + match.Value + " in DWG: " + oldfname);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            break;

                                                        case FigType.zone:

                                                            foreach (ObjectId oid in oidcSet)
                                                            {
                                                                DBText line = acTrans.GetObject(oid, OpenMode.ForWrite) as DBText;

                                                                if (oid == topMostID && !placedTopWpIds.Contains(oid))
                                                                {
                                                                    // Add Work Package above text
                                                                    DBText wp = new DBText();
                                                                    wp.TextString = newWP;
                                                                    wp.Position   = new Point3d(line.Position.X, line.Position.Y + .1, line.Position.Z);
                                                                    btr.AppendEntity(wp);
                                                                    acTrans.AddNewlyCreatedDBObject(wp, true);
                                                                    placedTopWpIds.Add(wp.Id);
                                                                }

                                                                // get and replace only old fig value in this line
                                                                if (figValRegex.IsMatch(line.TextString))
                                                                {
                                                                    if (changedFigIds.Contains(line.ObjectId))
                                                                    {
                                                                        continue;
                                                                    }

                                                                    oldValue = figValRegex.Match(line.TextString).Value.Trim();

                                                                    if (map["figzone"].TryGetValue(oldValue, out newValue))
                                                                    {
                                                                        try
                                                                        {
                                                                            line.TextString = line.TextString.Replace(oldValue, newValue);
                                                                            changedFigIds.Add(line.ObjectId);
                                                                        }
                                                                        catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }
                                                                    }
                                                                    else
                                                                    {
                                                                        logger.Log("New FIGZONE value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname + " at Y= " + line.Position.Y);
                                                                    }
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            // Won't get here
                                                            break;
                                                        }
                                                        continue;
                                                    }
                                                    #endregion

                                                    #region FIGSHEET (no FIG)
                                                    if (figSheetNoFigRegex.IsMatch(dbtText))
                                                    {
                                                        oldValue = figValRegex.Match(dbtText).Value.Trim();

                                                        if (map["figsheet"].TryGetValue(oldValue, out newValue))
                                                        {
                                                            // Replace old value with new value
                                                            try { dbt.TextString = dbt.TextString.Replace(oldValue, newValue); }
                                                            catch { logger.Log(oldValue + " could not be replaced with new value: " + newValue + " in DWG: " + oldfname); }

                                                            // Add Work Package above text
                                                            DBText wp = new DBText();
                                                            wp.TextString = newWP;
                                                            wp.Position   = new Point3d(dbt.Position.X, dbt.Position.Y + .1, dbt.Position.Z);
                                                            btr.AppendEntity(wp);
                                                            acTrans.AddNewlyCreatedDBObject(wp, true);
                                                        }
                                                        else
                                                        {
                                                            logger.Log("New FIGSHEET (no fig) value not found in XML file for old value: " + oldValue + " in DWG: " + oldfname);
                                                        }
                                                    }
                                                    #endregion
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (System.Exception se) { throw new System.Exception("Error processing DWG: " + se.Message); }

                try { db.SaveAs(newfname, DwgVersion.Current); }
                catch (System.IO.IOException se) { throw new System.IO.IOException("Error saving new DWG: " + se.Message); }
            }
        }