显示顺序信息

Display sequence messages

我正在尝试显示来自序列图的消息,但到目前为止还没有成功

这是我的代码:

函数 browse 递归调用自身来发现图表,但我对 DiagramLinks 或 DiagramObjects 不满意,有什么提示吗?

    private void browse(EA.Repository Repository, int ID, EA.ObjectType otype)
    {
        if (otype == EA.ObjectType.otPackage)
        {
            EA.Package pack = Repository.GetPackageByID(ID);
            foreach(EA.Element el in pack.Elements)
            {
                ID = el.ElementID;
                otype = el.ObjectType;
                this.browse(Repository, ID, otype);
            }
        }

        if (otype == EA.ObjectType.otElement)
        {
            EA.Element el = Repository.GetElementByID(ID);
            foreach (EA.Diagram diag in el.Diagrams)
            {
                ID = diag.DiagramID;
                otype = diag.ObjectType;
                this.browse(Repository, ID, otype);
            }
        }

        if (otype == EA.ObjectType.otDiagram)
        {
            EA.Diagram diag = Repository.GetDiagramByID(ID);
            //foreach (EA.DiagramLink dobj in diag.DiagramLinks)
            //{
                MessageBox.Show(diag.Name+diag.Type);
            //}
        }
    }

这是识别插件是从主菜单、树视图还是图表启动的函数。 它调用上面的函数 Browse

    private string simplify(EA.Repository Repository, string Location)
    {

        String s = "";


        if (Location == "MainMenu") {
            s = "ROOT";
            MessageBox.Show("test");
        }

        else if (Location == "TreeView")
        {


            //Get the element in the tree view which was clicked
            Object obj = null;
            EA.ObjectType otype = Repository.GetTreeSelectedItem(out obj);

            //Si le type n'arrive pas a etre determiné
            if (!Enum.IsDefined(typeof(EA.ObjectType), otype))
            {
                //Should not occur
                String error = "Type indeterminé.";
                MessageBox.Show(error, "Erreur");
            }

                //The user clicked on a package - try to determine the stereotype
            else if (otype == EA.ObjectType.otPackage)
            {
                EA.Package p = (EA.Package)obj;
                //If the package has no superpackage, it must be the very top package
                //-> if the very top package is clicked, ALL will be validated
                int ID = p.PackageID;
                bool hasParent = false;
                try
                {
                    int dummy = p.ParentID;
                    if (dummy != 0)
                        hasParent = true;
                }
                catch (Exception e) { }

                if (!hasParent)
                {
                    s = "ROOT";
                }
                else
                {
                    this.browse(Repository, ID, otype);
                }
            }

            else
            {
                int ID = 0;

                if (otype == EA.ObjectType.otDiagram)
                {
                    ID = ((EA.Diagram)obj).DiagramID;
                    EA.Diagram d = Repository.GetDiagramByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else if (otype == EA.ObjectType.otElement)
                {
                    ID = ((EA.Element)obj).ElementID;
                    EA.Element e = Repository.GetElementByID(ID);
                    this.browse(Repository, ID, otype);
                }


            }
            if (obj == null)
                s = "From Main Menu";
        }
        //If the users clicks into a diagram we must determine to which package
        //the diagram belongs
        else if (Location == "Diagram")
        {
            int ID = 0;
            try
            {
                Object obj = null;
                EA.ObjectType otype = Repository.GetContextItem(out obj);
                if (otype == EA.ObjectType.otDiagram)
                {
                    ID = ((EA.Diagram)obj).DiagramID;
                    EA.Diagram d = Repository.GetDiagramByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else if (otype == EA.ObjectType.otElement)
                {
                    ID = ((EA.Element)obj).ElementID;
                    EA.Element e = Repository.GetElementByID(ID);
                    this.browse(Repository, ID, otype);
                }
                else
                {
                    Repository.Models.GetAt(0);
                    s = "From Main Menu";
                }
            }
            catch (Exception ex) 
            {                 }         
        }

        return s;


        this.encours = true;
    }

以下 Perl 脚本片段(希望它是可读的)演示了如何获取连接器:

my $dia = $rep->GetDiagramByGUID("{7EA250AD-F37A-4e9a-9C52-BF8FCA3D87F7}"); # access the diagram
for (my $i = 0 ; $i < $dia->DiagramObjects->Count; $i++) { # every object inside the diagram
  my $do = $dia->DiagramObjects->GetAt($i);
  my $e = $rep->GetElementByID($do->ElementID); # the according element
  next unless $e->Type eq "Sequence"; # look only at life lines
  for (my $j = 0 ; $j < $e->Connectors->Count; $j++) { # now go through its connectors
    my $con = $e->Connectors->GetAt($j);
    print $con->Type . "\n"; # will print Sequence
  }
}

非常感谢你的帮助 Thomas 这是我用 C#

翻译的代码
if (otype == EA.ObjectType.otDiagram)
        {
            EA.Diagram diag = Repository.GetDiagramByID(ID);
            foreach (EA.DiagramObject dobj in diag.DiagramObjects)
            {
                EA.Element el = Repository.GetElementByID(dobj.ElementID);
                foreach (EA.Connector con in el.Connectors)
                {
                    if (con.Type == "Sequence")
                    {
                           MessageBox.Show(con.Name);

                    }

                }
            }
        }