Esempio n. 1
0
        private D2dAdaptableControl CreateControl(bool createCircutGroup)
        {
            var d2dControl = new D2dAdaptableControl();

            d2dControl.SuspendLayout();
            d2dControl.Dock = DockStyle.Fill;
            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.Scale        = new PointF(1.25f, 1.25f);
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale     = new PointF(0.000001f, 0.000001f);
            transformAdapter.MaxScale     = new PointF(5, 5);

            var annotationAdaptor = new D2dAnnotationAdapter(m_editor.Theme); // display annotations under diagram

            annotationAdaptor.PickingDisabled = true;
            var gridAdapter = new D2dGridAdapter();

            gridAdapter.Enabled = false;
            gridAdapter.Visible = true;

            D2dGraphAdapter <Module, Connection, ICircuitPin> graphAdapter;

            if (createCircutGroup)
            {
                var subG = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(m_editor.SubCircuitRenderer, transformAdapter);
                graphAdapter = subG;
            }
            else
            {
                graphAdapter = new D2dGraphAdapter <Module, Connection, ICircuitPin>(m_editor.CircuitRenderer, transformAdapter);
            }


            d2dControl.Adapt(
                transformAdapter,
                gridAdapter,
                annotationAdaptor,
                graphAdapter,
                new DraggableRect(this));

            d2dControl.ResumeLayout();

            transformAdapter.TransformChanged += (s, e) => UpdateControlName(((ITransformAdapter)s).Scale.X);
            d2dControl.SizeChanged            += d2dControl_SizeChanged;

            return(d2dControl);
        }
Esempio n. 2
0
        private D2dAdaptableControl CreateControl(bool createCircutGroup)
        {
            var d2dControl = new D2dAdaptableControl();

            d2dControl.SuspendLayout();

            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.Scale        = new PointF(1.25f, 1.25f);
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale     = new PointF(1.0f, 1.0f);
            transformAdapter.MaxScale     = new PointF(5, 5);

            var annotationAdaptor = new D2dAnnotationAdapter(m_editor.Theme); // display annotations under diagram
            var gridAdapter       = new D2dGridAdapter();

            gridAdapter.Enabled = false;
            gridAdapter.Visible = true;


            D2dGraphAdapter <Module, Connection, ICircuitPin> graphAdapter;

            if (createCircutGroup)
            {
                var subG = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(m_editor.SubCircuitRenderer, transformAdapter);
                subG.SettingVisibleWorldBoundsDisabled = true;
                graphAdapter = subG;
            }
            else
            {
                graphAdapter = new D2dGraphAdapter <Module, Connection, ICircuitPin>(m_editor.CircuitRenderer, transformAdapter);
            }

            d2dControl.Adapt(

                transformAdapter,
                new MouseWheelManipulator(transformAdapter),
                gridAdapter,
                annotationAdaptor, //Needs to be before circuitAdapter so that comments appear under elements.
                graphAdapter);

            d2dControl.ResumeLayout();
            d2dControl.Dock = DockStyle.Fill;

            transformAdapter.TransformChanged += (s, e) => UpdateControlName(((ITransformAdapter)s).Scale.X);
            return(d2dControl);
        }
