public GraphMenuItem(ShapeSummary mSummary, EventHandler handler)
     : base(mSummary.ShapeName,handler)
 {
     this.mSummary = mSummary;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds an item to the collection
 /// </summary>
 /// <param name="summary"></param>
 /// <returns></returns>
 public int Add(ShapeSummary summary)
 {
     return(this.InnerList.Add(summary));
 }
 public GraphTreeNode(ShapeSummary mSummary)
 {
     this.mSummary = mSummary;
     this.Text = mSummary.ShapeName;
 }
 public GraphMenuItem(ShapeSummary mSummary)
     : base()
 {
     this.mSummary = mSummary;
 }
		/// <summary>
		/// Loads the shapes from the assembly at the given path
		/// </summary>
		/// <param name="path"></param>
		protected void ImportShapes(string path)
		{
			GraphObjectsLibrary library = new GraphObjectsLibrary();
			ShapeSummary summary;
			ShapesTab tab;
			TreeNode categoryNode;
			library.Path = path;
			libraries.Add(library);
			int currentImageId;
			try
			{
			Assembly ass=Assembly.LoadFrom(path);
			if (ass==null) return;
			Type[] tps=ass.GetTypes();
			
				if (tps==null) return ;
				Shape shapeInstance=null;
				object[] objs;
				for(int k=0; k<tps.Length;k++) //loop over modules in assembly
				{
					
					if(!tps[k].IsClass) continue;		
					objs = tps[k].GetCustomAttributes(typeof(Netron.GraphLib.Attributes.NetronGraphShapeAttribute),false);
					if(objs.Length<1) continue;							
					//now, we are sure to have a shape object					
					
					try
					{
						//normally you'd need the constructor passing the Site but this instance will not actually live on the canvas and hence cause no problem
						//but you do need a ctor with no parameters!
						shapeInstance=(Shape) ass.CreateInstance(tps[k].FullName);
						NetronGraphShapeAttribute shapeAtts = objs[0] as NetronGraphShapeAttribute;
						summary = new ShapeSummary(path, shapeAtts.ShapeKey,shapeAtts.ShapeName, shapeAtts.ShapeCategory, shapeAtts.ReflectionName, shapeAtts.Description);
						library.ShapeSummaries.Add(summary);

						#region For the listview
						tab=this.GetTab(summary.ShapeCategory);

						//if not override the Shape gives a default bitmap
						Bitmap bmp = shapeInstance.GetThumbnail();
						imageList.ImageSize=new Size(48,48);
						imageList.ColorDepth=ColorDepth.Depth8Bit;
						if(bmp !=null)
						{
							
							//imageList.TransparentColor=Color.White;								
							currentImageId=imageList.Images.Add(bmp,Color.Empty);	
						}
						else
						{
							currentImageId = 0;
						}
						//this.pictureBox1.Image=bmp;
						//bmp.Save("c:\\temp\\test.gif",System.Drawing.Imaging.ImageFormat.Gif);
						tab.LargeImageList=imageList;
						tab.AddItem(summary,currentImageId);
						
						#endregion

						#region For the treeview
						categoryNode = this.GetTreeNode(summary.ShapeCategory);
						categoryNode.Nodes.Add(new GraphTreeNode(summary));

						#endregion
					}
					catch(Exception exc)
					{
						Trace.WriteLine(exc.Message);
						continue;
					}						
					
							
				}
				
			}
			catch(Exception exc)
			{
				Trace.WriteLine(exc.Message);
			}
		}
 public int Add(ShapeSummary summary)
 {
     return this.InnerList.Add(summary);
 }
        protected void ImportShapes(string path)
        {
            GraphObjectsLibrary library = new GraphObjectsLibrary();
            ShapeSummary shapeSum;
            ConnectionSummary conSum;
            library.Path = path;
            mLibraries.Add(library);

            try
            {
                Assembly ass=Assembly.LoadFrom(path);
                if (ass==null) return;
                Type[] tps=ass.GetTypes();

                if (tps==null) return ;

                object[] objs;
                for(int k=0; k<tps.Length;k++) //loop over modules in assembly
                {

                    if(!tps[k].IsClass) continue;
                    try
                    {
                        objs = tps[k].GetCustomAttributes(typeof(Netron.GraphLib.Attributes.NetronGraphShapeAttribute),false);
                        if(objs.Length>=1)
                        {

                            //now, we are sure to have a shape object

                            NetronGraphShapeAttribute shapeAtts = objs[0] as NetronGraphShapeAttribute;
                            shapeSum = new ShapeSummary(path, shapeAtts.ShapeKey,shapeAtts.ShapeName, shapeAtts.ShapeCategory,shapeAtts.ReflectionName);
                            library.ShapeSummaries.Add(shapeSum);
                            if(this.mEnableContextMenu)
                                AddToContextMenu(shapeSum);

                            continue;//cannot be a connection and a shape at the same time
                        }

                        //try a custom connection

                        objs = tps[k].GetCustomAttributes(typeof(Netron.GraphLib.Attributes.NetronGraphConnectionAttribute),false);
                        if(objs.Length>=1)
                        {
                            //now, we are sure to have a connection object

                            NetronGraphConnectionAttribute conAtts = objs[0] as NetronGraphConnectionAttribute;
                            conSum = new ConnectionSummary(path, conAtts.ConnectionName, conAtts.ReflectionName);
                            library.ConnectionSummaries.Add(conSum);
                            continue;
                        }
                    }
                    catch(Exception exc)
                    {
                        Trace.WriteLine(exc.Message);
                        continue;
                    }

                }

            }
            catch(Exception exc)
            {
                Trace.WriteLine(exc.Message);
            }
        }
 /// <summary>
 /// Adds the given shape summary to the context menu
 /// </summary>
 /// <param name="summary"></param>
 protected void AddToContextMenu(ShapeSummary summary)
 {
     MenuItem currentItem =null;
     foreach(MenuItem item in this.mContextMenu.MenuItems)
     {
         if(item.Text == summary.ShapeCategory){ currentItem = item; break;}
     }
     if(currentItem == null)
     {
         this.mContextMenu.MenuItems.Add("-");
         currentItem =new MenuItem(summary.ShapeCategory);
         this.mContextMenu.MenuItems.Add(currentItem);
     }
     GraphMenuItem i =new GraphMenuItem(summary,new EventHandler(OnContextMenuItem));
     currentItem.MenuItems.Add(i);
 }
 public void AddItem(ShapeSummary summary, int imageIndex)
 {
     this.listView.Items.Add(new ShapesTabItem(summary,imageIndex));
 }
 public void AddItem(ShapeSummary summary)
 {
     this.listView.Items.Add(new ShapesTabItem(summary,0));
 }
 public ShapesTabItem(ShapeSummary mSummary, int imageIndex)
 {
     this.mSummary=mSummary;
     this.ImageIndex=imageIndex;
     this.Text = mSummary.ShapeName;
 }