Пример #1
0
        public static XmlElement ToXmlElement(this BrushBase brush)
        {
            XmlElement res = XmlElementGenerator.FromString("Wheat", brush);

            res.AppendChildren(XmlElementGenerator.FromNameFieldsOf(brush, "pen", "font"));
            return(res);
        }
Пример #2
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     {
         toolStripProgressBar1.ProgressBar.SetColor(ProgressBarColor.Yellow);
         toolStripProgressBar1.Visible = false;
         //注册消息打印
         GlobalMessage.Handlers += PrintStatus;
     }
     {
         annoLinkListPanel.Dock   = DockStyle.Left;
         annoLinkListPanel.Aspect = 0;
     }
     {
         annoPictureListPanel.Dock  = DockStyle.Right;
         annoPictureListPanel.Width = 200;
         annoPictureListPanel.Targets.Add(canva);
         annoPictureListPanel.Targets.Add(annoLinkListPanel);
     }
     {
         brushListPanel.Dock  = DockStyle.Right;
         brushListPanel.Width = 30;
         foreach (Type item in BrushBase.GetBrushTypes())
         {
             brushListPanel.Add(Assembly.GetExecutingAssembly().CreateInstance(item.FullName) as BrushBase);
         }
         brushListPanel.Targets.Add(canva);
         //注册取消画笔消息接收
         GlobalMessage.Handlers += BrushCancel;
     }
     {
         canva.Dock = DockStyle.Left;
     }
 }
Пример #3
0
        public static BrushBase Alloc()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BrushBase_Alloc();
            BrushBase             ret  = (cPtr == global::System.IntPtr.Zero) ? null : new BrushBase(cPtr, false);

            return(ret);
        }
        public void MethodFillColorChangeDelta(Color value)
        {
            // Selection
            this.SetValueWithChildrenOnlyGroup((layerage) =>
            {
                ILayer layer = layerage.Self;

                // Refactoring
                layer.IsRefactoringRender = true;
                layerage.RefactoringParentsRender();
                layer.Style.Fill = BrushBase.ColorBrush(value);
            });

            this.Invalidate(); // Invalidate
        }
Пример #5
0
    private void DrawBrushMaterials()
    {
        SerializedProperty uniqueIdentifierProperty = brushProperty.FindPropertyRelative("uniqueIdentifier");

        ushort    uniqueIdentifier = (ushort)uniqueIdentifierProperty.intValue;
        BrushBase brush            = BrushTypes.AllBrushes[uniqueIdentifier];

        // Set materials lenght.
        brushMaterialsProperty.arraySize = brush.SubmeshNames.Length;

        for (int i = 0; i < brushMaterialsProperty.arraySize; i++)
        {
            SerializedProperty materialProperty = brushMaterialsProperty.GetArrayElementAtIndex(i);

            EditorGUILayout.PropertyField(materialProperty, new GUIContent(brush.SubmeshNames[i]));
        }
    }
        public void MethodFillColorChangeCompleted(Color value)
        {
            // History
            LayersPropertyHistory history = new LayersPropertyHistory(HistoryType.LayersProperty_SetStyle_Fill);

            // Selection
            switch (this.FillOrStroke)
            {
            case FillOrStroke.Fill:
                this.Color = value;
                break;
            }

            this.Fill = BrushBase.ColorBrush(value);
            this.SetValueWithChildrenOnlyGroup((layerage) =>
            {
                ILayer layer = layerage.Self;

                // History
                var previous        = layer.Style.StartingFill.Clone();
                history.UndoAction += () =>
                {
                    // Refactoring
                    layer.IsRefactoringRender     = true;
                    layer.IsRefactoringIconRender = true;
                    layer.Style.Fill = previous.Clone();
                };

                // Refactoring
                layer.IsRefactoringRender     = true;
                layer.IsRefactoringIconRender = true;
                layerage.RefactoringParentsRender();
                layerage.RefactoringParentsIconRender();
                layer.Style.Fill = BrushBase.ColorBrush(value);

                this.StandardStyleLayerage = layerage;
            });

            // History
            this.HistoryPush(history);

            this.Invalidate(InvalidateMode.HD); // Invalidate
        }