Esempio n. 3
0
        private void control_DoubleClick(object sender, EventArgs e)
        {
            AdaptableControl d2dHoverControl = (AdaptableControl)sender;
            Point            clientPoint     = d2dHoverControl.PointToClient(Control.MousePosition);

            D2dGraphAdapter <Module, Connection, ICircuitPin> graphAdapter =
                d2dHoverControl.As <D2dGraphAdapter <Module, Connection, ICircuitPin> >();
            GraphHitRecord <Module, Connection, ICircuitPin> hitRecord = graphAdapter.Pick(clientPoint);
            Group subGraph          = null;
            var   subGraphReference = hitRecord.Node.As <GroupReference>();

            if (subGraphReference != null)
            {
                var templatingContext = m_contextRegistry.GetMostRecentContext <TemplatingContext>();
                if (templatingContext != null && templatingContext.IsExternalTemplate(subGraphReference.Template))
                {
                    return;                                 // templates should only be editable in the document that owns the template
                }
                DialogResult checkResult = DialogResult.No; //direct editing
                if (checkResult == DialogResult.No)
                {
                    subGraph = subGraphReference.Group.As <Group>();
                    var graphValidator = subGraphReference.DomNode.GetRoot().Cast <CircuitValidator>();
                    graphValidator.UpdateTemplateInfo(subGraph);
                }
            }
            else
            {
                subGraph = hitRecord.Node.As <Group>();
            }
            if (subGraph != null)
            {
                var viewingContext = subGraph.Cast <ViewingContext>();
                if (viewingContext.Control != null)
                {
                    // sub-graph is already open, just show control
                    m_controlHostService.Show(viewingContext.Control);
                }
                else
                {
                    // create new circuit editing control for sub-circuit
                    AdaptableControl subCircuitControl = CreateCircuitControl(subGraph.DomNode);
                    viewingContext.Control = subCircuitControl;

                    // use group’s hierarchy as control name
                    string name  = string.Empty;
                    bool   first = true;
                    foreach (var domNode in subGraph.DomNode.GetPath())
                    {
                        if (domNode.Is <Group>())
                        {
                            if (first)
                            {
                                name  = domNode.Cast <Group>().Name;
                                first = false;
                            }
                            else
                            {
                                name += "/" + domNode.Cast <Group>().Name;
                            }
                        }
                    }

                    string description = name;

                    var editingContext = subGraph.DomNode.Cast <CircuitEditingContext>();
                    editingContext.GetLocalBound       = GetLocalBound;
                    editingContext.GetWorldOffset      = GetWorldOffset;
                    editingContext.GetTitleHeight      = GetTitleHeight;
                    editingContext.GetLabelHeight      = GetLabelHeight;
                    editingContext.GetSubContentOffset = GetSubContentOffset;

                    subCircuitControl.Context   = editingContext;
                    editingContext.SchemaLoader = m_schemaLoader; // schema needed for cut and paste between applications

                    ControlInfo controlInfo = new ControlInfo(name, description, StandardControlGroup.Center);
                    //controlInfo.Docking = new ControlInfo.DockingInfo() // smart docking behavior
                    //{
                    //    GroupTag = subGraph.DomNode.Lineage.AsIEnumerable<Group>().Last(),// use the top-level parent group
                    //    Order = subGraph.Level
                    //};
                    m_circuitControlRegistry.RegisterControl(subGraph.DomNode, subCircuitControl, controlInfo, this);

                    var enumerableContext = subGraph.DomNode.Cast <CircuitEditingContext>().Cast <IEnumerableContext>();
                    var items             = (enumerableContext != null) ? enumerableContext.Items : null;
                    subCircuitControl.As <IViewingContext>().Frame(items);
                }
            }
        }
