프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Controls / CAD / CadViewer.xaml.cs @ f324a940

이력 | 보기 | 이력해설 | 다운로드 (7.32 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Windows;
6
using System.Windows.Controls;
7
using System.Windows.Data;
8
using System.Windows.Documents;
9
using System.Windows.Input;
10
using System.Windows.Media;
11
using System.Windows.Media.Imaging;
12
using System.Windows.Navigation;
13
using System.Windows.Shapes;
14
using Teigha.Core;
15
using Teigha.TD;
16
using System.Windows.Interop;
17
using System.Windows.Forms;
18
using System.Reflection;
19
using System.Windows.Markup;
20

    
21
namespace KCOM.Controls
22
{
23
    public enum DrawType { nothing, sp, ep };
24
    public partial class CadViewer : Window
25
    {
26
        private static Window win = null;
27
        SaveFileDialog SaveDig = new SaveFileDialog(); //파일 세이브 다이얼로그
28
        public static DrawType drawType;
29

    
30
        public CadViewer()
31
        {
32
            drawType = DrawType.nothing;
33
            this.Loaded += CadViewer_Loaded;
34
        }
35

    
36
        private void CadViewer_Loaded(object sender, RoutedEventArgs e)
37
        {
38
            InitializeComponent();
39
            dwgControl.DeleteContext();
40

    
41
            win = new Window();
42
            win.Owner = (Window)this;
43
            win.Visibility = System.Windows.Visibility.Hidden;
44
            win.WindowStyle = System.Windows.WindowStyle.None;
45
            win.ShowInTaskbar = false;
46
            win.Background = Brushes.Transparent;
47
            win.AllowsTransparency = true;
48
            win.Show();
49
            win.Hide();
50
            dwgControl.SetInvisibleWin(win);
51

    
52
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
53
            dlg.DefaultExt = ".dwg";
54
            dlg.Filter = "DWG files (.dwg)|*.dwg";
55
            OdGePoint3d[] aa = new OdGePoint3d[4];
56
            Nullable<bool> result = dlg.ShowDialog();
57
            if (result == true)
58
            {
59
                filename = dlg.FileName;
60
                //mTeighaD3DImage.FilePath = filename;
61
                dwgControl.FilePath = filename;
62
                filepath.Text = filename;
63
                aa = dwgControl.PointLoad();
64

    
65
                if (aa != null)
66
                {
67
                    this.cadPanel_Instance.setCadPath(filename);
68
                    this.cadPanel_Instance.spLabel.Text = "(" + aa[1].x + ", " + aa[1].y + ")";
69
                    this.cadPanel_Instance.epLabel.Text = "(" + aa[3].x + ", " + aa[3].y + ")";
70
                    this.cadPanel_Instance.startPoint = new Point(aa[1].x, aa[1].y);
71
                    this.cadPanel_Instance.endPoint = new Point(aa[3].x, aa[3].y);
72
                }
73
            }
74
            win.Closed += Win_Closed;
75
            //this.dwgControl.MouseDown += DwgControl_MouseDown;
76
        }
77

    
78
        private void Win_Closed(object sender, EventArgs e)
79
        {
80
            dwgControl.DeleteContext();
81
        }
82

    
83
        public string filename = null;
84

    
85
        private void button1_Click(object sender, RoutedEventArgs e)
86
        {
87
            win = new Window();
88
            // win.Owner = cadViewer;
89
            win.Visibility = System.Windows.Visibility.Hidden;
90
            win.WindowStyle = System.Windows.WindowStyle.None;
91
            win.ShowInTaskbar = false;
92
            win.Background = Brushes.Transparent;
93
            win.AllowsTransparency = true;
94
            win.Show();
95
            win.Hide();
96
            dwgControl.SetInvisibleWin(win);
97
            //    }
98
            // Create OpenFileDialog 
99
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
100

    
101
            dlg.DefaultExt = ".dwg";
102
            dlg.Filter = "DWG files (.dwg)|*.dwg";
103

    
104
            // Nullable<bool> result = dlg.ShowDialog();
105

    
106
            OdGePoint3d[] aa = new OdGePoint3d[4];
107
            Nullable<bool> result = dlg.ShowDialog();
108
            if (result == true)
109
            {
110

    
111
                dwgControl.DeleteContext();
112
                //    if (null == win)
113
                //     {
114
                CadViewer cadViewer = new CadViewer();
115
                filename = dlg.FileName;
116
                //mTeighaD3DImage.FilePath = filename;
117
                dwgControl.FilePath = filename;
118
                filepath.Text = filename;
119
                aa = dwgControl.PointLoad();
120

    
121
                if (aa != null)
122
                {
123
                    this.cadPanel_Instance.setCadPath(filename);
124
                    this.cadPanel_Instance.spLabel.Text = "(" + aa[1].x + ", " + aa[1].y + ")";
125
                    this.cadPanel_Instance.epLabel.Text = "(" + aa[3].x + ", " + aa[3].y + ")";
126
                    this.cadPanel_Instance.startPoint = new Point(aa[1].x, aa[1].y);
127
                    this.cadPanel_Instance.endPoint = new Point(aa[3].x, aa[3].y);
128
                }
129
            }
130
            win.Closed += Win_Closed;
131
        }
132

    
133
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
134
        {
135
            base.OnRenderSizeChanged(sizeInfo);
136
        }
137

    
138
        private void dwgControl_SizeChanged(object sender, SizeChangedEventArgs e)
139
        {
140
            if (e.NewSize != e.PreviousSize)
141
            {
142
                dwgControl.ControlSizeChanged(e.NewSize);
143
            }
144
        }
145

    
146
        private void FileExport()
147
        {
148
            //SaveDig.FileName = "commentstring"; // Default file name
149
            // SaveDig.DefaultExt = ".json"; // Default file exte1nsion
150
            SaveDig.FilterIndex = 1;
151
            // SaveDig.Filter = "JSON Configuration|*.json";
152

    
153
            SaveDig.DefaultExt = ".dwg";
154
            SaveDig.Filter = "DWG files (.dwg)|*.dwg";
155

    
156
            SaveDig.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "configuration");
157

    
158
            SaveDig.ShowDialog();
159

    
160
            if (!string.IsNullOrEmpty(SaveDig.FileName))
161
            {
162
                //  File.WriteAllText(SaveDig.FileName, data);
163
                // File.WriteAllLines(SaveDig.FileName, data);
164
            }
165
        }
166

    
167
        private void DwgControl_MouseDown(object sender, MouseButtonEventArgs e)
168
        {
169
            //OdGsDCPoint[] pts = dwgControl.SelectionPointsByPointOnScreen(e.X, e.Y);
170
            OdGePoint3d point = dwgControl.PointCheck(sender, e, drawType);
171
            if (drawType == DrawType.sp)
172
            {
173
                this.cadPanel_Instance.spLabel.Text = "(" + point.x + ", " + point.y + ")";
174
                this.cadPanel_Instance.startPoint = new Point(point.x, point.y);
175
                dwgControl.DrawPoint(point, drawType);
176
                drawType = DrawType.nothing;
177
                CustomImage1.mDown = false;
178
            }
179
            else if (drawType == DrawType.ep)
180
            {
181
                this.cadPanel_Instance.epLabel.Text = "(" + point.x + ", " + point.y + ")";
182
                this.cadPanel_Instance.endPoint = new Point(point.x, point.y);
183
                dwgControl.DrawPoint(point, drawType);
184
                drawType = DrawType.nothing;
185
                CustomImage1.mDown = false;
186
            }
187
            else
188
            {
189
                CustomImage1.mDown = true;
190
            }
191
        }
192
    }
193

    
194
    class Srv : ExHostAppServices
195
    {
196
        public override bool getPassword(string dwgName, bool isXref, ref string password)
197
        {
198
            Console.WriteLine("Enter password to open drawing: {0}", dwgName);
199
            password = Console.ReadLine().ToUpper();
200
            return password != "";
201
        }
202

    
203
        public override String product()
204
        {
205
            return String.Format("Teigha.NET");
206
        }
207
    }
208
}
클립보드 이미지 추가 (최대 크기: 500 MB)