コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: monocraft/Core2D
        private void InitializeContext()
        {
            _renderer = new Win2dRenderer();

            _context = new T2d.EditorContext()
            {
                View = this,
                Renderers = new T2d.IRenderer[] { _renderer },
                ProjectFactory = new T2d.ProjectFactory(),
                TextClipboard = new TextClipboard(),
                Serializer = new T2d.NewtonsoftSerializer(),
                //PdfWriter = new T2d.PdfWriter(),
                //DxfWriter = new T2d.DxfWriter(),
                //CsvReader = new T2d.CsvHelperReader(),
                //CsvWriter = new T2d.CsvHelperWriter()
            };
            _context.InitializeEditor(null/*new T2d.TraceLog()*/);
            _context.Editor.Renderers[0].State.DrawShapeState.Flags = T2d.ShapeStateFlags.Visible;
            _context.Editor.GetImageKey = async () => await Task.Run(() => _imagePath);

            _context.Commands.OpenCommand =
                T2d.Command<object>.Create(
                    async (parameter) => await OnOpen(),
                    (parameter) => _context.IsEditMode());

            _context.Commands.SaveAsCommand =
                T2d.Command.Create(
                    async () => await OnSaveAs(),
                    () => _context.IsEditMode());

            DataContext = _context;
        }
コード例 #2
0
        private void InitializeContext()
        {
            _renderer = new Win2dRenderer();

            _context = new T2d.EditorContext()
            {
                View           = this,
                Renderers      = new T2d.IRenderer[] { _renderer },
                ProjectFactory = new T2d.ProjectFactory(),
                TextClipboard  = new TextClipboard(),
                Serializer     = new T2d.NewtonsoftSerializer(),
                //PdfWriter = new T2d.PdfWriter(),
                //DxfWriter = new T2d.DxfWriter(),
                //CsvReader = new T2d.CsvHelperReader(),
                //CsvWriter = new T2d.CsvHelperWriter()
            };
            _context.InitializeEditor(null /*new T2d.TraceLog()*/);
            _context.Editor.Renderers[0].State.DrawShapeState.Flags = T2d.ShapeStateFlags.Visible;
            _context.Editor.GetImageKey = async() => await Task.Run(() => _imagePath);

            _context.Commands.OpenCommand =
                T2d.Command <object> .Create(
                    async (parameter) => await OnOpen(),
                    (parameter) => _context.IsEditMode());

            _context.Commands.SaveAsCommand =
                T2d.Command.Create(
                    async() => await OnSaveAs(),
                    () => _context.IsEditMode());

            DataContext = _context;
        }