Esempio n. 4
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();

            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale       = true;
            transformAdapter.MinScale           = new PointF(0.01f, 0.01f);
            transformAdapter.MaxScale           = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);

            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();

            ((ILayoutConstraint)canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter      = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator     = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter          = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();

            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(Theme); // display annotations under diagram

            var d2dRectangleDragSelector = new D2dRectangleDragSelector();
            var d2dRectangleDragRenderer = new D2dRectangleDragRenderer(d2dRectangleDragSelector);
            var gridAdapter = new D2dGridAdapter();

            gridAdapter.ConstraintEnabled = SnapToGridEnabled;
            //gridAdapter.Enabled = false;
            //gridAdapter.Visible = true;
            if (circuitNode.Is <Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter <Module, Connection, ICircuitPin>(CircuitRenderer, transformAdapter);

                // The "AllFirst" policy will try to draw edges (wires) before nodes, as much as possible.
                //circuitAdapter.EdgeRenderPolicy = D2dGraphAdapter<Module, Connection, ICircuitPin>.DrawEdgePolicy.AllFirst;

                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    CircuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(CircuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector, //Needs to be before annotationAdaptor, so that drag-and-selecting text works.
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    gridAdapter,
                    annotationAdaptor,        //Needs to be before circuitAdapter so that comments appear under elements.
                    circuitAdapter,
                    circuitModuleEditAdapter, //lets user move circuit elements on canvas
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else if (circuitNode.Is <Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(SubCircuitRenderer,
                                                                                              transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    SubCircuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(SubCircuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = SubCircuitRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector,
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    gridAdapter,
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    groupPinEditor,
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else
            {
                throw new NotImplementedException(
                          "graph node type is not supported!");
            }

            control.ResumeLayout();

            control.DoubleClick += control_DoubleClick;
            control.MouseDown   += control_MouseDown;
            return(control);
        }
Esempio n. 5
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();

            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();

            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale       = true;
            transformAdapter.MinScale           = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale           = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);

            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();

            ((ILayoutConstraint)canvasAdapter).Enabled = false;  //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter      = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator     = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter          = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();

            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            if (circuitNode.Is <Circuit>())
            {
                var circuitAdapter           = new D2dGraphAdapter <Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else if (circuitNode.Is <Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter <Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                              transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter <Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter <Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator <Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    groupPinEditor,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else
            {
                throw new NotImplementedException(
                          "graph node type is not supported!");
            }

            control.ResumeLayout();

            control.DoubleClick += new EventHandler(control_DoubleClick);
            control.MouseDown   += new MouseEventHandler(control_MouseDown);
            return(control);
        }
Esempio n. 6
0
        private D2dAdaptableControl CreateControl(bool createCircutGroup)
        {
            var d2dControl = new D2dAdaptableControl();
            d2dControl.SuspendLayout();

            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.Scale = new PointF(1.25f, 1.25f);
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(1.0f, 1.0f);
            transformAdapter.MaxScale = new PointF(5, 5);

            var annotationAdaptor = new D2dAnnotationAdapter(m_editor.Theme); // display annotations under diagram
            var gridAdapter = new D2dGridAdapter();
            gridAdapter.Enabled = false;
            gridAdapter.Visible = true;
            

            D2dGraphAdapter<Module, Connection, ICircuitPin> graphAdapter;
            if (createCircutGroup)
            {
                var subG = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_editor.SubCircuitRenderer, transformAdapter);
                subG.SettingVisibleWorldBoundsDisabled = true;
                graphAdapter = subG;
            }
            else
            {
                graphAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_editor.CircuitRenderer, transformAdapter);
            }
            
            d2dControl.Adapt(

                transformAdapter,
                new MouseWheelManipulator(transformAdapter),
                gridAdapter,
                annotationAdaptor, //Needs to be before circuitAdapter so that comments appear under elements.
                graphAdapter);

            d2dControl.ResumeLayout();
            d2dControl.Dock = DockStyle.Fill;

            transformAdapter.TransformChanged += (s, e) => UpdateControlName(((ITransformAdapter)s).Scale.X);
            return d2dControl;
        }
Esempio n. 7
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();
            control.SuspendLayout();
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);
            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();
            ((ILayoutConstraint)canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();
            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            var d2dRectangleDragSelector = new D2dRectangleDragSelector();
            var d2dRectangleDragRenderer = new D2dRectangleDragRenderer(d2dRectangleDragSelector);

            if (circuitNode.Is<Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);

                // The "AllFirst" policy will try to draw edges (wires) before nodes, as much as possible.
                //circuitAdapter.EdgeRenderPolicy = D2dGraphAdapter<Module, Connection, ICircuitPin>.DrawEdgePolicy.AllFirst;
                
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    d2dRectangleDragSelector, //Needs to be before annotationAdaptor, so that drag-and-selecting text works.
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor, //Needs to be before circuitAdapter so that comments appear under elements.
                    circuitAdapter,
                    circuitModuleEditAdapter, //lets user move circuit elements on canvas
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    d2dRectangleDragRenderer,
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                    );
            }
            else if (circuitNode.Is<Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                      transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;

                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                    // This end of the list is drawn first and receives mouse events last.
                  hoverAdapter,
                  scrollbarAdapter,
                  autoTranslateAdapter,
                  d2dRectangleDragSelector,
                  transformAdapter,
                  viewingAdapter,
                  canvasAdapter,
                  mouseTransformManipulator,
                  mouseWheelManipulator,
                  new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                  new D2dGridAdapter(),
                  annotationAdaptor,
                  circuitAdapter,
                  circuitModuleEditAdapter,
                  circuitConnectionEditAdapter,
                  new LabelEditAdapter(),
                  groupPinEditor,
                  d2dRectangleDragRenderer,
                  new SelectionAdapter(),
                  new DragDropAdapter(m_statusService),
                  new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    // This end of the list is drawn last and receives mouse events first.
                  );
            }
            else throw new NotImplementedException(
               "graph node type is not supported!");

            control.ResumeLayout();

            control.DoubleClick += control_DoubleClick;
            control.MouseDown += control_MouseDown;
            return control;
        }
