flex topo

不能传源码文件。真是变态呀。
相关资料
http://blog.csdn.net/luqin1988/article/details/8533013

package graphics.hoperun.topo.implmnt.line
{
    import graphics.hoperun.topo.intrfce.line.ILine;
    import graphics.hoperun.topo.intrfce.node.INode;
    import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
    
    /**
     *The Line object.
     *
     * @author Loven
     */
    public class Line implements ILine
    {    
        //The identity code.
        private var _id:String;
        //The begin node.
        private var _fromNode:INode;
        //The target node.
        private var _toNode:INode;
        //The line renderer proxy object.
        private var _viewRenderer:ILineRenderer;
        //The business data object.
        private var _data:Object;
        
        public function get id():String{
            return _id;            
        }
        public function set id(id:String):void{
            _id=id;
        }
        
        public function get fromNode():INode{
            return _fromNode;            
        }
        public function set fromNode(fromNode:INode):void{
            _fromNode=fromNode;
        }
        
        public function get toNode():INode{
            return _toNode;            
        }
        public function set toNode(toNode:INode):void{
            _toNode=toNode;
        }
        
        public function get viewRenderer():ILineRenderer{
            return _viewRenderer;            
        }
        public function set viewRenderer(viewRenderer:ILineRenderer):void{
            _viewRenderer=viewRenderer;
        }
        
        public function get data():Object{
            return _data;            
        }
        public function set data(data:Object):void{
            _id=data.@id;
            _data=data;
        }
        
    }
}

package graphics.hoperun.topo.implmnt.model
{
	import graphics.hoperun.topo.intrfce.model.ILineLayoutModel;

	public class LineLayoutModel implements ILineLayoutModel
	{
		public function LineLayoutModel()
		{
		}
		private var _color:Number = 0;
		private var _markColor:Number = 0xff0000;
		private var _lineMarkFlag:Boolean = true;
		private var _lineArrowFlag:Boolean = true;
		
		
		public function get color():Number
		{
			return _color;
		}
		
		public function set color(num:Number):void
		{
			this._color = num;
		}
		
		public function get markColor():Number
		{
			return _markColor;
		}
		
		public function set markColor(num:Number):void
		{
			this._markColor = num;
		}
		public function get lineMarkFlag():Boolean
		{
			return _lineMarkFlag;
		}
		public function set lineMarkFlag(flag:Boolean):void
		{
			this._lineMarkFlag = flag;
		}
		
		public function get lineArrowFlag():Boolean
		{
			return _lineArrowFlag;
		}
		
		public function set lineArrowFlag(flag:Boolean):void
		{
			this._lineArrowFlag = flag;
		}
		
	}
}

package graphics.hoperun.topo.implmnt.node
{
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
	
	/**
	 *The Node object.
	 * 
	 * @author Loven
	 */
	public class Node implements INode
	{
		//The identity code.
		private var _id:String;
		//The coordinate-x.
		private var _x:int=0;
		//The coordinate-y.
		private var _y:int=0;
		//The edge renderer .
		private var _viewRenderer:IEdgeRenderer;
		//The business data for this node object.
		private var _data:Object;
		//Return the entering ILine object.
		protected var _inLines:Array=[];
		//Return the outting ILine object.
		protected var _outLines:Array=[];
		
		public function get id():String{
			return _id;			
		}
		public function set id(id:String):void{
			_id=id;
		}
		
		public function get x():int{
			return _x;			
		}
		public function set x(x:int):void{
			_x=x;
		}
		
		public function get y():int{
			return _y;			
		}
		public function set y(y:int):void{
			_y=y;
		}
		
		public function get viewRenderer():IEdgeRenderer{
			return _viewRenderer;			
		}
		public function set viewRenderer(viewRenderer:IEdgeRenderer):void{
			_viewRenderer=viewRenderer;
		}
		
		public function get data():Object{
			return _data;			
		}
		public function set data(data:Object):void{
			_id=data.@id;
			_data=data;
		}
			
		public function get inLines():Array {
			return _inLines;
		}
		public function get outLines():Array {
			return _outLines;
		}

		public function addInLine(line:ILine):void {
			_inLines[_inLines.length]=line;
		}
		
		public function addOutLine(line:ILine):void {
			_outLines[_outLines.length]=line;
		}

		public function removeInLine(line:ILine):void {
			
		}

		public function removeOutLine(line:ILine):void {
			
		}
		
	}
}


src\graphics\hoperun\topo\implmnt\renderer\edgeRenderer

<?xml version="1.0" encoding="utf-8"?>
<edge:IEdgeRenderer xmlns:mx="http://www.adobe.com/2006/mxml" width="32" height="32" xmlns:edge="graphics.hoperun.topo.intrfce.renderer.edgeRenderer.*" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import mx.controls.Image;
			import graphics.hoperun.topo.intrfce.node.INode;
			import resource.EmbeddedIcons;
			
			private var _node:INode = null;
			
			//Invoked by the createComplete Event.
			private function init():void{
				var imageObj:Image = EmbeddedIcons.generateImage(this.data.data.@imgUrl,this.width);
				imageObj.toolTip = this.data.data.@name;
				
				//Append the image object into here to display.
				this.addChild(imageObj);
			}

			override public function get node():INode{
				return _node;
			}
			override public function set node(node:INode):void{
				this._node = node;
			}
		]]>
	</mx:Script>
</edge:IEdgeRenderer>


