private void UpdateControls()
        {
            IsValid = true;

            if (!int.TryParse(FrameDelayTimeMsec, out int frameDelay) ||
                frameDelay <= 0 || frameDelay > MAX_FRAME_DELAY)
            {
                mFrameDelayIntMsec   = -1;
                FrameDelayLabelBrush = mErrorLabelColor;
                IsValid = false;
            }
            else
            {
                mFrameDelayIntMsec   = frameDelay;
                FrameDelayLabelBrush = mDefaultLabelColor;
            }

            bool isSourceItemSelected = (visSourceGrid.SelectedItem != null);
            bool isAnimItemSelected   = (visAnimGrid.SelectedItem != null);

            IsAddEnabled    = VisSourceItems.Count > 0 && isSourceItemSelected;
            IsRemoveEnabled = VisAnimItems.Count > 0 && isAnimItemSelected;
            IsUpEnabled     = isAnimItemSelected && visAnimGrid.SelectedIndex != 0;
            IsDownEnabled   = isAnimItemSelected &&
                              visAnimGrid.SelectedIndex != VisAnimItems.Count - 1;
            IsPreviewEnabled = VisAnimItems.Count > 0;

            IsValid &= IsPreviewEnabled;    // don't allow animations with no frames

            string        trimTag = Visualization.TrimAndValidateTag(TagString, out bool tagOk);
            Visualization match   =
                EditVisualizationSet.FindVisualizationByTag(mEditedList, trimTag);

            if (match != null && (mOrigAnim == null || trimTag != mOrigAnim.Tag))
            {
                // Another vis already has this tag.  We're checking the edited list, so we'll
                // be current with edits to this or other Visualizations in the same set.
                tagOk = false;
            }
            if (!tagOk)
            {
                TagLabelBrush = mErrorLabelColor;
                IsValid       = false;
            }
            else
            {
                TagLabelBrush = mDefaultLabelColor;
            }

            RefreshAnim();
        }
        private void UpdateControls()
        {
            IsValid = true;

            foreach (ParameterValue pv in ParameterList)
            {
                pv.ForegroundBrush = mDefaultLabelColor;
                if (pv.Descr.CsType == typeof(bool))
                {
                    // always fine
                    continue;
                }
                else if (pv.Descr.CsType == typeof(int))
                {
                    // integer, possibly Offset special
                    bool ok = ParseIntObj(pv.Value, pv.Descr.Special, out int intVal);
                    if (ok && (intVal < (int)pv.Descr.Min || intVal > (int)pv.Descr.Max))
                    {
                        // TODO(someday): make the range text red instead of the label
                        ok = false;
                    }
                    if (!ok)
                    {
                        pv.ForegroundBrush = mErrorLabelColor;
                        IsValid            = false;
                    }
                }
                else if (pv.Descr.CsType == typeof(float))
                {
                    // float
                    bool ok = ParseFloatObj(pv.Value, out float floatVal);
                    if (ok && (floatVal < (float)pv.Descr.Min || floatVal > (float)pv.Descr.Max))
                    {
                        ok = false;
                    }
                    if (!ok)
                    {
                        pv.ForegroundBrush = mErrorLabelColor;
                        IsValid            = false;
                    }
                }
                else
                {
                    // unexpected
                    Debug.Assert(false);
                }
            }

            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            BitmapDimensions = "?";
            if (!IsValid || item == null)
            {
                previewImage.Source = sBadParamsImage;
            }
            else
            {
                // Invoke the plugin.
                PluginErrMessage = string.Empty;

                IVisualization2d vis2d;
                try {
                    IPlugin_Visualizer plugin =
                        (IPlugin_Visualizer)mProject.GetPlugin(item.ScriptIdent);
                    vis2d = plugin.Generate2d(item.VisDescriptor, CreateVisGenParams());
                    if (vis2d == null)
                    {
                        Debug.WriteLine("Vis generator returned null");
                    }
                } catch (Exception ex) {
                    Debug.WriteLine("Vis generation failed: " + ex);
                    vis2d = null;
                    if (string.IsNullOrEmpty(LastPluginMessage))
                    {
                        LastPluginMessage = ex.Message;
                    }
                }
                if (vis2d == null)
                {
                    previewImage.Source = sBadParamsImage;
                    if (!string.IsNullOrEmpty(LastPluginMessage))
                    {
                        // Report the last message we got as an error.
                        PluginErrMessage = LastPluginMessage;
                    }
                    else
                    {
                        PluginErrMessage = (string)FindResource("str_VisGenFailed");
                    }
                    IsValid = false;
                }
                else
                {
                    previewImage.Source = Visualization.ConvertToBitmapSource(vis2d);
                    BitmapDimensions    = string.Format("{0}x{1}",
                                                        previewImage.Source.Width, previewImage.Source.Height);
                }
            }

            string        trimTag = Visualization.TrimAndValidateTag(TagString, out bool tagOk);
            Visualization match   =
                EditVisualizationSet.FindVisualizationByTag(mEditedList, trimTag);

            if (match != null && (mOrigVis == null || trimTag != mOrigVis.Tag))
            {
                // Another vis already has this tag.  We're checking the edited list, so we'll
                // be current with edits to this or other Visualizations in the same set.
                tagOk = false;
            }
            if (!tagOk)
            {
                TagLabelBrush = mErrorLabelColor;
                IsValid       = false;
            }
            else
            {
                TagLabelBrush = mDefaultLabelColor;
            }
        }
