示例#1
0
        /// <summary>
        /// Renders the list of primitives to the device.
        /// </summary>
        /// <param name="device">The device to use for rendering the primitives.</param>
        /// <param name="renderList">The list of primitives to render.</param>
        protected virtual void Render(Device device, ArrayList renderList)
        {
            PointF[] points = (PointF[])renderList.ToArray(typeof(PointF));
            device.VertexFormat = CustomVertex.PositionColored.Format;

            for (int i = 0; i < renderListTypes.Count; i++)
            {
                PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[i];
                int numVerts          = (pti.End - pti.Start + 1);

                CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[numVerts];
                P3Util.CreateColoredVertexList(colVerts, points, pti.Start, 0, numVerts, pti.Color);

                switch (pti.Type)
                {
                case PrimitiveType.TriangleFan:
                    device.DrawUserPrimitives(PrimitiveType.TriangleFan, colVerts.Length - 2, colVerts);
                    break;

                case PrimitiveType.TriangleList:
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, colVerts.Length / 3, colVerts);
                    break;

                case PrimitiveType.TriangleStrip:
                    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, colVerts.Length - 2, colVerts);
                    break;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Renders a portion the vertex buffer to the device.
        /// </summary>
        /// <param name="device">The device to use for rendering the primitives.</param>
        /// <param name="vb">The vertex buffer to render.</param>
        /// <param name="start">The start index of the vertices to render.</param>
        /// <param name="end">The end index of the vertices to render.</param>
        protected virtual void Render(Device device, VertexBuffer vb, int start, int end)
        {
            device.SetStreamSource(0, vb, 0);
            device.VertexFormat = CustomVertex.PositionColored.Format;

            for (int i = start; i <= end; i++)
            {
                PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[i];
                int numVerts          = (pti.End - pti.Start + 1);

                switch (pti.Type)
                {
                case PrimitiveType.LineStrip:
                    device.DrawPrimitives(PrimitiveType.LineStrip, pti.Start, numVerts - 1);
                    break;

                case PrimitiveType.TriangleFan:
                    device.DrawPrimitives(PrimitiveType.TriangleFan, pti.Start, numVerts - 2);
                    break;

                case PrimitiveType.TriangleList:
                    device.DrawPrimitives(PrimitiveType.TriangleList, pti.Start, numVerts / 3);
                    break;

                case PrimitiveType.TriangleStrip:
                    device.DrawPrimitives(PrimitiveType.TriangleStrip, pti.Start, numVerts - 2);
                    break;
                }
            }
        }
示例#3
0
        private object GetValue(object value)
        {
            if (value == null)
            {
                return(null);
            }

            // Check for primitive type.

            PrimitiveTypeInfo typeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(value.GetType());

            if (typeInfo != null)
            {
                return(TypeClone.Clone(value));
            }

            // Check if it is instrumentable.

            IInstrumentable instrumentable = value as IInstrumentable;

            if (instrumentable != null)
            {
                InstrumentationDetails details = new InstrumentationDetails();
                instrumentable.Write(details);
                return(details);
            }

            // Return the string.

            return(value.ToString());
        }
示例#4
0
        /// <summary>
        /// Implements <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor.TessVertex">
        /// TesselationVisitor.TessVertex</see>.
        /// </summary>
        public virtual void TessVertex(double[] vertex)
        {
            renderList.Add(new PointF((float)vertex[0], (float)vertex[1]));
            PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[renderListTypes.Count - 1];

            pti.End++;
            renderListTypes[renderListTypes.Count - 1] = pti;
        }
示例#5
0
        private static EventParameter ReadPrimitiveTypeParameter(XmlReadAdaptor adaptor, string name)
        {
            // Look for a primitive type.

            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.ReadXsiTypeAttribute(adaptor);

            if (primitiveTypeInfo == null)
            {
                return(null);
            }

            return(new EventParameter(name, TypeXmlConvert.ToType(adaptor.ReadInnerXml(), primitiveTypeInfo.PrimitiveType)));
        }
示例#6
0
        private EventParameter ClonePrimitiveTypeParameter()
        {
            // Look for the primitive type corresponding to the value's .NET type.

            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_value.GetType());

            if (primitiveTypeInfo != null)
            {
                return(new EventParameter(m_name, TypeClone.Clone(m_value)));
            }
            else
            {
                return(null);
            }
        }
示例#7
0
        private bool WritePrimitiveTypeParameter(BinaryWriter writer)
        {
            // Get the info.

            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_value.GetType());

            if (primitiveTypeInfo == null)
            {
                return(false);
            }

            // Indicate that the value is not null.

            WriteRawValueInfo(writer, m_valueFormat, false);

            BinaryWriteAdaptor adaptor = new BinaryWriteAdaptor(writer);

            adaptor.Write(m_value);
            return(true);
        }