package graphics.hoperun.topo.implmnt.renderer.lineRenderer
{
	import flash.display.Graphics;
	import flash.geom.Point;
	
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.main.IGraphicManager;
	import graphics.hoperun.topo.intrfce.model.ILineLayoutModel;
	import graphics.hoperun.topo.intrfce.node.INode;
	
	public class ArrowLineRenderer extends SimpleLineRenderer
	{
		/**
		 * The size of the arrowhead in pixel. The distance of the
		 * two points defining the base of the arrowhead.
		 * */
		private static var arrowBaseSize:Number = 10;
		
		private var _manager:IGraphicManager = null;
		/**
		 * The distance of the arrowbase from the tip in pixel.
		 * */
		private static var arrowHeadLength:Number = 20;
		
		public function ArrowLineRenderer(manager:IGraphicManager)
		{
			super();
			this._manager = manager;
		}

		//Draw the line object.
		override public function draw(line:ILine):void {
			var layout:ILineLayoutModel = _manager.lineLayoutModel;
			clearDraw();
			
			var lArrowBase:Point;
			var rArrowBase:Point;
			var mArrowBase:Point;
			
			var edgeAngle:Number;
			
			_iLine = line;
			var g:Graphics=this.graphics;
			var fromNode:INode = line.fromNode;
			var toNode:INode = line.toNode;
			var fP:Point = new Point(fromNode.viewRenderer.x + (fromNode.viewRenderer.width / 2.0),fromNode.viewRenderer.y + (fromNode.viewRenderer.height / 2.0));
			var tP:Point = new Point(toNode.viewRenderer.x + (toNode.viewRenderer.width / 2.0),toNode.viewRenderer.y + (toNode.viewRenderer.height / 2.0));

			g.lineStyle(1,layout.color);
			
			g.beginFill(layout.markColor);
			g.moveTo(fP.x, fP.y);
			g.lineTo(tP.x, tP.y);
			if(layout.lineMarkFlag){
				g.drawCircle((fP.x+tP.x)/2, (fP.y+tP.y)/2,5);
			}
			g.endFill();
			
			
			if(layout.lineArrowFlag){
				/* calculate the base bidpoint which is on
				 * the same vector defined between the two endpoints
				 *
				 * First Step: get the angle of the edge in radians
				 */
				edgeAngle = Math.atan2(tP.y - fP.y,tP.x - fP.x);
				/* Second step: the midpoint of the base can easily
				 * be specified in polar coords, using the same angle
				 * and as distance the original distance - the base distance
				 * then only the y value needs to be adjusted by the 
				 * y value of the from point
				 */
				mArrowBase = Point.polar(Point.distance(tP,fP) - arrowHeadLength,edgeAngle);
				mArrowBase.offset(fP.x,fP.y);
			
				/* Now find the left and right arrow base points
				 * in a similar way.
				 * 1. We can keep the angle but add/subtract 90 degrees.
				 * 2. As distance use the half of the base size
				 * 3. add the midpoint as reference 
				 */
				lArrowBase = Point.polar(arrowBaseSize / 2.9,(edgeAngle - (Math.PI / 2.0)));
				rArrowBase = Point.polar(arrowBaseSize / 2.9,(edgeAngle + (Math.PI / 2.0)));
				
				lArrowBase.offset(mArrowBase.x,mArrowBase.y);			
				rArrowBase.offset(mArrowBase.x,mArrowBase.y);
				
				/* now we actually draw */
				g.beginFill(uint(0));
				g.moveTo(fP.x, fP.y);
				g.lineTo(tP.x, tP.y);
				g.lineTo(lArrowBase.x, lArrowBase.y);
				g.lineTo(rArrowBase.x, rArrowBase.y);
				g.lineTo(tP.x, tP.y);
				g.endFill();
			}
			
		}
		
		//Free draw line object.
		override public function freeDraw(fP:Point,tP:Point):void {
			clearDraw();
			
			var g:Graphics=this.graphics;
			if(!fP || !tP){
				return;
			}

			g.lineStyle(2,0xF00000);
			
			g.beginFill(0xF00000);
			g.moveTo(fP.x, fP.y);
			g.lineTo(tP.x, tP.y);
			
			g.endFill();
		}
	}
}

package graphics.hoperun.topo.implmnt.renderer.lineRenderer
{
	import flash.display.Graphics;
	import flash.geom.Point;
	
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
	
	import mx.core.UIComponent;

	/**
	 * The simple line renderer object.
	 * 
	 * @author Loven
	 * */
	public class SimpleLineRenderer extends UIComponent implements ILineRenderer
	{
		protected var _iLine:ILine = null;
		public function SimpleLineRenderer()
		{
			super();
		}
		
		//Draw the line object.
		public function draw(line:ILine):void {
			clearDraw();
			_iLine = line;
			var g:Graphics=this.graphics;
			var fromNode:INode = line.fromNode;
			var toNode:INode = line.toNode;
			var fP:Point = new Point(fromNode.viewRenderer.x + (fromNode.viewRenderer.width / 2.0),fromNode.viewRenderer.y + (fromNode.viewRenderer.height / 2.0));
			var tP:Point = new Point(toNode.viewRenderer.x + (toNode.viewRenderer.width / 2.0),toNode.viewRenderer.y + (toNode.viewRenderer.height / 2.0));

			g.lineStyle(1,0);
			
			g.beginFill(0xff0000);
			g.moveTo(fP.x, fP.y);
			g.lineTo(tP.x, tP.y);
			
			
			g.drawCircle((fP.x+tP.x)/2, (fP.y+tP.y)/2,5);
			g.endFill();
			
		}
		
		//Free draw line object.
		public function freeDraw(fP:Point,tP:Point):void {
			clearDraw();
			
			var g:Graphics=this.graphics;
			if(!fP || !tP){
				return;
			}

			g.lineStyle(2,0xF00000);
			
			g.beginFill(0xF00000);
			g.moveTo(fP.x, fP.y);
			g.lineTo(tP.x, tP.y);
			
			g.endFill();
		}
		
		//Clear the last draw.
		public function clearDraw():void {
			this.graphics.clear();
		}
		
		public function get line():ILine{
			return _iLine;
		}
	}
}


