Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Exception "shouldn't get here" (Read 4074 times)
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Exception "shouldn't get here"
Mar 16th, 2009 at 5:27am
Print Post  
Hi,

When i load my diagram with loadfromfile, i get the exception "shouldn't get here".

... whats wrong?

Best regards
Marco
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception "shouldn't get here"
Reply #1 - Mar 16th, 2009 at 8:35am
Print Post  
Hi,

This could happen if you are using a custom item type that implements its own serialization methods, and in SaveTo it writes a number of bytes different than the number it reads in the LoadFrom method. Another way this could happen is if you have a serializable type whose instances are used as Tag values, and again it saves more or less bytes than it loads during deserialization.

Stoyan
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Exception "shouldn't get here"
Reply #2 - Mar 16th, 2009 at 12:28pm
Print Post  
Yes, im add a custom item typ to me diagram. In the same way as in the IconNode sample described.

The only two differents between the example and my application is:

1.) i have added an additional property to my IconNode class.

2.) i have added a Tag to me Nodes
(for example Nodes(0).Tag = "PipeResistance")

Marco



  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception "shouldn't get here"
Reply #3 - Mar 16th, 2009 at 12:33pm
Print Post  
Have you added a call to RegisterItemClass as in the IconNodes sample?
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Exception "shouldn't get here"
Reply #4 - Mar 16th, 2009 at 12:41pm
Print Post  
Yes i have...

FLowSim_Designer.diagram.RegisterItemClass(GetType(IconNode), "IconNode", 1)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception "shouldn't get here"
Reply #5 - Mar 16th, 2009 at 12:46pm
Print Post  
Have you changed anything in the saveto and loadfrom methods?
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Exception "shouldn't get here"
Reply #6 - Mar 16th, 2009 at 1:03pm
Print Post  
No, ....

If i come back home, i will post the code of my IconNode class and the code how i add my IconNodes to the diagram.

Thanks for your help Stoyo!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception "shouldn't get here"
Reply #7 - Mar 16th, 2009 at 1:13pm
Print Post  
Are you loading the file in the same application where you have saved it? If you need to use the same custom type in different applications, you will have to move it to a shared assembly, and call the RegisterItemClass method in both applications.

Stoyan
  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Exception "shouldn't get here"
Reply #8 - Mar 16th, 2009 at 5:33pm
Print Post  
Hi here is the code of my application to insert a IconNode:

MainFrame

Code
Select All
    Public Shared Sub Add_Inlet(ByVal sender As Object, ByVal e As MindFusion.Diagramming.DiagramEventArgs) Handles Add_Inlet_Event.Clicked
	  Dim IN_Inlet As IconNode

	  Select Case RT_Variable.QTY_Inlet_dyn
		Case Is >= 1
		    MiscFunctions.DesktopAlter("Fehlermeldung", "Es darf nur 1 Vorlauf pro Simulation definiert werden!")
		Case Else
		    'Einlass in Diagramm einfügen
		    IN_Inlet = New IconNode(FlowSim_Designer.Diagram)
		    IN_Inlet.Icon = FlowSim_Mainwindow.ImageList_DiagramNodes.Images(0)
		    IN_Inlet.Tag = "Inlet"
		    IN_Inlet.AnchorPattern = IconNodeProperties.INAP_Inlet
		    IN_Inlet.HandlesStyle = MindFusion.Diagramming.HandlesStyle.HatchHandles2
		    FlowSim_Designer.Diagram.Nodes.Add(IN_Inlet)

		    IN_Inlet.Move(e.MousePosition.X, e.MousePosition.Y)

		    'Eintrag im Projekt-Explorer
		    FlowSim_Designer.ProjectExplorer.Nodes(0).Nodes.Add("Inlet", "Vorlauf")
		    FlowSim_Designer.ProjectExplorer.Nodes(0).Nodes("Inlet").LeftImages.Add(FlowSim_Mainwindow.ImageList_TreeViewIcons.Images(2))

		    'Addiert einen Einlass zur Variable QTY_Inlet zum bestimmen der Gesamteinlassanzahl
		    RT_Variable.QTY_Inlet_dyn = RT_Variable.QTY_Inlet_dyn + 1
		    RT_Variable.QTY_Inlet_stat = RT_Variable.QTY_Inlet_stat + 1
	  End Select
    End Sub
 

  
Back to top
 
IP Logged
 
mberger
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 44
Joined: Jan 6th, 2009
Re: Exception "shouldn't get here"
Reply #9 - Mar 16th, 2009 at 5:36pm
Print Post  
IconNode class

Code
Select All
Imports MindFusion.Diagramming
Imports MindFusion.Drawing
Imports System.ComponentModel

