Пример #1
0
        /// <summary>
        /// Функция обновляет данные коннектора пор данным переданного ConnectorData
        /// </summary>
        /// <param name="connectorData"></param>
        public static void UpdateConnectorByData(ConnectorData connectorData)
        {
            EA.Connector connector = connectorData.Connector;

            connector.Name       = connectorData.Name;
            connector.Notes      = connectorData.Notes;
            connector.ClientID   = connectorData.SourceElementID;
            connector.SupplierID = connectorData.TargetElementID;
            connector.Update();

            if (connectorData.IsLibrary)
            {
                EATVHelper.TaggedValueSet(connector, DAConst.DP_LibraryTag, "");
                EATVHelper.TaggedValueSet(connector, DAConst.DP_LinkTypeTag, connectorData.LinkType.ToString());
                EATVHelper.TaggedValueSet(connector, DAConst.DP_FlowIDTag, connectorData.FlowID);
                EATVHelper.TaggedValueSet(connector, DAConst.DP_SegmentIDTag, connectorData.SegmentID);
            }

            Context.ConnectorData[connectorData.ConnectorID] = connectorData;
        }
Пример #2
0
        /// <summary>
        /// Функция устанавливает размер элемента по умолчанию, соответствующий размеру элемента на библиотечной диаграмме
        /// </summary>
        /// <returns></returns>
        public static ExecResult <Boolean> SetElementDefaultSize()
        {
            ExecResult <Boolean> result = new ExecResult <bool>();

            try
            {
                var obj = EARepository.GetContextObject();
                if (obj == null)
                {
                    throw new Exception("Нет текущего объекта");
                }
                if (!(obj is EA.Element) || !LibraryHelper.IsLibrary((EA.Element)obj))
                {
                    throw new Exception("Выделен не библиотечный элемент");
                }
                EA.Element curElement = (EA.Element)obj;

                // Ищем размер на библиотечных диаграммах
                ExecResult <Size> GetElementSizeOnLibDiagramResult = GetElementSizeOnLibDiagram(curElement);
                if (GetElementSizeOnLibDiagramResult.code != 0)
                {
                    throw new Exception(GetElementSizeOnLibDiagramResult.message);
                }

                EATVHelper.TaggedValueSet(curElement, DAConst.defaultWidthTag, GetElementSizeOnLibDiagramResult.value.Width.ToString());
                EATVHelper.TaggedValueSet(curElement, DAConst.defaultHeightTag, GetElementSizeOnLibDiagramResult.value.Height.ToString());

                Logger.Out("Найден элемент диаграммы для установки размеров " + GetElementSizeOnLibDiagramResult.value.Width.ToString() + "x" + GetElementSizeOnLibDiagramResult.value.Height.ToString());
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Установка Tags для выделенных элементов
        /// </summary>
        /// <returns></returns>
        public ExecResult <Boolean> SetElementTags(string location)
        {
            ExecResult <Boolean> result = new ExecResult <bool>();

            try
            {
                // Сначала получаем список выделеннеых библиотечных элементов
                List <EA.Element> selectedLibElements = new List <EA.Element>();

                switch (location)
                {
                case "TreeView":
                    selectedLibElements = EAHelper.GetSelectedLibElement_Tree();
                    break;

                case "Diagram":
                    if (!Context.CheckCurrentDiagram())
                    {
                        throw new Exception("Не установлена или не открыта текущая диаграмма");
                    }

                    selectedLibElements = EAHelper.GetSelectedLibElement_Diagram();
                    break;

                case "MainMenu":
                    if (CurrentDiagram != null)
                    {
                        if (Context.CheckCurrentDiagram())
                        {
                            selectedLibElements = EAHelper.GetSelectedLibElement_Diagram();
                        }
                        else
                        {
                            selectedLibElements = EAHelper.GetSelectedLibElement_Tree();
                        }
                    }
                    else
                    {
                        selectedLibElements = EAHelper.GetSelectedLibElement_Tree();
                    }
                    break;
                }

                if (selectedLibElements.Count == 0) // если не выделены элементы  - пытаемся найти выделенные коннекторы
                {
                    if (location == "Diagram" || location == "MainMenu")
                    {
                        EA.Connector selectedConnector = EAHelper.GetSelectedLibConnector_Diagram();
                        if (selectedConnector != null)
                        {
                            return(Context.LinkDesigner.SetConnectorTags(location));
                        }
                    }
                    else
                    {
                        throw new Exception("Не выделены библиотечные элементы");
                    }
                }


                // Конструируем данные тэгов для формы
                List <TagData> curTagDataList = new List <TagData>();
                foreach (EA.Element curElement in selectedLibElements)
                {
                    foreach (EA.TaggedValue taggedValue in curElement.TaggedValuesEx)
                    {
                        string tagName = taggedValue.Name;

                        TagData curTagData;
                        curTagData = curTagDataList.FirstOrDefault(item => (item.TagName == tagName));
                        if (curTagData == null)
                        {
                            curTagData = new TagData()
                            {
                                TagName = tagName, TagValue = taggedValue.Value
                            };
                            curTagDataList.Add(curTagData);
                        }
                        curTagData.TagState = true;
                        curTagData.Count++;
                        if (taggedValue.ElementID != curElement.ElementID)
                        {
                            curTagData.Ex = true;
                        }
                    }
                }
                // Открываем форму для установки Tags
                ExecResult <List <TagData> > setTagsResult = new FSetTags().Execute(curTagDataList);
                if (setTagsResult.code != 0)
                {
                    return(result);
                }

                // Прописываем в элементах что наустанавливали на форме
                foreach (EA.Element curElement in selectedLibElements)
                {
                    foreach (TagData curTagData in setTagsResult.value)
                    {
                        if (curTagData.Enabled) // записываем только для Tags, в котоорые разрешено
                        {
                            if (curTagData.TagState == false)
                            {
                                EATVHelper.TaggedValueRemove(curElement, curTagData.TagName);
                            }
                            else
                            {
                                EATVHelper.TaggedValueSet(curElement, curTagData.TagName, curTagData.TagValue);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }

            return(result);
        }
Пример #4
0
        public static EA.Connector CreateConnector(ConnectorData createNewLinkData, bool putOnDiagram = true)
        {
            EA.Connector newConnector = null;

            EA.Element firstElement  = EARepository.GetElementByID(createNewLinkData.SourceElementID);
            EA.Element secondElement = EARepository.GetElementByID(createNewLinkData.TargetElementID);

            // Определяем тип создаваемого коннектора
            string creatingConnectorType;

            switch (createNewLinkData.LinkType)
            {
            case LinkType.Communication:
            case LinkType.Deploy:
                creatingConnectorType = "Dependency";
                break;

            case LinkType.InformationFlow:
                creatingConnectorType = "InformationFlow";
                break;

            case LinkType.SoftwareClassification:
                creatingConnectorType = "Generalization";
                break;

            default:
                throw new Exception("Непредусмотренный тип коннектора при создании");
            }

            // Создаём
            newConnector = firstElement.Connectors.AddNew("", creatingConnectorType);

            if (createNewLinkData.LinkType == LinkType.InformationFlow || createNewLinkData.LinkType == LinkType.Deploy)
            {
                newConnector.Direction = "Source -> Destination";
            }
            else
            {
                newConnector.Direction = "Unspecified";
            }
            newConnector.ClientID   = firstElement.ElementID;
            newConnector.SupplierID = secondElement.ElementID;

            newConnector.Name  = createNewLinkData.Name;
            newConnector.Notes = createNewLinkData.Notes;

            newConnector.Update();

            EATVHelper.TaggedValueSet(newConnector, DAConst.DP_LibraryTag, "");
            EATVHelper.TaggedValueSet(newConnector, DAConst.DP_LinkTypeTag, Enum.GetName(typeof(LinkType), createNewLinkData.LinkType));
            EATVHelper.TaggedValueSet(newConnector, DAConst.DP_FlowIDTag, createNewLinkData.FlowID);
            EATVHelper.TaggedValueSet(newConnector, DAConst.DP_SegmentIDTag, createNewLinkData.SegmentID);
            //EAHelper.TaggedValueSet(newConnector, DAConst.DP_TempLinkTag, createNewLinkData.tempLink.ToString());
            //EAHelper.TaggedValueSet(newConnector, DAConst.DP_TempLinkDiagramIDTag, createNewLinkData.tempLink ? createNewLinkData.tempLinkDiagramID : "");


            newConnector.Update();
            newConnector.TaggedValues.Refresh();

            // Добавляем коннектор к кэш информации о коннекторах
            createNewLinkData.ConnectorID = newConnector.ConnectorID;
            Context.ConnectorData.Add(createNewLinkData.ConnectorID, createNewLinkData);

            if (putOnDiagram)
            {
                // Помещаем на диаграмму
                EA.DiagramLink diagramLink = DiagramLinkHelper.CreateDiagramLink(newConnector);
            }

            return(newConnector);
        }
Пример #5
0
        /// <summary>
        /// Установка Tags для выделеного коннектора и других видимых на диаграмме линков того же типа
        /// </summary>
        /// <returns></returns>
        public ExecResult <Boolean> SetSimilarLinksTags(string location)
        {
            ExecResult <Boolean> result = new ExecResult <bool>();

            try
            {
                // Сначала получаем список выделеннеых библиотечных элементов
                EA.Connector selectedConnector = EAHelper.GetSelectedLibConnector_Diagram();

                if (selectedConnector == null)
                {
                    throw new Exception("Не выделены библиотечные элементы");
                }

                // Создаём список коннекторов и добавляем к нему выделенный
                List <EA.Connector> connectorList = new List <EA.Connector>();

                // Ищем на диаграмме другие линки такого же типа
                foreach (EA.DiagramLink curDL in CurrentDiagram.DiagramLinks)
                {
                    EA.Connector curConnector = EARepository.GetConnectorByID(curDL.ConnectorID);
                    if (!curDL.IsHidden && curConnector.Type == selectedConnector.Type)
                    {
                        connectorList.Add(curConnector);
                    }
                }


                // Конструируем данные тэгов для формы
                List <TagData> curTagDataList = new List <TagData>();

                foreach (EA.Connector connector in connectorList)
                {
                    foreach (EA.ConnectorTag taggedValue in selectedConnector.TaggedValues)
                    {
                        string tagName = taggedValue.Name;

                        TagData curTagData;
                        curTagData = curTagDataList.FirstOrDefault(item => (item.TagName == tagName));
                        if (curTagData == null)
                        {
                            curTagData = new TagData()
                            {
                                TagName = tagName, TagValue = taggedValue.Value
                            };
                            curTagDataList.Add(curTagData);
                        }
                        curTagData.TagState = true;
                        curTagData.Ex       = false;
                        curTagData.Count++;
                    }
                }

                // Открываем форму для установки Tags
                ExecResult <List <TagData> > setTagsResult = new FSetTags().Execute(curTagDataList);
                if (setTagsResult.code != 0)
                {
                    return(result);
                }

                // Прописываем в элементах что наустанавливали на форме
                foreach (EA.Connector connector in connectorList)
                {
                    foreach (TagData curTagData in setTagsResult.value)
                    {
                        if (curTagData.Enabled) // записываем только для Tags, в котоорые разрешено
                        {
                            if (curTagData.TagState == false)
                            {
                                EATVHelper.TaggedValueRemove(connector, curTagData.TagName);
                            }
                            else
                            {
                                EATVHelper.TaggedValueSet(connector, curTagData.TagName, curTagData.TagValue);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Установка Tags для выделенного коннектора
        /// </summary>
        /// <returns></returns>
        public ExecResult <Boolean> SetConnectorTags(string location)
        {
            if (!Context.CheckCurrentDiagram())
            {
                throw new Exception("Не установлена или не открыта текущая диаграмма");
            }


            ExecResult <Boolean> result = new ExecResult <bool>();

            try
            {
                // Сначала получаем список выделеннеых библиотечных элементов
                EA.Connector selectedConnector = EAHelper.GetSelectedLibConnector_Diagram(false);

                if (selectedConnector == null)
                {
                    throw new Exception("Не выделены библиотечные элементы");
                }


                // Конструируем данные тэгов для формы
                List <TagData> curTagDataList = new List <TagData>();

                foreach (EA.ConnectorTag taggedValue in selectedConnector.TaggedValues)
                {
                    string tagName = taggedValue.Name;

                    TagData curTagData = new TagData()
                    {
                        TagName = tagName, TagValue = taggedValue.Value
                    };
                    curTagData.TagState = true;
                    curTagData.Ex       = false;
                    curTagData.Count    = 1;
                    curTagDataList.Add(curTagData);
                }

                // Открываем форму для установки Tags
                ExecResult <List <TagData> > setTagsResult = new FSetTags().Execute(curTagDataList);
                if (setTagsResult.code != 0)
                {
                    return(result);
                }

                // Прописываем в элементах что наустанавливали на форме
                foreach (TagData curTagData in setTagsResult.value)
                {
                    if (curTagData.Enabled) // записываем только для Tags, в котоорые разрешено
                    {
                        if (curTagData.TagState == false)
                        {
                            EATVHelper.TaggedValueRemove(selectedConnector, curTagData.TagName);
                        }
                        else
                        {
                            EATVHelper.TaggedValueSet(selectedConnector, curTagData.TagName, curTagData.TagValue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }

            return(result);
        }