예제 #1
0
        // TODO(Premek): check for invalid characters in the namePrefix
        private void CreateMemoryBlocksInner(object memBlockOwner, List <PropertyInfo> listOfBlockInfos, string namePrefix = "")
        {
            if (listOfBlockInfos.Count == 0)
            {
                return;
            }

            var usePrefix = (string.IsNullOrEmpty(namePrefix) && (memBlockOwner is IMemBlockNamePrefix))
                ? ((IMemBlockNamePrefix)memBlockOwner).MemBlockNamePrefix
                : namePrefix;

            var existingMemBlockNames = MyMemoryManager.Instance.GetBlocks(this).Select(mb => mb.Name).ToList();

            foreach (PropertyInfo pInfo in listOfBlockInfos)
            {
                MyAbstractMemoryBlock mb = MyMemoryManager.Instance.CreateMemoryBlock(this, pInfo.PropertyType);

                mb.Name = GetUniqueMemBlockName(usePrefix + pInfo.Name, existingMemBlockNames);

                mb.IsOutput    = MyNodeInfo.IsOutputMemoryBlock(pInfo);
                mb.Persistable = pInfo.GetCustomAttribute <MyPersistableAttribute>(true) != null;
                mb.Unmanaged   = pInfo.GetCustomAttribute <MyUnmanagedAttribute>(true) != null;
                mb.IsDynamic   = pInfo.GetCustomAttribute <DynamicBlockAttribute>(true) != null;

                pInfo.SetValue(memBlockOwner, mb);
            }
        }
예제 #2
0
        public void ColumnHintTests(ColumnHintTestData testData)
        {
            m_output.WriteLine("Running '{0}'", testData.Comment);

            MyAbstractMemoryBlock memBlock = GetMemBlock(testData.InitialDims);

            memBlock.ColumnHint = testData.ColumnHint;

            Assert.True(memBlock.Dims.Equals(testData.ExpectedDims));
        }
예제 #3
0
        public void ColumnHintUsedWhenDivisible()
        {
            MyAbstractMemoryBlock memBlock = GetMemBlock(new TensorDimensions(12));

            memBlock.ColumnHint = 3;

            Assert.Equal(12, memBlock.Count);
            Assert.Equal(2, memBlock.Dims.Rank);
            Assert.Equal(4, memBlock.Dims[1]);
        }
예제 #4
0
        public static void CheckControlSize(MyValidator validator, MyAbstractMemoryBlock controls, MyWorkingNode sender)
        {
            validator.AssertError(controls != null, sender, "Controls are not connected");

            if (controls != null)
            {
                int neededControls   = NrOfControls;
                int providedControls = controls.Count;
                validator.AssertError(providedControls >= neededControls, sender, String.Format("Wrong number of actions. With current control mode ({0}) you have to provide at least {1} controls. Provide the correct number of controls or change the control mode.", Mode, neededControls));
                validator.AssertWarning(providedControls != neededControls, sender, String.Format("With current control mode ({0}) you should provide {1} controls but you provided {2} controls. Make sure that this is what you want and you have correct control mode chosen.", Mode, neededControls, providedControls));
            }
        }
예제 #5
0
        protected void CopyOutputBlocksToDevice()
        {
            for (int i = 0; i < OutputBranches; i++)
            {
                MyAbstractMemoryBlock mb = GetAbstractOutput(i);

                if (mb != null)
                {
                    mb.SafeCopyToDevice();
                }
            }
        }
예제 #6
0
        private void CopyInputBlocksToHost()
        {
            for (int i = 0; i < InputBranches; i++)
            {
                MyAbstractMemoryBlock mb = GetAbstractInput(i);

                if (mb != null)
                {
                    mb.SafeCopyToHost();
                }
            }
        }
예제 #7
0
        public void UseColumnHintWhenSettingCountAfterIt()
        {
            MyAbstractMemoryBlock memBlock = GetMemBlock(new TensorDimensions());

            memBlock.ColumnHint = 3;
            Assert.Equal(0, memBlock.Dims.ElementCount);
            Assert.Equal(3, memBlock.ColumnHint);

            memBlock.Count = 12;
            Assert.Equal(12, memBlock.Dims.ElementCount);
            Assert.Equal(2, memBlock.Dims.Rank);
            Assert.Equal(4, memBlock.Dims[1]);
        }