/* 
 * The MIT License
 *
 * Copyright (c) 2007 The SixDegrees Project Team
 * (Jason Bellone, Juan Rodriguez, Segolene de Basquiat, Daniel Lang).
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package graphics.hoperun.topo.intrfce.layout {
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;
	
	import org.un.cava.birdeye.ravis.graphLayout.data.IGraph;
	import org.un.cava.birdeye.ravis.graphLayout.visual.IVisualGraph;
	import org.un.cava.birdeye.ravis.graphLayout.visual.IVisualNode;
	
	
	/**
	 * this interface defines all function calls
	 * that are needed to rearrange/layout a visualised
	 * graph.
	 * It also handles mouse interaction for moving objects
	 * (not for other stuff)
	 * */
	
	/**
	 * The interface to all layout algorithms that should work
	 * with VisualGraph components and underlying Graph data
	 * structures. This interface defines all the methods required
	 * to control the aspects of a layouter.
	 * */
	public interface ILayoutAlgorithm extends IEventDispatcher {
		
		/**
		 * Assign a VisualGraph object to the layouter,
		 * every layouter will need one to work, some may
		 * also offer to set it in their constructor.
		 * The layouter may choose to implicitly also set the
		 * graph object if it is found within the VisualGraph object.
		 * @param vg The VisualGraph object to assign.
		 * @see org.un.cava.birdeye.ravis.graphLayout.visual.VisualGraph#graph
		 * */
		function set vgraph(vg:IVisualGraph):void;
		
		/**
		 * Assign a Graph datastructure object to the
		 * layouter, every layouter will need one to work
		 * and some may allow to set it in their constructor
		 * @param g The Graph object to assign.
		 * */
		function set graph(g:IGraph):void;
		
		/**
		 * Access to a value that controls the length
		 * of links (or rather edges). It is up to the
		 * layouter what to do with it, and some may ignore
		 * this value under certain circumstances (like autoFit).
		 * The interface requires the value to be between 0 and 100;
		 * @default 10
		 * @param r The value to set.
		 * */
		function set linkLength(r:Number):void;
		
		/**
		 * @private
		 * */
		function get linkLength():Number;
		
		/**
		 * Flag to indicate whether the Layouter should attempt
		 * to automatically fit the layout to the screen.
		 * */
		function set autoFitEnabled(af:Boolean):void;
		
		/**
		 * @private
		 * */
		function get autoFitEnabled():Boolean;
		
		/**
		 * Indicator if the layout has changed or not. This
		 * can be used to notify the layouter, that some external
		 * means (like dragging & dropping a node) has changed the
		 * layout, and it will also be set by the layouter itself
		 * when the layouter updated the layout. This is used by
		 * the VisualGraphs "updateDisplayList()" method, to see
		 * whether to redraw all edges using the EdgeRenderer.
		 * @see org.un.cava.birdeye.ravis.graphLayout.visual.VisualGraph#updateDisplayList()
		 * */
		function set layoutChanged(lc:Boolean):void;
		
		/**
		 * @private
		 * */
		function get layoutChanged():Boolean;
		
		/**
		 * Indicator if currently an animation sequence is still
		 * in progress. During certain animation sequences, drag&drop
		 * might be disabled
		 * */
		function get animInProgress():Boolean;
		
		
		/**
		 * If set to true, animation is disabled and direct
		 * node location setting occurs (instantaneously).
		 * @default false
		 * */
		function set disableAnimation(d:Boolean):void;
		
		/**
		 * @private
		 * */
		function get disableAnimation():Boolean;
		
		
		/**
		 * This should reset all parameters of the layouter,
		 * which might not be needed for all layouters, and it is
		 * up to each layouter to do something with it.
		 * It would also stop any existing layouting loops/timers.
		 * */
		function resetAll():void;
		
		/**
		 * This is the main method of the layouter, that actually
		 * implements the calculation of the layout. It will be called
		 * by the VisualGraph on any significant change that will
		 * require a layout to be recomputed.
		 * @return true if something was done successfully, false otherwise.
		 * */
		function layoutPass():Boolean;
		
		/**
		 * This is an initialisation method to do any kind
		 * of initialisation before a layout pass. Not all 
		 * layouters may require this and thus implement it
		 * meaningfully.
		 * */
		function refreshInit():void;
		
		/**
		 * Notifies the layouter of a node drag event, in case
		 * it wants to react to that in special way.
		 * */
		function dragEvent(event:MouseEvent, vn:IVisualNode):void;
		
		/**
		 * Notifies the layouter of a node dragging-in-process event, in case
		 * it wants to react to that in special way.
		 * */
		function dragContinue(event:MouseEvent, vn:IVisualNode):void;
		
		/**
		 * Notifies the layouter of a node drop event, in case
		 * it wants to react to that in special way.
		 * */
		function dropEvent(event:MouseEvent, vn:IVisualNode):void;

		/**
		 * Notifies the layouter of a backgroung drag event, in case
		 * it wants to react to that in special way.
		 * */
		function bgDragEvent(event:MouseEvent):void;
		
		/**
		 * Notifies the layouter of a background drag-in-process event, in case
		 * it wants to react to that in special way.
		 * */
		function bgDragContinue(event:MouseEvent):void;
		
		/**
		 * Notifies the layouter of a background drop event, in case
		 * it wants to react to that in special way.
		 * */
		function bgDropEvent(event:MouseEvent):void;
	}
}

package graphics.hoperun.topo.intrfce.line
{
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
	
	/**
	 * The interface for Line model.
	 * 
	 * @author Loven
	 */
	public interface ILine
	{
		//The identity code.
		function get id():String;
		function set id(id:String):void;
		
		//The begin node.
		function get fromNode():INode;
		function set fromNode(fromNode:INode):void;
		
		//The target node.
		function get toNode():INode;
		function set toNode(toNode:INode):void;
		
		//The line renderer proxy object.
		function get viewRenderer():ILineRenderer;
		function set viewRenderer(viewRenderer:ILineRenderer):void;
		
		//The business data object.
		function get data():Object;
		function set data(data:Object):void;
	}
}

package graphics.hoperun.topo.intrfce.main
{
	public interface IDragDropManager
	{
		
	}
}

package graphics.hoperun.topo.intrfce.main
{
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.model.ILineLayoutModel;
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
	import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
	
	import mx.core.Container;
	
	public interface IGraphicManager
	{
		
		//C&R(create and return) the INode object, by the business data and view renderer object.
		function createNode(data:Object, edgeRenderer:IEdgeRenderer=null):INode;

		//C&R the ILine object, by the business data and view renderer object.
		function createLine(data:Object, lineRenderer:ILineRenderer=null):ILine;

		//Remove the INode object.
		function removeNode(node:INode):INode;

		//get node;s children number.
		function getNodeChildLength(node:INode):Number;

		//Remove the ILine object
		function removeLine(line:ILine):ILine;

		//Refresh the layout.
		function refresh():void;

		//Spread the effect by the IEdgeRenderer object.
		function updateLineRendererForNodeUI(edgeRenderer:IEdgeRenderer):void;
		
		//Auto layout.
		function autoLayoutByEdgeRenderer(edgeRenderer:IEdgeRenderer):void;
		
		//Return the INode by the IEdgeRenderer object.
		function getNodeByUI(edgeRenderer:IEdgeRenderer):INode;

		//Loaded from the XML object.
		function set dataXML(xml:XML):void;
		
		//Return the XML object.
		function get dataXML():XML;
		
		//Return the draw container object.
		function get drawSpace():Container;
		
		function get status():String;
		function set status(statusPara:String):void;
		
		function get lineLayoutModel():ILineLayoutModel;
		function set lineLayoutModel(lineLayoutModel:ILineLayoutModel):void;
	}
}

