Hi, I was wondering if someone could tell me the best way to create SymbolModels programmatically and dynamically. I''m trying to do something where I create my SymbolModels based on data received from a web service at run time. The data wouldn''t actually contain SymbolModels, just info used to create one (such as port numbers, name, attributes).
I tried to find the information in the documentation, but I couldn''t seem to locate it, other than finding a sentence that said SymbolModels could be dynamically created. Unfortunately no real info on how.
All I really want to do is make a square, maybe color it in, add a name, add some ports and attributes, and maybe turn off the display of some attributes in the property grid.
Any help would be appreciated. A shove in the right direction would do as well.
AD
Administrator
Syncfusion Team
April 16, 2004 07:59 PM UTC
Hi Vik,
The SymbolModel class is intended to be created only through the ''Symbol Designer'' utility and is not meant for programmatic initialization. Creating a SymbolModel from scratch is a non-trivial process and is not something that we would recommend. Per your description if the Symbol''s attributes are known beforehand then the more direct approach here would be to create the Symbol as demonstrated in the DynamicSymbol sample application.
However, if your application mandates a programmatically synthesized SymbolModel to be available as well then the easiest approach would be to use your persisted information to first generate an instance of the Symbol and then use this symbol instance to create the SymbolModel. Working in this way through the Symbol would be far more intuitive than directly providing the SymbolModel''s data. The following code should help you get started,
// First use your persisted data to create an instance of the Symbol
MySymbol symbl = new MySymbol();
// Now Create a new SymbolModel and provide it with a Name
SymbolModel symblmodel = new SymbolModel();
symblmodel.Name = String.Concat(symbl.Name, "Model");
// Assign the Symbol properties to the SymbolModel
String[] properties = symbl.GetPropertyNames();
foreach(String propname in properties)
symblmodel.SetPropertyValue(propname, symbl.GetPropertyValue(propname));
// Set the SymbolModel bounds
symblmodel.Bounds = symbl.Bounds;
symblmodel.LocalTransform = symbl.LocalTransform;
// Populate the SymbolModel with cloned child nodes from the Symbol
foreach(INode childnode in symbl.Nodes)
{
if((childnode is Label) == false)
symblmodel.DefaultLayer.Add(childnode.Clone() as INode);
}
// Populate the SymbolModel''s Labels collection
foreach(Label symbllabel in symbl.Labels)
{
symblmodel.Labels.Add(symbllabel.Clone() as Label);
}
// Set small/large icons for representing the Symbol
//symblmodel.SmallIcon = iconSmall;
//symblmodel.LargeIcon = iconLarge;
// Enable/disable the centerport property
symblmodel.CenterPortEnabled = symbl.CenterPort.Enabled;
// The SymbolModel creation is now complete and can now be used to create new Symbols
Symbol newsymbol = symblmodel.CreateSymbol();
// Use the InsertNodesCmd Diagram Command class to insert the symbol
Diagram.InsertNodesCmd inscmd = new Diagram.InsertNodesCmd();
inscmd.Nodes.Add(newsymbol);
inscmd.LayerName = this.diagram.Model.DefaultLayerName;
inscmd.Location = new Point(100,100);
this.diagram.Controller.ExecuteCommand(inscmd);
Prakash
Syncfusion, Inc
JL
Jarrod Lloyd
October 24, 2004 11:06 PM UTC
I have created the symbolmodel, but how do I now add it to the pallette?
I tried :
myModulepalette->AppendChild(symblmodel);
but i did not work
AD
Administrator
Syncfusion Team
October 25, 2004 04:46 PM UTC
Hi Jarrod
Here is a sample that demonstrates how a custom Symbol can be added to a Symbol Palette and add this Palette can be added to the PaletteGroupBar so that you can drag and drop the symbol on to the Diagram.
Here is a code snippet:
// New Symbol Palette
SymbolPalette mypalette = new SymbolPalette();
mypalette.Name = "MyCustomSymbol";
// SymbolModel
SymbolModel MySymbolModel = new SymbolModel();
MySymbolModel = mypalette.AddSymbol("MySymbol");
//Specify PlugInClass and PlugInAssembly
MySymbolModel.PlugInAssembly = "MyCustomSymbol";
MySymbolModel.PlugInClass = "MyCustomSymbol.MySymbol";
//Add to PaletteGroupBar
this.paletteGroupBar1.AddPalette(mypalette);
Regards
Arun
TL
Truman Lackey
October 25, 2004 07:33 PM UTC
I have tired the following in vb
Dim symbol as new MySymbol()
Dim sIcon as Icon = new Icon(iPath)
Dim sBitMapNode as new BitMapNode(bmpBath)
Dim node as INode
Dim properties as string()
Dim lbl as Label
Dim symbolModel as SymbolModel
symbol.AppendChild(sBitMapNode)
symbolModel = new SymbolModel()
symbolModel.Bounds = symbol.bounds
symbolModel.LocalTransfrom = symbol.LocalTransform
properties = symbol.GetPropertyNames()
for each prop in properties
symbolModel.SetPropertyValue(prop, symbol.GetPropertyValue(prop)
next
for each node in symbol.nodes
if not TypeOf(node) is Label Then
symbolModel.DefaultLayer.Add(node.Clone())
end if
next
for each lbl in symbol.Labels
symbolModel.Labels.Add(lbl.Clone())
Next
symbolModel.CenterPortEnabled = symbol.CenterPort.Enabled
symbolModel.SmallIcon = sIcon.ToBitMap()
symbolModel.LargeIcon = sIcon.ToBitMap()
symbolModel.PluginAssembley = "Custom"
symbolModel.PluginClass = "Custom.Symbol"
symbolModel.Name = "name"
dim testSymbol as Symbol = symbolModel.CreateSymbol()
What I am trying to do to create a symbolmodel that contains an image. The image is what is shown when the symbol model would be dragged from the palette to a diagram. When I do the CreateSymbol it is returning nothing. Any help would be appreciated.
Thanks
Truman
AD
Administrator
Syncfusion Team
October 25, 2004 08:28 PM UTC
It seems that as soon as I set the PluginClass and PluginAssembly that I only get nothing when I try to do CreateSymbol. If I leave them set as defualt values I can use the CreateSymbol to return a good symbol.
AD
Administrator
Syncfusion Team
October 25, 2004 09:53 PM UTC
Hi Truman,
1. In the sample posted earlier in this thread, the Custom Symbol (MySymbol) is part of the application (MyCustomSymbol) hence the PlugInClass and PlugInAssembly for the SymbolModel are set as shown below:
MySymbolModel.PlugInAssembly = "MyCustomSymbol";
MySymbolModel.PlugInClass = "MyCustomSymbol.MySymbol";
2. If the assembly containing the Custom Symbol Class is different and you have added a reference to that assembly in your application, take a look at
this forums posting for information.
Kindly upload a small sample if you are still encountering problems.
Regards
Arun
AD
Administrator
Syncfusion Team
November 9, 2005 08:09 PM UTC
Hi i have a similar requirement.
I am able to create a symbolmodel with a bitmap node but wann add it to existing pallette, Exactly like SymbolDesigner.
Any help would be useful
Thanks
AD
Administrator
Syncfusion Team
November 9, 2005 08:46 PM UTC
Hi i am able to get the symbol into the pallette but the LargeIcon does not appear. Also how do i serialize the current pallette newly added symbols.
this is what i am using:
Stream str = opn.OpenFile();
System.Drawing.Image _image = System.Drawing.Image.FromStream(str);
BitmapNode bmpNode = new BitmapNode(str);
SymbolModel customSymbolModel = symbolsPalette1.CurrentPalette.AddSymbol("test");
Symbol smbl = new Symbol();
smbl.AppendChild(bmpNode);
foreach(INode node in smbl.Nodes)
{
customSymbolModel.DefaultLayer.Add(node);
}
MF
Meera Fathima
Syncfusion Team
November 10, 2005 10:04 AM UTC
Hi,
If you are using the PaletteGroupView control, the PaletteGroupView.Palette.AddSymbol() method will let you add the SymbolModel into the SymbolPalette control. And these SymbolModels can be retrieved by calling the SymbolPalette.Nodes.GetNodeByName(..) method. SymbolModel.CreateSymbol() method will let you create a new instance of the symbol described by the symbol model.
SymbolModel.LargeIcon/SmallIcon property allows us to add the image to the symbol model.
Referring the DiagramSamples/QuickStart/DynamicSymbol,CustomSymbol samples will give you an idea about the above described information.
Please let me know if you have any further queries on this. We will be glad to assist.
Thanks and Regards,
Meera.
MF
Meera Fathima
Syncfusion Team
November 12, 2005 10:27 AM UTC
Hi,
If the SymbolModel is designed with the SymbolDesigner then it will have the LargeIcon/SmallIcon properties. And the images assigned to these properties will be used by the PaletteGroupView control for representing the SymbolModel in the palette. However while creating and adding the SymbolModel programmatically then the images will have to be added directly to the PaletteGroupView control.
In the following code snippet
SymbolModel mysymbolmodel = this.paletteGroupView1.Palette.AddSymbol("MySymbol");
// ...........
mysymbolmodel.SmallIcon = new Bitmap("\\symbol_small.bmp");
mysymbolmodel.LargeIcon = new Bitmap("\\symbol_large.bmp");
// Create a PaletteGroupView item to represent the SymbolModel and add it to the PaletteGroupView
int imageIdx = 0;
int lgImageIdx = 0;
int smImageIdx = 0;
if (mysymbolmodel.SmallIcon != null)
smImageIdx = this.paletteGroupView1.AddSmallIcon(mysymbolmodel.SmallIcon);
if (mysymbolmodel.LargeIcon != null)
lgImageIdx = this.paletteGroupView1.AddLargeIcon(mysymbolmodel.LargeIcon);
this.paletteGroupView.AddLargeIcon()/AddSmallIcon() methods will let you add the images for the symbol models loaded into the GroupView control.
I forgot to mention these above described informations in the previous update.I am sorry about this.
As I mentioned already, referring the DiagramSample/QuickStart/DynamicSymbol sample will help you to go about this.Please let me know if you have any queries on this issue.
Thanks and Regards,
Meera.
SA
Sachin
November 14, 2005 12:36 PM UTC
Hi Meera thanks for the prompt reply
I am using Pallete PaletteGroupBar which does not have add icon method.
I have another question how do i serialize and save this custome pallette created at runtime.
Thanks
MF
Meera Fathima
Syncfusion Team
November 15, 2005 03:52 PM UTC
Hello Sachin,
PaletteGroupBar is only a container for the PaletteGroupView control which implements the symbol palette.And the symbol models are actually displayed inside the PaletteGroupView control, and that the PaletteGroupBar provides only the outer tab that is used for switching between different palettes.
Kindly refer the SymbolDesigner.cs class. SymbolDesigner/MainForm.cs File_OpenClick() and File_SaveClick() methods will give you an idea about the serialization/deserialization of Palettes at runtime.
Please let me know if you need any further clarifications.
Thanks and Regards,
Meera.