示例#8
0
        private bool WritePrimitiveTypeParameter(XmlWriteAdaptor adaptor)
        {
            // Get the info.

            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_value.GetType());

            if (primitiveTypeInfo == null)
            {
                return(false);
            }

            // Apply the appropriate xsi:type attribute.

            primitiveTypeInfo.WriteXsiTypeAttribute(adaptor);

            // Write the value itself.

            adaptor.WriteElementValue(TypeXmlConvert.ToString(m_value));
            return(true);
        }
示例#9
0
        private static EventParameter CreateFromXml(string name, string className, ValueFormat format, string xml)
        {
            System.Type type = ClassInfo.GetTypeFromAssemblyQualifiedName(className);
            Debug.Assert(type != null, "type != null");

            // Is it a primitive type? If so, the data is the raw XML value, no elements, etc. so convert it
            // to an object.

            PrimitiveTypeInfo primitiveInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false);

            if (primitiveInfo != null)
            {
                return(new EventParameter(name, TypeXmlConvert.ToType(xml, primitiveInfo.PrimitiveType)));
            }

            if (format == ValueFormat.SystemXml)
            {
                if (type == typeof(ulong))
                {
                    return(new EventParameter(name, XmlConvert.ToUInt64(xml)));
                }
                else if (type == typeof(uint))
                {
                    return(new EventParameter(name, XmlConvert.ToUInt32(xml)));
                }
                else if (type == typeof(ushort))
                {
                    return(new EventParameter(name, XmlConvert.ToUInt16(xml)));
                }
                else if (type == typeof(sbyte))
                {
                    return(new EventParameter(name, XmlConvert.ToSByte(xml)));
                }
            }

            // Not a primitive type, so the XML string is the full serialized representation. Don't deserialize it
            // until needed.

            return(new EventParameter(name, className, xml, format));
        }
        private object GetValue(CurrencyManager currencyManager, int row)
        {
            DataView dataView = currencyManager.List as DataView;

            if (dataView != null)
            {
                if (row < dataView.Count)
                {
                    string value = (string)dataView[row][MappingName];
                    if (value != string.Empty)
                    {
                        return(TypeXmlConvert.ToType(value, m_control.PrimitiveType));
                    }
                }

                return(PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_control.PrimitiveType).Default);
            }
            else
            {
                return(null);
            }
        }
示例#11
0
        private ValueFormat GetDataFromBinary(out string stringValue, out byte[] binaryValue)
        {
            // We already have the binary data, but for a primitive type we want to store only the XML. In that
            // case unpack the value (deserialize from binary) and serialize to XML.

            System.Type type = ClassInfo.GetTypeFromAssemblyQualifiedName(m_class);
            Debug.Assert(type != null, "type != null");

            if (PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false) != null)
            {
                stringValue = TypeXmlConvert.ToString(Value);
                binaryValue = null;
                return(type.Namespace == m_systemNamespace ? ValueFormat.SystemXml : ValueFormat.LinkMeXml);
            }
            else if (type == typeof(ulong) || type == typeof(uint) || type == typeof(ushort) || type == typeof(sbyte))
            {
                stringValue = ((System.IFormattable)Value).ToString(null, NumberFormatInfo.InvariantInfo);
                binaryValue = null;
                return(ValueFormat.SystemXml);
            }

            // Not a primitive type - store the binary data.

            stringValue = null;
            binaryValue = (byte[])m_value;
            ValueFormat format = m_valueFormat;

            // Do we want the string representation as well?

            if (type.IsSubclassOf(typeof(System.Exception)) || type == typeof(System.Exception))
            {
                stringValue = Value.ToString();
            }

            return(format);
        }
示例#12
0
 public CatalogueName(PrimitiveType type)
     :       this(PrimitiveTypeInfo.GetPrimitiveTypeInfo(type).FullName)
 {
 }
示例#13
0
 protected override string GetTypeName(System.Type type)
 {
     return(PrimitiveTypeInfo.TrimTypeNamespace(base.GetTypeName(type)));
 }