package graphics.hoperun.topo.intrfce.model
{
	public interface ILineLayoutModel
	{
		function get color():Number;
		function set color(num:Number):void;
		
		function get markColor():Number;
		function set markColor(num:Number):void;
		
		function get lineMarkFlag():Boolean;
		function set lineMarkFlag(flag:Boolean):void;
		
		function get lineArrowFlag():Boolean;
		function set lineArrowFlag(flag:Boolean):void;

	}
}

package graphics.hoperun.topo.intrfce.node
{
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
	
	/**
	 * The interface for the node.
	 * 
	 * @author Loven
	 */
	public interface INode
	{
		//The identity code.
		function get id():String;
		function set id(id:String):void;
		
		//The coordinate-x.
		function get x():int;
		function set x(x:int):void;
		
		//The coordinate-y.
		function get y():int;
		function set y(y:int):void;
		
		//The edge renderer .
		function get viewRenderer():IEdgeRenderer;
		function set viewRenderer(viewRenderer:IEdgeRenderer):void;
		
		//The business data for this node object.
		function get data():Object;
		function set data(data:Object):void;
		
		//Return the entering ILine object.
		function get inLines():Array;
		//Return the outting ILine object.
		function get outLines():Array;
		
		//Add the ILine object into the entering-ILine collections.
		function addInLine(line:ILine):void;
		//Add the ILine object into the outting-ILine collections.
		function addOutLine(line:ILine):void;
		
		Remove the ILine object into the entering-ILine collections.
		function removeInLine(line:ILine):void;
		//Remove the ILine object into the outting-ILine collections.
		function removeOutLine(line:ILine):void;
	}
}

package graphics.hoperun.topo.intrfce.renderer
{
	public interface IRenderer
	{
		
	}
}

package graphics.hoperun.topo.intrfce.renderer.edgeRenderer
{
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.IRenderer;
	
	import mx.containers.VBox;
	
	public class IEdgeRenderer extends VBox implements IRenderer
	{
		public function get node():INode{
			return null;
		}
		public function set node(node:INode):void{
		}
	}
}

package graphics.hoperun.topo.intrfce.renderer.lineRenderer
{
	import flash.geom.Point;
	
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.renderer.IRenderer;
	
	/**
	 * The interface ILine renderer.
	 * 
	 * @author Loven
	 * */
	public interface ILineRenderer extends IRenderer
	{
		//Draw with the ILine.
		function draw(line:ILine):void;
		
		//Freely draw with the ILine.
		function freeDraw(fP:Point,tP:Point):void;
		
		//Clear the draw
		function clearDraw():void;
		
		//
		function get line():ILine;
	}
}

package graphics.hoperun.topo.utils
{
    import flash.events.ContextMenuEvent;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    
    import graphics.hoperun.topo.intrfce.line.ILine;
    import graphics.hoperun.topo.intrfce.main.IGraphicManager;
    import graphics.hoperun.topo.intrfce.node.INode;
    import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
    import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
    
    import mx.controls.Alert;
    import mx.core.UIComponent;
    import mx.events.CloseEvent;
    
    //Manager the context menu register.
    public class ContextMenuManger
    {
        //Line key.
        public static var KEY_LINE_NAME:String = "";
        //Image key.
        public static var KEY_IMAGE_NAME:String = "";
        
        protected var lineMenu:ContextMenu;
        protected var imageMenu:ContextMenu;
        
        private var deleteLine:ContextMenuItem;
        private var deleteImage:ContextMenuItem;

        
                //The graphics manager object.
        private var _graphicManager:IGraphicManager = null;
        public function ContextMenuManger(_graphicManager:IGraphicManager)
        {
            this._graphicManager = _graphicManager;
            lineMenu = new ContextMenu();
            imageMenu = new ContextMenu();
            lineMenu.hideBuiltInItems();
            imageMenu.hideBuiltInItems();
            
            deleteLine = new ContextMenuItem("Delete line");
            deleteImage = new ContextMenuItem("Remove node");
            
            deleteLine.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,custmerHandler );
            deleteImage.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,custmerHandler);
            
            lineMenu.customItems.push(deleteLine);
            imageMenu.customItems.push(deleteImage);
        }
        //Custmer menu selected event handler.
        private function custmerHandler(event:ContextMenuEvent):void{            
            switch (event.target) {
               case deleteLine:
                  var line:ILine = (event.mouseTarget as ILineRenderer).line;
                  _graphicManager.removeLine(line);
                  _graphicManager.refresh();
                  break;
               case deleteImage:
                   var node:INode = (event.mouseTarget.parent as IEdgeRenderer).node;
                   tempNode = node;
                   if(_graphicManager.getNodeChildLength(node)>0){
                        Alert.show("This node has child-nodes,are you sure to remove all relations?","Message",Alert.OK | Alert.CANCEL,null,callback);
                   }else{
                           callback();
                   }
                   
                  break;
               default:break;
               
            }
        }
        private var tempNode:INode = null;
        private function callback(event:CloseEvent=null):void{
            if(event!=null){
                if(event.detail == Alert.OK){
                     _graphicManager.removeNode(tempNode);
                 }
            }else{
                 _graphicManager.removeNode(tempNode);
            }
               
             
       }
        //reset the registers
        public function resetRegister(objectArr:Array=null):void{
            if(objectArr==null){
                objectArr = _graphicManager.drawSpace.getChildren();
            }
            trace("objectArr[0] = " + objectArr[0]+"   objectArr.length = "+objectArr.length);
            //var contextMenu:
            for each(var child:Object in objectArr){
                if(child is IEdgeRenderer){
                    (child as IEdgeRenderer).contextMenu = imageMenu;
                }else if(child is ILineRenderer){
                    (child as UIComponent).contextMenu = lineMenu;
                }
            }
        }
    }
}

