public void SaveToMike11(string m11name)
    {
      NWK11File nwk = new NWK11File();

      double x0 = double.MaxValue;
      double x1 = double.MinValue;
      double y0 = double.MaxValue;
      double y1 = double.MinValue;

      int pointcount =1;

      //This is necessary because it fails if DHI.CrossSection.Dll tries to load UFS.dll
      DFS0 d = new DFS0(@"v");
      d.Dispose();



      CrossSectionCollection csc = new CrossSectionCollection();
      csc.Connection.FilePath = Path.ChangeExtension(m11name, ".xns11");
      csc.Connection.Bridge = csc.Connection.AvailableBridges[0];


      foreach (var b in Branches)
      {
        var newbranch = nwk.MIKE_11_Network_editor.BRANCHES.AddBranch();
        newbranch.definitions.Par1 = b.Name;

        double lastchainage = 0;
        for (int i = 0; i < b.Links.Count; i++)
        {
          var bp = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
          bp.Par1 = pointcount;
          bp.Par2 = b.Links[i].UpstreamNode.Location.X;
          bp.Par3 = b.Links[i].UpstreamNode.Location.Y;

          x0 = Math.Min(b.Links[i].UpstreamNode.Location.X, x0);
          x1 = Math.Max(b.Links[i].UpstreamNode.Location.X, x1);
          y0 = Math.Min(b.Links[i].UpstreamNode.Location.Y, y0);
          y1 = Math.Max(b.Links[i].UpstreamNode.Location.Y, y1);

          if (i == 0)
          {
            bp.Par4 = 1;
          }
          else
          {
            bp.Par4 = 0;
            lastchainage += b.Links[i - 1].Length;
          }
          bp.Par5 = lastchainage;
          newbranch.points.AddValue(pointcount);


          //CrossSections

          CrossSection cs = new CrossSection(new DHI.Generic.RouteLocation(b.Name, "Topo-id", lastchainage, b.Links[i].pfslink.Par5));
          if (b.Links[i].Xsec != null && b.Links[i].Xsec.TypeNo == 4)
          {
            double bottom = double.MaxValue;
            int bottomindex = 0;
            int index = 0;
            foreach (var dat in b.Links[i].Xsec.Datas)
            {
              var z = dat.GetValue(1);
              if (z < bottom)
              {
                bottom = z;
                bottomindex = index;
              }
              cs.Points.AddPoint(new CrossSectionPoint(dat.GetValue(0), z));
              index++;
            }

            if (bottom == 0)
              cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;

            cs.Points.SetMarkerAt(1, 0);
            cs.Points.SetMarkerAt(3, b.Links[i].Xsec.Datas.Count - 1);
            cs.Points.SetMarkerAt(2, bottomindex);
            csc.Add(cs);
          }
          else if (b.Links[i].pfslink.Par4 == 1) //Assume circular
          {
            cs.Geometry = DHI.Mike1D.CrossSections.Geometry.ClosedCircular;
            cs.SetDiameter(b.Links[i].pfslink.Par7);
            cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;
            csc.Add(cs);
          }

          if (i == b.Links.Count - 1)
          {
            lastchainage += b.Links[i].Length;

            var connectionlink = b.Links[i].DownstreamNode.Links.FirstOrDefault(l => l.UpstreamNode == b.Links[i].DownstreamNode);
            if (connectionlink != null) //Create a connection
            {
              var branch = Branches.Single(br => br.Links.Contains(connectionlink));
              newbranch.connections.Par3 = branch.Name;
              newbranch.connections.Par4 = branch.GetChainage(connectionlink);
            }
            pointcount++;
            var bpn = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
            bpn.Par1 = pointcount;
            bpn.Par2 = b.Links[i].DownstreamNode.Location.X;
            bpn.Par3 = b.Links[i].DownstreamNode.Location.Y;
            bpn.Par4 = 0;
            bpn.Par5 = lastchainage;
            newbranch.points.AddValue(pointcount);
          }
          pointcount++;
        }
        newbranch.definitions.Par3 = 0;
        newbranch.definitions.Par4 = (int) lastchainage;
        newbranch.definitions.Par6 = 1000;
        newbranch.definitions.Par7 = 3;
      }

      nwk.MIKE_11_Network_editor.DATA_AREA.x0 =(int) (x0- 0.1* (x1-x0));
      nwk.MIKE_11_Network_editor.DATA_AREA.x1 = (int)(x1 + 0.1 * (x1 - x0));
      nwk.MIKE_11_Network_editor.DATA_AREA.y0 = (int)(y0 - 0.1 * (y1 - y0));
      nwk.MIKE_11_Network_editor.DATA_AREA.y1 = (int)(y1 + 0.1 * (y1 - y0));

      nwk.FileName = m11name;
      nwk.Save();
      csc.Connection.Save();


    }