コード例 #3
0
ファイル: MainWindow.paml.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        private void InitializeContext()
        {
            _context = new EditorContext()
            {
                View = this,
                Renderers = new IRenderer[] { new PerspexRenderer() },
                ProjectFactory = new ProjectFactory(),
                TextClipboard = new TextClipboard(),
                Serializer = new NewtonsoftSerializer(),
                PdfWriter = new PdfWriter(),
                DxfWriter = new DxfWriter(),
                CsvReader = new CsvHelperReader(),
                CsvWriter = new CsvHelperWriter()
            };

            _context.Renderers[0].State.EnableAutofit = true;
            _context.InitializeEditor(new TraceLog(), System.IO.Path.Combine(GetAssemblyPath(), _logFileName));
            _context.Editor.Renderers[0].State.DrawShapeState.Flags = ShapeStateFlags.Visible;
            _context.Editor.GetImageKey = async () => await OnGetImageKey();

            _context.Commands.OpenCommand =
                Command<object>.Create(
                    async (parameter) => await OnOpen(parameter),
                    (parameter) => _context.IsEditMode());

            _context.Commands.SaveCommand =
                Command.Create(
                    async () => await OnSave(),
                    () => _context.IsEditMode());

            _context.Commands.SaveAsCommand =
                Command.Create(
                    async () => await OnSaveAs(),
                    () => _context.IsEditMode());

            _context.Commands.ExportCommand =
                Command<object>.Create(
                    async (item) => await OnExport(),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportDataCommand =
                Command<object>.Create(
                    async (item) => await OnImportData(),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportDataCommand =
                Command<object>.Create(
                    async (item) => await OnExportData(),
                    (item) => _context.IsEditMode());

            _context.Commands.UpdateDataCommand =
                Command<object>.Create(
                    async (item) => await OnUpdateData(),
                    (item) => _context.IsEditMode());
            
            _context.Commands.ImportStyleCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Style),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStylesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Styles),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStyleLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.StyleLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStyleLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.StyleLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Group),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupsCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Groups),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.GroupLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.GroupLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportTemplateCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Template),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportTemplatesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Templates),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Style),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStylesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Styles),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.StyleLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.StyleLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Group),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupsCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Groups),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.GroupLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.GroupLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportTemplateCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Template),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportTemplatesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Templates),
                    (item) => _context.IsEditMode());

            // TODO: Initialize other commands.

            if (_enableRecent)
            {
                try
                {
                    var path = System.IO.Path.Combine(GetAssemblyPath(), _recentFileName);
                    if (System.IO.File.Exists(path))
                    {
                        _context.LoadRecent(path);
                    }
                }
                catch (Exception ex)
                {
                    if (_context.Editor.Log != null)
                    {
                        _context.Editor.Log.LogError("{0}{1}{2}",
                            ex.Message,
                            Environment.NewLine,
                            ex.StackTrace);
                    }
                }
            }
            
            DataContext = _context;
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        private void InitializeContext()
        {
            this.SetStyle(
                ControlStyles.AllPaintingInWmPaint
                | ControlStyles.UserPaint
                | ControlStyles.DoubleBuffer
                | ControlStyles.SupportsTransparentBackColor,
                true);

            var context = new EditorContext()
            {
                View = this,
                Renderers = new IRenderer[] { new EmfRenderer(72.0 / 96.0) },
                ProjectFactory = new ProjectFactory(),
                TextClipboard = new TextClipboard(),
                Serializer = new NewtonsoftSerializer(),
                PdfWriter = new PdfWriter(),
                DxfWriter = new DxfWriter(),
                CsvReader = new CsvHelperReader(),
                CsvWriter = new CsvHelperWriter()
            };

            context.Renderers[0].State.EnableAutofit = true;
            context.InitializeEditor(new TraceLog(), System.IO.Path.Combine(GetAssemblyPath(), _logFileName));
            context.Editor.Renderers[0].State.DrawShapeState.Flags = ShapeStateFlags.Visible;
            context.Editor.GetImageKey = async () => await GetImageKey();

            DataContext = context;
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: monocraft/Core2D
        /// <summary>
        /// 
        /// </summary>
        private void InitializeContext()
        {
            var context = new EditorContext()
            {
                View = this,
                Renderers = new IRenderer[] { new WpfRenderer(), new WpfRenderer() },
                ProjectFactory = new ProjectFactory(),
                TextClipboard = new TextClipboard(),
                Serializer = new NewtonsoftSerializer(),
                PdfWriter = new PdfWriter(),
                DxfWriter = new DxfWriter(),
                CsvReader = new CsvHelperReader(),
                CsvWriter = new CsvHelperWriter()
            };

            context.Renderers[0].State.EnableAutofit = true;
            context.InitializeEditor(new TraceLog(), System.IO.Path.Combine(GetAssemblyPath(), _logFileName));
            context.Editor.Renderers[0].State.DrawShapeState.Flags = ShapeStateFlags.Visible;
            context.Editor.Renderers[1].State.DrawShapeState.Flags = ShapeStateFlags.Visible;
            context.Editor.GetImageKey = async () => await GetImageKey();

            InitializeCommands(context);
            InitializeZoom(context);
            InitializeDrop(context);

            Loaded +=
                (s, e) =>
                {
                    if (_isLoaded)
                        return;
                    else
                        _isLoaded = true;

                    InitializeLayouts();

                    if (_autoRecent)
                    {
                        AutoLoadRecent(context);
                    }

                    if (_restoreLayout)
                    {
                        AutoLoadLayout(context);
                    }
                };

            Unloaded += (s, e) =>
            {
                if (!_isLoaded)
                    return;
                else
                    _isLoaded = false;

                DeInitializeContext();

                if (_autoRecent)
                {
                    AutoSaveRecent(context);
                }

                if (_restoreLayout)
                {
                    AutoSaveLayout(context);
                }
            };

            DataContext = context;
        }