package graphics.hoperun.topo.utils
{
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	import graphics.hoperun.topo.implmnt.renderer.edgeRenderer.ImageNodeRenderer;
	import graphics.hoperun.topo.implmnt.renderer.lineRenderer.ArrowLineRenderer;
	import graphics.hoperun.topo.implmnt.renderer.lineRenderer.SimpleLineRenderer;
	import graphics.hoperun.topo.intrfce.line.ILine;
	import graphics.hoperun.topo.intrfce.main.IGraphicManager;
	import graphics.hoperun.topo.intrfce.node.INode;
	import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
	import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
	
	import mx.containers.Canvas;
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.core.Container;
	import mx.core.UIComponent;
	import mx.events.CloseEvent;
	import mx.events.DragEvent;
	import mx.managers.DragManager;
	
	//Manager the node Events and Listeners register or remove
	public class DragDropManager
	{
		//The judgement drop&drag.
		public static var KEY_IMAGE_DRAG_DROP:String = "itemSource";
		//Draw the container.
		private var _drawSpace:Container = null;
		//The graphics manager object. 
		private var _graphicManager:IGraphicManager = null;
		//The begin line object.
		private var lineFromPoint:Point;
		//The begin node object
		private var fromNode:INode;
		private var curLine:SimpleLineRenderer;
		
		private var _contextMenuManger:ContextMenuManger;
		
		public function DragDropManager(_graphicManager:GraphicManager)
		{
			this._graphicManager = _graphicManager;
			this._drawSpace =_graphicManager.drawSpace;
			this._contextMenuManger = new ContextMenuManger(this._graphicManager);
			this._contextMenuManger.resetRegister();
		}
		
		//reset the registers
		public function resetRegister():void{
			var childDisplayObj:DisplayObject = null;
			for each(var child:Object in _drawSpace.getChildren()){						
				doResetRegisterByObject(child,_graphicManager.status);
	    	}
		}
		/**
		 * Reset the registers.
		 * 
		 * @param child the child object
		 * @param status the register status.
		 * */
		private function doResetRegisterByObject(child:Object,status:String):void{
			var childDisplayObj:DisplayObject = null;
			switch (_graphicManager.status) {
				case GraphicManager.S_DRAWLINE:
					if(child is IEdgeRenderer){
						childDisplayObj = (child as DisplayObject); 
    		    		childDisplayObj.removeEventListener(MouseEvent.MOUSE_DOWN, innerStartDragging);
						childDisplayObj.removeEventListener(MouseEvent.MOUSE_UP, innerStopDragging);
    		    		childDisplayObj.addEventListener(MouseEvent.MOUSE_DOWN,addLine,false,0,true);
    		    		//Disabled the double-click event.
    		    		(childDisplayObj as IEdgeRenderer).doubleClickEnabled = false;
    		    		childDisplayObj.removeEventListener(MouseEvent.DOUBLE_CLICK,dbclickHandler);
    		    		
    		    		childDisplayObj.removeEventListener(DragEvent.DRAG_ENTER,dragEnterHandler);
    		    		childDisplayObj.removeEventListener(DragEvent.DRAG_DROP,dragDropHandler);
		    		}else if(child is ILineRenderer){
		    			childDisplayObj = (child as DisplayObject); 
		    			childDisplayObj.removeEventListener(DragEvent.DRAG_ENTER,dragEnterHandler);
    		    		childDisplayObj.removeEventListener(DragEvent.DRAG_DROP,dragDropHandler);
		    		}
					break;
					
				default://S_NORMAL
					if(child is IEdgeRenderer){
						childDisplayObj = (child as DisplayObject); 
    		    		childDisplayObj.addEventListener(MouseEvent.MOUSE_DOWN, innerStartDragging,false,0,true);
						childDisplayObj.addEventListener(MouseEvent.MOUSE_UP, innerStopDragging,false,0,true);
    		    		childDisplayObj.removeEventListener(MouseEvent.MOUSE_DOWN,addLine);

    		    		childDisplayObj.addEventListener(DragEvent.DRAG_ENTER,dragEnterHandler);
    		    		childDisplayObj.addEventListener(DragEvent.DRAG_DROP,dragDropHandler);
    		    		
    		    		//Enabled the double-click event.
    		    		(childDisplayObj as IEdgeRenderer).doubleClickEnabled = true;
    		    		childDisplayObj.addEventListener(MouseEvent.DOUBLE_CLICK,dbclickHandler);
		    		}else if(child is ILineRenderer){
		    			childDisplayObj = (child as DisplayObject); 
		    			childDisplayObj.addEventListener(DragEvent.DRAG_ENTER,dragEnterHandler);
    		    		childDisplayObj.addEventListener(DragEvent.DRAG_DROP,dragDropHandler);
		    		}
					break;
			}
		}
		//Double click event handler.
		private function dbclickHandler(event:MouseEvent):void{
			_graphicManager.autoLayoutByEdgeRenderer(event.currentTarget as IEdgeRenderer);
		}
		// Called when the user moves the drag proxy onto the drop target.
		private function dragEnterHandler(event:DragEvent):void {
		
			if (event.dragSource.hasFormat(KEY_IMAGE_DRAG_DROP)) {
				var dropTarget:UIComponent=UIComponent(event.currentTarget);
				// Accept the drop.
				DragManager.acceptDragDrop(dropTarget);
			}
			
		}
		//Add the new node.
		private function dragDropHandler(event:DragEvent):void {
			var eventObj:Object = null;
			var data:Object = null;
			if(event.currentTarget is IEdgeRenderer){
				data = event.dragSource.dataForFormat(KEY_IMAGE_DRAG_DROP);
				var dragItem:ImageNodeRenderer=new ImageNodeRenderer();
				var tData:XML=<node id="undifine" name="unknow" desc="unknow" x="200" y="600" imgUrl=""/>;
				tData.@id=getTimer();
				tData.@x=Canvas(event.currentTarget.parent).mouseX+50;
				tData.@y=Canvas(event.currentTarget.parent).mouseY+50;
				tData.@imgUrl=(data as Image).source+"";
	
				var newNode:INode = _graphicManager.createNode(tData,dragItem);
				var oldNode:INode = _graphicManager.getNodeByUI(event.currentTarget as IEdgeRenderer);
				
				var lineData:XML=<line id="" fromNode="" toNode=""/>;
				lineData.@id=getTimer();
				lineData.@fromNode=oldNode.data.@id;
				lineData.@toNode=newNode.data.@id;
		
				var newLine:ILine = _graphicManager.createLine(lineData,new ArrowLineRenderer(_graphicManager));
				newLine.viewRenderer.draw(newLine);
				
				//New item should be added listener.
				doResetRegisterByObject(dragItem,_graphicManager.status);
				//Register the context listeners.
				this._contextMenuManger.resetRegister([dragItem,newLine.viewRenderer]);
			}else if(event.currentTarget is ILineRenderer){
				eventObj = event.currentTarget;
				data = event.dragSource.dataForFormat(KEY_IMAGE_DRAG_DROP);
				Alert.show("Are you sure to lay the net cell on this position, which would be inserted to between both of net cells.",null,Alert.OK | Alert.CANCEL,null,inserNetCellHandler);
			}
			function inserNetCellHandler(event:CloseEvent):void{
				if(event.detail == Alert.OK){
					var dragItem:ImageNodeRenderer=new ImageNodeRenderer();
					var lineRenderer:ILineRenderer = eventObj as ILineRenderer;
					var line:ILine = lineRenderer.line;
					var fromNode:INode = line.fromNode;

					var toNode:INode = line.toNode;
					//Remove the original line.
					_graphicManager.removeLine(line);
					var tData:XML=<node id="undifine" name="unknow" desc="unknow" x="200" y="600" imgUrl=""/>;
					tData.@id=getTimer();
					tData.@x=(fromNode.viewRenderer.x+toNode.viewRenderer.x)/2;
					tData.@y=(fromNode.viewRenderer.y+toNode.viewRenderer.y)/2;
					tData.@imgUrl=(data as Image).source+"";
					var newNode:INode = _graphicManager.createNode(tData,dragItem);
					
					var fLineData:XML=<line id="" fromNode="" toNode=""/>;
					var tLineData:XML=<line id="" fromNode="" toNode=""/>;
					fLineData.@id=getTimer();
					fLineData.@fromNode=fromNode.data.@id;
					fLineData.@toNode=newNode.data.@id;
					
					tLineData.@id=getTimer();
					tLineData.@fromNode=newNode.data.@id;
					tLineData.@toNode=toNode.data.@id;
					
					var fromLine:ILine = _graphicManager.createLine(fLineData,new ArrowLineRenderer(_graphicManager));
					var toLine:ILine = _graphicManager.createLine(tLineData,new ArrowLineRenderer(_graphicManager));
					fromLine.viewRenderer.draw(fromLine);
					toLine.viewRenderer.draw(toLine);
					
					//New item should be added listener.
					doResetRegisterByObject(dragItem,_graphicManager.status);
					//Register the context listeners.
					_contextMenuManger.resetRegister([dragItem,fromLine.viewRenderer,toLine.viewRenderer]);
				}
			}
		}
		
		//Add the line.
		private function addLine(event:MouseEvent):void{
			if(curLine!=null){
				curLine.parent.removeChild(curLine);
				curLine=null;
			}
			
		    fromNode=_graphicManager.getNodeByUI(event.currentTarget as IEdgeRenderer);
		    if(fromNode){
		    	for each(var child:Object in _drawSpace.getChildren()){
					if(child!=event.currentTarget){
						(child as DisplayObject).addEventListener(MouseEvent.MOUSE_UP,completeDrawLine);
					} 
					
		    	}
		    	curLine=new ArrowLineRenderer(_graphicManager);
				_drawSpace.addChildAt(curLine,0);
				var parent:Canvas=((event.currentTarget as UIComponent).parent) as Canvas;
				var x:int =parent.mouseX;
				var y:int =parent.mouseY;
				lineFromPoint=new Point(x,y);
				curLine.freeDraw(lineFromPoint,lineFromPoint);
				_drawSpace.addEventListener(MouseEvent.MOUSE_MOVE,doDrawLine,false,0,true);
				_drawSpace.addEventListener(MouseEvent.MOUSE_UP,stopDrawLineAndRemove,false,0,true);
		    }
		}
		//After dragging, draw a line.
		private function completeDrawLine(event:MouseEvent):void{
			var toNode:INode=_graphicManager.getNodeByUI(event.currentTarget as IEdgeRenderer);
			
			var tData:XML=<line id="" fromNode="" toNode=""/>;
			tData.@id=getTimer();
			tData.@fromNode=fromNode.data.@id;
			tData.@toNode=toNode.data.@id;
			
			//dragItem.data=data;	
			var newLine:ILine=_graphicManager.createLine(tData,curLine);
			newLine.viewRenderer.draw(newLine);
			removeDrawLineListener();
			
			//Register the context listeners.
			this._contextMenuManger.resetRegister([newLine.viewRenderer]);
		}
		//Stop dragging and drawing
		private function stopDrawLineAndRemove(event:MouseEvent):void{
			curLine.parent.removeChild(curLine);
			removeDrawLineListener();
			
			
			//curLine.clearDraw();
		
		}
		//Remove the drawing listener.
		private function removeDrawLineListener():void{
			_drawSpace.removeEventListener(MouseEvent.MOUSE_MOVE,doDrawLine);
			_drawSpace.removeEventListener(MouseEvent.MOUSE_UP,stopDrawLineAndRemove);
			for each(var child:Object in _drawSpace.getChildren()){						
				(child as DisplayObject).removeEventListener(MouseEvent.MOUSE_UP,completeDrawLine);	
		    }
		    curLine=null;				
		}
		//Drawing the temp line.
		private function doDrawLine(event:MouseEvent):void
		{	
			var x:int =Canvas(event.currentTarget).mouseX;
			var y:int =Canvas(event.currentTarget).mouseY;
			var lineToPoint:Point=new Point(x,y);
			curLine.freeDraw(lineFromPoint,lineToPoint);
		}
		// Invoked by the mouse-on  event.
		private function innerStartDragging(event:MouseEvent):void
		{
			var parent:Container=(event.currentTarget as UIComponent).parent as Container;
			(event.currentTarget as UIComponent).startDrag();
			event.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE,updateDraggingLine);
		}
		//
		private function updateDraggingLine(event:MouseEvent):void{
			_graphicManager.updateLineRendererForNodeUI(event.currentTarget as IEdgeRenderer);
		}
		// Invoked by the mouse-up event 
		private function innerStopDragging(event:MouseEvent):void
		{	
			_graphicManager.updateLineRendererForNodeUI(event.currentTarget as IEdgeRenderer);
			event.currentTarget.stopDrag();
			event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE,updateDraggingLine);
		}
	}
}

