Exemplo n.º 1
0
        /// <summary>
        /// Процедура отображения ребер графа в документе Visio
        /// </summary>
        /// <param name="visioDocs">Документы Visio</param>
        /// <param name="visioPage">Текущая страница в Visio</param>
        private void PresentEdges(Visio.Documents visioDocs, Visio.Page visioPage)
        {
            Visio.Document visioConnectors = visioDocs.OpenEx("Basic Flowchart Shapes (US units).vss", (short)Visio.VisOpenSaveArgs.visOpenDocked);

            // Соединение вершин графа ребрами
            for (int i = 0; i < graph.VerticesEdges.Count(); ++i)
            {
                // Ребро
                var edge = graph.VerticesEdges.ElementAt(i);

                // Фигура соединидельной линии (коннектора)
                Visio.Shape connector = visioPage.Drop(visioConnectors.Masters.get_ItemU("Dynamic connector"), 0, 0);
                connector.get_Cells("ConLineRouteExt").FormulaU = "2";
                connector.get_Cells("EndArrow").Formula         = "=5";

                // Стили ребра
                string label     = edge.Attributes.ContainsKey("label") ? edge.Attributes["label"] : "";
                string color     = edge.Attributes.ContainsKey("color") ? edge.Attributes["color"] : "black";
                string linestyle = edge.Attributes.ContainsKey("style") ? LineStyle(edge.Attributes["style"].ToLower()) : "1";

                // Установка стилей для фигуры на странице Visio
                connector.Text = label;
                connector.get_CellsU("LineColor").FormulaU   = VisioColor.ColorToRgb(color.ToLower());
                connector.get_CellsU("LinePattern").FormulaU = linestyle;

                // Соединение вершин при помощи данного коннектора
                vertices[edge.Source].AutoConnect(vertices[edge.Destination], Visio.VisAutoConnectDir.visAutoConnectDirDown, connector);

                edges.Add(edge, vertices[edge.Source].FromConnects[vertices[edge.Source].FromConnects.Count].FromSheet);

                // Удаление коннектора-болванки
                connector.Delete();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Closes the form. Does not save any un-applied changes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitBtn_Click(object sender, EventArgs e)
        {
            if (ownerShape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION) == 0)
            {
                ownerShape.Delete();
            }

            this.Close();
        }
Exemplo n.º 3
0
        private void deleteShapesExcept(Visio.Shape shape)
        {
            ArrayList arr = new ArrayList();

            int count = visioControl.Window.Document.Pages[1].Shapes.Count;

            for (int i = 1; i <= count; i++)
            {
                Visio.Shape shp = visioControl.Window.Document.Pages[1].Shapes[i];
                if (shp.NameID != shape.NameID)
                {
                    arr.Add(shp);
                }
            }
            foreach (Visio.Shape shp in arr)
            {
                shp.Delete();
            }
        }
        public override void DropImage(string imageFile, bool isSvg)
        {
            Visio.Page vPag       = vApp.ActivePage;
            double     magicScale = isSvg ? 1 : 96 / (double)LatexData.DPI;

            if (vPag != null)
            {
                var shpNew = vPag.Import(imageFile);

                if (selectedShape != null)
                {
                    shpNew.CellsU["PinX"].FormulaU = selectedShape.CellsU["PinX"].FormulaU;
                    shpNew.CellsU["PinY"].FormulaU = selectedShape.CellsU["PinY"].FormulaU;
                }

                //Set size
                string oldWidth_s = shpNew.CellsU["Width"].FormulaU;
                double oldWidth_d = double.Parse(oldWidth_s.Replace(" mm", ""), CultureInfo.InvariantCulture);

                shpNew.CellsU["Width"].FormulaU = String.Format("{0:f} mm", oldWidth_d * magicScale * LatexData.fontSize / 10);

                string oldHeight_s = shpNew.CellsU["Height"].FormulaU;
                double oldHeight_d = double.Parse(oldHeight_s.Replace(" mm", ""), CultureInfo.InvariantCulture);
                shpNew.CellsU["Height"].FormulaU = String.Format("{0:f} mm", oldHeight_d * magicScale * LatexData.fontSize / 10);

                shpNew.AddNamedRow((short)Visio.VisSectionIndices.visSectionAction, "RightClick", 0);
                shpNew.CellsU["Actions.RightClick"].FormulaU        = "\"Edit LaTeX image\"";
                shpNew.CellsU["Actions.RightClick.Action"].FormulaU = "RUNADDONWARGS(\"QueueMarkerEvent\", \"/app=VisioTex\")";

                using (var ms = new MemoryStream())
                {
                    var ser = new DataContractJsonSerializer(typeof(LatexData));
                    ser.WriteObject(ms, LatexData);
                    byte[] json = ms.ToArray();

                    shpNew.Data1 = Encoding.UTF8.GetString(json, 0, json.Length);
                }

                selectedShape?.Delete();
            }
        }
Exemplo n.º 5
0
        private void MapItButtonClick(object sender, EventArgs e)
        {
            // open log if not yet open
            var tr2 = new TextWriterTraceListener(File.CreateText(selectedLogFileName.Text));

            Trace.Listeners.Add(tr2);

            // Excel related aspects

            var xlApp = new Microsoft.Office.Interop.Excel.Application {
                Visible = true
            };

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            // open the excel file
            String   excelFileName = mapFileName.Text;
            Workbook xlWorkBook    = xlApp.Workbooks.Open(excelFileName,
                                                          _missing, _missing, _missing, _missing, _missing, _missing, _missing, _missing,
                                                          _missing, _missing, _missing, _missing, _missing, _missing);


            // read the columns of the sheets containing the map and the elements


            // reference column number --> tag for the elements
            var elementColumnMap = new Dictionary <int, string>();
            int elementMaxColumnNr;
            int elementNameColumnNr;

            MmExcelUtil.BuildColumnMap(xlWorkBook, elementSheetName.Text, elementNameColumnName.Text, elementColumnMap, out elementMaxColumnNr, out elementNameColumnNr);


            // reference column number --> tag for the map
            var taxXColumnMap = new Dictionary <int, string>();
            int taxXMaxColumnNr;
            int taxXNameColumnNr;

            MmExcelUtil.BuildColumnMap(xlWorkBook, xTaxonomySheetName.Text, xTaxonomyNameColumnName.Text, taxXColumnMap, out taxXMaxColumnNr, out taxXNameColumnNr);

            // reference column number --> tag for the map
            var taxYColumnMap = new Dictionary <int, string>();
            int taxYMaxColumnNr;
            int taxYNameColumnNr;

            MmExcelUtil.BuildColumnMap(xlWorkBook, yTaxonomySheetName.Text, yTaxonomyNameColumnName.Text, taxYColumnMap, out taxYMaxColumnNr, out taxYNameColumnNr);

            // list of all the elements to be maped
            var elementList = new List <GenericElement>();

            MmExcelUtil.BuildList(xlWorkBook, elementSheetName.Text, elementNameColumnNr, elementMaxColumnNr, elementColumnMap, elementList, elementNameColumnName.Text);

            // list of all the constituents of the map
            var xTaxonomyList = new List <GenericElement>();

            MmExcelUtil.BuildList(xlWorkBook, xTaxonomySheetName.Text, taxXNameColumnNr, taxXMaxColumnNr, taxXColumnMap, xTaxonomyList, xTaxonomyNameColumnName.Text);

            // list of all the constituents of the map
            var yTaxonomyList = new List <GenericElement>();

            MmExcelUtil.BuildList(xlWorkBook, yTaxonomySheetName.Text, taxYNameColumnNr, taxYMaxColumnNr, taxYColumnMap, yTaxonomyList, yTaxonomyNameColumnName.Text);


            // xTaxonomyMapping
            var xTaxonomyMappingList = new List <Mapping>();

            MmExcelUtil.BuildMapping(xlWorkBook, xTaxonomyMappingList, xMapSheetName.Text, xMapElementNameColumnName.Text,
                                     xMapXTaxNameColumnName.Text);

            var yTaxonomyMappingList = new List <Mapping>();

            MmExcelUtil.BuildMapping(xlWorkBook, yTaxonomyMappingList, yMapSheetName.Text, yMapElementNameColumnName.Text,
                                     yMapYTaxNameColumnName.Text);

            // create the map

            int x      = 0;
            int y      = 0;
            var matrix = new List <String> [xTaxonomyList.Count, yTaxonomyList.Count];

            for (int xi = 0; xi < xTaxonomyList.Count(); xi++)
            {
                for (int yi = 0; yi < yTaxonomyList.Count(); yi++)
                {
                    matrix[xi, yi] = new List <String>();
                }
            }


            foreach (GenericElement yElement in yTaxonomyList)
            {
                x = 0;
                foreach (GenericElement xElement in xTaxonomyList)
                {
                    Trace.WriteLine("  checking for x " + xElement.Name + " and y " + yElement.Name);


                    foreach (GenericElement element in elementList)
                    {
                        // if there is a mapping element to x and y taxonomy then add the element to the matrix

                        Mapping yMap = yTaxonomyMappingList.Find(
                            delegate(Mapping me)
                        {
                            return
                            (me.ElementName == element.Name &&
                             me.MapName == yElement.Name);
                        }
                            );
                        Mapping xMap = xTaxonomyMappingList.Find(
                            delegate(Mapping me)
                        {
                            return
                            (me.ElementName == element.Name &&
                             me.MapName == xElement.Name);
                        }
                            );

                        if (xMap != null && yMap != null)
                        {
                            matrix[x, y].Add(element.Name);
                        }
                    }
                    x += 1;
                }
                y += 1;
            }

            // determine per row the number of different applications and the max number in a cell

            int[] maxNumApplications      = new int [yTaxonomyList.Count];
            int   totalMaxNumApplications = 0;

            int[] diffNumApplications      = new int[yTaxonomyList.Count];
            int   totalDiffNumApplications = 0;
            int   emptyRows = 0;

            for (int yi = 0; yi < yTaxonomyList.Count(); yi++)
            {
                maxNumApplications[yi] = 0;
                List <String> appNames = new List <string>();
                for (int xi = 0; xi < xTaxonomyList.Count(); xi++)
                {
                    maxNumApplications[yi] = Math.Max(maxNumApplications[yi], matrix[xi, yi].Count);
                    foreach (String s in matrix[xi, yi])
                    {
                        if (!appNames.Contains(s))
                        {
                            appNames.Add(s);
                        }
                    }
                }
                diffNumApplications[yi]   = appNames.Count;
                totalDiffNumApplications += diffNumApplications[yi];
                totalMaxNumApplications  += maxNumApplications[yi];
                if (maxNumApplications[yi] == 0)
                {
                    emptyRows++;
                }

                Trace.WriteLine(" Row " + yi + " max num application " + maxNumApplications[yi] + " diff num applications " + diffNumApplications[yi]);
            }

            Trace.WriteLine("Max total number applications " + totalMaxNumApplications);
            Trace.WriteLine("Total number of different applications " + totalDiffNumApplications);
            Trace.WriteLine("Number of empty rows " + emptyRows);

            // Visio related aspects

            var visapp = new Microsoft.Office.Interop.Visio.Application();

            // Prepare Visio
            Document landscape = visapp.Documents.Open(visioFileName.Text);
            Document stencil   = visapp.Documents.OpenEx(stencilFileName.Text, (short)VisOpenSaveArgs.visOpenDocked);
            Page     page      = visapp.ActivePage;


            Master elementStencil   = stencil.Masters[elementStencilName.Text];
            Master taxonomyXStencil = stencil.Masters[xTaxonomyStencilName.Text];
            Master taxomomyYStencil = stencil.Masters[yTaxonomyStencilName.Text];

            if (elementStencil == null)
            {
                throw new ArgumentNullException("elementStencil");
            }
            if (taxonomyXStencil == null)
            {
                throw new ArgumentNullException("taxonomyXStencil");
            }
            if (taxomomyYStencil == null)
            {
                throw new ArgumentNullException("taxomomyYStencil");
            }

            Shape elementShape   = page.Drop(elementStencil, 0.0, 0.0);
            Shape taxonomyXShape = page.Drop(taxonomyXStencil, 0.0, 0.0);
            Shape taxonomyYShape = page.Drop(taxomomyYStencil, 0.0, 0.0);

            double pageWidth = page.PageSheet.CellsU["PageWidth"].ResultIU;
            double pageHight = page.PageSheet.CellsU["PageHeight"].ResultIU;

            double elementWidth  = elementShape.CellsU["Width"].ResultIU;
            double elementHeight = elementShape.CellsU["Height"].ResultIU;

            double taxonomyXHeight = taxonomyXShape.CellsU["Height"].ResultIU;
            double taxonomyXWidth  = taxonomyXShape.CellsU["Width"].ResultIU;
            double taxonomyYHeight = taxonomyYShape.CellsU["Height"].ResultIU;
            double taxonomyYWidth  = taxonomyYShape.CellsU["Width"].ResultIU;


            double space = double.Parse(spaceText.Text);

            elementShape.Delete();
            taxonomyXShape.Delete();
            taxonomyYShape.Delete();

            Trace.WriteLine("Size of an page    " + pageWidth + " " + pageHight);
            Trace.WriteLine("Size of an element " + elementWidth + " " + elementHeight);

            double yTaxonomyYRoot = pageHight - 2 * space - taxonomyXHeight;
            double xTaxonomyXRoot = 2 * space + taxonomyYWidth;

            double taxYHeight = 0.0;

            if (emptyRowSuppressionCheckBox.Checked)
            {
                taxYHeight = (yTaxonomyYRoot - 2 * space) / totalDiffNumApplications;
            }
            else
            {
                taxYHeight = (yTaxonomyYRoot - 2 * space) / (totalDiffNumApplications + emptyRows);
            }
            double taxXWidth = (pageWidth - xTaxonomyXRoot - 2 * space) / xTaxonomyList.Count;


            double yPos = yTaxonomyYRoot;


            for (int xi = 0; xi < xTaxonomyList.Count; xi++)
            {
                MmVisioUtil.PlaceGenericElement(page, taxonomyXStencil, xTaxonomyList[xi],
                                                xTaxonomyXRoot + (xi + 0.5) * taxXWidth,
                                                yTaxonomyYRoot + taxonomyXHeight * 0.5,
                                                taxXWidth,
                                                taxonomyXHeight,
                                                taxXColumnMap,
                                                false);
            }



            for (int yi = 0; yi < yTaxonomyList.Count(); yi++)
            {
                double xPos = space * 2.0 + taxonomyXWidth / 2.0;

                if (emptyRowSuppressionCheckBox.Checked && diffNumApplications[yi] == 0)
                {
                    // do noting
                }
                else
                {
                    double height = Math.Max(1, diffNumApplications[yi]) * taxYHeight;

                    MmVisioUtil.PlaceGenericElement(page, taxomomyYStencil, yTaxonomyList[yi],
                                                    xPos, yPos - height / 2,
                                                    taxonomyYWidth, height,
                                                    taxYColumnMap,
                                                    false);

                    // draw applications

                    List <String> appNames = new List <string>();

                    for (int xi = 0; xi < xTaxonomyList.Count; xi++)
                    {
                        foreach (String s in matrix[xi, yi])
                        {
                            if (!appNames.Contains(s))
                            {
                                appNames.Add(s);
                            }
                        }
                    }

                    int nApp = 0;
                    foreach (String Name in appNames)
                    {
                        GenericElement app = elementList.Find(
                            delegate(GenericElement ele)
                        {
                            return(ele.Name == Name);
                        }
                            );

                        if (app != null)
                        {
                            elementShape = null;

                            for (int xi = 0; xi < xTaxonomyList.Count; xi++)
                            {
                                if (matrix[xi, yi].Contains(Name))
                                {
                                    if (mergeApplicationsCheckBox.Checked && elementShape != null)
                                    {
                                        elementShape.CellsU["Width"].ResultIU += taxXWidth;
                                        elementShape.CellsU["PinX"].ResultIU  += taxXWidth / 2;
                                    }
                                    else
                                    {
                                        if (applySpaceCheckBox.Checked)
                                        {
                                            elementShape = MmVisioUtil.PlaceGenericElement(page, elementStencil, app,
                                                                                           xTaxonomyXRoot +
                                                                                           (xi + 0.5) * (taxXWidth),
                                                                                           yPos -
                                                                                           (nApp + 0.5) * taxYHeight,
                                                                                           taxXWidth - space, taxYHeight,
                                                                                           elementColumnMap,
                                                                                           false);
                                        }
                                        else
                                        {
                                            elementShape = MmVisioUtil.PlaceGenericElement(page, elementStencil, app,
                                                                                           xTaxonomyXRoot +
                                                                                           (xi + 0.5) * taxXWidth,
                                                                                           yPos -
                                                                                           (nApp + 0.5) * taxYHeight,
                                                                                           taxXWidth, taxYHeight,
                                                                                           elementColumnMap,
                                                                                           false);
                                        }
                                    }
                                }
                                else
                                {
                                    elementShape = null;
                                }
                            }
                            nApp++;
                        }
                        else
                        {
                            String error = "### unknown element " + elementShape.Name;
                            Trace.WriteLine(error);
                            errorListBox.Items.Add(error);
                        }
                    }


                    yPos -= height;
                }
            }


            Trace.Flush();
            Trace.Close();
        }
Exemplo n.º 6
0
        /// <summary>
        /// The main routine which generates the map based on the parameters specified in the
        /// dialog on the user interface. The resolut is the final map with placed elements
        /// and right sized and adjusted map in the background.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GenerateLandscapeButtonClick(object sender, EventArgs e)
        {
            // open log if not yet open
            var tr2 = new TextWriterTraceListener(File.CreateText(selectedLogFileName.Text));

            Trace.Listeners.Add(tr2);

            var errorList = new List <String>();

            // Excel related aspects
            var xlApp = new Microsoft.Office.Interop.Excel.Application {
                Visible = true
            };

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            // open the excel file
            String   excelFileName = mapFileName.Text;
            Workbook xlWorkBook    = xlApp.Workbooks.Open(excelFileName,
                                                          _missing, _missing, _missing, _missing, _missing, _missing,
                                                          _missing, _missing,
                                                          _missing, _missing, _missing, _missing, _missing, _missing);


            // read the columns of the sheets containing the map and the elements

            // reference column number --> tag for the map
            var mapColumnMap = new Dictionary <int, string>();
            int mapMaxColumn;
            int mapNameColumn;

            MmExcelUtil.BuildColumnMap(xlWorkBook, mapSheetName.Text, mapNameColumnName.Text, mapColumnMap,
                                       out mapMaxColumn, out mapNameColumn);

            // reference column number --> tag for the elements
            var elementColumnMap = new Dictionary <int, string>();
            int elementMaxColumn;
            int elementNameColumn;

            MmExcelUtil.BuildColumnMap(xlWorkBook, elementSheetName.Text, elementNameColumnName.Text, elementColumnMap,
                                       out elementMaxColumn, out elementNameColumn);

            // list of all the constituents of the map
            var mapList = new List <GenericElement>();

            MmExcelUtil.BuildList(xlWorkBook, mapSheetName.Text, mapNameColumn, mapMaxColumn, mapColumnMap, mapList,
                                  mapNameColumnName.Text);

            // list of all the elements to be maped
            var elementList = new List <GenericElement>();

            MmExcelUtil.BuildList(xlWorkBook, elementSheetName.Text, elementNameColumn, elementMaxColumn,
                                  elementColumnMap, elementList, elementNameColumnName.Text);



            // Visio related aspects

            var visapp = new Microsoft.Office.Interop.Visio.Application();

            // Prepare Visio
            Document landscape = visapp.Documents.Open(visioFileName.Text);
            Document stencil   = visapp.Documents.OpenEx(stencilFileName.Text, (short)VisOpenSaveArgs.visOpenDocked);
            Page     page      = visapp.ActivePage;


            var placedMapShapes     = new Dictionary <String, ShapeRef>();
            var placedElementShapes = new Dictionary <String, ShapeRef>();

            MmVisioUtil.GetShapeList(mapStencilName.Text, page, mapNameColumnName.Text, placedMapShapes);
            MmVisioUtil.GetShapeList(elementStencilName.Text, page, elementNameColumnName.Text, placedElementShapes);


            var missingMapShapes = new List <String>();

            DetermineMissingMapShapes(mapList, placedMapShapes, missingMapShapes);


            // Read all the mappings

            var mappingList = new List <Mapping>();

            MmExcelUtil.BuildMapping(xlWorkBook, mappingList, mappingSheetName.Text, mappingElementNameColumnName.Text,
                                     mappingMapNameColumnName.Text);


            // Create the mapping layout data structure

            var mapLayout = new Dictionary <String, MapLayoutElement>();

            PopulateMapLayout(mapList, elementList, mappingList, mapLayout);


            Master elementStencil = stencil.Masters[elementStencilName.Text];

//            Master marker = stencil.Masters["Marker"];

            Shape elementShape = page.Drop(elementStencil, 0.0, 0.0);

            double pageWidth = page.PageSheet.CellsU["PageWidth"].ResultIU;
            double pageHight = page.PageSheet.CellsU["PageHeight"].ResultIU;

            double elementWidth  = elementShape.CellsU["Width"].ResultIU;
            double elementHeight = elementShape.CellsU["Height"].ResultIU;
            double space         = double.Parse(spaceText.Text);

            double numColumns = (pageWidth - space) / (elementWidth + space);
            double numRows    = (pageHight - space) / (elementHeight + space);


            Trace.WriteLine("Size of an page     w " + pageWidth + " " + pageHight);
            Trace.WriteLine("Size of an element  w " + elementWidth + " " + elementHeight);
            Trace.WriteLine("Space                 " + space);
            Trace.WriteLine("Number                " + numRows + " rows " + numColumns + " columns");

            elementShape.Delete();

            // determines size of map stencil on drawing in terms of elements which can be placed on it
            // the results are kept in the MapLayoutElement
            CaclulateMapLayout(mapLayout, placedMapShapes, elementHeight, elementWidth, space);

            // Move elements on map to lower left

            foreach (ShapeRef sr in placedElementShapes.Values)
            {
                sr.Shape.Cells["PinX"].ResultIU = 0;
                sr.Shape.Cells["PinY"].ResultIU = 0;
            }

            // Populate Map with Elements

            if (optimitzeElementLayoutCheckBox.Checked)
            {
                foreach (MapLayoutElement mle in mapLayout.Values)
                {
                    String mapElementName = mle.Name;
                    if (placedMapShapes.ContainsKey(mapElementName))
                    {
                        Shape mapShape = placedMapShapes[mapElementName].Shape;


                        double mapWidth  = mapShape.CellsU["Width"].ResultIU;
                        double mapHeight = mapShape.CellsU["Height"].ResultIU;
                        double mapX      = mapShape.CellsU["PinX"].ResultIU;
                        double mapY      = mapShape.CellsU["PinY"].ResultIU;

                        if (titleSpaceCheckBox.Checked)
                        {
                            mapHeight -= space * 1.5;
                            mapY      -= space * 0.75;
                        }

                        double offsetX = elementWidth / 2 + (mapWidth - (mle.MaxColumn - mle.MinColumn + 1) * elementWidth - (mle.MaxColumn - mle.MinColumn) * space) / 2;
                        double offsetY = mapHeight - (mle.MaxRow - mle.MinRow + 1) * elementHeight - (mle.MaxRow - mle.MinRow) * space;

                        int row = mle.MaxRow;
                        int col = mle.MinColumn;

                        if (titleRowCheckBox.Checked)
                        {
                            row--;
                        }

                        int topRow = row; // keep to use below in layout

                        mle.mapElements().Sort();

                        foreach (String meName in mle.mapElements())
                        {
                            GenericElement ge = elementList.Find(delegate(GenericElement x)
                            {
                                return(x.Name == meName);
                            });

                            double ex = mapX - mapWidth / 2 + (col - mle.MinColumn) * (elementWidth + space) + offsetX;
                            double ey = mapY - mapHeight / 2 + (row - mle.MinRow) * (elementHeight + space) + offsetY;
                            MmVisioUtil.PlaceGenericElement(page, elementStencil, ge, ex, ey, elementColumnMap, showDescriptionsCheckBox.Checked);


                            DetermineNextCell(mle, topRow, ref row, ref col);
                        }
                    }
                }
            }
            else
            {
                foreach (MapLayoutElement mle in mapLayout.Values)
                {
                    int row = mle.MaxRow;
                    int col = mle.MinColumn;

                    if (titleRowCheckBox.Checked)
                    {
                        row--;
                    }
                    int topRow = row; // keep to use below in layout

                    mle.mapElements().Sort();

                    foreach (String meName in mle.mapElements())
                    {
                        GenericElement ge = elementList.Find(delegate(GenericElement x)
                        {
                            return(x.Name == meName);
                        });


                        MmVisioUtil.PlaceGenericElement(page, elementStencil, ge, row, col, space, elementColumnMap, true);


                        DetermineNextCell(mle, topRow, ref row, ref col);
                    }
                }
            }

            // Beautify Map

            if (!freezeMapCheckBox.Checked)
            {
                foreach (MapLayoutElement mle in mapLayout.Values)
                {
                    String mapElementName = mle.Name;
                    if (placedMapShapes.ContainsKey(mapElementName))
                    {
                        Shape mapShape = placedMapShapes[mapElementName].Shape;



                        double x = MmVisioUtil.CalculateX(mle.MinColumn, elementWidth, space) +
                                   (MmVisioUtil.CalculateX(mle.MaxColumn, elementWidth, space) -
                                    MmVisioUtil.CalculateX(mle.MinColumn, elementWidth, space)) / 2;
                        double y = MmVisioUtil.CalculateY(mle.MinRow, elementHeight, space) + 0.2 * space +
                                   (MmVisioUtil.CalculateY(mle.MaxRow, elementHeight, space) -
                                    MmVisioUtil.CalculateY(mle.MinRow, elementHeight, space)) / 2;
                        double w = (mle.MaxColumn - mle.MinColumn + 1) * (elementWidth + space) - 0.2 * space;
                        double h = (mle.MaxRow - mle.MinRow + 1) * (elementHeight + space) - 0.2 * space;

                        Trace.WriteLine(mle.Name + " raw    " +
                                        " X= " + String.Format("{0:0.00}", x) + " Y= " + String.Format("{0:0.00}", y) +
                                        " W= " + String.Format("{0:0.00}", w) + " H= " + String.Format("{0:0.00}", h));

                        if (titleSpaceCheckBox.Checked)
                        {
                            h += space * 1.5;
                            y += space * 0.75;
                        }

                        Trace.WriteLine(mle.Name + " spaced " +
                                        " X= " + String.Format("{0:0.00}", x) + " Y= " + String.Format("{0:0.00}", y) +
                                        " W= " + String.Format("{0:0.00}", w) + " H= " + String.Format("{0:0.00}", h));


                        mapShape.Cells["PinX"].ResultIU   = x;
                        mapShape.Cells["PinY"].ResultIU   = y;
                        mapShape.Cells["Width"].ResultIU  = w;
                        mapShape.Cells["Height"].ResultIU = h;
                    }
                }
            }

            Trace.Flush();
            Trace.Close();
        }