Пример #7
0
    static BrushTypes()
    {
        AllBrushes = new Dictionary <ushort, BrushBase>();

        IEnumerable <Type> types = typeof(BrushBase).Assembly.GetTypes()
                                   .Where(x => typeof(BrushBase).IsAssignableFrom(x))
                                   .Where(x => x.IsAbstract == false);

        foreach (Type type in types)
        {
            BrushBase brush = (BrushBase)System.Activator.CreateInstance(type);

            if (AllBrushes.ContainsKey((ushort)brush.UniqueIdentifier))
            {
                throw new System.InvalidOperationException($"Unique ID for brush already exists!" +
                                                           $"\nExisting brush is {AllBrushes[(ushort)brush.UniqueIdentifier]} and new brush is {brush}");
            }

            AllBrushes.Add((ushort)brush.UniqueIdentifier, brush);
        }
    }
Пример #8
0
 public static object FromXmlElement(this BrushBase brush, XmlElement element)
 {
     XmlElementConverter.ToNameFieldsOf(brush, element.GetChildElements(), "pen", "font");
     return(brush);
 }
Пример #9
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BrushBase obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Пример #10
0
        /// <summary>
        /// Called when the volume is created in the editor.
        /// </summary>
        /// <param name="volume">The generated volume game object.</param>
        public override void OnCreateVolume(GameObject volume)
        {
            VolumetricAudioVolumeComponent component = volume.AddComponent <VolumetricAudioVolumeComponent>();

            // configure the volume:

            component.spatialDistance2D = spatialDistance2D;
            component.spatialDistance3D = spatialDistance3D;

            // if the user duplicated this brush the unique identifier may appear twice in the scene.
            // make sure we change our unique identifier in case this happens.
            if (FindObjectsOfType <BrushBase>().Any(brush => brush.Volume && brush.Volume != this && brush.Volume.GetType() == typeof(VolumetricAudioVolume) && ((VolumetricAudioVolume)brush.Volume).uniqueIdentifier == uniqueIdentifier))
            {
                // generate a unique identifier for this volumetric audio volume.
                uniqueIdentifier = GUID.Generate().ToString();
            }
            component.uniqueIdentifier = uniqueIdentifier;

            // check whether we have a parent volume and set or reset the parent identifier accordingly.
            parentIdentifier = "";
            // find this volume brush in the scene.
            BrushBase thisBrush = FindObjectsOfType <BrushBase>().Where(brush => brush.Volume == this).FirstOrDefault();

            if (thisBrush && thisBrush.transform.parent)
            {
                // find our parent brush (if there is one).
                BrushBase parentBrush = thisBrush.transform.parent.GetComponent <BrushBase>();
                if (parentBrush && parentBrush.Volume && parentBrush.Volume.GetType() == typeof(VolumetricAudioVolume))
                {
                    // we found a parent volumetric audio volume.
                    parentIdentifier = ((VolumetricAudioVolume)parentBrush.Volume).uniqueIdentifier;
                }
            }
            // store the parent identifier in the component.
            component.parentIdentifier = parentIdentifier;

            // we only create an audio source if we have a parent.
            if (!IsChildVolume)
            {
                // create a new game object to act as an audio source.
                GameObject audioSource = new GameObject("Audio Source");
                // parent it to the volume.
                audioSource.transform.SetParent(volume.transform, false);
                // add an audio source component.
                AudioSource audioSourceComponent = audioSource.AddComponent <AudioSource>();
                // hide the icon.
                RemoveEditorIcon(audioSource);

                // configure the audio source:

                // immediately start playing the sound.
                audioSourceComponent.playOnAwake = true;
                // always loop the sound.
                audioSourceComponent.loop = true;
                // enable full spatial blend (precaution against initial 2D sound on start).
                audioSourceComponent.spatialBlend = 1.0f;
                // set the user-defined volume properties.
                audioSourceComponent.clip = audioClip;
                audioSourceComponent.outputAudioMixerGroup = outputAudioMixerGroup;
                audioSourceComponent.bypassEffects         = bypassEffects;
                audioSourceComponent.bypassListenerEffects = bypassListenerEffects;
                audioSourceComponent.bypassReverbZones     = bypassReverbZones;
                audioSourceComponent.priority      = priority;
                audioSourceComponent.volume        = audioVolume;
                audioSourceComponent.pitch         = pitch;
                audioSourceComponent.reverbZoneMix = reverbZoneMix;
                audioSourceComponent.dopplerLevel  = dopplerLevel;
                audioSourceComponent.spread        = spread;
                audioSourceComponent.rolloffMode   = rolloffMode;
                audioSourceComponent.minDistance   = minDistance;
                audioSourceComponent.maxDistance   = maxDistance;
                if (rolloffMode == AudioRolloffMode.Custom)
                {
                    audioSourceComponent.SetCustomCurve(AudioSourceCurveType.CustomRolloff, customRolloff);
                }

                // editor preview tends to stop playing any audio sources that were previously here.
                // we force it to play this one at least unless they mute the game window.
                if (!Application.isPlaying && !EditorUtility.audioMasterMute)
                {
                    audioSourceComponent.Play();
                }
            }

            // update the collection of volumetric audio volume components in the scene.
            UpdateVolumetricAudioVolumeComponents();
        }