package graphics.hoperun.topo.utils
{

    import flash.utils.Dictionary;
    
    import graphics.hoperun.topo.implmnt.line.Line;
    import graphics.hoperun.topo.implmnt.model.LineLayoutModel;
    import graphics.hoperun.topo.implmnt.node.Node;
    import graphics.hoperun.topo.implmnt.renderer.edgeRenderer.ImageNodeRenderer;
    import graphics.hoperun.topo.implmnt.renderer.lineRenderer.ArrowLineRenderer;
    import graphics.hoperun.topo.implmnt.renderer.lineRenderer.SimpleLineRenderer;
    import graphics.hoperun.topo.intrfce.line.ILine;
    import graphics.hoperun.topo.intrfce.main.IGraphicManager;
    import graphics.hoperun.topo.intrfce.model.ILineLayoutModel;
    import graphics.hoperun.topo.intrfce.node.INode;
    import graphics.hoperun.topo.intrfce.renderer.edgeRenderer.IEdgeRenderer;
    import graphics.hoperun.topo.intrfce.renderer.lineRenderer.ILineRenderer;
    
    import mx.core.Container;
    import mx.core.UIComponent;


    public class GraphicManager implements IGraphicManager
    {
        //The dictionary for node with ID as key.
        protected var _nodeIdMap:Dictionary = new Dictionary();
        //The dictionary for node with IEdgeRenderer as key.
        protected var _nodeUIMap:Dictionary = new Dictionary();
        //The canvas object.
        protected var _drawSpace:Container;
        //The ILine object collections.
        protected var _lineMap:Dictionary=new Dictionary();
        //Initialized the status.
        public static const S_NORMAL:String="s_normal";
        //Beging drawing status.
        public static const S_DRAWLINE:String="s_drawing";
        //The current status.
        protected var _status:String;
        //The line layout model.
        protected var _lineLayoutModel:ILineLayoutModel;
        
        public function GraphicManager(drawSpace:Container,statusP:String=S_NORMAL)
        {
            super();
            this._drawSpace = drawSpace;
            this.status = statusP;
            _lineLayoutModel = new LineLayoutModel();
        }
        
        public function get lineLayoutModel():ILineLayoutModel{
            return _lineLayoutModel;
        }
        public function set lineLayoutModel(lineLayoutModel:ILineLayoutModel):void{
            this._lineLayoutModel = lineLayoutModel;
        }
        
        public function get status():String{
            return _status;
        }
        public function set status(statusP:String ):void{
            this._status = statusP;
        }                
        //Return the drawSpace object.
        public function get drawSpace():Container{
            return _drawSpace;
        }
        //Create the INdoe object
        public function createNode(data:Object, edgeRenderer:IEdgeRenderer=null):INode
        {
            var node:INode = new Node();
            node.data = data;
            if (edgeRenderer == null)
            {
                node.viewRenderer = new ImageNodeRenderer();
            }
            else
            {
                node.viewRenderer = edgeRenderer;
            }
            (node.viewRenderer as Container).data = node;
            node.viewRenderer.node = node;
            //Record the node objects
            _nodeIdMap[node.id]=node;
            _nodeUIMap[node.viewRenderer]=node;
            _drawSpace.addChild(node.viewRenderer);
            
            node.viewRenderer.x=int(data.@x);
            node.viewRenderer.y=int(data.@y);

            return node;
        }
        //Create the ILine Object.
        public function createLine(data:Object, lineRenderer:ILineRenderer=null):ILine
        {
            var line:ILine=new Line();
            line.data=data;
            //            
            line.fromNode=_nodeIdMap[data.@fromNode + ""];
            if (line.fromNode)
            {
                line.fromNode.addOutLine(line);
            }
            line.toNode=_nodeIdMap[data.@toNode + ""];
            if (line.toNode)
            {
                line.toNode.addInLine(line);
            }
            if (lineRenderer)
            {
                line.viewRenderer=lineRenderer;
            }
            else
            {
                line.viewRenderer=new SimpleLineRenderer();
            }

            (line.viewRenderer as ILineRenderer).draw(line);
            _lineMap[line.id]=line;
            if ((line.viewRenderer as UIComponent).parent)
            {
                (line.viewRenderer as UIComponent).parent.removeChild(line.viewRenderer as UIComponent);
            }
            //trace("_drawSpace.addChildAt(line.viewRenderer as UIComponent, 0) = "+line.viewRenderer);
            _drawSpace.addChildAt(line.viewRenderer as UIComponent, 0);
            return line;
        }
        //Remove the INode object.
        public function removeNode(node:INode):INode
        {
            for each(var inLine:ILine in node.inLines){
                removeLine(inLine);
            }
            for each(var outLine:ILine in node.outLines){
                removeLine(outLine);
            }
            _drawSpace.removeChild(node.viewRenderer);
            delete _nodeIdMap[node.id];
            delete _nodeUIMap[node.viewRenderer];
            return node;
        }
        //get node;s children number.
        public function getNodeChildLength(node:INode):Number{
            var num:Number = 0;
            for each(var outLine:ILine in node.outLines){
                if(_drawSpace.contains(outLine.viewRenderer as UIComponent)){
                    num++;
                }
            }
            return num;
        }
        //Remove the ILine object.
        public function removeLine(line:ILine):ILine
        {
            if(_drawSpace.contains(line.viewRenderer as UIComponent)){
                //trace("line.viewRenderer = "+line.viewRenderer);
                _drawSpace.removeChild(line.viewRenderer as UIComponent);
                //trace("Successful remove: "+line.viewRenderer);
                delete _lineMap[line.id];
            }
            return line;
        }
        //Refresh the layout.
        public function refresh():void
        {
            for each(var line:ILine in _lineMap){
                line.viewRenderer.draw(line);
            }
            //_drawSpace.invalidateDisplayList();
        }
        //Spread the effect by the IEdgeRenderer object.
        public function updateLineRendererForNodeUI(edgeRenderer:IEdgeRenderer):void
        {
            var node:INode=getNodeByUI(edgeRenderer);
            if (node)
            {
                var inLines:Array=node.inLines;
                for each (var line:Object in inLines)
                {
                    (line as ILine).viewRenderer.draw(line as ILine);
                }
                var outLines:Array=node.outLines;
                for each (line in outLines)
                {
                    (line as ILine).viewRenderer.draw(line as ILine);
                }
            }
        }
        //Auto layout.
        public function autoLayoutByEdgeRenderer(edgeRenderer:IEdgeRenderer):void{
            var node:INode=getNodeByUI(edgeRenderer);
            node.viewRenderer.x=node.viewRenderer.x+10;
            node.viewRenderer.y=node.viewRenderer.y+10;
            updateLineRendererForNodeUI(edgeRenderer);
            doLayoutByEdgeRenderer(edgeRenderer);
        }
        //Do caculate the layout of the node.
        private function doLayoutByEdgeRenderer(edgeRenderer:IEdgeRenderer,index:Number=0):void{
            //TODO:
            
        }
        
        //Return the INode by the IEdgeRenderer object.
        public function getNodeByUI(edgeRenderer:IEdgeRenderer):INode
        {
            return _nodeUIMap[edgeRenderer] as INode;
        }
        
        //Loaded the date from the XML Object.
        public function set dataXML(xml:XML):void
        {
            //The node-objects' collections.
            for each (var nodeXML:XML in xml.node)
            {
                createNode(nodeXML);
            }
            //The nodes' relation-collections.
            for each (var lineXML:XML in xml.line)
            {
                createLine(lineXML,new ArrowLineRenderer(this));
            }
        }
        
        public function get dataXML():XML
        {
            var root:XML=new XML("<root></root>");
            for each (var node:Object in _nodeIdMap)
            {
                root.appendChild((node as INode).data);
            }
            for each (var line:Object in _lineMap)
            {
                root.appendChild((line as ILine).data);
            }

            return root;
        }
        
    }
}