Esempio n. 8
0
        /// <summary>
        /// Opens or creates a document at the given URI. Create an AdaptableControl with control adapters for viewing state machine.
        /// Handles application data persistence.</summary>
        /// <param name="uri">Document URI</param>
        /// <returns>Document, or null if the document couldn't be opened or created</returns>
        public IDocument Open(Uri uri)
        {
            DomNode node = null;
            string filePath = uri.LocalPath;
            string fileName = Path.GetFileName(filePath);

            if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    DomXmlReader reader = new DomXmlReader(m_schemaLoader);
                    node = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = new DomNode(Schema.fsmType.Type, Schema.fsmRootElement);
                // create an empty root prototype folder
                node.SetChild(
                    Schema.fsmType.prototypeFolderChild,
                    new DomNode(Schema.prototypeFolderType.Type));
            }

            Document document = null;
            if (node != null)
            {
                // set up the AdaptableControl for editing FSMs
                var control = new D2dAdaptableControl();
                control.SuspendLayout();

                control.BackColor = SystemColors.ControlLight;
                control.AllowDrop = true;

                var transformAdapter = new TransformAdapter(); // required by several of the other adapters
                transformAdapter.UniformScale = true;
                transformAdapter.MinScale = new PointF(0.25f, 0.25f);
                transformAdapter.MaxScale = new PointF(4, 4);

                var viewingAdapter = new ViewingAdapter(transformAdapter); // implements IViewingContext for framing or ensuring that items are visible

                var canvasAdapter = new CanvasAdapter(); // implements a bounded canvas to limit scrolling

                var autoTranslateAdapter = // implements auto translate when the user drags out of control's client area
                    new AutoTranslateAdapter(transformAdapter);
                var mouseTransformManipulator = // implements mouse drag translate and scale
                    new MouseTransformManipulator(transformAdapter);
                var mouseWheelManipulator = // implements mouse wheel scale
                    new MouseWheelManipulator(transformAdapter);
                var scrollbarAdapter = // adds scroll bars to control, driven by canvas and transform
                    new ScrollbarAdapter(transformAdapter, canvasAdapter);

                var hoverAdapter = new HoverAdapter(); // add hover events over pickable items
                hoverAdapter.HoverStarted += control_HoverStarted;
                hoverAdapter.HoverStopped += control_HoverStopped;

                var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

                var fsmAdapter = // adapt control to allow binding to graph data
                    new D2dGraphAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, transformAdapter);

                var fsmStateEditAdapter = // adapt control to allow state editing
                    new D2dGraphNodeEditAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);

                var fsmTransitionEditAdapter = // adapt control to allow transition
                    new D2dGraphEdgeEditAdapter<State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);

                var mouseLayoutManipulator = new MouseLayoutManipulator(transformAdapter);

                // apply adapters to control; ordering is from back to front, that is, the first adapter
                //  will be conceptually underneath all the others. Mouse and keyboard events are fed to
                //  the adapters in the reverse order, so it all makes sense to the user.
                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardGraphNavigator<State, Transition, NumberedRoute>(),
                    //new GridAdapter(),
                    annotationAdaptor,
                    fsmAdapter,
                    fsmStateEditAdapter,
                    fsmTransitionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    mouseLayoutManipulator,
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );

                control.ResumeLayout();

                // associate the control with the viewing context; other adapters use this
                //  adapter for viewing, layout and calculating bounds.
                ViewingContext viewingContext = node.Cast<ViewingContext>();
                viewingContext.Control = control;

                // set document URI
                document = node.As<Document>();
                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                //Set IsDocument to true to prevent exception in command service if two files with the
                //  same name, but in different directories, are opened.
                controlInfo.IsDocument = true;

                document.ControlInfo = controlInfo;
                document.Uri = uri;

                // now that the data is complete, initialize the rest of the extensions to the Dom data;
                //  this is needed for adapters such as validators, which may not be referenced anywhere
                //  but still need to be initialized.
                node.InitializeExtensions();

                // set control's context to main editing context
                EditingContext editingContext = node.Cast<EditingContext>();
                control.Context = editingContext;

                // show the FSM control
                m_controlHostService.RegisterControl(control, controlInfo, this);
            }
            
            return document;
        }