Public Class IconNode

    Inherits DiagramNode


    Shared Sub New()

	  defaultIcon = New Bitmap(50, 50)

	  Dim graphics As Graphics = graphics.FromImage(defaultIcon)
	  Dim font As Font = New Font("Arial", 48, FontStyle.Bold, GraphicsUnit.Pixel)

	  graphics.FillRectangle(Brushes.Transparent, 0, 0, 50, 50)
	  graphics.DrawString("?", font, Brushes.Black, 0, 0)

	  font.Dispose()
	  graphics.Dispose()

    End Sub

    Public Sub New(ByVal diagram As Diagram)
	  MyBase.New(diagram)

	  imgIcon = defaultIcon
	  title = "Test-Titel"

	  format = New StringFormat
	  format.Alignment = StringAlignment.Center
	  format.LineAlignment = StringAlignment.Center

	  Bounds = New RectangleF(Bounds.Location, CalculateSize())

    End Sub

    Public Overrides Sub Draw(ByVal graphics As IGraphics, ByVal options As RenderOptions)

	  Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)
	  Dim imageSize As RectangleF = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels)

	  ' Draw the icon center at the top
	  graphics.DrawImage(imgIcon, _
	   Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y)

	  'Draw the label at the bottom
	  Dim labelBounds As RectangleF = RectangleF.FromLTRB( _
	   Bounds.X, Bounds.Y + imageSize.Height, Bounds.Right, Bounds.Bottom)

	  graphics.DrawString(title, _
	   Font, Brushes.Black, labelBounds, format)

    End Sub

    Public Overrides Sub DrawShadow(ByVal graphics As IGraphics, ByVal options As RenderOptions)

    End Sub

    Private Function CalculateSize() As SizeF

	  Dim tempImage As Bitmap = New Bitmap(1, 1)
	  Dim graphics As Graphics = graphics.FromImage(tempImage)
	  Dim measureGraphics As IGraphics = New GdiGraphics(graphics)

	  measureGraphics.PageUnit = Parent.MeasureUnit
	  Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)
	  Dim imageSize As RectangleF = MindFusion.Utilities.DeviceToDoc( _
    measureGraphics, iconSizePixels)

	  measureGraphics.Dispose()
	  tempImage.Dispose()

	  Dim textSize As SizeF = Parent.MeasureString(title, Font, Integer.MaxValue, format)

	  Return New SizeF( _
	   Math.Max(imageSize.Width, textSize.Width), _
	   imageSize.Height + textSize.Height)
    End Function

    Protected Overrides Sub UpdateCreate(ByVal current As PointF)

	  MyBase.UpdateCreate(current)
	  Bounds = New RectangleF(current, CalculateSize())
    End Sub

    Protected Overrides Sub SaveTo(ByVal writer As System.IO.BinaryWriter, ByVal ctx As PersistContext)

	  MyBase.SaveTo(writer, ctx)

	  ' Save the label using the standard .NET BinaryWriter
	  writer.Write(title)

	  'writer.Write(NodeName) macht Probleme beim laden
	  'writer.Write(NodeName)

	  ' Save the image using the FlowChart.NET built-in image saving code,
	  ' which stores the contents of shared images only once.
	  ctx.SaveImage(imgIcon)
    End Sub

    Protected Overrides Sub LoadFrom(ByVal reader As System.IO.BinaryReader, ByVal ctx As PersistContext)

	  MyBase.LoadFrom(reader, ctx)

	  title = reader.ReadString()
	  NodeName = reader.ReadString()

	  'imgIcon = ctx.LoadImage() macht Probleme beim laden
	  'imgIcon = ctx.LoadImage()
    End Sub



    Public Property Icon() As Image
	  Get
		Return imgIcon
	  End Get
	  Set(ByVal Value As Image)

		imgIcon = Value
		Bounds = New RectangleF(Bounds.Location, CalculateSize())
	  End Set
    End Property



    Public Property Label() As String
	  Get
		Return title
	  End Get
	  Set(ByVal Value As String)

		title = Value
		Bounds = New RectangleF(Bounds.Location, CalculateSize())
	  End Set
    End Property


    <CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Name eingeben")> _
Public Property Name() As String
	  Get
		Return NodeName
	  End Get
	  Set(ByVal Value As String)

		NodeName = Value
	  End Set
    End Property


    Private imgIcon As Image
    Private title As String
    Private NodeName As String
    Private format As StringFormat
    Private Shared defaultIcon As Image

End Class
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Exception "shouldn't get here"
Reply #10 - Mar 16th, 2009 at 6:26pm
Print Post  
SaveTo writes a string and an image, but LoadFrom tries to read two strings and no image?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint