public ShowWireframeAnimation(Window owner, WireframeObject wireObj, ReadOnlyDictionary <string, object> parms) { InitializeComponent(); Owner = owner; mWireObj = wireObj; mCurX = mInitialX = Util.GetFromObjDict(parms, VisWireframeAnimation.P_EULER_ROT_X, 0); mCurY = mInitialY = Util.GetFromObjDict(parms, VisWireframeAnimation.P_EULER_ROT_Y, 0); mCurZ = mInitialZ = Util.GetFromObjDict(parms, VisWireframeAnimation.P_EULER_ROT_Z, 0); mDeltaX = Util.GetFromObjDict(parms, VisWireframeAnimation.P_DELTA_ROT_X, 0); mDeltaY = Util.GetFromObjDict(parms, VisWireframeAnimation.P_DELTA_ROT_Y, 0); mDeltaZ = Util.GetFromObjDict(parms, VisWireframeAnimation.P_DELTA_ROT_Z, 0); mFrameCount = Util.GetFromObjDict(parms, VisWireframeAnimation.P_FRAME_COUNT, 1); mDoPersp = Util.GetFromObjDict(parms, VisWireframe.P_IS_PERSPECTIVE, true); mDoBfc = Util.GetFromObjDict(parms, VisWireframe.P_IS_BFC_ENABLED, false); mDoRecenter = Util.GetFromObjDict(parms, VisWireframe.P_IS_RECENTERED, false); int intervalMsec = Util.GetFromObjDict(parms, VisWireframeAnimation.P_FRAME_DELAY_MSEC, 100); mCurFrame = 0; mTimer = new DispatcherTimer(DispatcherPriority.Render); mTimer.Interval = TimeSpan.FromMilliseconds(intervalMsec); mTimer.Tick += Tick; }
public ExportVisualization(Window owner, Visualization vis, WireframeObject wireObj, string fileNameBase) { InitializeComponent(); Owner = owner; DataContext = this; mVis = vis; mWireObj = wireObj; mFileNameBase = fileNameBase; OutputSizeList = new List <OutputSize>(); // Normally, bitmap and wireframe visualizations don't really differ, because // we're just working off the cached image rendering. It matters for us though, // so we need to see if a wireframe-only parameter exists. bool isWireframe = (vis is VisWireframeAnimation) || vis.VisGenParams.ContainsKey(VisWireframeAnimation.P_IS_ANIMATED); IsBitmap = !isWireframe; if (isWireframe) { int dim = 64; while (dim <= 1024) { OutputSizeList.Add(new OutputSize(dim, dim)); dim *= 2; } } else { int baseWidth = (int)vis.CachedImage.Width; int baseHeight = (int)vis.CachedImage.Height; // ensure there's at least one entry, then add other options OutputSizeList.Add(new OutputSize(baseWidth, baseHeight)); int mult = 2; while (baseWidth * mult < 2048 && baseHeight * mult < 2048) { OutputSizeList.Add(new OutputSize(baseWidth * mult, baseHeight * mult)); mult *= 2; } } sizeComboBox.SelectedIndex = 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; } }