Exemple #2
0
        public void SaveToMike11(string m11name)
        {
            NWK11File nwk = new NWK11File();

            double x0 = double.MaxValue;
            double x1 = double.MinValue;
            double y0 = double.MaxValue;
            double y1 = double.MinValue;

            int pointcount = 1;

            //This is necessary because it fails if DHI.CrossSection.Dll tries to load UFS.dll
            DFS0 d = new DFS0(@"v");

            d.Dispose();



            CrossSectionCollection csc = new CrossSectionCollection();

            csc.Connection.FilePath = Path.ChangeExtension(m11name, ".xns11");
            csc.Connection.Bridge   = csc.Connection.AvailableBridges[0];


            foreach (var b in Branches)
            {
                var newbranch = nwk.MIKE_11_Network_editor.BRANCHES.AddBranch();
                newbranch.definitions.Par1 = b.Name;

                double lastchainage = 0;
                for (int i = 0; i < b.Links.Count; i++)
                {
                    var bp = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
                    bp.Par1 = pointcount;
                    bp.Par2 = b.Links[i].UpstreamNode.Location.X;
                    bp.Par3 = b.Links[i].UpstreamNode.Location.Y;

                    x0 = Math.Min(b.Links[i].UpstreamNode.Location.X, x0);
                    x1 = Math.Max(b.Links[i].UpstreamNode.Location.X, x1);
                    y0 = Math.Min(b.Links[i].UpstreamNode.Location.Y, y0);
                    y1 = Math.Max(b.Links[i].UpstreamNode.Location.Y, y1);

                    if (i == 0)
                    {
                        bp.Par4 = 1;
                    }
                    else
                    {
                        bp.Par4       = 0;
                        lastchainage += b.Links[i - 1].Length;
                    }
                    bp.Par5 = lastchainage;
                    newbranch.points.AddValue(pointcount);


                    //CrossSections

                    CrossSection cs = new CrossSection(new DHI.Generic.RouteLocation(b.Name, "Topo-id", lastchainage, b.Links[i].pfslink.Par5));
                    if (b.Links[i].Xsec != null && b.Links[i].Xsec.TypeNo == 4)
                    {
                        double bottom      = double.MaxValue;
                        int    bottomindex = 0;
                        int    index       = 0;
                        foreach (var dat in b.Links[i].Xsec.Datas)
                        {
                            var z = dat.GetValue(1);
                            if (z < bottom)
                            {
                                bottom      = z;
                                bottomindex = index;
                            }
                            cs.Points.AddPoint(new CrossSectionPoint(dat.GetValue(0), z));
                            index++;
                        }

                        if (bottom == 0)
                        {
                            cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;
                        }

                        cs.Points.SetMarkerAt(1, 0);
                        cs.Points.SetMarkerAt(3, b.Links[i].Xsec.Datas.Count - 1);
                        cs.Points.SetMarkerAt(2, bottomindex);
                        csc.Add(cs);
                    }
                    else if (b.Links[i].pfslink.Par4 == 1) //Assume circular
                    {
                        cs.Geometry = DHI.Mike1D.CrossSections.Geometry.ClosedCircular;
                        cs.SetDiameter(b.Links[i].pfslink.Par7);
                        cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;
                        csc.Add(cs);
                    }

                    if (i == b.Links.Count - 1)
                    {
                        lastchainage += b.Links[i].Length;

                        var connectionlink = b.Links[i].DownstreamNode.Links.FirstOrDefault(l => l.UpstreamNode == b.Links[i].DownstreamNode);
                        if (connectionlink != null) //Create a connection
                        {
                            var branch = Branches.Single(br => br.Links.Contains(connectionlink));
                            newbranch.connections.Par3 = branch.Name;
                            newbranch.connections.Par4 = branch.GetChainage(connectionlink);
                        }
                        pointcount++;
                        var bpn = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
                        bpn.Par1 = pointcount;
                        bpn.Par2 = b.Links[i].DownstreamNode.Location.X;
                        bpn.Par3 = b.Links[i].DownstreamNode.Location.Y;
                        bpn.Par4 = 0;
                        bpn.Par5 = lastchainage;
                        newbranch.points.AddValue(pointcount);
                    }
                    pointcount++;
                }
                newbranch.definitions.Par3 = 0;
                newbranch.definitions.Par4 = (int)lastchainage;
                newbranch.definitions.Par6 = 1000;
                newbranch.definitions.Par7 = 3;
            }

            nwk.MIKE_11_Network_editor.DATA_AREA.x0 = (int)(x0 - 0.1 * (x1 - x0));
            nwk.MIKE_11_Network_editor.DATA_AREA.x1 = (int)(x1 + 0.1 * (x1 - x0));
            nwk.MIKE_11_Network_editor.DATA_AREA.y0 = (int)(y0 - 0.1 * (y1 - y0));
            nwk.MIKE_11_Network_editor.DATA_AREA.y1 = (int)(y1 + 0.1 * (y1 - y0));

            nwk.FileName = m11name;
            nwk.Save();
            csc.Connection.Save();
        }