Ejemplo n.º 3
0
        private void UpdateControls()
        {
            IsValid = true;

            foreach (ParameterValue pv in ParameterList)
            {
                pv.ForegroundBrush = mDefaultLabelColor;
                if (pv.Descr.CsType == typeof(bool))
                {
                    // always fine
                    continue;
                }
                else if (pv.Descr.CsType == typeof(int))
                {
                    // integer, possibly Offset special
                    bool ok = ParseIntObj(pv.Value, pv.Descr.Special, out int intVal);
                    if (ok && (intVal < (int)pv.Descr.Min || intVal > (int)pv.Descr.Max))
                    {
                        // TODO(someday): make the range text red instead of the label
                        ok = false;
                    }
                    if (!ok)
                    {
                        pv.ForegroundBrush = mErrorLabelColor;
                        IsValid            = false;
                    }
                }
                else if (pv.Descr.CsType == typeof(float))
                {
                    // float
                    bool ok = ParseFloatObj(pv.Value, out float floatVal);
                    if (ok && (floatVal < (float)pv.Descr.Min || floatVal > (float)pv.Descr.Max))
                    {
                        ok = false;
                    }
                    if (!ok)
                    {
                        pv.ForegroundBrush = mErrorLabelColor;
                        IsValid            = false;
                    }
                }
                else
                {
                    // unexpected
                    Debug.Assert(false);
                }
            }

            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            BitmapDimensions       = "?";
            previewGrid.Background = null;
            wireframePath.Data     = new GeometryGroup();
            if (!IsValid || item == null)
            {
                previewImage.Source = sBadParamsImage;
            }
            else
            {
                // Invoke the plugin.
                PluginErrMessage = string.Empty;

                IVisualization2d                    vis2d   = null;
                IVisualizationWireframe             visWire = null;
                ReadOnlyDictionary <string, object> parms   = null;
                try {
                    IPlugin_Visualizer plugin =
                        (IPlugin_Visualizer)mProject.GetPlugin(item.ScriptIdent);
                    if (item.VisDescriptor.VisualizationType == VisDescr.VisType.Bitmap)
                    {
                        parms = CreateVisGenParams(false);
                        vis2d = plugin.Generate2d(item.VisDescriptor, parms);
                        if (vis2d == null)
                        {
                            Debug.WriteLine("Vis2d generator returned null");
                        }
                    }
                    else if (item.VisDescriptor.VisualizationType == VisDescr.VisType.Wireframe)
                    {
                        parms = CreateVisGenParams(true);
                        IPlugin_Visualizer_v2 plugin2 = (IPlugin_Visualizer_v2)plugin;
                        visWire = plugin2.GenerateWireframe(item.VisDescriptor, parms);
                        if (visWire == null)
                        {
                            Debug.WriteLine("VisWire generator returned null");
                        }
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                } catch (Exception ex) {
                    Debug.WriteLine("Vis generation failed: " + ex);
                    if (string.IsNullOrEmpty(LastPluginMessage))
                    {
                        LastPluginMessage = ex.Message;
                    }
                }
                bool failed = false;
                if (vis2d == null && visWire == null)
                {
                    failed = true;
                }
                else if (vis2d != null)
                {
                    previewGrid.Background = null;
                    previewImage.Source    = Visualization.ConvertToBitmapSource(vis2d);
                    wireframePath.Data     = new GeometryGroup();
                    BitmapDimensions       = string.Format("{0}x{1}",
                                                           previewImage.Source.Width, previewImage.Source.Height);

                    mThumbnail = (BitmapSource)previewImage.Source;
                }
                else
                {
                    WireframeObject wireObj = WireframeObject.Create(visWire);
                    if (wireObj != null)
                    {
                        previewGrid.Background = Brushes.Black;
                        previewImage.Source    = Visualization.BLANK_IMAGE;
                        double dim = Math.Floor(
                            Math.Min(previewGrid.ActualWidth, previewGrid.ActualHeight));
                        wireframePath.Data =
                            Visualization.GenerateWireframePath(wireObj, dim, parms);
                        BitmapDimensions = "n/a";

                        mWireObj = wireObj;
                    }
                    else
                    {
                        failed = true;
                    }
                }
                if (failed)
                {
                    previewImage.Source = sBadParamsImage;
                    if (!string.IsNullOrEmpty(LastPluginMessage))
                    {
                        // Report the last message we got as an error.
                        PluginErrMessage = LastPluginMessage;
                    }
                    else
                    {
                        // Generic failure message.
                        PluginErrMessage = (string)FindResource("str_VisGenFailed");
                    }
                    IsValid = false;
                }
            }

            string        trimTag = Visualization.TrimAndValidateTag(TagString, out bool tagOk);
            Visualization match   =
                EditVisualizationSet.FindVisualizationByTag(mEditedList, trimTag);

            if (match != null && (mOrigVis == null || trimTag != mOrigVis.Tag))
            {
                // Another vis already has this tag.  We're checking the edited list, so we'll
                // be current with edits to this or other Visualizations in the same set.
                tagOk = false;
            }
            if (!tagOk)
            {
                TagLabelBrush = mErrorLabelColor;
                IsValid       = false;
            }
            else
            {
                TagLabelBrush = mDefaultLabelColor;
            }
        }