예제 #8
0
        protected void CreateMemoryBlocks()
        {
            foreach (PropertyInfo pInfo in GetInfo().OwnedMemoryBlocks)
            {
                MyAbstractMemoryBlock mb = MyMemoryManager.Instance.CreateMemoryBlock(this, pInfo.PropertyType);
                mb.Name        = pInfo.Name;
                mb.Persistable = pInfo.GetCustomAttribute <MyPersistableAttribute>(true) != null;
                mb.Unmanaged   = pInfo.GetCustomAttribute <MyUnmanagedAttribute>(true) != null;
                mb.IsOutput    = pInfo.GetCustomAttribute <MyOutputBlockAttribute>(true) != null;

                pInfo.SetValue(this, mb);
            }
        }
예제 #9
0
        internal override void ValidateMandatory(MyValidator validator)
        {
            base.ValidateMandatory(validator);

            if (LoadOnStart || validator.Simulation.LoadAllNodesData)
            {
                if (MyMemoryBlockSerializer.TempDataExists(this))
                {
                    validator.AddInfo(this, "Node will load data from temporal storage.");
                }
                else if (DataFolder != null && DataFolder != String.Empty)
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: " + DataFolder);
                }
                else if (validator.Simulation.LoadAllNodesData && !(String.IsNullOrEmpty(validator.Simulation.GlobalDataFolder)))
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: "
                                      + validator.Simulation.GlobalDataFolder + "\\" + MyMemoryBlockSerializer.GetNodeFolder(this));
                }
                else if (validator.Simulation.LoadAllNodesData && (String.IsNullOrEmpty(validator.Simulation.GlobalDataFolder)))
                {
                    validator.AddInfo(this, "Node will load data from temporal storage.");
                }
                else
                {
                    validator.AddWarning(this, "LoadOnStart is active but no temporal data and no local or global data folder is set. Data will NOT be loaded.");
                }
            }

            validator.AssertInfo(!(SaveOnStop || validator.Simulation.SaveAllNodesData), this, "Node will save data to temporal storage before stop.");

            foreach (PropertyInfo pInfo in GetInfo().OwnedMemoryBlocks)
            {
                MyAbstractMemoryBlock mb = (pInfo.GetValue(this) as MyAbstractMemoryBlock);
                validator.AssertError(mb.Count >= 0, this, "Size of " + mb.Name + " memory block cannot be negative.");
            }

            List <PropertyInfo> inputBlocks = GetInfo().InputBlocks;

            for (int i = 0; i < inputBlocks.Count; i++)
            {
                PropertyInfo pInfo = inputBlocks[i];

                if (GetAbstractInput(i) != pInfo.GetValue(this))
                {
                    validator.AddError(this, "Incompatible memory block for \"" + pInfo.Name + "\" (" + GetAbstractInput(i).GetType().GenericTypeArguments[0].Name + " != " + pInfo.PropertyType.GenericTypeArguments[0].Name + ")");
                }
            }
        }
예제 #10
0
        public static long SumAllIncomingSignals(MyNode target)
        {
            long result = 0;

            for (int i = 0; i < target.InputBranches; i++)
            {
                MyAbstractMemoryBlock mb = target.GetAbstractInput(i);

                if (mb != null)
                {
                    result |= mb.Owner.OutgoingSignals;
                }
            }

            return(result);
        }
예제 #11
0
        public static long UseFirstInputSignal(MyNode target)
        {
            if (target.InputBranches == 0)
            {
                return(0);
            }

            long result = 0;

            MyAbstractMemoryBlock mb = target.GetAbstractInput(0);

            if (mb != null)
            {
                result |= mb.Owner.OutgoingSignals;
            }

            return(result);
        }
