Profile Picture

How could I create a custome Shape class

Posted By Hamdy Ghanem 13 Years Ago
Author
Message
Tezcan Cirakoglu
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 5, Visits: 1
What if you use something like below?






public class NFaiencePolygonShape: NPolygonShape
{
#region CTors

public NFaiencePolygonShape() { }

public NFaiencePolygonShape(NPointF[] points): base(points)
{

}

public NFaiencePolygonShape(NPolygonPath primitive): base(primitive)
{

}

#endregion

#region Properties

private string _Key = Guid.NewGuid().ToString();
public string Key { get { return _Key; } }

public int XPFaienceId { get; set; }
public FaienceDisplayMode FaienceDisplayMode { get; set; }
public bool AutoDecorate { get; set; }
public float DerzWidth { get; set; }
public float OffsetX { get; set; }
public float OffsetY { get; set; }
public float RotationAngle { get; set; }

public Color DerzColor { get; set; }
public float Tracker { get; set; }
public int TamFayansCount { get; set; }
public int BrokenFayansCount { get; set; }

#endregion
}

Hamdy Ghanem
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 7, Visits: 1
Still sending the same error

Failed to save to file. Exception was: There was an error generating the XML document.

I wonder, I put a breakpoint in the load xml and save xml in the custom property class and the compiler not going to this line

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

We double checked the issue. In order to serialize a custom object to XML you need to register it with the serializer.
This is demonstrated in the following example:

Serialization > Persistency Manager

The code to do it is the following:

// IMPORTANT: custom types added to the DOM must be registered

// in the persistency manager if you intend to save/load in XML format

persistencyManager.Serializer.XmlExtraTypes = new Type[] {typeof(NCustomShape)};

Hope this helps - questions or comments - please feel free...



Best Regards,
Nevron Support Team



Hamdy Ghanem
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 7, Visits: 1
This is my class and still not saving and give this message "Failed to save to file. Exception was: There was an error generating the XML document."
so please if you have a sample or if you can help me where is the error
----------------------------------------------

Imports System.Drawing
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Collections.Generic
Imports Nevron.UI
Imports Nevron.UI.WinForm.Controls
Imports System.Reflection
Imports Nevron.Chart.WinForm
Imports Nevron.Diagram
Imports Nevron.Diagram.Shapes
Imports Nevron.GraphicsCore
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.Serialization
("CreateCustomPropertiesSchema")> _
Public Class CustomProperties
Implements IXmlSerializable, ICloneable

#Region "Constructions ..."
Public Sub New()

End Sub
Public Sub New(ByVal strShapeName As String, ByVal strType As String, ByVal iWeight As Integer, ByVal strPhysics As String, ByVal iShapeImage As Integer, ByVal strDesc As String)
_ShapeName = strShapeName
_ShapeType = strType
_Weight = iWeight
_Physics = strPhysics
_ShapeImage = iShapeImage
_Decription = strDesc
End Sub

Public Shared Function CreateCustomPropertiesSchema(ByVal schemaSet As XmlSchemaSet) As XmlQualifiedName
Dim schema As XmlSchema = New XmlSchema()

Return ""
End Function

#End Region

#Region " properties ..."

Dim _Shapeid As Integer = 0
Public Property Shapeid() As Integer
Get
Return _Shapeid
End Get
Set(ByVal value As Integer)
_Shapeid = value
End Set
End Property
Dim _ShapeName As String = ""
Public Property ShapeName() As String
Get
Return _ShapeName
End Get
Set(ByVal value As String)
_ShapeName = value
End Set
End Property


Dim _ShapeType As String = ""
Public Property ShapeType() As String
Get
Return _ShapeType
End Get
Set(ByVal value As String)
_ShapeType = value
End Set
End Property

Dim _Weight As Integer = 0
Public Property Weight() As Integer
Get
Return _Weight
End Get
Set(ByVal value As Integer)
_Weight = value
End Set
End Property

Dim _Physics As String = ""
Public Property Physics() As String
Get
Return _Physics
End Get
Set(ByVal value As String)
_Physics = value
End Set
End Property

Dim _ShapeImage As String = ""
Public Property ShapeImage() As String
Get
Return _ShapeImage
End Get
Set(ByVal value As String)
_ShapeImage = value
End Set
End Property
Dim _Decription As String = ""
Public Property Decription() As String
Get
Return _Decription
End Get
Set(ByVal value As String)
_Decription = value
End Set
End Property

Private _Tasks As Dictionary(Of Integer, Task)
_
Public Property Tasks() As Dictionary(Of Integer, Task)
Get
Return Me._Tasks
End Get
Set(ByVal value As Dictionary(Of Integer, Task))
_Tasks = value
End Set
End Property

#End Region
Public Overrides Function ToString() As String
Return _ShapeType
End Function
#Region "Implement .."
Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements IXmlSerializable.GetSchema
Throw New System.NotImplementedException()
End Function

Public Sub WriteXml(ByVal writer As XmlWriter) Implements IXmlSerializable.WriteXml
writer.WriteStartElement("ShapeCustomProperties", "urn:devx-com")

