예제 #1
0
파일: Editor.cs 프로젝트: zparr/ATF
        /// <summary>
        /// Finishes initializing component by setting up the scripting service</summary>
        void IInitializable.Initialize()
        {
            if (m_scriptingService != null)
            {
                // load this assembly into script domain.
                m_scriptingService.LoadAssembly(GetType().Assembly);
                m_scriptingService.ImportAllTypes("FsmEditorSample");
                m_scriptingService.ImportAllTypes("Sce.Atf.Controls.Adaptable.Graphs");

                m_scriptingService.SetVariable("editor", this);

                m_contextRegistry.ActiveContextChanged += delegate
                {
                    EditingContext  editingContext = m_contextRegistry.GetActiveContext <EditingContext>();
                    ViewingContext  viewContext    = m_contextRegistry.GetActiveContext <ViewingContext>();
                    IHistoryContext hist           = m_contextRegistry.GetActiveContext <IHistoryContext>();
                    m_scriptingService.SetVariable("editingContext", editingContext);
                    m_scriptingService.SetVariable("fsm", editingContext != null ? editingContext.Fsm : null);
                    m_scriptingService.SetVariable("view", viewContext);
                    m_scriptingService.SetVariable("hist", hist);
                };
            }
        }
예제 #2
0
파일: Editor.cs 프로젝트: zparr/ATF
        /// <summary>
        /// Closes the document and removes any views of it from the UI</summary>
        /// <param name="document">Document to close</param>
        public void Close(IDocument document)
        {
            EditingContext context = Adapters.As <EditingContext>(document);

            // close all active EditingContexts in the document
            foreach (DomNode node in context.DomNode.Subtree)
            {
                foreach (EditingContext editingContext in node.AsAll <EditingContext>())
                {
                    m_contextRegistry.RemoveContext(editingContext);
                }
            }

            // close the document
            m_documentRegistry.Remove(document);

            // finally unregister the control and release the reference to it
            ViewingContext viewingContext = Adapters.As <ViewingContext>(document);

            m_controlHostService.UnregisterControl(viewingContext.Control);
            viewingContext.Control.Dispose();
            viewingContext.Control = null;
        }
예제 #3
0
 public void SetDocument(EditingContext editingContext, ViewingContext viewingContext)
 {
     m_editingContext = editingContext;
     m_viewingContext = viewingContext;
     SetDefaultPrinterSettings();
 }
예제 #4
0
 public void SetDocument(EditingContext editingContext, ViewingContext viewingContext)
 {
     m_editingContext = editingContext;
     m_viewingContext = viewingContext;
     SetDefaultPrinterSettings();
 }
예제 #5
0
파일: Editor.cs 프로젝트: zparr/ATF
        /// <summary>
        /// Makes the document visible to the user</summary>
        /// <param name="document">Document to show</param>
        public void Show(IDocument document)
        {
            ViewingContext viewingContext = Adapters.As <ViewingContext>(document);

            m_controlHostService.Show(viewingContext.Control);
        }
예제 #6
0
파일: Editor.cs 프로젝트: 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);
        }