Beispiel #1
0
        private void NewFile_Click(object sender, RoutedEventArgs e)
        {
            TopFile top = new TopFile();

            this.topFile = top;
            LoadGrid();
        }
Beispiel #2
0
        public Member(Component parent, string name, Linear linear) : base(parent, name, linear)
        {
            type       = Types.Member;
            memberType = MemberType.Normal;

            TopFile.UsedType(returnType);
        }
Beispiel #3
0
 public Test(TopFile fajl)
 {
     this.Name       = fajl.FileName;
     this.Test2Items = new ObservableCollection <Test2>();
     foreach (var stationPair in fajl.StationMappings)
     {
         this.Test2Items.Add(new Test2(stationPair));
     }
 }
        internal static void ConnectMultipleTopFiles(List <TopFile> multipleTopFiles)
        {
            {
                List <string> checkedPairs = new List <string>();

                for (int i = 0; i < multipleTopFiles.Count; i++)
                {
                    TopFile       srcFile            = multipleTopFiles[i];
                    List <string> allSrcStationNames = srcFile.Shots.Select(s => new string[] { s.From, s.To }).SelectMany(item => item).Where(item => item != null).Distinct().ToList <string>();

                    for (int j = i; j < multipleTopFiles.Count; j++)
                    {
                        if (j == i)
                        {
                            continue;
                        }
                        TopFile       destFile            = multipleTopFiles[j];
                        List <string> allDestStationNames = destFile.Shots.Select(s => new string[] { s.From, s.To }).SelectMany(item => item).Where(item => item != null).Distinct().ToList <string>();
                        if (allDestStationNames.Any(dest => allSrcStationNames.Any(src => src == dest)))
                        {
                            List <string> stations = allDestStationNames.Where(dest => allSrcStationNames.Contains(dest)).ToList();
                            foreach (var station in stations)
                            {
                                //if(srcFile.Shots)
                                Tuple <int, string, string> newTuple = new Tuple <int, string, string>(destFile.MultipleIndex, station, station);
                                if (!srcFile.ConnectingStation.Contains(newTuple) && srcFile.MultipleIndex != i)
                                {
                                    srcFile.ConnectingStation.Add(newTuple);
                                }

                                Tuple <int, string, string> newTupleDest = new Tuple <int, string, string>(srcFile.MultipleIndex, station, station);
                                if (!destFile.ConnectingStation.Contains(newTupleDest) && destFile.MultipleIndex != i)
                                {
                                    destFile.ConnectingStation.Add(newTupleDest);
                                }
                            }
                            if (srcFile.ConnectingStation.Count > 5 || destFile.ConnectingStation.Count > 5)
                            {
                            }

                            /*if (srcFile.ConnectingStation.Contains() srcFile.ConnectingStation = station;
                            *  if (destFile.ConnectingStation == null) destFile.ConnectingStation = station;*/
                            //break;
                        }
                        if (srcFile.ConnectingStation.Count == 0)
                        {
                        }
                    }
                }
                //CleanDoubleConnections(multipleTopFiles);
            }
        }
Beispiel #5
0
 private void LoadAllTopFilesFromFolder(string sFolderName)
 {
     string[] files = Directory.GetFiles(sFolderName);
     topFilesFromFolder = new List <TopFile>();
     foreach (string file in files)
     {
         if (file.Substring(file.LastIndexOf(".")).Contains("top"))
         {
             TopFile TopFile = new TopFile(new BinaryReader((new StreamReader(file)).BaseStream));
             topFilesFromFolder.Add(TopFile);
         }
     }
     MessageBox.Show("Done");
 }
Beispiel #6
0
 private IEnumerable <string> GetLinesFromPocketTopo(TopFile tfile)
 {
     foreach (var groupedElements in tfile.Shots.GroupBy(x => new { x.From, x.To }))
     {
         if (groupedElements.Key.To == null)
         {
             /*foreach (var pt in groupedElements)
              *  yield return string.Format("{0}\t{1}\t{2}\t{3}\t{4}", pt.From, pt.To == null ? "*" : pt.To, pt.Distance, pt.Azimuth, pt.Inclination);*/
         }
         else
         {
             yield return(string.Format("{0}\t{1}\t{2}\t{3}\t{4}", groupedElements.First().From, groupedElements.First().To == null ? "*" : groupedElements.First().To, groupedElements.Average(el => el.Distance), groupedElements.Average(el => el.Azimuth), groupedElements.Average(el => el.Inclination)));
         }
     }
 }
Beispiel #7
0
        private void Import_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.Filter = "top files (*.svx)|*.svx";
            dlg.Title  = "Please select an svx file to open.";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                string filename = dlg.FileName;
                using (StreamReader b = new StreamReader(filename))
                {
                    this.topFile = new TopFile(b);

                    LoadGrid();
                }
            }
        }