writer.WriteAttributeString("ShapeName", _ShapeName)
writer.WriteAttributeString("ShapeType", _ShapeType)
writer.WriteAttributeString("Weight", _Weight)
writer.WriteAttributeString("Physics", _Physics)
writer.WriteAttributeString("ShapeImage", _ShapeImage)
writer.WriteAttributeString("Decription", _Decription)
writer.WriteEndElement()
End Sub

Public Sub ReadXml(ByVal reader As XmlReader) Implements IXmlSerializable.ReadXml
Dim type As XmlNodeType = reader.MoveToContent()
If ((type = XmlNodeType.Element) And (reader.LocalName = "ShapeCustomProperties")) Then
_ShapeName = reader("ShapeName")
_ShapeType = reader("ShapeType")
_Weight = reader("Weight")
_Physics = reader("Physics")
_ShapeImage = reader("ShapeImage")
_Decription = reader("Decription")
End If
End Sub
Public Function Clone() As Object Implements ICloneable.Clone
Dim des As New CustomProperties
'Dim src As CustomProperties = DirectCast(MemberwiseClone(), CustomProperties)
des._ShapeName = _ShapeName
des._ShapeType = _ShapeType
des._Weight = _Weight
des._Physics = _Physics
des._ShapeImage = _ShapeImage
des._Decription = _Decription
Return des

End Function
#End Region

End Class


Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi, the serializable attribute affects only the binary serialization. So the sample class is meant to be serialized binary. If you want to use the XML serialization with a custom class it should implement the IXmlSerializable interface.

Best Regards,
Nevron Support Team



Hamdy Ghanem
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 7, Visits: 1
Sorry , but still sending the same error :
Failed to save to file. Exception was: There was an error generating the XML document.
and it is only about the tag, if i remove the tag it will save successfully

here is my class


Imports System.Drawing
Imports System.Xml
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Collections.Generic
Imports Nevron.UI
Imports Nevron.UI.WinForm.Controls
Imports System.Reflection
Imports Nevron.Chart.WinForm
Imports Nevron.Diagram
Imports Nevron.Diagram.Shapes
Imports Nevron.GraphicsCore
_
Public Class CustomProperties
Implements ICloneable

Public Sub New()

End Sub

#Region " properties ..."
Dim _Shapeid As Integer = 0
Public Property Shapeid() As Integer
Get
Return _Shapeid
End Get
Set(ByVal value As Integer)
_Shapeid = value
End Set
End Property
Dim _ShapeName As String = ""
Public Property ShapeName() As String
Get
Return _ShapeName
End Get
Set(ByVal value As String)
_ShapeName = value
End Set
End Property

Dim _ShapeType As String = ""
Public Property ShapeType() As String
Get
Return _ShapeType
End Get
Set(ByVal value As String)
_ShapeType = value
End Set
End Property

Dim _Weight As Integer = 0
Public Property Weight() As Integer
Get
Return _Weight
End Get
Set(ByVal value As Integer)
_Weight = value
End Set
End Property

Dim _Physics As String = ""
Public Property Physics() As String
Get
Return _Physics
End Get
Set(ByVal value As String)
_Physics = value
End Set
End Property

Dim _ShapeImage As String = ""
Public Property ShapeImage() As String
Get
Return _ShapeImage
End Get
Set(ByVal value As String)
_ShapeImage = value
End Set
End Property
Dim _Decription As String = ""
Public Property Decription() As String
Get
Return _Decription
End Get
Set(ByVal value As String)
_Decription = value
End Set
End Property


#End Region
Public Overrides Function ToString() As String
Return _ShapeType
End Function

Public Function Clone() As Object Implements ICloneable.Clone

Dim des As New CustomProperties
'Dim src As CustomProperties = DirectCast(MemberwiseClone(), CustomProperties)
des._ShapeName = _ShapeName
des._ShapeType = _ShapeType
des._Weight = _Weight
des._Physics = _Physics
des._ShapeImage = _ShapeImage
des._Decription = _Decription
Return des

End Function

End Class


Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

Here's a sample implementation of a class you can use as a Tag property for your shapes:

 

[Serializable]

public class NShapeExt : ICloneable

{

      public NShapeExt()

      {

            m_bMyProperty1 = true;

            m_sMyProperty2 = String.Empty;

      }

 

      public bool MyProperty1

      {

            get

            {

                  return m_bMyProperty1;

            }

            set

            {

                  m_bMyProperty1 = value;

            }

      }

      public string MyProperty2

      {

            get

            {

                  return m_sMyProperty2;

            }

            set

            {

                  m_sMyProperty2 = value;

            }

      }

 

      public object Clone()

      {

            NShapeExt shapeExt = new NShapeExt();

            shapeExt.m_bMyProperty1 = m_bMyProperty1;

            shapeExt.m_sMyProperty2 = m_sMyProperty2;

            return shapeExt;

      }

 

      private bool m_bMyProperty1;

      private string m_sMyProperty2;

}



Best Regards,
Nevron Support Team



Hamdy Ghanem
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 7, Visits: 1
could u plz send a sample class

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi, you should create a class that hold the additinal properties you want and assign an instance of it to the Tag property of a shape. The class should implement the 3 points mentioned above. Have you done that? If yes and there's still a problem, please send your code to support@nevron.com and we'll tell you what's wrong.



Best Regards,
Nevron Support Team



Hamdy Ghanem
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 7, Visits: 1
I did the three points and still giving error while saving



Similar Topics


Reading This Topic