public override void Run(RenderControl render) { if (!ReadData()) { return; } var material = MeshPhongMaterial.Create("cae-material"); material.GetTemplate().SetVertexColors(true); material.SetFaceSide(EnumFaceSide.DoubleSide); var position = BufferAttribute.Create(EnumAttributeSemantic.Position, EnumAttributeComponents.Three, mPositions); var color = BufferAttribute.Create(EnumAttributeSemantic.Color, EnumAttributeComponents.Three, mColors); BufferGeometry geometry = new BufferGeometry(); geometry.AddAttribute(position); geometry.AddAttribute(color); NormalCalculator.ComputeVertexNormals(geometry); var node = new PrimitiveSceneNode(geometry, EnumPrimitiveType.TRIANGLES, material); node.SetPickable(false); PaletteWidget pw = new PaletteWidget(); pw.Update(mColorTable); render.ShowSceneNode(pw); render.ShowSceneNode(node); }
} // Reparse /// <summary> /// TextModuleName return the Verilog module name for the text located AtLine and AtPosition /// </summary> /// <param name="AtLine"></param> /// <param name="AtPosition"></param> /// <returns></returns> public static string TextModuleName(int AtLine, int AtPosition) { string res = "global"; int hint = GetBufferHint(AtLine); //foreach (var thisBufferAttribute in BufferAttributes) for (int i = hint; i < BufferAttributes.Count - 1; i++) { BufferAttribute thisBufferAttribute = BufferAttributes[i]; if (thisBufferAttribute.LineNumber == AtLine) // we only need the line number (we don't use the hint, in case wit was zero!) { byte thisModuleNameKey = thisBufferAttribute.ModuleNameKey; ModuleNames.TryGetValue(thisModuleNameKey, out res); break; // no need to continue searching on foreach once we have an answer } // we're assuming thisBufferAttribute is inseeuqntial order; once LineNumber is greater than our target, give up. if (thisBufferAttribute.LineNumber > AtLine) { break; } } return(res); }
public bool Register(out CacheHandle handle, Buffer buffer, BufferAttribute attr) { UnsafeHelpers.SkipParamInit(out handle); // Validate pre-conditions. Assert.SdkRequiresNotNull(Entries); Assert.SdkRequiresNotNull(ref handle); // Get the entry. ref Entry entry = ref AcquireEntry(buffer, attr);
public bool Register(out CacheHandle handle, Buffer buffer, BufferAttribute attr) { UnsafeHelpers.SkipParamInit(out handle); // Validate pre-conditions. Assert.True(Entries != null); Assert.True(!Unsafe.IsNullRef(ref handle)); // Get the entry. ref Entry entry = ref AcquireEntry(buffer, attr);
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); camera = new PerspectiveCamera(50, control.Width / (float)control.Height, 1, 10); this.camera.Position.Z = 2; scene = new Scene(); // geometry const int triangles = 500; var geometry = new BufferGeometry(); var vertices = new BufferAttribute <float>(new float[triangles * 3 * 3], 3); for (var i = 0; i < vertices.length / vertices.ItemSize; i++) { vertices.SetXYZ(i, (float)(Mat.Random() - 0.5), (float)(Mat.Random() - 0.5), (float)(Mat.Random() - 0.5)); } geometry.AddAttribute("position", vertices); var colors = new BufferAttribute <float>(new float[triangles * 3 * 4], 4); for (var i = 0; i < colors.length / colors.ItemSize; i++) { colors.SetXYZW(i, Mat.Random(), Mat.Random(), Mat.Random(), Mat.Random()); } geometry.AddAttribute("color", colors); // material var material = new RawShaderMaterial() { Uniforms = new Uniforms { { "time", new Uniform() { { "type", "f" }, { "value", 1.0f } } } }, VertexShader = VertexShader, FragmentShader = FragmentShader, Side = Three.DoubleSide, Transparent = true, }; mesh = new Mesh(geometry, material); scene.Add(mesh); renderer.SetClearColor((Color)colorConvertor.ConvertFromString("#101010")); }
/// <summary> /// TextIsComment - is the text on line [AtLine] starting at position [AtPosition] a comment? /// </summary> /// <param name="AtLine"></param> /// <param name="AtPosition"></param> /// <returns></returns> public static bool TextIsComment(int AtLine, int AtPosition) { bool IsComment = false; //BufferAttribute LastBufferAttribute; lock (BufferAttributes) // reminder that this is rebuilt, (possibly in a thread) in editingBufferAttributes { int hint = 0; if ((BufferAttribute_at_LineNumber != null) && (BufferAttribute_at_LineNumber.Length > AtLine) && (AtLine >= 0)) { try { hint = VerilogGlobals.BufferAttribute_at_LineNumber[AtLine]; } catch (Exception ex) { // System.Diagnostics.Debug.WriteLine("ERROR: TextIsComment hint exception AtLine = {0}, Length={1}; message={2}", AtLine, BufferAttribute_at_LineNumber.Length, ex.Message); hint = 0; throw new Exception(ex.Message, ex.InnerException); } } else { // System.Diagnostics.Debug.WriteLine("TextIsComment hint not available in BufferAttribute_at_LineNumber"); } // now using hint for starting point, instead of: foreach (var thisBufferAttribute in BufferAttributes) for (int i = hint; i < BufferAttributes.Count - 1; i++) { BufferAttribute thisBufferAttribute = BufferAttributes[i]; if ((thisBufferAttribute.LineNumber == AtLine) && // TODO: can we stop looking when thisBufferAttribute.LineNumber > AtLine? (thisBufferAttribute.LineStart <= AtPosition) && ((AtPosition <= thisBufferAttribute.LineEnd) || (thisBufferAttribute.LineEnd == -1)) ) { IsComment = thisBufferAttribute.IsComment; break; // no need to continue searching on foreach once we have an answer } // we assume the BufferAttributes are in sequential order if (thisBufferAttribute.LineNumber > AtLine) { break; } } } return(IsComment); }
public void Initialize(CacheHandle handle, Buffer buffer, BufferAttribute attribute) { _handle = handle; _buffer = buffer; _attribute = attribute; }
// ReSharper disable once UnusedParameter.Local private int GetCacheSizeMin(BufferAttribute attr) { return(CacheSizeMin); }
// ReSharper disable once UnusedParameter.Local private int GetCacheCountMin(BufferAttribute attr) { return(CacheCountMin); }
/// <summary> /// Adds a <see cref="Buffer"/> to the cache. /// The buffer must have been allocated from this <see cref="IBufferManager"/>.<br/> /// The buffer must not be used after adding it to the cache. /// </summary> /// <param name="buffer">The buffer to cache.</param> /// <param name="attribute">The buffer attribute.</param> /// <returns>A handle that can be used to retrieve the buffer at a later time.</returns> public CacheHandle RegisterCache(Buffer buffer, BufferAttribute attribute) => DoRegisterCache(buffer, attribute);
public Buffer AllocateBuffer(int size, BufferAttribute attribute) => DoAllocateBuffer(size, attribute);
protected abstract CacheHandle DoRegisterCache(Buffer buffer, BufferAttribute attribute);
protected abstract Buffer DoAllocateBuffer(int size, BufferAttribute attribute);
public static void ReparseWork(ITextBuffer buffer, string targetFile) { int thisBufferVersion = 0; System.Diagnostics.Debug.WriteLine("Starting ReparseWork..."); // ensure our ParseStatus dictionary of ParseAttribute items has an item for our current file //if (!ParseStatus.ContainsKey(targetFile)) //{ // ParseStatus.Add(targetFile, new ParseAttribute()); //} lock (_synchronizationParseStatus) { VerilogGlobals.ParseStatusController.EnsureExists(targetFile); ParseStatus[targetFile].IsReparsing = true; //IsReparsing = true; if (buffer == null) { ParseStatus[targetFile].IsReparsing = false; // IsReparsing = false; return; } if (buffer.EditInProgress) { ParseStatus[targetFile].IsReparsing = false; // IsReparsing = false; return; } try { thisBufferVersion = buffer.CurrentSnapshot.Version.VersionNumber; } catch { thisBufferVersion = 0; } // if we could not determine a version ( = 0), or if the last time we reparsed was for this same buffer, then exit if ((thisBufferVersion == 0) || (ParseStatus[targetFile].LastReparseVersion == thisBufferVersion)) { ParseStatus[targetFile].IsReparsing = false; // IsReparsing = false; return; } } //if ((DateTime.Now - ProfileStart).TotalMilliseconds < 1000) //{ // ProfileStart = DateTime.Now; // return; // never reparse more than once a second //} ProfileStart = DateTime.Now; ITextSnapshot newSnapshot = buffer.CurrentSnapshot; string thisChar = ""; string lastChar = ""; string thisLine = ""; bool IsActiveLineComment = false; bool IsActiveBlockComment = false; int thisLineNumber = 0; double duration2; double duration3; editingBufferAttributes = new List <BufferAttribute>(); // re-initialize the global editingBufferAttributes used for editing // TODO lock on private object, see _synchronizationParseStatus lock (editingBufferAttributes) { BufferAttribute bufferAttribute = new BufferAttribute(); // // Reparse AppendBufferAttribute // void AppendBufferAttribute() { duration2 = (DateTime.Now - ProfileStart).TotalMilliseconds; bufferAttribute.LineNumber = thisLineNumber; // TODO move this to separate function if (thisModuleName != "") { if (!ModuleNames.ContainsValue(thisModuleName)) { byte thisNewKey; if (ModuleNames.Count < 256) { thisNewKey = (byte)ModuleNames.Count; } else { // TODO this is actually an error! do something here (popup warning?) thisNewKey = 0; // we'll (incorrectly) assume global space if there are more than 255 modules } ModuleNames.Add(thisNewKey, thisModuleName); ModuleKeys.Add(thisModuleName, thisNewKey); // build two dictionaries for runtime performance // create placeholder for variables if (!VerilogVariables.ContainsKey(thisModuleName)) { VerilogVariables.Add(thisModuleName, new Dictionary <string, VerilogTokenTypes> { }); } // ensure VerilogVariableHoverText has a dictionary for [thisModuleName] if (!VerilogVariableHoverText.ContainsKey(thisModuleName)) { VerilogVariableHoverText.Add(thisModuleName, new Dictionary <string, string> { }); } } bufferAttribute.ModuleNameKey = ModuleKeys[thisModuleName]; // ModuleNames.FirstOrDefault(x => x.Value == thisModuleName).Key; // thanks stackoverflow https://stackoverflow.com/questions/2444033/get-dictionary-key-by-value } editingBufferAttributes.Add(bufferAttribute); bufferAttribute = new BufferAttribute(); // set rollover params bufferAttribute.RoundBracketDepth = editingBufferAttributes[editingBufferAttributes.Count - 1].RoundBracketDepth; bufferAttribute.SquareBracketDepth = editingBufferAttributes[editingBufferAttributes.Count - 1].SquareBracketDepth; bufferAttribute.SquigglyBracketDepth = editingBufferAttributes[editingBufferAttributes.Count - 1].SquigglyBracketDepth; bufferAttribute.IsComment = IsActiveBlockComment; bufferAttribute.IsEmpty = true; // although we may have carried over some values, at this point it is still "empty" duration3 = (DateTime.Now - ProfileStart).TotalMilliseconds; } void CharParse() { for (int i = 0; i < thisLine.Length; i++) { thisChar = thisLine.Substring(i, 1); switch (thisChar) { case "[": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.SquareBracketDepth++; bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); } break; case "]": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); bufferAttribute.SquareBracketDepth = (bufferAttribute.SquareBracketDepth > 0) ? (--bufferAttribute.SquareBracketDepth) : 0; } break; case "(": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.RoundBracketDepth++; bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); } break; case ")": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); bufferAttribute.RoundBracketDepth = (bufferAttribute.RoundBracketDepth > 0) ? (--bufferAttribute.RoundBracketDepth) : 0; } break; case "{": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.SquigglyBracketDepth++; bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); } break; case "}": if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.LineStart = i; // brackets are only 1 char long, starting bufferAttribute.LineEnd = i; // and ending at the same positions AppendBufferAttribute(); bufferAttribute.SquigglyBracketDepth = (bufferAttribute.SquigglyBracketDepth > 0) ? (--bufferAttribute.SquigglyBracketDepth) : 0; } break; case "*": // encountered "/*" if (lastChar == "/") { if (IsActiveLineComment || IsActiveBlockComment) { // AttributesChanged = false; // if there's an active line comment - nothing changes! } else { bufferAttribute.LineStart = i - 1; // started on prior char // bufferAttribute.LineEnd TBD IsActiveBlockComment = true; bufferAttribute.IsComment = true; AppendBufferAttribute(); } } else { // AttributesChanged = false; } break; case "/": // check for block comment end "*/" if (lastChar == "*") { if (!IsActiveLineComment) { IsActiveBlockComment = false; bufferAttribute.LineEnd = i; // bufferAttribute.IsComment = false; AppendBufferAttribute(); } else { // AttributesChanged = false; } } else { // detect line comments "//" if (lastChar == "/" && !IsActiveLineComment) // encountered first "//" on a line, can only be ended by new line { IsActiveLineComment = true; bufferAttribute.IsComment = true; bufferAttribute.LineStart = i - 1; // comment actually starts on prior char bufferAttribute.LineEnd = -1; // a value of -1 means the entire line, regardless of actual length. // AttributesChanged = (i > 1); // the attribute of the line will not change if the first char starts a comment AppendBufferAttribute(); } else { // AttributesChanged = false; } } break; default: // we'll keep track of ending string segment that may need to be added below; note if something interesting is found, we'll overwrite these bufferAttribute values, above if (bufferAttribute.LineStart < 0) { bufferAttribute.LineStart = i; // the first time we end up here, is the start of the string that does not match one of the above special cases } bufferAttribute.LineEnd = i; // keep track of the end. break; } lastChar = thisChar; } // end of for loop looking at each char in line } VerilogGlobals.InitHoverBuilder(); double duration4 = (DateTime.Now - ProfileStart).TotalMilliseconds; // reminder bufferAttribute is pointing to the contents of the last item in editingBufferAttributes foreach (var line in newSnapshot.Lines) { //Thread.Sleep(10); thisLine = line.GetText(); thisLineNumber = line.LineNumber; // zero-based line numbers // parse the entire line for tokens double duration6 = (DateTime.Now - ProfileStart).TotalMilliseconds; LineParse(thisLine, thisLineNumber); double duration7 = (DateTime.Now - ProfileStart).TotalMilliseconds; // some things, like bracket depth, require us to look at each character... // we'll build a helper table to be able to lookup bracket depth at // arbitrary points CharParse(); double duration8 = (DateTime.Now - ProfileStart).TotalMilliseconds; lastChar = ""; // the lastChar is irrelevant when spanning multiple lines, as we are only using it for comment detection if (!bufferAttribute.IsEmpty) { AppendBufferAttribute(); } if (editingBufferAttributes.Count > 0) { // when we reach the end of the line, we reach the end of the line comment! IsActiveLineComment = false; } double duration9 = (DateTime.Now - ProfileStart).TotalMilliseconds; if (!BufferFirstParseComplete) { // TODO - this was supposed to help intial file load of large files, but does not seem to help. BufferAttributes = editingBufferAttributes; } } // foreach line } // lock editingBufferAttributes double duration5 = (DateTime.Now - ProfileStart).TotalMilliseconds; // TODO - do we need a final, end-of-file bufferAttribute (probably not) lock (_synchronizationParseStatus) { // in case we got here from someplace that set NeedReparse to true - reset to indicate completion: VerilogGlobals.ParseStatus[targetFile].NeedReparse = true; //VerilogGlobals.NeedReparse = false; VerilogGlobals.ParseStatus[targetFile].LastParseTime = DateTime.Now; //VerilogGlobals.LastParseTime = DateTime.Now; VerilogGlobals.ParseStatus[targetFile].LastReparseVersion = thisBufferVersion; } double duration = (DateTime.Now - ProfileStart).TotalMilliseconds; BufferAttributes = editingBufferAttributes; BufferFirstParseComplete = true; lock (_synchronizationParseStatus) { ParseStatus[targetFile].IsReparsing = false; } } // Reparse