package resource
{
	import mx.controls.Image;
		
	public class EmbeddedIcons {
	 	[Bindable]
		[Embed(source="image/monitor/olt.png")]
	 	static public var OLT:Class;
	 	[Bindable]
		[Embed(source="image/monitor/onu.png")]
	 	static public var ONU:Class;
	 	[Bindable]
		[Embed(source="image/monitor/other.png")]
	 	static public var OTHER:Class;
	 	[Bindable]
		[Embed(source="image/monitor/splitter.png")]
	 	static public var SPLITTER:Class;
	 	
	 	/**
	 	 * Generate the image.
	 	 * 
	 	 * @param type the type of image
	 	 * @param size the size of image
	 	 * */
	 	public static function generateImage(type:String, size:int = -1):Image {
	 		var img:Image = new Image();
	 		if(size>=0){
		 		img.width = size;
		 		img.height = size;
	 		}
	 		
			switch(type) {
				case "olt":
				    img.source = EmbeddedIcons.OLT;
					break;
				case "onu":
				    img.source = EmbeddedIcons.ONU;
					break;
				case "other":
				    img.source = EmbeddedIcons.OTHER;
					break;
				case "splitter":
				    img.source = EmbeddedIcons.SPLITTER;
					break;
			    default:
					img.source = EmbeddedIcons.OLT;
					break;
			}
			return img;
	 	}
	}
}

