Пример #1
0
        /// <summary>
        /// Rotate the arrow to demonstrate orientation.
        /// </summary>
        /// <param name="contact">the contact to diagram</param>
        private void UpdateOrientationArrow(Contact contact)
        {
            bool isTag = contact.IsTagRecognized;

            UIElement relativeTo = this;
            double? contactOrientation = contact.GetOrientation(relativeTo);

            // Only show orientation arrow if this contact is recognized as a tag
            // and there is orientation data available.
            if (isTag && contactOrientation != null)
            {
                // Show the arrow.
                OrientationArrow.Visibility = Visibility.Visible;

                // Set the arrow orientation.
                ArrowRotateTransform.Angle = (double)contactOrientation;

                // Set the arrow position.
                Point position = contact.GetPosition(relativeTo);
                ArrowTranslateTransform.X = position.X;
                ArrowTranslateTransform.Y = position.Y;
            }
            else
            {
                // Hide the arrow.
                OrientationArrow.Visibility = Visibility.Hidden;
            }
        }
Пример #2
0
 public void addContact(Contact c, Grid parentGrid)
 {
     if(c.Tag.Type == TagType.Byte)
     {
         Point p = c.GetPosition(parentGrid);
         double orientation = c.GetOrientation(parentGrid);
         ContactDescriptor desc = new ContactDescriptor(c.Tag.Byte.Value, (int)p.X, (int) p.Y,(int) (orientation*10.0));
         contactDictionary.Add(c, desc);
         try
         {
             deviceInfoDictionary.Add(c.Tag.Byte.Value, new DeviceInformation(c.Tag.Byte.Value, ""));
         }catch (Exception e) {
             Console.WriteLine("Device With Byte Value %d already in deviceInfoDictionary", c.Tag.Byte.Value);
             Console.WriteLine(e.ToString());
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Update the text description with the most recent property values. Position
        /// the textbox so that it does not go offscreen (outside parentGrid). Also
        /// position the connecting line between the contact and the textbox.
        /// </summary>
        /// <param name="parentGrid">the container for this diagram-
        /// description text will not go outside of this container's bounds</param>
        /// <param name="contact">the contact to diagram</param>
        /// <param name="showContactInfo">Whether or not the contact info will be visible</param>
        private void UpdateDescription(Grid parentGrid, Contact contact, bool showContactInfo)
        {
            // Show or hide the contact info based on showContactInfo
            Description.Visibility = showContactInfo ? Visibility.Visible : Visibility.Hidden;
            ConnectingLine.Visibility = showContactInfo ? Visibility.Visible : Visibility.Hidden;

            if(!showContactInfo)
            {
                // Don't need to do the calculations if info isn't going to be shown
                return;
            }

            Point position = contact.GetPosition(parentGrid);
            Rect bounds = new Rect(0, 0, parentGrid.ActualWidth, parentGrid.ActualHeight);
            // Determine where around the contact the description should be displayed.
            // The default position is above and to the left.
            bool isAbove = true;
            bool isLeft = true;

            // Description text for tags is different than non-tags
            double descriptionXDistance;
            bool isTag = contact.IsTagRecognized;

            if (isTag)
            {
                descriptionXDistance = tagDescriptionXDistance;
            }
            else
            {
                descriptionXDistance = nonTagDescriptionXDistance;
            }

            // Put description below contact if default location is out of bounds.
            Rect upperLeftBounds = GetDescriptionBounds(position, isAbove, isLeft, descriptionXDistance, descriptionYDistance);
            if (upperLeftBounds.Top < bounds.Top)
            {
                isAbove = false;
            }

            // Put description to the right of the contact if default location is out of bounds.
            if (upperLeftBounds.Left < bounds.Left)
            {
                isLeft = false;
            }

            // Calculate the final bounds that will be used for the textbox position
            // based on the updated isAbove and isLeft values.
            Rect finalBounds = GetDescriptionBounds(position, isAbove, isLeft, descriptionXDistance, descriptionYDistance);
            Canvas.SetLeft(Description, finalBounds.Left);
            Canvas.SetTop(Description, finalBounds.Top);

            // Set the justification of the type in the textbox based
            // on which side of the contact the textbox is on.
            if(isLeft)
            {
                Description.TextAlignment = TextAlignment.Right;
            }
            else
            {
                Description.TextAlignment = TextAlignment.Left;
            }

            // Create the description string.
            StringBuilder descriptionText = new StringBuilder();
            descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "RecognizedTypes: {0}", GetContactTypeString(contact)));
            descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Id: {0}", contact.Id));

            // Use the "f1" format specifier to limit the amount of decimal positions shown.
            descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "X: {0}", position.X.ToString("f1", CultureInfo.InvariantCulture)));
            descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Y: {0}", position.Y.ToString("f1", CultureInfo.InvariantCulture)));

            // Display "null" for Orientation if the contact does not have an orientation value.
            string orientationString;
            double? contactOrientation = contact.GetOrientation(parentGrid);
            if(contactOrientation == null)
            {
                orientationString = "null";
            }
            else
            {
                orientationString = ((double)contactOrientation).ToString("f1", CultureInfo.InvariantCulture);
            }
            descriptionText.AppendLine(String.Format(CultureInfo.InvariantCulture, "Orientation: {0}", orientationString));

            if (contact.Tag.Type == TagType.Byte)
            {
                descriptionText.AppendLine("Value: " + contact.Tag.Byte.Value.ToString("X", CultureInfo.InvariantCulture));
            }
            else if (contact.Tag.Type == TagType.Identity)
            {
                descriptionText.AppendLine("Series: " + contact.Tag.Identity.Series.ToString("x16", CultureInfo.InvariantCulture));
                descriptionText.AppendLine("Value:  " + contact.Tag.Identity.Value.ToString("x16", CultureInfo.InvariantCulture));
            }

            // Update the description textbox.
            Description.Text = descriptionText.ToString();

            // Update the line that connects the contact to the description textbox.
            double x2;
            if(isLeft)
            {
                x2 = finalBounds.Right;
            }
            else
            {
                x2 = finalBounds.Left;
            }
            // Position (X1,Y1) is the center of the Contact.
            // Position (X2,Y2) is the edge of the description text box.
            ConnectingLine.X1 = position.X;
            ConnectingLine.Y1 = position.Y;
            ConnectingLine.X2 = x2;
            ConnectingLine.Y2 = finalBounds.Top + finalBounds.Height * 0.5;
        }
Пример #4
0
 public void updateContact(Contact c, Grid parentGrid)
 {
     if (c.Tag.Type == TagType.Byte)
        {
        ContactDescriptor desc;
        if (contactDictionary.Remove(c))
        {
            Point p = c.GetPosition(parentGrid);
            desc = new ContactDescriptor(c.Tag.Byte.Value, (int)p.X, (int)p.Y, (int)(c.GetOrientation(parentGrid)));
            contactDictionary.Add(c, desc);
        }
        }
 }