Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) ShapeDesigner, saving shapes, etc (Read 7405 times)
jstraylor
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Dec 28th, 2006
ShapeDesigner, saving shapes, etc
Jul 19th, 2007 at 12:02pm
Print Post  
Good Day all,

We seem to be pushing the flowchart control in all sorts of interesting directions and I need to see if what I want to do is at all possible.

We have the need to allow our users to design custom shapes (building layouts, etc) and we need to be able to save and load these shapes at any time.  So, my questions are:

1. Using the ShapeDesignerCtrl is there a way to save a single shape, rather than a shape library?
2.  Is there a way to load a single shape, and possibly NOT add it to the shape library?
3.  I understand that when saving a flowchart to XML that only the ShapeID is saved, is it possible to save a secondary stream with the shape definition of the custom shape??

The idea is that users would design custom shapes for their floorplan areas (i.e. an L shaped room) that would be saved in the database (streamed as XML) and re-read from the database.  We also want the ability to send an exported flowchart to another user who only has a custom viewer application, and have that exported flowchart render faithfully in the viewer application without the need for the database.

Is this possible??  Did I explain it clearly enough??

Final question on the ShapeDesignerCtrl - is there any way to enlarge the available drawing surface.  The current surface appears to be too small for my purposes.  (I'm starting with the ShapeDesigner example project).

Thank you,
Jeff Traylor
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #1 - Jul 19th, 2007 at 1:34pm
Print Post  
Good day,

The ShapeTemplate class provides

public void SaveTo(XmlWriter w) ;
public static ShapeTemplate FromXmlElement(XmlElement e) ;

methods that the ShapeLibrary class uses to save or load individual shapes in the library.

The Settings\Shape Size menu command in ShapeDesigner seems to enlarge the drawing surface. Check its handler to see what property of the designer control is used to implement that.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
jstraylor
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Dec 28th, 2006
Re: ShapeDesigner, saving shapes, etc
Reply #2 - Jul 25th, 2007 at 1:11pm
Print Post  
Do you have any example code for the save/restore functions??

Also, what happens when you try to add a shape to the library that already exists??  Does it just throw an error that I can catch??

Finally, can the XML of the shapes be tacked on to the end of the saved drawing, or do I need to create a zip of the 2 files together??

Thanks again,
Jeff
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #3 - Jul 25th, 2007 at 2:24pm
Print Post  
Code
Select All
XmlTextWriter w = new XmlTextWriter(new FileStream(filename, FileMode.Create), Encoding.UTF8);
w.Formatting = Formatting.Indented;
w.WriteStartDocument();
w.WriteStartElement("shapes", NAMESPACE);
foreach (ShapeTemplate shape in shapes)
	shape.SaveTo(w);
w.WriteEndElement();
w.WriteEndDocument();
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #4 - Jul 25th, 2007 at 2:28pm
Print Post  
Code
Select All
XmlDocument doc = new XmlDocument();
doc.Load(filename);

ArrayList res = new ArrayList();
foreach (XmlNode nd in doc.DocumentElement.GetElementsByTagName("shape", NAMESPACE))
	res.Add(ShapeTemplate.FromXmlElement((XmlElement)nd));
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #5 - Jul 25th, 2007 at 2:35pm
Print Post  
If a shape with the same id exists when loading a shape library, it will be overwritten by the newly loaded shape.

You can use Flowchart.SaveToStream to save the flowchart data, and then append anything additional you need to the stream. To load the chart, call FlowChart.LoadFromStream - that will leave the stream position at the beginning of your additional data, so you can read it in the same order it was written.

Stoyan
  
Back to top
 
IP Logged
 
jstraylor
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Dec 28th, 2006
Re: ShapeDesigner, saving shapes, etc
Reply #6 - Aug 28th, 2007 at 5:47pm
Print Post  
Stoyo,

I am saving a shape like this:
[code]
                       Dim fStream As FileStream = New FileStream("C:\Test.shp", FileMode.OpenOrCreate)
                       Dim w As XmlTextWriter = New XmlTextWriter(fStream, System.Text.Encoding.UTF8)
                       w.Formatting = Formatting.Indented
                       w.WriteStartDocument()
                       w.WriteStartElement("CustomShapes")
                       st.SaveTo(w)
                       w.WriteEndElement()
                       w.WriteEndDocument()
                       w.Flush()
                       w.Close()

[/code]

and attempting to retrieve it like this:
[code]
    Private Function GetShapeFromFile(ByVal fname As String) As ShapeTemplate
       Dim doc As XmlDocument = New XmlDocument()
       doc.Load(fname)

       Dim sc As Integer = 0
       Dim nd As XmlNode
       For Each nd In doc.GetElementsByTagName("CustomShapes")
           sc += 1
       Next
       If sc > 0 Then
           Return ShapeTemplate.FromXmlElement(nd)
       Else
           Return ShapeTemplate.FromId("Rectangle")
       End If

    End Function
[/code]

and I am getting this error when trying to read the shape back in:
[code]
Must specify valid information for parsing in the string.
[/code]

Any ideas what I am doing wrong??

BTW, I can now edit non-square shapes and will be sending the code back to you once I complete this portion of the project.

Thanks,
Jeff
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #7 - Aug 29th, 2007 at 7:31am
Print Post  
Could you also post the stack trace here?

Stoyan
  
Back to top
 
IP Logged
 
jstraylor
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Dec 28th, 2006
Re: ShapeDesigner, saving shapes, etc
Reply #8 - Aug 29th, 2007 at 1:18pm
Print Post  
Stack Trace:
[code]
"   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at System.Enum.Parse(Type enumType, String value)
   at MindFusion.Diagramming.WinForms.ShapeTemplate.FromXmlElement(XmlElement e)
   at JunoCommon.CompoundEdit.GetShapeFromFile(String fname) in C:\Documents and Settings\jefftraylor\My Documents\Visual Studio 2005\Projects\JunoClient\JunoCommon\ItemEditors\CompoundEdit.vb:line 3485
   at JunoCommon.CompoundEdit.LayoutCompound(String SiteCode) in C:\Documents and Settings\jefftraylor\My Documents\Visual Studio 2005\Projects\JunoClient\JunoCommon\ItemEditors\CompoundEdit.vb:line 1931
   at JunoCommon.CompoundEdit.LoadSite(String SiteCode) in C:\Documents and Settings\jefftraylor\My Documents\Visual Studio 2005\Projects\JunoClient\JunoCommon\ItemEditors\CompoundEdit.vb:line 2363
   at JunoCommon.CompoundEdit.CompoundEdit_Load(Object sender, EventArgs e) in C:\Documents and Settings\jefftraylor\My Documents\Visual Studio 2005\Projects\JunoClient\JunoCommon\ItemEditors\CompoundEdit.vb:line 145
   at System.Windows.Forms.UserControl.OnLoad(EventArgs e)
   at System.Windows.Forms.UserControl.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)"
