/// <summary>
        /// Return diagrams owned by given package
        /// </summary>
        /// <param name="parent">Parent package</param>
        /// <returns>List of diagrams</returns>
        internal List <IUMLClassDiagram> GetOwnedErdDiagrams(IUMLPackage parent)
        {
            List <IUMLClassDiagram> result = new List <IUMLClassDiagram>();

            for (int i = 0; i < parent.GetOwnedDiagramCount(); i++)
            {
                // Collect only IUMLPackage elements
                IDiagram         diagram      = parent.GetOwnedDiagramAt(i);
                IUMLClassDiagram classDiagram = diagram as IUMLClassDiagram;
                if (classDiagram != null)
                {
                    result.Add(classDiagram);
                }
            }

            return(result);
        }
        internal void AddErdDiagram(IUMLPackage parentPackage, string diagramName, List <IR.Table> tables)
        {
            // For perfomance reasons informs the main program that a sequence of models is created
            ErdAddIn.StarUMLApp.BeginGroupAction();

            IUMLClassDiagram erdDiagram = m_UMLFactory.CreateExtendedClassDiagram(parentPackage, Symbols.ERD_PROFILE_NAME, Symbols.ERD_DIAGRAM_TYPE);

            erdDiagram.Name = diagramName;

            ResetLocationFactors();
            foreach (var table in tables)
            {
                AddErdTable(parentPackage, erdDiagram, table);
            }

            // End of creation of a sequence of models
            ErdAddIn.StarUMLApp.EndGroupAction();
        }
        internal void AddErdTable(IUMLPackage parentPackage, IUMLClassDiagram parentDiagram, IR.Table tableData)
        {
            IUMLClass newTable = m_UMLFactory.CreateClass(parentPackage);

            newTable.Name = tableData.TableName;
            newTable.SetStereotype2(Symbols.ERD_PROFILE_NAME, Symbols.ERD_STEREOTYPE_TABLE);

            UpdateLocationFactors();
            IUMLClassDiagramView diagramView = parentDiagram.DiagramView as IUMLClassDiagramView;
            IUMLClassView        newView     = diagramView.CreateViewOf(newTable, m_xPos, m_yPos) as IUMLClassView;

            newView.Update();
            UpdateYGrow(newView.Height);

            foreach (var irAttr in tableData.Attribues)
            {
                AddErdTableAttribute(parentPackage, newTable, parentDiagram.Name, irAttr);
            }
        }
        /// <summary>
        /// Gets a list of IR nodes representing ERD tables
        /// </summary>
        /// <param name="diagram">ERD Diagram to get data from</param>
        /// <returns>List of created IR nodes</returns>
        internal List <IR.Table> GetErdTables(IUMLClassDiagram diagram)
        {
            List <IR.Table> result = new List <IR.Table>();

            IDiagramView diagramView = diagram.DiagramView;

            if (diagramView != null)
            {
                int nbOfElems = diagramView.GetOwnedViewCount();
                for (int i = 0; i < nbOfElems; i++)
                {
                    try
                    {
                        IUMLClass umlClass = null;
                        IView     view     = diagramView.GetOwnedViewAt(i);
                        if (view != null)
                        {
                            umlClass = view.Model as IUMLClass;
                        }

                        if (umlClass != null)
                        {
                            // Collect only ERD tables
                            if (
                                (umlClass.StereotypeProfile == Symbols.ERD_PROFILE_NAME) &&
                                (umlClass.StereotypeName == Symbols.ERD_STEREOTYPE_TABLE)
                                )
                            {
                                IR.Table irTable = new IR.Table();
                                irTable.TableName = umlClass.Name;
                                irTable.Attribues = BuildIRTableAttributes(umlClass);
                                result.Add(irTable);
                            }
                        }
                    }
                    catch (System.Exception) { } // Ignore offending model elements
                }
            }

            return(result);
        }