Beispiel #8
0
        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.Filter = "top files (*.top)|*.top";
            dlg.Title  = "Please select an top file to open.";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                string filename = dlg.FileName;
                using (BinaryReader b = new BinaryReader(File.Open(filename, FileMode.Open)))
                {
                    int pos    = 0;
                    int length = (int)b.BaseStream.Length;
                    this.topFile = new TopFile(b);
                    LoadGrid();
                }
            }
        }
        internal static List <TopFile> LoadMultipleFilesFromFolder(string path4MultipleFiles)
        {
            List <TopFile> MultipleTopFiles = new List <TopFile>();
            int            pos = 1;

            foreach (var filename in Directory.GetFiles(path4MultipleFiles).Where(s => s.EndsWith(".top")))
            {
                using (BinaryReader b = new BinaryReader(File.Open(filename, FileMode.Open)))
                {
                    int     length       = (int)b.BaseStream.Length;
                    TopFile localTopFile = new TopFile(b);
                    localTopFile.MultipleIndex = pos;
                    localTopFile.FileName      = Path.GetFileName(filename);
                    MultipleTopFiles.Add(localTopFile);
                    pos += 1;
                }
            }
            ImportExportHelper.ConnectMultipleTopFiles(MultipleTopFiles);

            return(MultipleTopFiles);
        }
Beispiel #10
0
        public Component SolveNativeFunction(string Name)
        {
            ///
            /// Check native function call
            ///
            if (Name.StartsWith(Properties.NativeFunctionPrefix))
            {
                // Is C function
                if (Name.StartsWith(Properties.NativeFunctionPrefix + "c_"))
                {
                    Name = Name.Substring(5);
                    var spl = Name.Split('_');
                    var lib = spl[0];
                    Name = spl[1];

                    TopFile.IncludeDefault(lib);

                    //Create dummy component function
                    var fun = new Function(null, null);
                    fun.name = Name;
                    return(fun);
                }
            }

            ///
            /// Check internal var reference
            ///
            if (this is Components.Container)
            {
                var cont = (Components.Container) this;
                var ivar = cont.ivarMan.Get(Name);
                if (ivar != null)
                {
                    return(new Member(ivar));
                }
            }

            return(null);
        }
Beispiel #11
0
        public override string GetRealName(Component relativeTo = null)
        {
            if (parent == null || isEntryPoint) // in case of native functions
            {
                return(name);
            }

            //todo: circa (to improve)
            string apex = "";

            if (Parent is File)
            {
                apex = TopFile.GetPath("_") + "_";
            }

            if (Parent is Class)
            {
                return(name);
            }
            else
            {
                return(apex + name);
            }
        }
Beispiel #12
0
        override public string WriteTo(Lang Lang)
        {
            if (disabled)
            {
                return("");
            }

            ///
            /// Special treatments
            ///

            // Temporary
            if (_linear.Op == "import")
            {
                TopFile.Include(Lang, _linear.component.attached);
                return("");
            }

            ///
            /// The others
            ///

            var ts = Lang.GetTypesSet;

            ///
            /// Handle return - ie string var = ...
            ///
            if (!String.IsNullOrEmpty(_linear.Return)) // is it has a sense?
            {
                ///
                /// Get return type
                ///
                var var = Parent.ivarMan.Get(_linear.Return);
                if (var != null) // Is InternalVariable
                {
                    if (var.IsUsed(_linear))
                    {
                        var.setRealVar(Lang);
                        if (!String.IsNullOrEmpty(var.realVarType))
                        {
                            writeToCont(var.realVarType);
                            writeToCont(" ");
                        }
                        writeToCont(var.realVarName);
                        writeToCont("=");
                    }
                }
                else // is normal variable
                {
                    //todo: handle getter and setter
                    var varPath = Parent.CalculateRealPath(_linear.Return, Lang);
                    writeToCont(varPath);
                    writeToCont("=");
                }
            }

            ///
            /// Operation analyzing
            ///
            if (_linear.HasOperator)
            {
                if (_linear.Type == "=")
                {
                    writeAttributeVariable(Lang, _linear.Name, returnType);
                }
                else
                {
                    string t1 = null, t2 = _linear.Attributes[0];

                    if (_linear.Type != "!")
                    {
                        t1 = t2;
                        t2 = _linear.Attributes[1];
                    }

                    if (t1 != null)
                    {
                        writeAttributeVariable(Lang, t1, returnType);
                    }

                    writeToCont(_linear.Type);
                    writeAttributeVariable(Lang, t2, returnType);
                }
            }
            else if (_linear.IsCall)
            {
                //var toCall = Parent.Solve(_linear.Name);

                var name = Parent.CalculateRealPath(_linear.Name, Lang);
                writeToCont(name);

                // Write parameters
                writeToCont("(");
                var ac = _linear.Attributes.Count;
                for (var a = 0; a < ac; a++)
                {
                    var attr = _linear.Attributes[a];

                    writeAttributeVariable(Lang, attr);

                    if (a < ac - 1)
                    {
                        writeToCont(",");
                    }
                }

                writeToCont(")");
            }
            else if (_linear.IsCast)
            {
                throw new Exception("todo");
            }

            writeToCont(";");

            return(writeReturn());
        }