[/code]

XML Generated by the Save(w):
[code]
<?xml version="1.0" encoding="utf-8"?>
<CustomShapes>
  <shape id="Compound_000" fill-mode="Winding" xmlns="http://mindfusion.org/flowchart">
    <outline>
     <line dash-style="Custom" width="-1">
       <point x="3.8" y="4.2" />
       <point x="100" y="0" />
     </line>
     <line dash-style="Custom" width="-1">
       <point x="100" y="0" />
       <point x="100" y="100" />
     </line>
     <line dash-style="Custom" width="-1">
       <point x="100" y="100" />
       <point x="0" y="100" />
     </line>
     <line dash-style="Custom" width="-1">
       <point x="0" y="100" />
       <point x="3.8" y="4.2" />
     </line>
    </outline>
    <decorations />
  </shape>
</CustomShapes>
[/code]

Thanks for checking this out,
Jeff
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #9 - Aug 30th, 2007 at 6:39am
Print Post  
Try this:

Code
Select All
 Private Function GetShapeFromFile(ByVal fname As String) As Shape
        Dim doc As XmlDocument = New XmlDocument

        doc.Load(fname)

        Dim shapes As XmlNodeList = doc.GetElementsByTagName("shape")
        If shapes.Count > 0 Then
            Return MindFusion.Diagramming.Shape.FromXmlElement(shapes.Item(0))
        Else
            Return Shape.FromId("Rectangle")
        End If

    End Function
 



Stoyan
  
Back to top
 
IP Logged
 
jstraylor
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 50
Joined: Dec 28th, 2006
Re: ShapeDesigner, saving shapes, etc
Reply #10 - Aug 30th, 2007 at 9:36am
Print Post  
Thank You!  It works very well now.  Somehow I knew that it would be my poor understanding of the XML classes that would be the problem.

Slight changes to the code and it works great!

New Code:
[code]
    Private Function GetShapeFromFile(ByVal fname As String) As ShapeTemplate
       Dim doc As XmlDocument = New XmlDocument()
       If My.Computer.FileSystem.FileExists(fname) Then
           doc.Load(fname)

           Dim shapes As XmlNodeList = doc.GetElementsByTagName("shape")
           If shapes.Count > 0 Then
               Return ShapeTemplate.FromXmlElement(shapes.Item(0))
           Else
               Return ShapeTemplate.FromId("Rectangle")
           End If
       Else
           Return ShapeTemplate.FromId("Rectangle")
       End If

    End Function
[/code]
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ShapeDesigner, saving shapes, etc
Reply #11 - Aug 30th, 2007 at 9:51am
Print Post  
That's great  8) It seems my code was for the version 5 API where ShapeTemplate is now called Shape.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint