/// <summary>
 /// Zwraca in¿yniera odpowiedzialnego za maszynê lub narzêdzie
 /// reprezentowany przez dany obiekt.
 /// </summary>
 /// <param name="item">sprawdzany obiekt</param>
 /// <returns>in¿ynier odpowiedzialny</returns>
 public Engineer GetResponsible(VisualizationItem item)
 {
     if (item is Tool)
     {
         Tool t = (Tool)item;
         return(t.ToolCart.Responsible);
     }
     if (item is ToolCart)
     {
         ToolCart tc = (ToolCart)item;
         return(tc.Responsible);
     }
     if (item is MachineComponent)
     {
         MachineComponent c = (MachineComponent)item;
         if (c.Responsible != null)
         {
             return(c.Responsible);
         }
         if (c.Parent != null)
         {
             return(c.Parent.Responsible);
         }
     }
     return(null);
 }
Beispiel #2
0
        private void VisComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            if (item == null)
            {
                Debug.Assert(false);    // not expected
                return;
            }
            Debug.WriteLine("VisComboBox sel change: " + item.VisDescriptor.Ident);
            GenerateParamControls(item.VisDescriptor);

            // Configure the viewer controls from the visualization, or from the previous edit.
            if (mOrigVis != null)
            {
                initialXSlider.Value = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                           VisWireframeAnimation.P_EULER_ROT_X, 0);
                initialYSlider.Value = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                           VisWireframeAnimation.P_EULER_ROT_Y, 0);
                initialZSlider.Value = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                           VisWireframeAnimation.P_EULER_ROT_Z, 0);

                // Set this according to the object type, rather than P_IS_ANIMATED.  The two
                // should always be in sync.  This should help make it more obvious if they
                // aren't.
                IsWireframeAnimated = (mOrigVis is VisWireframeAnimation);

                // This should make it *really* obvious.
                Debug.Assert(IsWireframeAnimated == Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                                        VisWireframeAnimation.P_IS_ANIMATED, false));

                RotDeltaX = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                VisWireframeAnimation.P_DELTA_ROT_X, 0);
                RotDeltaY = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                VisWireframeAnimation.P_DELTA_ROT_Y, 0);
                RotDeltaZ = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                VisWireframeAnimation.P_DELTA_ROT_Z, 0);
                FrameCount = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                 VisWireframeAnimation.P_FRAME_COUNT, 1);
                FrameDelayMsec = Util.GetFromObjDict(mOrigVis.VisGenParams,
                                                     VisWireframeAnimation.P_FRAME_DELAY_MSEC, 100);
            }
            else
            {
                initialXSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_X, 0);
                initialYSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_Y, 0);
                initialZSlider.Value = GetLastValue(VisWireframeAnimation.P_EULER_ROT_Z, 0);
                IsWireframeAnimated  = GetLastValue(VisWireframeAnimation.P_IS_ANIMATED, false);
                RotDeltaX            = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_X, 0);
                RotDeltaY            = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_Y, 0);
                RotDeltaZ            = GetLastValue(VisWireframeAnimation.P_DELTA_ROT_Z, 0);
                FrameCount           = GetLastValue(VisWireframeAnimation.P_FRAME_COUNT, 1);
                FrameDelayMsec       = GetLastValue(VisWireframeAnimation.P_FRAME_DELAY_MSEC, 100);
            }

            UpdateControls();
        }
        private void VisComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            if (item == null)
            {
                Debug.Assert(false);    // not expected
                return;
            }
            Debug.WriteLine("VisComboBox sel change: " + item.VisDescriptor.Ident);
            GenerateParamControls(item.VisDescriptor);
            UpdateControls();
        }
        private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            Debug.Assert(item != null);
            ReadOnlyDictionary <string, object> valueDict = sLastParams = CreateVisGenParams();
            string trimTag = Visualization.TrimAndValidateTag(TagString, out bool isTagValid);

            Debug.Assert(isTagValid);
            NewVis             = new Visualization(trimTag, item.VisDescriptor.Ident, valueDict, mOrigVis);
            NewVis.CachedImage = (BitmapSource)previewImage.Source;

            sLastVisIdent = NewVis.VisGenIdent;

            DialogResult = true;
        }
        /// <summary>
        /// Generates the visualization that we will return as the result object, based on
        /// the currents state of the controls.
        /// </summary>
        /// <returns>New Visualization or VisWireframeAnimation object.</returns>
        private Visualization PrepResultVis()
        {
            VisualizationItem item = (VisualizationItem)visComboBox.SelectedItem;

            Debug.Assert(item != null);

            // Generate parameter dictionary.  Save a reference to it for next time.
            bool isWireframe = (item.VisDescriptor.VisualizationType == VisDescr.VisType.Wireframe);
            ReadOnlyDictionary <string, object> valueDict = CreateVisGenParams(isWireframe);

            sLastParams = valueDict;

            string trimTag = Visualization.TrimAndValidateTag(TagString, out bool isTagValid);

            Debug.Assert(isTagValid);
            Visualization vis;

            if (isWireframe && IsWireframeAnimated)
            {
                vis = new VisWireframeAnimation(trimTag, item.VisDescriptor.Ident, valueDict,
                                                mOrigVis, mWireObj);
            }
            else
            {
                vis = new Visualization(trimTag, item.VisDescriptor.Ident, valueDict, mOrigVis);
            }

            // Set the thumbnail image.
            if (isWireframe)
            {
                Debug.Assert(mWireObj != null);
                vis.CachedImage = Visualization.GenerateWireframeImage(mWireObj,
                                                                       Visualization.THUMBNAIL_DIM, valueDict);
            }
            else
            {
                Debug.Assert(mThumbnail != null);
                vis.CachedImage = mThumbnail;
            }

            return(vis);
        }
        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;
            }
        }
Beispiel #7
0
 /// <summary>
 /// Return the engineer that is responsible for the machine
 /// or tool that a simulated item represents.
 /// </summary>
 /// <param name="item">the interesting item</param>
 /// <returns>the responsible engineer</returns>
 public Engineer GetResponsible(VisualizationItem item)
 {
     return(item.Responsible);
 }
Beispiel #8
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;
            }
        }