Esempio n. 9
0
File: Editor.cs Progetto: zparr/ATF
        /// <summary>
        /// Opens or creates a document at the given URI. Create an AdaptableControl with control adapters for viewing state machine.
        /// Handles application data persistence.</summary>
        /// <param name="uri">Document URI</param>
        /// <returns>Document, or null if the document couldn't be opened or created</returns>
        public IDocument Open(Uri uri)
        {
            DomNode node     = null;
            string  filePath = uri.LocalPath;
            string  fileName = Path.GetFileName(filePath);

            if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    DomXmlReader reader = new DomXmlReader(m_schemaLoader);
                    node = reader.Read(stream, uri);
                }
            }
            else
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = new DomNode(Schema.fsmType.Type, Schema.fsmRootElement);
                // create an empty root prototype folder
                node.SetChild(
                    Schema.fsmType.prototypeFolderChild,
                    new DomNode(Schema.prototypeFolderType.Type));
            }

            Document document = null;

            if (node != null)
            {
                // set up the AdaptableControl for editing FSMs
                var control = new D2dAdaptableControl();
                control.SuspendLayout();

                control.BackColor = SystemColors.ControlLight;
                control.AllowDrop = true;

                var transformAdapter = new TransformAdapter(); // required by several of the other adapters
                transformAdapter.UniformScale = true;
                transformAdapter.MinScale     = new PointF(0.25f, 0.25f);
                transformAdapter.MaxScale     = new PointF(4, 4);

                var viewingAdapter = new ViewingAdapter(transformAdapter); // implements IViewingContext for framing or ensuring that items are visible

                var canvasAdapter = new CanvasAdapter();                   // implements a bounded canvas to limit scrolling

                var autoTranslateAdapter =                                 // implements auto translate when the user drags out of control's client area
                                           new AutoTranslateAdapter(transformAdapter);
                var mouseTransformManipulator =                            // implements mouse drag translate and scale
                                                new MouseTransformManipulator(transformAdapter);
                var mouseWheelManipulator =                                // implements mouse wheel scale
                                            new MouseWheelManipulator(transformAdapter);
                var scrollbarAdapter =                                     // adds scroll bars to control, driven by canvas and transform
                                       new ScrollbarAdapter(transformAdapter, canvasAdapter);

                var hoverAdapter = new HoverAdapter(); // add hover events over pickable items
                hoverAdapter.HoverStarted += control_HoverStarted;
                hoverAdapter.HoverStopped += control_HoverStopped;

                var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

                var fsmAdapter =                                           // adapt control to allow binding to graph data
                                 new D2dGraphAdapter <State, Transition, NumberedRoute>(m_fsmRenderer, transformAdapter);

                var fsmStateEditAdapter = // adapt control to allow state editing
                                          new D2dGraphNodeEditAdapter <State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);

                var fsmTransitionEditAdapter = // adapt control to allow transition
                                               new D2dGraphEdgeEditAdapter <State, Transition, NumberedRoute>(m_fsmRenderer, fsmAdapter, transformAdapter);

                var mouseLayoutManipulator = new MouseLayoutManipulator(transformAdapter);

                // apply adapters to control; ordering is from back to front, that is, the first adapter
                //  will be conceptually underneath all the others. Mouse and keyboard events are fed to
                //  the adapters in the reverse order, so it all makes sense to the user.
                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardGraphNavigator <State, Transition, NumberedRoute>(),
                    //new GridAdapter(),
                    annotationAdaptor,
                    fsmAdapter,
                    fsmStateEditAdapter,
                    fsmTransitionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    mouseLayoutManipulator,
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );

                control.ResumeLayout();

                // associate the control with the viewing context; other adapters use this
                //  adapter for viewing, layout and calculating bounds.
                ViewingContext viewingContext = node.Cast <ViewingContext>();
                viewingContext.Control = control;

                // set document URI
                document = node.As <Document>();
                ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                //Set IsDocument to true to prevent exception in command service if two files with the
                //  same name, but in different directories, are opened.
                controlInfo.IsDocument = true;

                document.ControlInfo = controlInfo;
                document.Uri         = uri;

                // now that the data is complete, initialize the rest of the extensions to the Dom data;
                //  this is needed for adapters such as validators, which may not be referenced anywhere
                //  but still need to be initialized.
                node.InitializeExtensions();

                // set control's context to main editing context
                EditingContext editingContext = node.Cast <EditingContext>();
                control.Context = editingContext;

                // show the FSM control
                m_controlHostService.RegisterControl(control, controlInfo, this);
            }

            return(document);
        }