예제 #12
0
        private Size ComputeTiledTextureSize(TensorDimensions dims, MyAbstractMemoryBlock target)
        {
            int effectivePixelsDisplayed;

            if (Method == RenderingMethod.RGB)
            {
                // check if:
                // memory block has 3 chanels
                // chanels are divisible by requested TileWidth and TileHeight
                // TileWidth and TileHeight are not too big
                if (
                    dims.ElementCount % 3 != 0 ||
                    dims.ElementCount / TileWidth / TileHeight % 3 != 0 ||
                    dims.ElementCount / TileWidth / TileHeight / 3 == 0)
                {
                    MyLog.WARNING.WriteLine("Memory block '{0}: {1}' observer: {2}", Target.Owner.Name, Target.Name,
                                            "RGB rendering, but Memory block.count and TileWidth and TileHeight values incompatible with the RGB format!" +
                                            " Swtiching to RedGreenScale. Use correct CustomDimensions");
                    Method = RenderingMethod.RedGreenScale;
                    effectivePixelsDisplayed = dims.ElementCount;
                }
                else
                {
                    effectivePixelsDisplayed = (int)Math.Ceiling((decimal)((float)dims.ElementCount / (float)3));
                }
            }
            else
            {
                effectivePixelsDisplayed = dims.ElementCount;
            }

            if (TileWidth * TileHeight * TilesInRow > effectivePixelsDisplayed)
            {
                TilesInRow = effectivePixelsDisplayed / (TileWidth * TileHeight);
                String message = " (Parsed from " + (UseCustomDimensions ? "CustomDimensions)" : "MemoryBlock.Dims)");
                MyLog.WARNING.WriteLine("Memory block '{0}: {1}' observer: {2}", Target.Owner.Name, Target.Name,
                                        "TilesInRow too big, adjusting to the max. value " + TilesInRow + "\n\t\t..for TileWidth=" + TileWidth + ", TileHeight=" + TileHeight + message);
            }

            m_noBlocks    = effectivePixelsDisplayed / (TileWidth * TileHeight);
            TilesInColumn = (int)Math.Ceiling((decimal)((float)m_noBlocks / (float)TilesInRow));

            return(new Size(TileWidth * TilesInRow, TilesInColumn * TileHeight));
        }
예제 #13
0
        private static void RefreshConnectionView(NodeConnection connection)
        {
            var from           = (connection.From.Node as MyNodeView).Node;
            var to             = (connection.To.Node as MyNodeView).Node;
            var connectionView = (connection as MyNodeViewConnection);

            // If order == 0, the node is likely an output.
            connectionView.Backward = to.TopologicalOrder != 0 && @from.TopologicalOrder >= to.TopologicalOrder;

            // If order == 0, the node is likely an output.
            MyAbstractMemoryBlock output = from.GetAbstractOutput((int)connection.From.Item.Tag);

            if (output != null)
            {
                connectionView.Dynamic = output.IsDynamic;
            }
            else
            {
                connectionView.Dynamic = false;
            }
        }
예제 #14
0
        private void addListViewItem(MyAbstractMemoryBlock block, string name, bool owned = true)
        {
            //SizeT size = block.GetSize();
            //string sizeStr = size > 1024 ? size / 1024 + " KB" : size + " B";

            string typeStr = "";

            if (block.GetType().GetGenericArguments().Length > 0)
            {
                typeStr = block.GetType().GetGenericArguments()[0].Name;
            }

            string size = block.Count.ToString();

            if (block.ColumnHint > 1 && block.ColumnHint < block.Count)
            {
                size = block.ColumnHint + "x" + (block.Count / block.ColumnHint) + " (" + block.Count.ToString() + ")";
            }

            ListViewItem item = new ListViewItem(new string[] { name, size, typeStr });

            item.Tag = block;

            if (owned)
            {
                item.ForeColor = block.IsOutput ? Color.MidnightBlue : SystemColors.WindowText;
            }
            else
            {
                item.ForeColor = SystemColors.GrayText;
            }

            item.UseItemStyleForSubItems = false;
            item.SubItems[1].Font        = new System.Drawing.Font(FontFamily.GenericMonospace, 9);

            item.SubItems[1].ForeColor = item.ForeColor;
            item.SubItems[2].ForeColor = item.ForeColor;

            listView.Items.Add(item);
        }