src\resource\data    circleNode.xml

<root>
  <center type='circle' radius='200' x='400' y='400' ></center>
  
  <node id="1" name="A"   alpth="0" imgUrl="a1" />
  <node id="2" name="B.1" alpth="60" imgUrl="a2" />
  <node id="3" name="B.2" alpth="120" imgUrl="a2" />
  <node id="4" name="C.1" alpth="180" imgUrl="a3" />
  <node id="5" name="C.2" alpth="240" imgUrl="a3"/>
  <node id="6" name="C.3" alpth="300" imgUrl="a3"/>

  
  <line id="1" fromNode="1" toNode="2" />  
  <line id="2" fromNode="2" toNode="3" />
  <line id="3" fromNode="3" toNode="4"/>
  <line id="4" fromNode="4" toNode="5"/>
  <line id="5" fromNode="5" toNode="6" />
  <line id="6" fromNode="6" toNode="1" />
</root>
testNode.xml

<root>
  <node id="1" name="A" x="300" y="20" imgUrl="olt" />
  <node id="2" name="B.1" x="150" y="70" imgUrl="splitter" />
  <node id="3" name="B.2" x="450" y="70" imgUrl="splitter" />
  <node id="4" name="C.1" x="75" y="120" imgUrl="onu" />
  <node id="5" name="C.2" x="225" y="120" imgUrl="onu"/>
  <node id="6" name="C.3" x="375" y="120" imgUrl="onu"/>
  <node id="7" name="C.4" x="525" y="120" imgUrl="onu" />
  
  
  <line id="1" fromNode="1" toNode="2" />  
  <line id="2" fromNode="1" toNode="3" />
  <line id="3" fromNode="2" toNode="4"/>
  <line id="4" fromNode="2" toNode="5"/>
  <line id="5" fromNode="3" toNode="6" />
  <line id="6" fromNode="3" toNode="7" />
</root>


src\resource\image\monitor

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Python topoJSON 库主要用于处理和生成 TopoJSON 文件,TopoJSON 是一种地理空间数据压缩格式,它结合了矢量地图、拓扑信息以及高级压缩技术。这种格式由 Michael Bostock 开发,并且能够非常有效地表示复杂的空间数据集。 在 Python 中,你可以通过安装名为 `topojson` 的库来利用 TopoJSON 功能。这个库允许用户创建、读取、转换和操作 TopoJSON 格式的文件。 ### 安装 topopython 为了在你的 Python 环境中使用 `topopython` 库,你需要先将其安装到你的系统上: ```bash pip install topopython ``` ### 使用示例 假设你有以下 JSON 数据: ```json { "type": "Topology", "objects": { "world": [ {"type": "Polygon", "id": 0}, {"type": "Polygon", "id": 1} ] }, "geometries": [], "links": [], "meta": {} } ``` 你想将这样的 JSON 转换为 TopoJSON 文件,首先需要导入相应的模块并编写一些代码: ```python from topopython import TopologyEncoder # 将 JSON 字符串转换为 Python 对象 data = """ { "type": "Topology", "objects": { "world": [ {"type": "Polygon", "id": 0}, {"type": "Polygon", "id": 1} ] }, "geometries": [], "links": [], "meta": {} } """ # 解析 JSON 数据 import json topo_data = json.loads(data) # 创建编码器实例并将 JSON 数据传递给它 encoder = TopologyEncoder() topojson_output = encoder.encode(topo_data) print("Generated TopoJSON:") print(topojson_output) ``` 这只是一个基本示例。实际上,`topopython` 提供了许多其他功能,如解析、合并和分割 TopoJSON 文件等。 ### 相关问题: 1. **如何优化大型地理数据集的存储与传输**? - 使用 TopoJSON 可以显著减少地理数据的体积,同时保留所有拓扑关系,这对于大数据集来说是一个巨大优势。 2. **Python topoJSON 库支持哪些数据格式**? - Python topoJSON 库通常支持多种输入格式(例如 GeoJSON 或简单的 JSON),可以将它们转换为 TopoJSON 输出。 3. **在什么场景下使用 TopoJSON 最有效**? - 当处理大量复杂的地理数据,尤其是在需要高效处理和传输数据的Web应用或者GIS项目中,使用 TopoJSON 可以极大地提高性能并节省资源。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值