示例#14
0
        private ValueFormat GetDataFromRawValue(out string stringValue, out byte[] binaryValue)
        {
            Debug.Assert(m_value != null, "m_value != null");

            // Do we need the binary value, the string value or both?

            System.Type       type = m_value.GetType();
            PrimitiveTypeInfo primitiveTypeInfo = PrimitiveTypeInfo.GetPrimitiveTypeInfo(type, false);

            if (primitiveTypeInfo != null)
            {
                // Primitive type - store only the XML.

                stringValue = TypeXmlConvert.ToString(m_value);
                binaryValue = null;
                return(type.Namespace == m_systemNamespace ? ValueFormat.SystemXml : ValueFormat.LinkMeXml);
            }

            // Also check for the types that are not LinkMe primtive types, but can still be stored as a string
            // and searched.

            if (m_value is ulong || m_value is uint || m_value is ushort || m_value is sbyte)
            {
                stringValue = ((System.IFormattable)m_value).ToString(null, NumberFormatInfo.InvariantInfo);
                binaryValue = null;
                return(ValueFormat.SystemXml);
            }

            // Try to write to binary. Try system serialization first, then LinkMe IBinarySerializable.
            // DataObject fails to deserialize when user code directly calls IBinarySerializable.
            // The byte stream will be read by UnpackSystemBinaryParameter() or UnpackLinkMeBinaryParameter().

            ValueFormat format = ValueFormat.Raw;

            binaryValue = null;
            IBinarySerializable serializable;

            if (type.IsSerializable)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    try
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(stream, m_value);
                        binaryValue = stream.ToArray();
                        format      = ValueFormat.SystemBinary;
                    }
                    catch (System.Exception)
                    {
                    }
                }
            }
            else if ((serializable = m_value as IBinarySerializable) != null)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    try
                    {
                        BinaryWriter writer = new BinaryWriter(stream);
                        serializable.Write(writer);
                        binaryValue = stream.ToArray();
                        format      = ValueFormat.LinkMeBinary;
                    }
                    catch (System.Exception)
                    {
                    }
                }
            }

            if (format != ValueFormat.Raw)
            {
                // All details should be in the binary data, but write the string as well for certain types,
                // so that they can be searched.

                if (m_value is System.Exception)
                {
                    stringValue = m_value.ToString();
                }
                else
                {
                    stringValue = null;
                }
            }
            else
            {
                // We don't have the binary data, so export XML or at least the ToString() value.

                try
                {
                    stringValue = XmlSerializer.Serialize(m_value);
                    format      = ValueFormat.LinkMeXml;                // May actually be SystemXml, but doesn't matter in this case.
                }
                catch (System.Exception)
                {
                    stringValue = m_value.ToString();
                    format      = ValueFormat.String;
                }
            }

            Debug.Assert(format != ValueFormat.Raw, "format != ValueFormat.Raw");
            return(format);
        }