Пример #11
0
        /// <summary>
        /// Called when the inspector GUI is drawn in the editor.
        /// </summary>
        /// <param name="selectedVolumes">The selected volumes in the editor (for multi-editing).</param>
        /// <returns>True if a property changed or else false.</returns>
        public override bool OnInspectorGUI(Volume[] selectedVolumes)
        {
            SerializedObject serializedVolume = new SerializedObject(this);
            var  audioVolumes = selectedVolumes.Cast <VolumetricAudioVolume>();
            bool invalidate   = false;

            // asset store insists we add undo/redo support.
            // sadly the way volumes were implemented it's a bit of a nearly impossible task...
            // but we can re-create the audio here and hope it covers most cases.
            if (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
            {
                // we look at the current editor selection (which undo operations recover) to find brushes:
                BrushBase[] results;
                if ((results = Selection.GetFiltered <BrushBase>(SelectionMode.Unfiltered)).Any())
                {
                    // iterate through all the brushes that are currently selected:
                    for (int i = 0; i < results.Length; i++)
                    {
                        // if the brush has a volumetric audio volume then we have to act:
                        if (results[i].Volume && results[i].Volume.GetType() == typeof(VolumetricAudioVolume))
                        {
                            // this is where the hack comes in, find the hidden volume game object:
                            Transform volumeTransform = results[i].transform.Find(Constants.GameObjectVolumeComponentIdentifier);
                            if (volumeTransform)
                            {
                                // delete the audio source we create in "OnCreateVolume".
                                AudioSource audioSource = volumeTransform.GetComponentInChildren <AudioSource>();
                                if (audioSource)
                                {
                                    DestroyImmediate(audioSource.gameObject);
                                }
                                // delete the volumetric audio volume component we create in "OnCreateVolume".
                                DestroyImmediate(volumeTransform.GetComponent <VolumetricAudioVolumeComponent>());
                                // now call the sabrecsg method to pretend like we are a new volume, recreating our stuff:
                                ((VolumetricAudioVolume)results[i].Volume).OnCreateVolume(volumeTransform.gameObject);
                            }
                        }
                    }
                    return(false);
                }
            }

            for (int i = 0; i < selectedVolumes.Length; i++)
            {
                Undo.RecordObject(selectedVolumes[i], "Volumetric Audio Settings");
                // find the volume brush in the scene.
                BrushBase volumeBrush = FindObjectsOfType <BrushBase>().Where(brush => brush.Volume == selectedVolumes[i]).FirstOrDefault();
                if (volumeBrush)
                {
                    VolumetricAudioVolumeComponent component = volumeBrush.GetComponentInChildren <VolumetricAudioVolumeComponent>();
                    if (component)
                    {
                        Undo.RecordObject(component, "Volumetric Audio Settings");
                    }
                }
            }

            GUILayout.BeginVertical("Box");
            {
                EditorGUILayout.LabelField("Volumetric Geometry Options", EditorStyles.boldLabel);
                GUILayout.Space(4);

                EditorGUI.indentLevel = 1;
                GUILayout.BeginVertical();
                {
                    if (!IsChildVolume)
                    {
                        // display instructions on how to link multiple volumetric audio volumes together.
                        EditorGUILayout.HelpBox("You can combine multiple volumetric audio volumes together so that they will share the same audio source. This is useful for complex shapes like pipelines that shouldn't play the same sound multiple times at every twist and turn. To begin, simply parent volumetric audio volumes that you wish to combine under this one in the hierarchy.", MessageType.Info);
                        GUILayout.Space(8);
                    }
                    else
                    {
                        // display notifications that this volumetric audio volume is now a child volume.
                        EditorGUILayout.HelpBox("This volumetric audio volume is a child and does not have its own audio source.", MessageType.Info);
                        GUILayout.Space(8);

                        // provide button to select the parent volume.
                        if (GUILayout.Button("Select Parent"))
                        {
                            // find this volume brush in the scene.
                            BrushBase thisBrush = FindObjectsOfType <BrushBase>().Where(brush => brush.Volume == this).FirstOrDefault();
                            if (thisBrush && thisBrush.transform.parent)
                            {
                                Selection.objects = new Object[] { thisBrush.transform.parent.gameObject }
                            }
                            ;
                        }
                    }
                }

                GUILayout.EndVertical();
                EditorGUI.indentLevel = 0;
            }
            GUILayout.EndVertical();

            // child volumes do not have audio source options.
            if (!IsChildVolume)
            {
                GUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("Audio Source Options", EditorStyles.boldLabel);
                    GUILayout.Space(4);

                    EditorGUI.indentLevel = 1;
                    GUILayout.BeginVertical();
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.ObjectField(serializedVolume.FindProperty("audioClip"), new GUIContent("Audio Clip", "The audio clip played by the volumetric audio source."));
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedVolume.ApplyModifiedProperties();
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.audioClip = audioClip;
                            }
                            invalidate = true;
                        }

                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.ObjectField(serializedVolume.FindProperty("outputAudioMixerGroup"), new GUIContent("Output Mixer Group", "Set whether the sound should play through an Audio Mixer first or directly to the Audio Listener."));
                        if (EditorGUI.EndChangeCheck())
                        {
                            serializedVolume.ApplyModifiedProperties();
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.outputAudioMixerGroup = outputAudioMixerGroup;
                            }
                            invalidate = true;
                        }

                        bool previousBoolean;
                        bypassEffects = EditorGUILayout.Toggle(new GUIContent("Bypass Effects", "Bypass/ignore any applied effects on the volumetric audio source."), previousBoolean = bypassEffects);
                        if (bypassEffects != previousBoolean)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.bypassEffects = bypassEffects;
                            }
                            invalidate = true;
                        }

                        bypassListenerEffects = EditorGUILayout.Toggle(new GUIContent("Bypass Listener Effects", "Bypass/ignore any applied effects from the Audio Listener."), previousBoolean = bypassListenerEffects);
                        if (bypassListenerEffects != previousBoolean)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.bypassListenerEffects = bypassListenerEffects;
                            }
                            invalidate = true;
                        }

                        bypassReverbZones = EditorGUILayout.Toggle(new GUIContent("Bypass Reverb Zones", "Bypass/ignore any reverb zones."), previousBoolean = bypassReverbZones);
                        if (bypassReverbZones != previousBoolean)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.bypassReverbZones = bypassReverbZones;
                            }
                            invalidate = true;
                        }

                        int previousInteger;
                        priority = EditorGUILayout.IntSlider(new GUIContent("Priority", "Sets the priority of the volumetric audio source. Note that a sound with a larger priority value will more likely be stolen by sounds with smaller priority values."), previousInteger = priority, 0, 256);
                        if (priority != previousInteger)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.priority = priority;
                            }
                            invalidate = true;
                        }

                        float previousFloat;
                        audioVolume = EditorGUILayout.Slider(new GUIContent("Volume", "Sets the overall volume of the sound."), previousFloat = audioVolume, 0, 1);
                        if (audioVolume != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.audioVolume = audioVolume;
                            }
                            invalidate = true;
                        }

                        pitch = EditorGUILayout.Slider(new GUIContent("Pitch", "Sets the frequency of the sound. Use this to slow down or speed up the sound."), previousFloat = pitch, -3, 3);
                        if (pitch != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.pitch = pitch;
                            }
                            invalidate = true;
                        }

                        reverbZoneMix = EditorGUILayout.Slider(new GUIContent("Reverb Zone Mix", "Sets how much of the signal this volumetric audio source is mixing into the global reverb associated with the zones. [0, 1] is the linear range (like sound volume) while [1, 1.1] lets you boost the reverb mix by 10 dB."), previousFloat = reverbZoneMix, 0, 1.1f);
                        if (reverbZoneMix != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.reverbZoneMix = reverbZoneMix;
                            }
                            invalidate = true;
                        }

                        dopplerLevel = EditorGUILayout.Slider(new GUIContent("Doppler Level", "Specifies how much the pitch is changed based on the relative velocity between the audio listener and the volumetric audio source."), previousFloat = dopplerLevel, 0, 5);
                        if (dopplerLevel != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.dopplerLevel = dopplerLevel;
                            }
                            invalidate = true;
                        }

                        spread = EditorGUILayout.IntSlider(new GUIContent("Spread", "Sets the spread of a 3D sound in speaker space (prevents having sound all in one ear sometimes)."), previousInteger = spread, 0, 360);
                        if (spread != previousInteger)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.spread = spread;
                            }
                            invalidate = true;
                        }

                        AudioRolloffMode previousAudioRolloffMode;
                        rolloffMode = (AudioRolloffMode)EditorGUILayout.EnumPopup(new GUIContent("Volume Rolloff", "Which type of volume rolloff curve to use for the volumetric audio source."), previousAudioRolloffMode = rolloffMode);
                        if (rolloffMode != previousAudioRolloffMode)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.rolloffMode = rolloffMode;
                            }
                            invalidate = true;
                        }

                        if (rolloffMode == AudioRolloffMode.Custom)
                        {
                            EditorGUI.BeginChangeCheck();
                            customRolloff = EditorGUILayout.CurveField(new GUIContent("Custom Rolloff", "The custom rolloff animation curve to use for the volumetric audio source."), customRolloff);
                            if (EditorGUI.EndChangeCheck())
                            {
                                foreach (VolumetricAudioVolume volume in audioVolumes)
                                {
                                    volume.customRolloff = customRolloff;
                                }
                                invalidate = true;
                            }
                        }

                        minDistance = EditorGUILayout.FloatField(new GUIContent("Min Distance", "The minimum distance where the volumetric audio source volume stays the loudest possible. Outside of this minimum distance it begins to attenuate."), previousFloat = minDistance);
                        if (minDistance < 0)
                        {
                            minDistance = 0;
                        }
                        if (minDistance != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.minDistance = minDistance;
                            }
                            invalidate = true;
                        }

                        maxDistance = EditorGUILayout.FloatField(new GUIContent("Max Distance", "The maximum distance the volumetric audio source stops attenuating at."), previousFloat = maxDistance);
                        if (maxDistance < minDistance)
                        {
                            maxDistance = minDistance + 0.001f;
                        }
                        if (maxDistance != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.maxDistance = maxDistance;
                            }
                            invalidate = true;
                        }
                    }
                    GUILayout.EndVertical();
                    EditorGUI.indentLevel = 0;
                }
                GUILayout.EndVertical();

                GUILayout.BeginVertical("Box");
                {
                    EditorGUILayout.LabelField("Volumetric Audio Options", EditorStyles.boldLabel);
                    GUILayout.Space(4);

                    EditorGUI.indentLevel = 1;
                    GUILayout.BeginVertical();
                    {
                        float previousFloat;
                        spatialDistance2D = EditorGUILayout.FloatField(new GUIContent("Spatial 2D Distance", "The spatial 2D distance affects the distance from the volume before the volumetric sound fully transitions to 2D (inner radius)."), previousFloat = spatialDistance2D);
                        if (spatialDistance2D < 0)
                        {
                            spatialDistance2D = 0;
                        }
                        if (spatialDistance2D != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.spatialDistance2D = spatialDistance2D;
                            }
                            invalidate = true;
                        }

                        spatialDistance3D = EditorGUILayout.FloatField(new GUIContent("Spatial 3D Distance", "The spatial 3D distance affects the distance from the volume before the volumetric sound fully transitions to 3D (outer radius)."), previousFloat = spatialDistance3D);
                        if (spatialDistance3D < spatialDistance2D)
                        {
                            spatialDistance3D = spatialDistance2D;
                        }
                        if (spatialDistance3D != previousFloat)
                        {
                            foreach (VolumetricAudioVolume volume in audioVolumes)
                            {
                                volume.spatialDistance3D = spatialDistance3D;
                            }
                            invalidate = true;
                        }
                    }

                    GUILayout.EndVertical();
                    EditorGUI.indentLevel = 0;
                }
                GUILayout.EndVertical();
            }

            return(invalidate);
        }