Esempio n. 10
0
        private D2dAdaptableControl CreateControl(bool createCircutGroup)
        {
            var d2dControl = new D2dAdaptableControl();
            d2dControl.SuspendLayout();
            d2dControl.Dock = DockStyle.Fill;
            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.Scale = new PointF(1.25f, 1.25f);
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(0.000001f, 0.000001f);
            transformAdapter.MaxScale = new PointF(5, 5);

            var annotationAdaptor = new D2dAnnotationAdapter(m_editor.Theme); // display annotations under diagram
            annotationAdaptor.PickingDisabled = true;
            var gridAdapter = new D2dGridAdapter();
            gridAdapter.Enabled = false;
            gridAdapter.Visible = true;

            D2dGraphAdapter<Module, Connection, ICircuitPin> graphAdapter;
            if (createCircutGroup)
            {
                var subG = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_editor.SubCircuitRenderer, transformAdapter);               
                graphAdapter = subG;
            }
            else
            {
                graphAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_editor.CircuitRenderer, transformAdapter);
            }

            
            d2dControl.Adapt(
                transformAdapter,                
                gridAdapter,
                annotationAdaptor, 
                graphAdapter,
                new DraggableRect(this));
            
            d2dControl.ResumeLayout();
           
            transformAdapter.TransformChanged += (s, e) => UpdateControlName(((ITransformAdapter)s).Scale.X);            
            d2dControl.SizeChanged += d2dControl_SizeChanged;
            
            return d2dControl;
        }        