예제 #15
0
        public virtual bool AcceptsConnection(MyNode fromNode, int fromIndex, int toIndex)
        {
            MyAbstractMemoryBlock outputBlock = fromNode.GetAbstractOutput(fromIndex);

            if (outputBlock != null && outputBlock.IsDynamic)
            {
                // TODO(HonzaS): Enable this later when variable count of dynamic memblocks is supported.
                if (toIndex >= GetInfo().InputBlocks.Count)
                {
                    return(false);
                }

                PropertyInfo inputBlock       = GetInfo().InputBlocks[toIndex];
                var          dynamicAttribute = inputBlock.GetCustomAttribute <DynamicBlockAttribute>();
                if (dynamicAttribute == null)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #16
0
        public void CreateAndShowObserverView(MyAbstractMemoryBlock memoryBlock, MyNode declaredOwner, Type mbObserverType)
        {
            bool isPlot = mbObserverType == typeof(MyTimePlotObserver);

            if (isPlot && !(memoryBlock is MyMemoryBlock <float>))
            {
                MyLog.ERROR.WriteLine("Plot observers are not allowed for non-float memory blocks");
                return;
            }

            try
            {
                MyAbstractObserver observer;

                if (isPlot)
                {
                    MyTimePlotObserver plotObserver = new MyTimePlotObserver();
                    plotObserver.Target = (MyMemoryBlock <float>)memoryBlock;

                    observer = plotObserver;
                }
                else
                {
                    MyAbstractMemoryBlockObserver memObserver = (MyAbstractMemoryBlockObserver)Activator.CreateInstance(mbObserverType);
                    memObserver.Target = memoryBlock;

                    observer = memObserver;
                }

                ObserverForm newView = new ObserverForm(this, observer, declaredOwner);
                ObserverViews.Add(newView);

                newView.Show(dockPanel, DockState.Float);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Error creating observer: " + e.Message);
            }
        }
        public void LoadBlock(MyAbstractMemoryBlock memoryBlock, string globalDataFolder)
        {
            int length = m_buffer.Length;
            SizeT size = memoryBlock.GetSize();

            while (size > length)
            {
                length *= 2;
            }

            if (length != m_buffer.Length)
            {
                m_buffer = new byte[length];
            }

            try
            {
                string filePath = ResolveFilePath(memoryBlock, globalDataFolder);
                long fileSize = new FileInfo(filePath).Length;

                if (fileSize != size)
                {
                    throw new InvalidDataException("Different size of a stored memory block (" + fileSize + " B != " + size + " B)");
                }

                using (var reader = new BinaryReader(File.OpenRead(filePath)))
                {
                    reader.Read(m_buffer, 0, size);
                }

                memoryBlock.Fill(m_buffer);
            }
            catch (Exception e)
            {
                MyLog.WARNING.WriteLine("Memory block loading failed (node: {0} (id: {1}), block: {2}): {3}", memoryBlock.Owner.Name,
                    memoryBlock.Owner.Id, memoryBlock.Name, e.Message);
            }
        }
 public static string GetUniqueName(MyAbstractMemoryBlock memoryBlock)
 {
     return memoryBlock.Owner.Id.ToString() + "#" + memoryBlock.Name;
 }
 public static string GetFileName(MyAbstractMemoryBlock memoryBlock)
 {
     return memoryBlock.Name + ".mb";
 }
        private static string ResolveFilePath(MyAbstractMemoryBlock memoryBlock, string globalDataFolder)
        {
            string fileName = GetTempStorage(memoryBlock.Owner.Owner) + "\\" + GetNodeFolder(memoryBlock.Owner) + "\\" + GetFileName(memoryBlock);

            if (!File.Exists(fileName))
            {
                MyWorkingNode node = memoryBlock.Owner as MyWorkingNode;

                if (!string.IsNullOrEmpty(node.DataFolder))
                {
                    fileName = node.DataFolder;
                }
                else if (!string.IsNullOrEmpty(globalDataFolder))
                {
                    fileName = globalDataFolder + "\\" + GetNodeFolder(memoryBlock.Owner);
                }
                else
                {
                    throw new FileNotFoundException(
                        "File not found in temporal folder and no data folder defined: " + fileName);
                }

                fileName += "\\" + GetFileName(memoryBlock);
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Memory block file not found: " + fileName);
            }

            return fileName;
        }
        public void SaveBlock(MyAbstractMemoryBlock memoryBlock)
        {
            int length = m_buffer.Length;
            SizeT size = memoryBlock.GetSize();

            while (size > length)
            {
                length *= 2;
            }

            if (length != m_buffer.Length)
            {
                m_buffer = new byte[length];
            }
            memoryBlock.GetBytes(m_buffer);

            string tempFolder = GetTempStorage(memoryBlock.Owner.Owner) + "\\" + GetNodeFolder(memoryBlock.Owner);
            Directory.CreateDirectory(tempFolder);

            string filePath = tempFolder + "\\" + GetFileName(memoryBlock);

            try
            {
                using (var writer = new BinaryWriter(File.Open(filePath, FileMode.Create)))
                {
                    writer.Write(m_buffer, 0, size);
                }
            }
            catch (Exception e)
            {
                MyLog.WARNING.WriteLine("Memory block saving failed (node: {0} (id: {1}), block: {2}): {3}", memoryBlock.Owner.Name,
                    memoryBlock.Owner.Id, memoryBlock.Name, e.Message);
            }
        }
예제 #22
0
        private void addListViewItem(MyAbstractMemoryBlock block, string name, bool owned = true)
        {
            //SizeT size = block.GetSize();
            //string sizeStr = size > 1024 ? size / 1024 + " KB" : size + " B";

            string typeStr = "";
            if (block.GetType().GetGenericArguments().Length > 0)
            {
                typeStr = block.GetType().GetGenericArguments()[0].Name;
            }

            string size = block.Count.ToString();

            if (block.ColumnHint > 1 && block.ColumnHint < block.Count)
            {
                size = block.ColumnHint + "x" + (block.Count / block.ColumnHint) + " (" + block.Count.ToString() + ")";
            }

            ListViewItem item = new ListViewItem(new string[] { name, size, typeStr });
            item.Tag = block;

            if (owned)
            {
                item.ForeColor = block.IsOutput ? Color.MidnightBlue : SystemColors.WindowText;
            }
            else
            {
                item.ForeColor = SystemColors.GrayText;
            }

            item.UseItemStyleForSubItems = false;
            item.SubItems[1].Font = new System.Drawing.Font(FontFamily.GenericMonospace, 9);

            item.SubItems[1].ForeColor = item.ForeColor;
            item.SubItems[2].ForeColor = item.ForeColor;

            listView.Items.Add(item);
        }
예제 #23
0
 internal abstract void ApplyAttribute(MyAbstractMemoryBlock myAbstractMemoryBlock);
예제 #24
0
 private static string PrintBlockSize(MyAbstractMemoryBlock block)
 {
     return((block != null)
         ? block.Dims.Print(printTotalSize: true)
         : "?");
 }
예제 #25
0
        public int GetOutputSize(int index)
        {
            MyAbstractMemoryBlock output = GetAbstractOutput(index);

            return(output != null ? output.Count : 0);
        }
예제 #26
0
 private void AddAttribute(MyAbstractMemoryBlock memoryBlock, MemBlockAttribute attr,
     IDictionary<string, MemBlockAttribute> attributes)
 {
     if (attr.IsCustom)
     {
         attributes.Add(GetUniqueName(memoryBlock), attr);
     }
 }
예제 #27
0
        public void SaveBlock(MyAbstractMemoryBlock memoryBlock)
        {
            int length = buffer.Length;
            SizeT size = memoryBlock.GetSize();

            while (size > length)
            {
                length *= 2;
            }

            if (length != buffer.Length)
            {
                buffer = new byte[length];
            }
            memoryBlock.GetBytes(buffer);

            string tempFolder = GetTempStorage(memoryBlock.Owner.Owner) + "\\" + GetNodeFolder(memoryBlock.Owner);
            Directory.CreateDirectory(tempFolder);

            string filePath = tempFolder + "\\" + GetFileName(memoryBlock);

            try
            {
                BinaryWriter writer = new BinaryWriter(File.Open(filePath, FileMode.Create));

                writer.Write(buffer, 0, size);
                writer.Close();
            }
            catch (Exception e)
            {
                MyLog.WARNING.WriteLine("Memory block saving failed (" + memoryBlock.Owner.Name + "." + memoryBlock.Name + "): " + e.Message);
            }
        }
예제 #28
0
        public void CreateAndShowObserverView(MyAbstractMemoryBlock memoryBlock, MyNode declaredOwner, Type mbObserverType)
        {
            bool isPlot = mbObserverType == typeof(MyTimePlotObserver);

            if (isPlot && !(memoryBlock is MyMemoryBlock<float>))
            {
                MyLog.ERROR.WriteLine("Plot observers are not allowed for non-float memory blocks");
                return;
            }

            try
            {
                MyAbstractObserver observer;

                if (isPlot)
                {
                    MyTimePlotObserver plotObserver = new MyTimePlotObserver();
                    plotObserver.Target = (MyMemoryBlock<float>)memoryBlock;

                    observer = plotObserver;
                }
                else
                {
                    MyAbstractMemoryBlockObserver memObserver = (MyAbstractMemoryBlockObserver)Activator.CreateInstance(mbObserverType);
                    memObserver.Target = memoryBlock;

                    observer = memObserver;
                }

                ObserverForm newView = new ObserverForm(this, observer, declaredOwner);
                ObserverViews.Add(newView);

                newView.Show(dockPanel, DockState.Float);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Error creating observer: " + e.Message);
            }
        }
예제 #29
0
 private static string PrintBlockSize(MyAbstractMemoryBlock block)
 {
     return (block != null)
         ? block.Dims.Print(printTotalSize: true, indicateComputedDim: true)
         : "?";
 }
예제 #30
0
        public int GetInputSize(int index)
        {
            MyAbstractMemoryBlock input = GetAbstractInput(index);

            return(input != null ? input.Count : 0);
        }
예제 #31
0
        public void UpdateView()
        {
            listView.Items.Clear();
            toolStrip.Enabled = false;
            splitContainer.Panel2Collapsed = true;

            if (Target != null)
            {
                if (m_mainForm.SimulationHandler.State == MySimulationHandler.SimulationState.STOPPED)
                {
                    try
                    {
                        Target.UpdateMemoryBlocks();
                    }
                    catch (Exception e)
                    {
                        MyLog.ERROR.WriteLine("Exeption occured while updating node " + Target.Name + ": " + e.Message);
                    }
                }

                List <MyAbstractMemoryBlock> blocks = MyMemoryManager.Instance.GetBlocks(Target);


                for (int i = 0; i < Target.InputBranches; i++)
                {
                    MyAbstractMemoryBlock mb = Target.GetAbstractInput(i);

                    if (mb != null)
                    {
                        if (Target is IMyVariableBranchViewNodeBase)
                        {
                            addListViewItem(mb, "<Input_" + (i + 1) + ">", false);
                        }
                        else if (Target is MyNodeGroup)
                        {
                            addListViewItem(mb, (Target as MyNodeGroup).GroupInputNodes[i].Name, false);
                        }
                        else
                        {
                            addListViewItem(mb, Target.GetInfo().InputBlocks[i].Name, false);
                        }
                    }
                }

                if (Target is MyNodeGroup)
                {
                    for (int i = 0; i < Target.OutputBranches; i++)
                    {
                        MyAbstractMemoryBlock mb = Target.GetAbstractOutput(i);

                        if (mb != null)
                        {
                            addListViewItem(mb, (Target as MyNodeGroup).GroupOutputNodes[i].Name, false);
                        }
                    }
                }
                else if (Target is MyParentInput)
                {
                    MyAbstractMemoryBlock mb = Target.GetAbstractOutput(0);

                    if (mb != null)
                    {
                        addListViewItem(mb, MyProject.ShortenMemoryBlockName(mb.Name), false);
                    }
                }

                foreach (MyAbstractMemoryBlock block in blocks)
                {
                    addListViewItem(block, block.Name);
                }
            }
        }
예제 #32
0
        public void CollectAttributes(MyAbstractMemoryBlock memoryBlock,
            IDictionary<string, MemBlockAttribute> attributes)
        {
            if (memoryBlock == null)
                return;

            AddAttribute(memoryBlock, memoryBlock.Dims, attributes);
        }
예제 #33
0
        public static void CheckControlSize(MyValidator validator, MyAbstractMemoryBlock controls, MyWorkingNode sender)
        {
            validator.AssertError(controls != null, sender, "Controls are not connected");

            if (controls != null)
            {
                int neededControls = NrOfControls;
                int providedControls = controls.Count;
                validator.AssertError(providedControls >= neededControls, sender, String.Format("Wrong number of actions. With current control mode ({0}) you have to provide at least {1} controls. Provide the correct number of controls or change the control mode.", Mode, neededControls));
                validator.AssertWarning(providedControls != neededControls, sender, String.Format("With current control mode ({0}) you should provide {1} controls but you provided {2} controls. Make sure that this is what you want and you have correct control mode chosen.", Mode, neededControls, providedControls));
            }
        }
예제 #34
0
        private Size ComputeTiledTextureSize(TensorDimensions dims, MyAbstractMemoryBlock target)
        {
            int effectivePixelsDisplayed;

            if (Method == RenderingMethod.RGB)
            {
                // check if:
                // memory block has 3 chanels
                // chanels are divisible by requested TileWidth and TileHeight
                // TileWidth and TileHeight are not too big
                if (
                    dims.ElementCount % 3 != 0 ||
                    dims.ElementCount / TileWidth / TileHeight % 3 != 0 ||
                    dims.ElementCount / TileWidth / TileHeight / 3 == 0)
                {
                    MyLog.WARNING.WriteLine("Memory block '{0}: {1}' observer: {2}", Target.Owner.Name, Target.Name,
                        "RGB rendering, but Memory block.count and TileWidth and TileHeight values incompatible with the RGB format!" +
                        " Swtiching to RedGreenScale. Use correct CustomDimensions");
                    Method = RenderingMethod.RedGreenScale;
                    effectivePixelsDisplayed = dims.ElementCount;
                }
                else
                {
                    effectivePixelsDisplayed = (int)Math.Ceiling((decimal)((float)dims.ElementCount / (float)3));
                }
            }
            else
            {
                effectivePixelsDisplayed = dims.ElementCount;
            }

            if (TileWidth * TileHeight * TilesInRow > effectivePixelsDisplayed)
            {
                TilesInRow = effectivePixelsDisplayed / (TileWidth * TileHeight);
                String message = " (Parsed from " + (UseCustomDimensions ? "CustomDimensions)" : "MemoryBlock.Dims)");
                MyLog.WARNING.WriteLine("Memory block '{0}: {1}' observer: {2}", Target.Owner.Name, Target.Name,
                    "TilesInRow too big, adjusting to the max. value " + TilesInRow + "\n\t\t..for TileWidth=" + TileWidth + ", TileHeight=" + TileHeight + message);
            }

            m_noBlocks = effectivePixelsDisplayed / (TileWidth * TileHeight);
            TilesInColumn = (int)Math.Ceiling((decimal)((float)m_noBlocks / (float)TilesInRow));

            return new Size(TileWidth * TilesInRow, TilesInColumn * TileHeight);
        }
예제 #35
0
        public void CreateAndShowObserverView(MyAbstractMemoryBlock memoryBlock, MyNode declaredOwner, Type mbObserverType)
        {
            bool isPlot = mbObserverType == typeof(MyTimePlotObserver) || mbObserverType == typeof(TimePlotObserver);

            if (isPlot && !(memoryBlock is MyMemoryBlock<float>))
            {
                MyLog.ERROR.WriteLine("Plot observers are not allowed for non-float memory blocks");
                return;
            }

            try
            {
                MyAbstractObserver observer = null;

                if (isPlot)
                {
                    if (mbObserverType == typeof(MyTimePlotObserver))
                    {
                        observer = new MyTimePlotObserver { Target = (MyMemoryBlock<float>)memoryBlock };
                    }
                    else if (mbObserverType == typeof(TimePlotObserver))
                    {
                        observer = new TimePlotObserver { Target = (MyMemoryBlock<float>)memoryBlock };
                    }
                }
                else
                {
                    MyAbstractMemoryBlockObserver memObserver = (MyAbstractMemoryBlockObserver)Activator.CreateInstance(mbObserverType);
                    memObserver.Target = memoryBlock;

                    observer = memObserver;
                }

                if (observer == null)
                    throw new InvalidOperationException("No observer was initialized");

                ObserverForm newView = new ObserverForm(this, observer, declaredOwner);
                ObserverViews.Add(newView);

                newView.Show(dockPanel, DockState.Float);

                ProjectStateChanged("Memory block observer added");
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Error creating observer: " + e.Message);
            }
        }
예제 #36
0
        public void LoadBlock(MyAbstractMemoryBlock memoryBlock, string globalDataFolder)
        {
            int length = buffer.Length;
            SizeT size = memoryBlock.GetSize();

            while (size > length)
            {
                length *= 2;
            }

            if (length != buffer.Length)
            {
                buffer = new byte[length];
            }

            try
            {
                string filePath = ResolveFilePath(memoryBlock, globalDataFolder);
                long fileSize = new FileInfo(filePath).Length;

                if (fileSize != size)
                {
                    throw new InvalidDataException("Different size of a stored memory block (" + fileSize + " B != " + size + " B)");
                }

                BinaryReader reader = new BinaryReader(File.OpenRead(filePath));
                reader.Read(buffer, 0, size);
                reader.Close();

                memoryBlock.Fill(buffer);
            }
            catch (Exception e)
            {
                MyLog.WARNING.WriteLine("Memory block loading failed (" + memoryBlock.Owner.Name + "." + memoryBlock.Name + "): " + e.Message);
            }
        }
예제 #37
0
 internal override void ApplyAttribute(MyAbstractMemoryBlock memoryBlock)
 {
     memoryBlock.Dims = this;
 }