Пример #12
0
        private async void AnnoLoaderForm_Load(object sender, EventArgs e)
        {
            {
                toolStripProgressBar1.ProgressBar.SetColor(ProgressBarColor.Yellow);
                toolStripProgressBar1.Visible = false;
                //注册消息打印
                GlobalMessage.Handlers += PrintStatus;
            }
            {
                textBox1.MouseUp += TextBox1_MouseUp;;
            }
            {
                brushListPanel.Dock  = DockStyle.Left;
                brushListPanel.Width = 30;
                foreach (Type item in BrushBase.GetBrushTypes())
                {
                    brushListPanel.Add(Assembly.GetExecutingAssembly().CreateInstance(item.FullName) as BrushBase);
                }

                brushListPanel.ItemSelected += (_sender, _item, _e) =>
                {
                    if (_item == null)
                    {
                        return;
                    }
                    listView1.Columns.Clear();
                    listView1.Groups.Clear();
                    listView1.Items.Clear();

                    foreach (FieldInfo field in _item.AnnoType.GetFields(FieldsOrder.BaseToSub))
                    {
                        listView1.Columns.Add($"{field.Name}<{field.FieldType.Name}>");
                    }

                    listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                    TextBox2_TextChanged(this, EventArgs.Empty);
                };
                brushListPanel.Index = 0;
            }

            try
            {
                using (StreamReader sr = new StreamReader(AnnoFilePath))
                {
                    GlobalMessage.Add("status", "正在读取文本...");
                    FileContext = await sr.ReadToEndAsync();

                    GlobalMessage.Add("status", "正在加载文本...");
                    string display = FileContext.Substring(0, Math.Min(textBox1.MaxLength, FileContext.Length)).Replace("\n", "\r\n");
                    textBox1.Text = display;
                    if (FileContext.Length > textBox1.MaxLength)
                    {
                        GlobalMessage.Add("status", $"就绪,显示文本前{ textBox1.MaxLength }个字符");
                    }
                    else
                    {
                        GlobalMessage.Add("status", "就绪");
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                GlobalMessage.Add("exception", ex.Message);
            }
        }
Пример #13
0
        /// <summary>
        /// 给定若干个字符串和若干个正则表达式,生成若干个标注实例。
        /// </summary>
        /// <param name="brush">用来确定标注类型的画笔类实例</param>
        /// <param name="inputs">给定字符串</param>\
        /// <param name="patterns">正则表达式</param>
        /// <param name="fields">与正则表达式对应的字段</param>
        /// <param name="abort">提前终止条件</param>
        /// <param name="progress">进度报告</param>
        /// <returns>返回若干个标注实例</returns>
        /// <remarks>
        /// <para>生成规则(以单个字符串为例):</para>
        /// <para>1.按照标注类型的字段顺序,逐一和正则表达式相对应。字段数小于表达式数时,多余表达式忽略;字段数大于表达式数时,无表达式对应的字段始终为默认值。</para>
        /// <para>2.每个正则表达式多次提取,假设最终生成n个标注实例,则理论上每个正则都应匹配到1个或n个结果。</para>
        /// <para>3.若某个正则表达式匹配到1个结果,则n个标注实例的该字段都为该结果。</para>
        /// <para>4.若某个正则表达式匹配到1<x<n个结果,则前x个标注实例的该字段对应赋值,后(n-x)个标注实例该字段为空。</para>
        /// </remarks>
        private AnnotationBase[] GetAnnoFromRegex(BrushBase brush, string[] inputs, string[] patterns, FieldInfo[] fields = null,
                                                  Process.Abort abort = null, IProgress <int> progress = null)
        {
            if (brush == null)
            {
                return(null);
            }
            if (fields == null)
            {
                fields = brush.AnnoType.GetFields();
            }

            //所有有效的正则表达式产生的匹配结果(集合长度等同于有效字段个数)
            MatchCollection[] matches = new MatchCollection[Math.Min(fields.Length, patterns.Length)];

            List <AnnotationBase> result = new List <AnnotationBase>();

            foreach (string input in inputs)
            {
                if (abort != null && abort())
                {
                    return(null);
                }

                //正则匹配
                int maxLength = 0;
                for (int i = 0; i < matches.Length; i++)
                {
                    if (abort != null && abort())
                    {
                        return(null);
                    }
                    if (patterns[i].Length <= 0)
                    {
                        continue;
                    }

                    matches[i] = Regex.Matches(input, patterns[i]);
                    if (matches[i].Count > maxLength)
                    {
                        maxLength = matches[i].Count;
                    }
                }


                for (int i = 0; i < maxLength; i++)
                {
                    if (abort != null && abort())
                    {
                        return(null);
                    }

                    object[] values = new object[fields.Length];
                    for (int j = 0; j < values.Length; j++)
                    {
                        if (j >= matches.Length || matches[j] == null)
                        {
                            continue;
                        }

                        if (i < matches[j].Count)
                        {
                            values[j] = matches[j][i].Value;
                        }
                        else if (matches[j].Count == 1)
                        {
                            values[j] = matches[j][0].Value;
                        }
                    }
                    result.Add(brush.CreatAnnotation().SetFieldsValues(fields, values));
                }

                if (progress != null)
                {
                    progress.Report((Array.IndexOf(inputs, input) + 1) * 100 / inputs.Length);
                }
            }

            return(result.ToArray());
        }