示例#15
0
        public static TypeDescription convertTypeInfo(TypeInfo info)
        {
            switch (info.getCategory())
            {
            case ObjectInspectorCategory.PRIMITIVE:
            {
                PrimitiveTypeInfo pinfo = (PrimitiveTypeInfo)info;
                switch (pinfo.getPrimitiveCategory())
                {
                case PrimitiveCategory.BOOLEAN:
                    return(TypeDescription.createBoolean());

                case PrimitiveCategory.BYTE:
                    return(TypeDescription.createByte());

                case PrimitiveCategory.SHORT:
                    return(TypeDescription.createShort());

                case PrimitiveCategory.INT:
                    return(TypeDescription.createInt());

                case PrimitiveCategory.LONG:
                    return(TypeDescription.createLong());

                case PrimitiveCategory.FLOAT:
                    return(TypeDescription.createFloat());

                case PrimitiveCategory.DOUBLE:
                    return(TypeDescription.createDouble());

                case PrimitiveCategory.STRING:
                    return(TypeDescription.createString());

                case PrimitiveCategory.DATE:
                    return(TypeDescription.createDate());

                case PrimitiveCategory.TIMESTAMP:
                    return(TypeDescription.createTimestamp());

                case PrimitiveCategory.BINARY:
                    return(TypeDescription.createBinary());

                case PrimitiveCategory.DECIMAL:
                {
                    DecimalTypeInfo dinfo = (DecimalTypeInfo)pinfo;
                    return(TypeDescription.createDecimal()
                           .withScale(dinfo.scale())
                           .withPrecision(dinfo.precision()));
                }

                case PrimitiveCategory.VARCHAR:
                {
                    BaseCharTypeInfo cinfo = (BaseCharTypeInfo)pinfo;
                    return(TypeDescription.createVarchar()
                           .withMaxLength(cinfo.getLength()));
                }

                case PrimitiveCategory.CHAR:
                {
                    BaseCharTypeInfo cinfo = (BaseCharTypeInfo)pinfo;
                    return(TypeDescription.createChar()
                           .withMaxLength(cinfo.getLength()));
                }

                default:
                    throw new ArgumentException("ORC doesn't handle primitive" +
                                                " category " + pinfo.getPrimitiveCategory());
                }
            }

            case ObjectInspectorCategory.LIST:
            {
                ListTypeInfo linfo = (ListTypeInfo)info;
                return(TypeDescription.createList
                           (convertTypeInfo(linfo.getListElementTypeInfo())));
            }

            case ObjectInspectorCategory.MAP:
            {
                MapTypeInfo minfo = (MapTypeInfo)info;
                return(TypeDescription.createMap
                           (convertTypeInfo(minfo.getMapKeyTypeInfo()),
                           convertTypeInfo(minfo.getMapValueTypeInfo())));
            }

            case ObjectInspectorCategory.UNION:
            {
                UnionTypeInfo   minfo  = (UnionTypeInfo)info;
                TypeDescription result = TypeDescription.createUnion();
                foreach (TypeInfo child in minfo.getAllUnionObjectTypeInfos())
                {
                    result.addUnionChild(convertTypeInfo(child));
                }
                return(result);
            }

            case ObjectInspectorCategory.STRUCT:
            {
                StructTypeInfo  sinfo  = (StructTypeInfo)info;
                TypeDescription result = TypeDescription.createStruct();
                foreach (string fieldName in sinfo.getAllStructFieldNames())
                {
                    result.addField(fieldName,
                                    convertTypeInfo(sinfo.getStructFieldTypeInfo(fieldName)));
                }
                return(result);
            }

            default:
                throw new ArgumentException("ORC doesn't handle " +
                                            info.getCategory());
            }
        }
        protected override void Edit(CurrencyManager currencyManager, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
        {
            if (readOnly)
            {
                Rectangle rectangle = bounds;
                m_textbox.ReadOnly = true;
                m_textbox.Text     = GetText(GetColumnValueAtRow(currencyManager, rowNum));

                if (cellIsVisible)
                {
                    bounds.Offset(m_xMargin, 2 * m_yMargin);
                    bounds.Width       -= m_xMargin;
                    bounds.Height      -= 2 * m_yMargin;
                    m_textbox.Bounds    = bounds;
                    m_textbox.Visible   = true;
                    m_textbox.TextAlign = Alignment;
                }
                else
                {
                    m_textbox.Bounds = Rectangle.Empty;
                }

                m_textbox.RightToLeft = DataGridTableStyle.DataGrid.RightToLeft;
                m_textbox.Focus();

                if (m_textbox.Visible)
                {
                    DataGridTableStyle.DataGrid.Invalidate(rectangle);

                    m_textbox.Show();
                    m_textbox.BringToFront();
                    m_textbox.Focus();
                    m_textbox.SelectAll();
                }
            }
            else
            {
                if (!m_inEdit)
                {
                    // Store information.

                    m_currentRow      = rowNum;
                    m_currencyManager = currencyManager;

                    if (m_control.IsValid)
                    {
                        m_originalValue = m_control.Value;
                    }
                    else
                    {
                        m_originalValue = PrimitiveTypeInfo.GetPrimitiveTypeInfo(m_control.PrimitiveType).Default;
                    }

                    // Set the visual aspect of the control.

                    Rectangle originalBounds = bounds;
                    if (cellIsVisible)
                    {
                        bounds.Offset(m_xMargin, 2 * m_yMargin);
                        bounds.Width     -= m_xMargin;
                        bounds.Height    -= 2 * m_yMargin;
                        m_control.Bounds  = bounds;
                        m_control.Font    = DataGridTableStyle.DataGrid.Font;
                        m_control.Visible = true;
                    }
                    else
                    {
                        m_control.Bounds  = originalBounds;
                        m_control.Visible = false;
                    }

                    // Set the value of the control (temporarily disabling the event processing because it
                    // interferes with the editing state of the column).

                    m_control.ValueChanged -= new System.EventHandler(m_control_ValueChanged);
                    m_control.Value         = GetValue(currencyManager, rowNum);
                    m_control.ValueChanged += new System.EventHandler(m_control_ValueChanged);

                    // If it is visible then re-paint it.

                    if (m_control.Visible)
                    {
                        DataGridTableStyle.DataGrid.Invalidate(originalBounds);

                        m_control.Show();
                        m_control.BringToFront();
                        m_control.Focus();
                        m_control.SelectValue();
                    }
                }
                else
                {
                    // This can be called twice in the case of editing a new row.
                    // Make the control visible and place on top of textbox.

                    m_control.Show();
                    m_control.BringToFront();
                    m_control.Focus();
                }
            }
        }