Esempio n. 11
0
        internal D2dAdaptableControl CreateCircuitControl(DomNode circuitNode)
        {
            var control = new D2dAdaptableControl();
            control.SuspendLayout();             
            control.BackColor = SystemColors.ControlLight;
            control.AllowDrop = true;

            var transformAdapter = new TransformAdapter();
            transformAdapter.EnforceConstraints = false; //to allow the canvas to be panned to view negative coordinates
            transformAdapter.UniformScale = true;
            transformAdapter.MinScale = new PointF(0.25f, 0.25f);
            transformAdapter.MaxScale = new PointF(4, 4);
            var viewingAdapter = new ViewingAdapter(transformAdapter);
            viewingAdapter.MarginSize = new Size(25, 25);
            var canvasAdapter = new CanvasAdapter();
            ((ILayoutConstraint) canvasAdapter).Enabled = false; //to allow negative coordinates for circuit elements within groups

            var autoTranslateAdapter = new AutoTranslateAdapter(transformAdapter);
            var mouseTransformManipulator = new MouseTransformManipulator(transformAdapter);
            var mouseWheelManipulator = new MouseWheelManipulator(transformAdapter);
            var scrollbarAdapter = new ScrollbarAdapter(transformAdapter, canvasAdapter);

            var hoverAdapter = new HoverAdapter();
            hoverAdapter.HoverStarted += control_HoverStarted;
            hoverAdapter.HoverStopped += control_HoverStopped;

            var annotationAdaptor = new D2dAnnotationAdapter(m_theme); // display annotations under diagram

            if (circuitNode.Is<Circuit>())
            {
                var circuitAdapter = new D2dGraphAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_circuitRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                control.Adapt(
                    hoverAdapter,
                    scrollbarAdapter,
                    autoTranslateAdapter,
                    new RectangleDragSelector(),
                    transformAdapter,
                    viewingAdapter,
                    canvasAdapter,
                    mouseTransformManipulator,
                    mouseWheelManipulator,
                    new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                    new D2dGridAdapter(),
                    annotationAdaptor,
                    circuitAdapter,
                    circuitModuleEditAdapter,
                    circuitConnectionEditAdapter,
                    new LabelEditAdapter(),
                    new SelectionAdapter(),
                    new DragDropAdapter(m_statusService),
                    new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                    );
            }
            else if (circuitNode.Is<Group>())
            {
                var circuitAdapter = new D2dSubgraphAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer,
                                                                                      transformAdapter);
                var circuitModuleEditAdapter = new D2dGraphNodeEditAdapter<Module, Connection, ICircuitPin>(
                    m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitModuleEditAdapter.DraggingSubNodes = false;

                var circuitConnectionEditAdapter =
                    new D2dGraphEdgeEditAdapter<Module, Connection, ICircuitPin>(m_subGraphRenderer, circuitAdapter, transformAdapter);
                circuitConnectionEditAdapter.EdgeRouteTraverser = CircuitUtil.EdgeRouteTraverser;

                var groupPinEditor = new GroupPinEditor(transformAdapter);
                groupPinEditor.GetPinOffset = m_subGraphRenderer.GetPinOffset;
 
                canvasAdapter.UpdateTranslateMinMax = groupPinEditor.UpdateTranslateMinMax;

                control.Adapt(
                  hoverAdapter,
                  scrollbarAdapter,
                  autoTranslateAdapter,
                  new RectangleDragSelector(),
                  transformAdapter,
                  viewingAdapter,
                  canvasAdapter,
                  mouseTransformManipulator,
                  mouseWheelManipulator,
                  new KeyboardIOGraphNavigator<Module, Connection, ICircuitPin>(),
                  new D2dGridAdapter(),
                  annotationAdaptor,
                  circuitAdapter,
                  circuitModuleEditAdapter,
                  circuitConnectionEditAdapter,
                  new LabelEditAdapter(),
                  groupPinEditor,
                  new SelectionAdapter(),
                  new DragDropAdapter(m_statusService),
                  new ContextMenuAdapter(m_commandService, m_contextMenuCommandProviders)
                  );
            }
            else throw new NotImplementedException(
               "graph node type is not supported!");

            control.ResumeLayout();

            control.DoubleClick += new EventHandler(control_DoubleClick);
            control.MouseDown += new MouseEventHandler(control_MouseDown);
            return control;
        }