├── .gitignore
├── LICENSE
├── README.md
├── doc
├── SharpCAD.txt
└── images
│ └── sharpcad.png
├── src
├── 3rdlib
│ └── LitMath.dll
├── SharpCAD.sln
├── SharpCAD
│ ├── ApplicationServices
│ │ ├── CommonColors.cs
│ │ ├── Document.cs
│ │ ├── Selection.cs
│ │ └── Selections.cs
│ ├── Commands
│ │ ├── Command.cs
│ │ ├── CommandNames.cs
│ │ ├── CommandsFactory.cs
│ │ ├── CommandsMgr.cs
│ │ ├── Draw
│ │ │ ├── ArcCmd.cs
│ │ │ ├── CircleCmd.cs
│ │ │ ├── EllipseCmd.cs
│ │ │ ├── LinesChainCmd.cs
│ │ │ ├── PointCmd.cs
│ │ │ ├── PolygonCmd.cs
│ │ │ ├── PolylineCmd.cs
│ │ │ ├── RayCmd.cs
│ │ │ ├── RectangleCmd.cs
│ │ │ ├── XlineCmd.cs
│ │ │ └── _DrawCmd.cs
│ │ ├── Edit
│ │ │ ├── RedoCmd.cs
│ │ │ └── UndoCmd.cs
│ │ ├── GripPointMoveCmd.cs
│ │ ├── Layer
│ │ │ ├── AddLayerCmd.cs
│ │ │ ├── ModifyLayerCmd.cs
│ │ │ └── RemoveLayersCmd.cs
│ │ ├── Modify
│ │ │ ├── CopyCmd.cs
│ │ │ ├── DeleteCmd.cs
│ │ │ ├── MirrorCmd.cs
│ │ │ ├── MoveCmd.cs
│ │ │ ├── Offset
│ │ │ │ ├── OffsetArc.cs
│ │ │ │ ├── OffsetCircle.cs
│ │ │ │ ├── OffsetLine.cs
│ │ │ │ ├── _OffsetOperation.cs
│ │ │ │ └── _OffsetOpsMgr.cs
│ │ │ ├── OffsetCmd.cs
│ │ │ └── _ModifyCmd.cs
│ │ └── Text
│ │ │ └── EditCmd.cs
│ ├── DatabaseUtils
│ │ ├── ArcUtils.cs
│ │ └── DatabaseUtils.cs
│ ├── Languages
│ │ ├── Chinese.xml
│ │ ├── English.xml
│ │ ├── GlobalData.cs
│ │ └── Language.cs
│ ├── Math
│ │ └── MathUtils.cs
│ ├── Presenter
│ │ ├── Anchor
│ │ │ └── AnchorsMgr.cs
│ │ ├── CSYS.cs
│ │ ├── DynamicInputer
│ │ │ ├── DynInputCtrl
│ │ │ │ ├── DynInputCtrl.cs
│ │ │ │ ├── DynInputDouble.cs
│ │ │ │ ├── DynInputInteger.cs
│ │ │ │ ├── DynInputPoint.cs
│ │ │ │ ├── DynInputString.cs
│ │ │ │ └── DynInputTextBoxOne.cs
│ │ │ ├── DynInputResult
│ │ │ │ ├── DynInputResult.cs
│ │ │ │ ├── DynInputResultT.cs
│ │ │ │ └── DynInputStatus.cs
│ │ │ └── DynamicInputer.cs
│ │ ├── GDIResMgr.cs
│ │ ├── LocateCross.cs
│ │ ├── Origin.cs
│ │ ├── PickupBox
│ │ │ ├── ArcHitter.cs
│ │ │ ├── CircleHitter.cs
│ │ │ ├── EllipseHitter.cs
│ │ │ ├── EntityHitter.cs
│ │ │ ├── LineHitter.cs
│ │ │ ├── PolylineHitter.cs
│ │ │ ├── RayHitter.cs
│ │ │ ├── TextHitter.cs
│ │ │ ├── XPointHitter.cs
│ │ │ ├── XlineHitter.cs
│ │ │ └── _PickupBox.cs
│ │ ├── Pointer.cs
│ │ ├── Presenter.cs
│ │ ├── SelectRectangle
│ │ │ ├── ArcRS.cs
│ │ │ ├── CircleRS.cs
│ │ │ ├── EllipseRS.cs
│ │ │ ├── EntityRS.cs
│ │ │ ├── EntityRSMgr.cs
│ │ │ ├── LineRS.cs
│ │ │ ├── PolylineRS.cs
│ │ │ ├── RayRS.cs
│ │ │ ├── SelectRectangle.cs
│ │ │ ├── TextRS.cs
│ │ │ ├── XPointRS.cs
│ │ │ └── XlineRS.cs
│ │ ├── SnapNodesMgr.cs
│ │ └── XorGDI.cs
│ ├── Program.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── Resource1.Designer.cs
│ ├── Resource1.resx
│ ├── Resources
│ │ ├── draw_arc_cse.bmp
│ │ ├── draw_circle_cr.bmp
│ │ ├── draw_ellipse_cenax.bmp
│ │ ├── draw_line.bmp
│ │ ├── draw_point.bmp
│ │ ├── draw_polygon.bmp
│ │ ├── draw_polyline.bmp
│ │ ├── draw_ray.bmp
│ │ ├── draw_rectangle.bmp
│ │ └── draw_xline.bmp
│ ├── SharpCAD.csproj
│ ├── Windows
│ │ ├── Canvas.Designer.cs
│ │ ├── Canvas.cs
│ │ ├── Canvas.resx
│ │ ├── DocumentForm.Designer.cs
│ │ ├── DocumentForm.cs
│ │ ├── DocumentForm.resx
│ │ ├── DynamicInputTextBox.cs
│ │ ├── LayerItemForm.Designer.cs
│ │ ├── LayerItemForm.cs
│ │ ├── LayerItemForm.resx
│ │ ├── LayersManagementForm.Designer.cs
│ │ ├── LayersManagementForm.cs
│ │ ├── LayersManagementForm.resx
│ │ ├── MainWin.Designer.cs
│ │ ├── MainWin.cs
│ │ ├── MainWin.resx
│ │ ├── MenuNames.cs
│ │ └── ToolStripMgr.cs
│ ├── app.config
│ └── res
│ │ ├── common_plus.png
│ │ ├── common_subtract.png
│ │ ├── draw
│ │ ├── draw_arc_3pnts.ico
│ │ ├── draw_arc_cse.ico
│ │ ├── draw_circle_cr.ico
│ │ ├── draw_line.ico
│ │ ├── draw_polygon.ico
│ │ ├── draw_polyline.ico
│ │ ├── draw_ray.ico
│ │ ├── draw_rectangle.ico
│ │ └── draw_xline.ico
│ │ ├── edit
│ │ ├── edit_redo.ico
│ │ └── edit_undo.ico
│ │ ├── file
│ │ ├── file_new.ico
│ │ ├── file_open.ico
│ │ ├── file_save.ico
│ │ └── file_saveas.ico
│ │ ├── format_layer.png
│ │ └── modify
│ │ ├── modify_array.ico
│ │ ├── modify_copy.ico
│ │ ├── modify_erase.ico
│ │ ├── modify_extemd.ico
│ │ ├── modify_mirror.ico
│ │ ├── modify_move.ico
│ │ ├── modify_offset.ico
│ │ ├── modify_rotate.ico
│ │ ├── modify_scale.ico
│ │ └── modify_trim.ico
├── lcdb
│ ├── Bounding.cs
│ ├── Colors
│ │ ├── Color.cs
│ │ └── ColorMethod.cs
│ ├── DBObject.cs
│ ├── Database.cs
│ ├── Entity
│ │ ├── Arc.cs
│ │ ├── BlockReference.cs
│ │ ├── Circle.cs
│ │ ├── Ellipse.cs
│ │ ├── Entity.cs
│ │ ├── Line.cs
│ │ ├── Polyline.cs
│ │ ├── Ray.cs
│ │ ├── Text.cs
│ │ ├── TextAlignment.cs
│ │ ├── XPoint.cs
│ │ └── Xline.cs
│ ├── Filer
│ │ ├── XmlFiler.cs
│ │ └── XmlFilerImpl.cs
│ ├── GripPoint.cs
│ ├── GripPointType.cs
│ ├── IDatabaseObserver.cs
│ ├── LineType.cs
│ ├── LineWeight.cs
│ ├── MathUtils.cs
│ ├── ObjectId.cs
│ ├── ObjectIdMgr.cs
│ ├── ObjectSnapMode.cs
│ ├── ObjectSnapPoint.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Table
│ │ ├── BlockTable.cs
│ │ ├── DBTable.cs
│ │ ├── LayerTable.cs
│ │ └── TableIds.cs
│ ├── TableRecord
│ │ ├── Block.cs
│ │ ├── DBTableRecord.cs
│ │ └── Layer.cs
│ └── lcdb.csproj
└── lcinterface
│ ├── Interface
│ ├── ICanvas.cs
│ ├── ICommand.cs
│ ├── IDocument.cs
│ ├── IGraphicsContext.cs
│ ├── IGraphicsDraw.cs
│ └── IPresenter.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── lcinterface.csproj
└── test
└── test.scad
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Hisin Wang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SharpCAD
2 | SharpCAD is developed on the basis of LitCAD. It is a very simple 2D CAD drawing application developed by C#.
3 |
4 | SharpCAD是基于LitCAD,并且采用C#开发的一款非常简单的二维CAD绘图程序。
5 |
6 | 
7 |
8 | SharpCAD is free software; you can redistribute it and/or modify it under the terms of the [MIT License](https://opensource.org/licenses/MIT).
9 |
10 | SharpCAD是自由软件,你可以在遵守 MIT 协议下再分发或修改该软件。
11 |
12 | #### Building 编译
13 |
14 | Download the source code and open ./src/SharpCAD.sln by Visual Studio 2010, then you can directly compile and build this project.
15 |
16 | 下载源码,然后使用VS2010 打开解决方案:./src/SharpCAD.sln,直接编译即可。
17 |
18 | #### Main Features 主要特征
19 |
20 | * Supports entities: line, xline, ray, polyline, cirlce, arc, text.
21 |
22 | 支持多种图元:线段、构造线、射线、多段线、圆、圆弧、文字。
23 |
24 | * Zoom and pan.
25 |
26 | 缩放和平移视图。
27 |
28 | * Layer。
29 |
30 | 支持图层。
31 |
32 | * Grip points.
33 |
34 | 图元支持夹点,并且可以通过移动夹点来修改图元。
35 |
36 | * Snap.
37 |
38 | 捕捉。目前支持的捕捉类型有:端点、中点、中心点、象限点。
39 |
40 | * Basic editing tools: delete, copy, mirror, offset, move.
41 |
42 | 基本的编辑操作:删除、复制、镜像、偏移、移动。
43 |
44 | * Undo and Redo.
45 |
46 | 撤销和重做。
47 |
48 | * Multiple Ways For Object Selection: Pick Single、Window、Cross.
49 |
50 | 支持点选和框选来选择图元。
51 |
52 | * Open and Save *.scad file.
53 |
54 | 支持打开和保存为 *.scad 文件。
55 |
56 | * Can switch between Chinese and English.
57 |
58 | 可以中英文语言切换。
59 |
60 | #### Entities supported 支持的图元
61 |
62 | * xpoint 点
63 | * line 线段
64 | * xline 构造线
65 | * ray 射线
66 | * polyline 多段线
67 | * circle 圆
68 | * ellipse 椭圆
69 | * arc 圆弧
70 | * text 文字
71 |
72 | # LICENSE
73 |
74 | This project is licensed under the [MIT License](LICENSE).
75 |
--------------------------------------------------------------------------------
/doc/SharpCAD.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/doc/SharpCAD.txt
--------------------------------------------------------------------------------
/doc/images/sharpcad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/doc/images/sharpcad.png
--------------------------------------------------------------------------------
/src/3rdlib/LitMath.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/3rdlib/LitMath.dll
--------------------------------------------------------------------------------
/src/SharpCAD.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lcdb", "lcdb\lcdb.csproj", "{A984479A-E0FC-45E0-8CA3-EB39D197E652}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "lcinterface", "lcinterface\lcinterface.csproj", "{39C4BCAF-8AAE-4410-9BC4-B586B18E964A}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCAD", "SharpCAD\SharpCAD.csproj", "{6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|x64.ActiveCfg = Debug|x64
23 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|x64.Build.0 = Debug|x64
24 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|x86.ActiveCfg = Debug|x86
25 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Debug|x86.Build.0 = Debug|x86
26 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|x64.ActiveCfg = Release|x64
29 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|x64.Build.0 = Release|x64
30 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|x86.ActiveCfg = Release|x86
31 | {A984479A-E0FC-45E0-8CA3-EB39D197E652}.Release|x86.Build.0 = Release|x86
32 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Debug|x64.ActiveCfg = Debug|Any CPU
35 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Debug|x86.ActiveCfg = Debug|Any CPU
36 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Release|x64.ActiveCfg = Release|Any CPU
39 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}.Release|x86.ActiveCfg = Release|Any CPU
40 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|x64.ActiveCfg = Debug|x64
43 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|x64.Build.0 = Debug|x64
44 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|x86.ActiveCfg = Debug|x86
45 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Debug|x86.Build.0 = Debug|x86
46 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|x64.ActiveCfg = Release|x64
49 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|x64.Build.0 = Release|x64
50 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|x86.ActiveCfg = Release|x86
51 | {6B044BFC-D977-41C1-A86C-AC6B0E3A60C1}.Release|x86.Build.0 = Release|x86
52 | EndGlobalSection
53 | GlobalSection(SolutionProperties) = preSolution
54 | HideSolutionNode = FALSE
55 | EndGlobalSection
56 | EndGlobal
57 |
--------------------------------------------------------------------------------
/src/SharpCAD/ApplicationServices/CommonColors.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.Colors;
5 |
6 | namespace SharpCAD.ApplicationServices
7 | {
8 | ///
9 | /// 常用颜色集合
10 | ///
11 | internal class CommonColors : IEnumerable
12 | {
13 | private Dictionary _predefinedColors = new Dictionary();
14 | private List _commonColors = new List();
15 |
16 | public CommonColors()
17 | {
18 | InitPredefinedColors();
19 | }
20 |
21 | ///
22 | /// Initialize predefined colors
23 | ///
24 | private void InitPredefinedColors()
25 | {
26 | _predefinedColors.Add(Color.ByLayer, Color.ByLayer.Name);
27 | _predefinedColors.Add(Color.ByBlock, Color.ByBlock.Name);
28 |
29 | // Red
30 | _predefinedColors.Add(Color.FromRGB(255, 0, 0), GlobalData.GlobalLanguage.Color_Red);
31 | // Yellow
32 | _predefinedColors.Add(Color.FromRGB(255, 255, 0), GlobalData.GlobalLanguage.Color_Yellow);
33 | // Green
34 | _predefinedColors.Add(Color.FromRGB(0, 255, 0), GlobalData.GlobalLanguage.Color_Green);
35 | // Cyan
36 | _predefinedColors.Add(Color.FromRGB(0, 255, 255), GlobalData.GlobalLanguage.Color_Cyan);
37 | // Blue
38 | _predefinedColors.Add(Color.FromRGB(0, 0, 255), GlobalData.GlobalLanguage.Color_Blue);
39 | // Magenta
40 | _predefinedColors.Add(Color.FromRGB(255, 0, 255), GlobalData.GlobalLanguage.Color_Magenta);
41 | // White
42 | _predefinedColors.Add(Color.FromRGB(255, 255, 255), GlobalData.GlobalLanguage.Color_White);
43 | }
44 |
45 | public string GetColorName(Color color)
46 | {
47 | if (_predefinedColors.ContainsKey(color))
48 | {
49 | return _predefinedColors[color];
50 | }
51 | else
52 | {
53 | return color.Name;
54 | }
55 | }
56 |
57 | public bool Add(Color color)
58 | {
59 | if (_predefinedColors.ContainsKey(color)
60 | || _commonColors.Contains(color))
61 | {
62 | return false;
63 | }
64 | else
65 | {
66 | _commonColors.Add(color);
67 | return true;
68 | }
69 | }
70 |
71 | public void Clear()
72 | {
73 | _commonColors.Clear();
74 | }
75 |
76 | #region IEnumerable
77 | public IEnumerator GetEnumerator()
78 | {
79 | List colors = new List(_predefinedColors.Count + _commonColors.Count);
80 | foreach (Color color in _predefinedColors.Keys)
81 | {
82 | colors.Add(color);
83 | }
84 | foreach (Color color in _commonColors)
85 | {
86 | colors.Add(color);
87 | }
88 |
89 | return colors.GetEnumerator();
90 | }
91 |
92 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
93 | {
94 | return this.GetEnumerator();
95 | }
96 | #endregion
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/SharpCAD/ApplicationServices/Document.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 | using SharpCAD.Colors;
6 |
7 | namespace SharpCAD.ApplicationServices
8 | {
9 | public class Document : IDocument
10 | {
11 | ///
12 | /// 数据库
13 | ///
14 | private Database _database = null;
15 | public Database database
16 | {
17 | get { return _database; }
18 | }
19 |
20 | ///
21 | /// 当前块名称
22 | ///
23 | private string _currentBlockName = "ModelSpace";
24 | public string currentBlockName
25 | {
26 | get { return _currentBlockName; }
27 | }
28 |
29 | ///
30 | /// 选择集
31 | ///
32 | private Selections _selections = null;
33 | public Selections selections
34 | {
35 | get { return _selections; }
36 | }
37 |
38 | ///
39 | /// 当前图层
40 | ///
41 | private ObjectId _currLayerId = ObjectId.Null;
42 | public ObjectId currentLayerId
43 | {
44 | get { return _currLayerId; }
45 | set
46 | {
47 | if (_currLayerId != value)
48 | {
49 | Layer layer = _database.GetObject(value) as Layer;
50 | if (layer != null)
51 | {
52 | ObjectId last = _currLayerId;
53 | _currLayerId = value;
54 | if (currentLayerChanged != null)
55 | {
56 | currentLayerChanged.Invoke(last, _currLayerId);
57 | }
58 | }
59 | else
60 | {
61 | throw new System.Exception("invalid layer id");
62 | }
63 | }
64 | }
65 | }
66 |
67 | public delegate void CurrentLayerChanged(ObjectId last, ObjectId current);
68 | public event CurrentLayerChanged currentLayerChanged;
69 |
70 | ///
71 | /// 常用颜色集
72 | ///
73 | private CommonColors _commonColors = null;
74 | internal CommonColors commonColors
75 | {
76 | get { return _commonColors; }
77 | }
78 |
79 | ///
80 | /// 当前图元颜色
81 | ///
82 | private Color _currColor = Color.ByLayer;
83 | public Color currentColor
84 | {
85 | get { return _currColor; }
86 | set
87 | {
88 | Color last = _currColor;
89 | _currColor = value;
90 | if (currentColorChanged != null)
91 | {
92 | currentColorChanged.Invoke(last, _currColor);
93 | }
94 | }
95 | }
96 |
97 | public System.Drawing.Color currentColorValue
98 | {
99 | get
100 | {
101 | switch (_currColor.colorMethod)
102 | {
103 | case ColorMethod.ByLayer:
104 | Layer layer = _database.GetObject(_currLayerId) as Layer;
105 | if (layer != null)
106 | {
107 | return layer.colorValue;
108 | }
109 | else
110 | {
111 | return System.Drawing.Color.FromArgb(
112 | _currColor.r, _currColor.g, _currColor.b);
113 | }
114 |
115 | case ColorMethod.ByColor:
116 | case ColorMethod.ByBlock:
117 | case ColorMethod.None:
118 | default:
119 | return System.Drawing.Color.FromArgb(
120 | _currColor.r, _currColor.g, _currColor.b);
121 | }
122 | }
123 | }
124 |
125 | public delegate void CurrentColorChanged(Color last, Color current);
126 | public event CurrentColorChanged currentColorChanged;
127 |
128 | ///
129 | /// 构造函数
130 | ///
131 | internal Document()
132 | {
133 | _database = new DatabaseServices.Database();
134 | _selections = new Selections();
135 | _commonColors = new CommonColors();
136 | _currLayerId = _database.layerTable["0"].id;
137 | _currColor = Color.ByLayer;
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/SharpCAD/ApplicationServices/Selection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD.ApplicationServices
7 | {
8 | public struct Selection
9 | {
10 | private ObjectId _objectId;
11 | public ObjectId objectId
12 | {
13 | get { return _objectId; }
14 | set { _objectId = value; }
15 | }
16 |
17 | private LitMath.Vector2 _position;
18 | public LitMath.Vector2 position
19 | {
20 | get { return _position; }
21 | set { _position = value; }
22 | }
23 |
24 | public Selection(ObjectId objectId, LitMath.Vector2 pickPosition)
25 | {
26 | _objectId = objectId;
27 | _position = pickPosition;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/CommandNames.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.Commands
4 | {
5 | internal class CommandNames
6 | {
7 | // 绘制
8 | public static string Draw_XPoint = "xpoint";
9 | public static string Draw_Line = "line";
10 | public static string Draw_Xline = "xline";
11 | public static string Draw_Ray = "ray";
12 | public static string Draw_Polyline = "polyline";
13 | public static string Draw_Polygon = "polygon";
14 | public static string Draw_Rectangle = "rectangle";
15 | public static string Draw_Circle = "circle";
16 | public static string Draw_Ellipse = "ellipse";
17 | public static string Draw_Arc = "arc";
18 |
19 | // 编辑
20 | public static string Edit_Redo = "redo";
21 | public static string Edit_Undo = "undo";
22 |
23 | // 修改
24 | public static string Modify_Delete = "delete";
25 | public static string Modify_Copy = "copy";
26 | public static string Modify_Mirror = "mirror";
27 | public static string Modify_Offset = "offset";
28 | public static string Modify_Move = "move";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/CommandsFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.Commands
5 | {
6 | internal class CommandsFactory
7 | {
8 | private Dictionary _cmdName2Proxy
9 | = new Dictionary();
10 |
11 | private void RegisterCommand(string cmdName, CommandProxyBase proxy)
12 | {
13 | _cmdName2Proxy[cmdName] = proxy;
14 | }
15 |
16 | public CommandsFactory()
17 | {
18 | // Draw
19 | RegisterCommand(CommandNames.Draw_XPoint,
20 | new CommandProxy());
21 | RegisterCommand(CommandNames.Draw_Line,
22 | new CommandProxy());
23 | RegisterCommand(CommandNames.Draw_Xline,
24 | new CommandProxy());
25 | RegisterCommand(CommandNames.Draw_Ray,
26 | new CommandProxy());
27 | RegisterCommand(CommandNames.Draw_Polyline,
28 | new CommandProxy());
29 | RegisterCommand(CommandNames.Draw_Polygon,
30 | new CommandProxy());
31 | RegisterCommand(CommandNames.Draw_Rectangle,
32 | new CommandProxy());
33 | RegisterCommand(CommandNames.Draw_Circle,
34 | new CommandProxy());
35 | RegisterCommand(CommandNames.Draw_Ellipse,
36 | new CommandProxy());
37 | RegisterCommand(CommandNames.Draw_Arc,
38 | new CommandProxy());
39 |
40 | // Edit
41 | RegisterCommand(CommandNames.Edit_Redo,
42 | new CommandProxy());
43 | RegisterCommand(CommandNames.Edit_Undo,
44 | new CommandProxy());
45 |
46 | // Modify
47 | RegisterCommand(CommandNames.Modify_Delete,
48 | new CommandProxy());
49 | RegisterCommand(CommandNames.Modify_Copy,
50 | new CommandProxy());
51 | RegisterCommand(CommandNames.Modify_Mirror,
52 | new CommandProxy());
53 | RegisterCommand(CommandNames.Modify_Offset,
54 | new CommandProxy());
55 | RegisterCommand(CommandNames.Modify_Move,
56 | new CommandProxy());
57 | }
58 |
59 | ///
60 | /// 新建命令
61 | ///
62 | public Command NewCommand(string cmdName)
63 | {
64 | if (_cmdName2Proxy.ContainsKey(cmdName))
65 | {
66 | return _cmdName2Proxy[cmdName].NewCmd();
67 | }
68 | else
69 | {
70 | return null;
71 | }
72 | }
73 |
74 | private abstract class CommandProxyBase
75 | {
76 | public abstract Command NewCmd();
77 | }
78 |
79 | private class CommandProxy : CommandProxyBase where T : Command, new()
80 | {
81 | public override Command NewCmd()
82 | {
83 | return new T();
84 | }
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/CircleCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD.Commands.Draw
9 | {
10 | internal class CircleCmd : DrawCmd
11 | {
12 | private Circle _circle = null;
13 |
14 | ///
15 | /// 新增的图元
16 | ///
17 | protected override IEnumerable newEntities
18 | {
19 | get { return new Circle[1] { _circle }; }
20 | }
21 |
22 | ///
23 | /// 步骤
24 | ///
25 | private enum Step
26 | {
27 | Step1_SpecifyCenter = 1,
28 | Step2_SpecityRadius = 2,
29 | }
30 | private Step _step = Step.Step1_SpecifyCenter;
31 |
32 | ///
33 | /// 初始化
34 | ///
35 | public override void Initialize()
36 | {
37 | base.Initialize();
38 |
39 | //
40 | _step = Step.Step1_SpecifyCenter;
41 | this.pointer.mode = UI.Pointer.Mode.Locate;
42 | }
43 |
44 | public override EventResult OnMouseDown(MouseEventArgs e)
45 | {
46 | if (_step == Step.Step1_SpecifyCenter)
47 | {
48 | if (e.Button == MouseButtons.Left)
49 | {
50 | _circle = new Circle();
51 | _circle.center = this.pointer.currentSnapPoint;
52 | _circle.radius = 0;
53 | _circle.layerId = this.document.currentLayerId;
54 | _circle.color = this.document.currentColor;
55 |
56 | _step = Step.Step2_SpecityRadius;
57 | }
58 | }
59 | else if (_step == Step.Step2_SpecityRadius)
60 | {
61 | if (e.Button == MouseButtons.Left)
62 | {
63 | _circle.radius = (_circle.center - this.pointer.currentSnapPoint).length;
64 | _circle.layerId = this.document.currentLayerId;
65 | _circle.color = this.document.currentColor;
66 |
67 | _mgr.FinishCurrentCommand();
68 | }
69 | }
70 |
71 | return EventResult.Handled;
72 | }
73 |
74 | public override EventResult OnMouseUp(MouseEventArgs e)
75 | {
76 | return EventResult.Handled;
77 | }
78 |
79 | public override EventResult OnMouseMove(MouseEventArgs e)
80 | {
81 | if (e.Button == MouseButtons.Middle)
82 | {
83 | return EventResult.Handled;
84 | }
85 |
86 | if (_circle != null)
87 | {
88 | _circle.radius = (_circle.center - this.pointer.currentSnapPoint).length;
89 | }
90 |
91 | return EventResult.Handled;
92 | }
93 |
94 | public override void OnPaint(Graphics g)
95 | {
96 | if (_circle != null)
97 | {
98 | Presenter presenter = _mgr.presenter as Presenter;
99 | presenter.DrawEntity(g, _circle);
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/EllipseCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 | using System.Windows.Forms;
7 | using System.Drawing;
8 |
9 | namespace SharpCAD.Commands.Draw
10 | {
11 | internal class EllipseCmd : DrawCmd
12 | {
13 | private Ellipse _ellipse = null;
14 |
15 | ///
16 | /// 新增的图元
17 | ///
18 | protected override IEnumerable newEntities
19 | {
20 | get { return new Ellipse[1] { _ellipse }; }
21 | }
22 |
23 | ///
24 | /// 步骤
25 | ///
26 | private enum Step
27 | {
28 | Step1_SpecifyCenter = 1,
29 | Step2_SpecityRadiusX = 2,
30 | Step3_SpecityRadiusY = 3,
31 | }
32 | private Step _step = Step.Step1_SpecifyCenter;
33 |
34 | ///
35 | /// 初始化
36 | ///
37 | public override void Initialize()
38 | {
39 | base.Initialize();
40 |
41 | //
42 | _step = Step.Step1_SpecifyCenter;
43 | this.pointer.mode = UI.Pointer.Mode.Locate;
44 | }
45 |
46 | public override EventResult OnMouseDown(MouseEventArgs e)
47 | {
48 | if (_step == Step.Step1_SpecifyCenter)
49 | {
50 | if (e.Button == MouseButtons.Left)
51 | {
52 | _ellipse = new Ellipse();
53 | _ellipse.center = this.pointer.currentSnapPoint;
54 | _ellipse.radiusX = 0;
55 | _ellipse.radiusY = 0;
56 | _ellipse.layerId = this.document.currentLayerId;
57 | _ellipse.color = this.document.currentColor;
58 |
59 | _step = Step.Step2_SpecityRadiusX;
60 | }
61 | }
62 | else if (_step == Step.Step2_SpecityRadiusX)
63 | {
64 | if (e.Button == MouseButtons.Left)
65 | {
66 | _ellipse.radiusX = Math.Abs(_ellipse.center.x - this.pointer.currentSnapPoint.x);
67 | _ellipse.radiusY = _ellipse.radiusX / 2.0;
68 | _ellipse.layerId = this.document.currentLayerId;
69 | _ellipse.color = this.document.currentColor;
70 |
71 | _step = Step.Step3_SpecityRadiusY;
72 | }
73 | }
74 | else if (_step == Step.Step3_SpecityRadiusY)
75 | {
76 | if (e.Button == MouseButtons.Left)
77 | {
78 | _ellipse.radiusY = Math.Abs(_ellipse.center.y - this.pointer.currentSnapPoint.y);
79 | _ellipse.layerId = this.document.currentLayerId;
80 | _ellipse.color = this.document.currentColor;
81 |
82 | _mgr.FinishCurrentCommand();
83 | }
84 | }
85 |
86 | return EventResult.Handled;
87 | }
88 |
89 | public override EventResult OnMouseUp(MouseEventArgs e)
90 | {
91 | return EventResult.Handled;
92 | }
93 |
94 | public override EventResult OnMouseMove(MouseEventArgs e)
95 | {
96 | if (e.Button == MouseButtons.Middle)
97 | {
98 | return EventResult.Handled;
99 | }
100 |
101 | if (_ellipse != null)
102 | {
103 | if (_step == Step.Step2_SpecityRadiusX)
104 | {
105 | _ellipse.radiusX = Math.Abs(_ellipse.center.x - this.pointer.currentSnapPoint.x);
106 | _ellipse.radiusY = _ellipse.radiusX / 2.0;
107 | }
108 | else if (_step == Step.Step3_SpecityRadiusY)
109 | {
110 | _ellipse.radiusY = Math.Abs(_ellipse.center.y - this.pointer.currentSnapPoint.y);
111 | }
112 | }
113 |
114 | return EventResult.Handled;
115 | }
116 |
117 | public override void OnPaint(Graphics g)
118 | {
119 | if (_ellipse != null)
120 | {
121 | Presenter presenter = _mgr.presenter as Presenter;
122 | presenter.DrawEntity(g, _ellipse);
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/PointCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 | using System.Windows.Forms;
7 | using System.Drawing;
8 |
9 | namespace SharpCAD.Commands.Draw
10 | {
11 | ///
12 | /// 绘制点命令
13 | ///
14 | internal class PointCmd : DrawCmd
15 | {
16 | private XPoint _point = null;
17 |
18 | ///
19 | /// 新增的图元
20 | ///
21 | protected override IEnumerable newEntities
22 | {
23 | get { return new XPoint[1] { _point }; }
24 | }
25 |
26 | ///
27 | /// 初始化
28 | ///
29 | public override void Initialize()
30 | {
31 | base.Initialize();
32 |
33 | this.pointer.mode = UI.Pointer.Mode.Locate;
34 | }
35 |
36 | public override EventResult OnMouseDown(MouseEventArgs e)
37 | {
38 | if (e.Button == MouseButtons.Left)
39 | {
40 | _point = new XPoint(this.pointer.currentSnapPoint);
41 | _point.color = this.document.currentColor;
42 | _mgr.FinishCurrentCommand();
43 | }
44 |
45 | return EventResult.Handled;
46 | }
47 |
48 | public override EventResult OnMouseUp(MouseEventArgs e)
49 | {
50 | return EventResult.Handled;
51 | }
52 |
53 | public override EventResult OnMouseMove(MouseEventArgs e)
54 | {
55 | return EventResult.Handled;
56 | }
57 |
58 | public override void OnPaint(Graphics g)
59 | {
60 | if (_point != null)
61 | {
62 | this.presenter.DrawEntity(g, _point);
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/PolylineCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD.Commands.Draw
9 | {
10 | internal class PolylineCmd : DrawCmd
11 | {
12 | private Polyline _polyline = null;
13 | private Line _line = null;
14 |
15 | ///
16 | /// 新增的图元
17 | ///
18 | protected override IEnumerable newEntities
19 | {
20 | get{ return new Polyline[1] { _polyline }; }
21 | }
22 |
23 | ///
24 | /// 步骤
25 | ///
26 | private enum Step
27 | {
28 | Step1_SpecifyStartPoint = 1,
29 | Step2_SpecifyOtherPoint = 2,
30 | }
31 | private Step _step = Step.Step1_SpecifyStartPoint;
32 |
33 | ///
34 | /// 初始化
35 | ///
36 | public override void Initialize()
37 | {
38 | base.Initialize();
39 |
40 | //
41 | _step = Step.Step1_SpecifyStartPoint;
42 | this.pointer.mode = UI.Pointer.Mode.Locate;
43 | }
44 |
45 | public override EventResult OnMouseDown(MouseEventArgs e)
46 | {
47 | switch (_step)
48 | {
49 | case Step.Step1_SpecifyStartPoint:
50 | if (e.Button == MouseButtons.Left)
51 | {
52 | _polyline = new Polyline();
53 | _polyline.AddVertexAt(_polyline.NumberOfVertices, this.pointer.currentSnapPoint);
54 |
55 | _line = new Line();
56 | _line.startPoint = _line.endPoint = this.pointer.currentSnapPoint;
57 |
58 | _step = Step.Step2_SpecifyOtherPoint;
59 | }
60 | break;
61 |
62 | case Step.Step2_SpecifyOtherPoint:
63 | if (e.Button == MouseButtons.Left)
64 | {
65 | _polyline.AddVertexAt(_polyline.NumberOfVertices, this.pointer.currentSnapPoint);
66 | _line.startPoint = this.pointer.currentSnapPoint;
67 | }
68 | break;
69 | }
70 |
71 | return EventResult.Handled;
72 | }
73 |
74 | public override EventResult OnMouseUp(MouseEventArgs e)
75 | {
76 | return EventResult.Handled;
77 | }
78 |
79 | public override EventResult OnMouseMove(MouseEventArgs e)
80 | {
81 | if (e.Button == MouseButtons.Middle)
82 | {
83 | return EventResult.Handled;
84 | }
85 |
86 | switch (_step)
87 | {
88 | case Step.Step1_SpecifyStartPoint:
89 | break;
90 |
91 | case Step.Step2_SpecifyOtherPoint:
92 | if (_line != null)
93 | {
94 | _line.endPoint = this.pointer.currentSnapPoint;
95 | }
96 | break;
97 | }
98 |
99 | return EventResult.Handled;
100 | }
101 |
102 | public override EventResult OnKeyDown(KeyEventArgs e)
103 | {
104 | if (e.KeyCode == Keys.Escape)
105 | {
106 | if (_polyline.NumberOfVertices > 1)
107 | {
108 | _polyline.layerId = this.document.currentLayerId;
109 | _polyline.color = this.document.currentColor;
110 | _mgr.FinishCurrentCommand();
111 | }
112 | else
113 | {
114 | _mgr.CancelCurrentCommand();
115 | }
116 | }
117 | return EventResult.Handled;
118 | }
119 |
120 | public override EventResult OnKeyUp(KeyEventArgs e)
121 | {
122 | return EventResult.Handled;
123 | }
124 |
125 | public override void OnPaint(Graphics g)
126 | {
127 | if (_polyline != null)
128 | {
129 | _mgr.presenter.DrawEntity(g, _polyline);
130 | }
131 | if (_line != null)
132 | {
133 | _mgr.presenter.DrawEntity(g, _line);
134 | }
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/RectangleCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD.Commands.Draw
9 | {
10 | internal class RectangleCmd : DrawCmd
11 | {
12 | private Polyline _rectangle = null;
13 |
14 | ///
15 | /// 新增的图元
16 | ///
17 | protected override IEnumerable newEntities
18 | {
19 | get { return new Polyline[1] { _rectangle }; }
20 | }
21 |
22 | // 起点+终点
23 | private LitMath.Vector2 _point1st = new LitMath.Vector2(0, 0);
24 | private LitMath.Vector2 _point2nd = new LitMath.Vector2(0, 0);
25 |
26 | private void UpdateRectangle()
27 | {
28 | if (_rectangle == null)
29 | {
30 | _rectangle = new Polyline();
31 | _rectangle.closed = true;
32 | for (int i = 0; i < 4; ++i)
33 | {
34 | _rectangle.AddVertexAt(0, new LitMath.Vector2(0, 0));
35 | }
36 | }
37 |
38 | _rectangle.SetPointAt(0, _point1st);
39 | _rectangle.SetPointAt(1, new LitMath.Vector2(_point2nd.x, _point1st.y));
40 | _rectangle.SetPointAt(2, _point2nd);
41 | _rectangle.SetPointAt(3, new LitMath.Vector2(_point1st.x, _point2nd.y));
42 | _rectangle.layerId = this.document.currentLayerId;
43 | _rectangle.color = this.document.currentColor;
44 | }
45 |
46 | ///
47 | /// 步骤
48 | ///
49 | private enum Step
50 | {
51 | Step1_SpecifyPoint1st = 1,
52 | Step2_SpecifyPoint2nd = 2,
53 | }
54 | private Step _step = Step.Step1_SpecifyPoint1st;
55 |
56 | ///
57 | /// 初始化
58 | ///
59 | public override void Initialize()
60 | {
61 | base.Initialize();
62 |
63 | //
64 | _step = Step.Step1_SpecifyPoint1st;
65 | this.pointer.mode = UI.Pointer.Mode.Locate;
66 | }
67 |
68 | public override EventResult OnMouseDown(MouseEventArgs e)
69 | {
70 | switch (_step)
71 | {
72 | case Step.Step1_SpecifyPoint1st:
73 | if (e.Button == MouseButtons.Left)
74 | {
75 | _point1st = this.pointer.currentSnapPoint;
76 | _step = Step.Step2_SpecifyPoint2nd;
77 | }
78 | break;
79 |
80 | case Step.Step2_SpecifyPoint2nd:
81 | if (e.Button == MouseButtons.Left)
82 | {
83 | _point2nd = this.pointer.currentSnapPoint;
84 | this.UpdateRectangle();
85 |
86 | _mgr.FinishCurrentCommand();
87 | }
88 | break;
89 | }
90 |
91 | return EventResult.Handled;
92 | }
93 |
94 | public override EventResult OnMouseUp(MouseEventArgs e)
95 | {
96 | return EventResult.Handled;
97 | }
98 |
99 | public override EventResult OnMouseMove(MouseEventArgs e)
100 | {
101 | if (e.Button == MouseButtons.Middle)
102 | {
103 | return EventResult.Handled;
104 | }
105 |
106 | if (_step == Step.Step2_SpecifyPoint2nd)
107 | {
108 | _point2nd = this.pointer.currentSnapPoint;
109 | this.UpdateRectangle();
110 | }
111 |
112 | return EventResult.Handled;
113 | }
114 |
115 | public override void OnPaint(Graphics g)
116 | {
117 | if (_rectangle != null)
118 | {
119 | this.presenter.DrawEntity(g, _rectangle);
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Draw/_DrawCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.DatabaseServices;
7 | using SharpCAD.ApplicationServices;
8 | using SharpCAD.UI;
9 |
10 | namespace SharpCAD.Commands.Draw
11 | {
12 | internal abstract class DrawCmd : Command
13 | {
14 | protected abstract IEnumerable newEntities { get; }
15 |
16 | ///
17 | /// 初始化
18 | ///
19 | public override void Initialize()
20 | {
21 | base.Initialize();
22 |
23 | _mgr.presenter.selections.Clear();
24 | this.pointer.isShowAnchor = false;
25 | }
26 |
27 | ///
28 | /// 结束
29 | ///
30 | public override void Terminate()
31 | {
32 | _mgr.presenter.selections.Clear();
33 |
34 | base.Terminate();
35 | }
36 |
37 | ///
38 | /// 提交到数据库
39 | ///
40 | protected override void Commit()
41 | {
42 | foreach (Entity entity in this.newEntities)
43 | {
44 | this.presenter.AppendEntity(entity);
45 | }
46 | }
47 |
48 | ///
49 | /// 回滚撤销
50 | ///
51 | protected override void Rollback()
52 | {
53 | foreach (Entity entity in this.newEntities)
54 | {
55 | entity.Erase();
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Edit/RedoCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD.Commands.Edit
6 | {
7 | internal class RedoCmd : Command
8 | {
9 | public override void Initialize()
10 | {
11 | base.Initialize();
12 |
13 | _mgr.FinishCurrentCommand();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Edit/UndoCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD.Commands.Edit
6 | {
7 | internal class UndoCmd : Command
8 | {
9 | public override void Initialize()
10 | {
11 | base.Initialize();
12 |
13 | _mgr.FinishCurrentCommand();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/GripPointMoveCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 | using System.Drawing;
4 |
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD.Commands
8 | {
9 | ///
10 | /// 夹点移动命令
11 | ///
12 | internal class GripPointMoveCmd : Command
13 | {
14 | ///
15 | /// 夹点
16 | ///
17 | protected GripPoint _gripPoint = null;
18 | protected int _index = -1;
19 |
20 | protected LitMath.Vector2 _originalGripPos;
21 | protected LitMath.Vector2 _resultGripPos;
22 |
23 | ///
24 | /// 图元
25 | ///
26 | protected Entity _entity = null;
27 | protected Entity _entityCopy = null;
28 |
29 | ///
30 | /// 鼠标位置(世界坐标系)
31 | ///
32 | protected LitMath.Vector2 _mousePosInWorld;
33 |
34 | ///
35 | /// 构造函数
36 | ///
37 | public GripPointMoveCmd(Entity entity, int index, GripPoint gripPoint)
38 | {
39 | _entity = entity;
40 | _entityCopy = entity.Clone() as Entity;
41 | _index = index;
42 | _gripPoint = gripPoint;
43 |
44 | _originalGripPos = _gripPoint.position;
45 | _resultGripPos = _gripPoint.position;
46 | _mousePosInWorld = _gripPoint.position;
47 | }
48 |
49 | ///
50 | /// 初始化
51 | ///
52 | public override void Initialize()
53 | {
54 | base.Initialize();
55 |
56 | //
57 | this.pointer.isShowAnchor = true;
58 | this.pointer.mode = UI.Pointer.Mode.Locate;
59 | }
60 |
61 | ///
62 | /// 撤销
63 | ///
64 | public override void Undo()
65 | {
66 | base.Undo();
67 | _entity.SetGripPointAt(_index, _gripPoint, _originalGripPos);
68 | }
69 |
70 | ///
71 | /// 重做
72 | ///
73 | public override void Redo()
74 | {
75 | base.Redo();
76 | _entity.SetGripPointAt(_index, _gripPoint, _resultGripPos);
77 | }
78 |
79 | ///
80 | /// 完成
81 | ///
82 | public override void Finish()
83 | {
84 | _resultGripPos = _mousePosInWorld;
85 | _entity.SetGripPointAt(_index, _gripPoint, _resultGripPos);
86 | pointer.UpdateGripPoints();
87 | base.Finish();
88 | }
89 |
90 | ///
91 | /// 撤销
92 | ///
93 | public override void Cancel()
94 | {
95 | base.Cancel();
96 | }
97 |
98 | public override EventResult OnMouseDown(MouseEventArgs e)
99 | {
100 | if (e.Button == MouseButtons.Left)
101 | {
102 | _mousePosInWorld = this.pointer.currentSnapPoint;
103 | _mgr.FinishCurrentCommand();
104 | }
105 |
106 | return EventResult.Handled;
107 | }
108 |
109 | public override EventResult OnMouseUp(MouseEventArgs e)
110 | {
111 | return EventResult.Handled;
112 | }
113 |
114 | public override EventResult OnMouseMove(MouseEventArgs e)
115 | {
116 | _mousePosInWorld = this.pointer.currentSnapPoint;
117 | _entityCopy.SetGripPointAt(_index, _gripPoint, _mousePosInWorld);
118 | return EventResult.Handled;
119 | }
120 |
121 | public override EventResult OnKeyDown(KeyEventArgs e)
122 | {
123 | if (e.KeyCode == Keys.Escape)
124 | {
125 | _mgr.CancelCurrentCommand();
126 | }
127 |
128 | return EventResult.Handled;
129 | }
130 |
131 | public override EventResult OnKeyUp(KeyEventArgs e)
132 | {
133 | return EventResult.Handled;
134 | }
135 |
136 | public override void OnPaint(Graphics g)
137 | {
138 | //this.anchor.OnDraw(_mgr.presenter, g, Color.Red);
139 | this.DrawPath(g);
140 | _mgr.presenter.DrawEntity(g, _entityCopy);
141 | }
142 |
143 | protected virtual void DrawPath(Graphics g)
144 | {
145 | _mgr.presenter.DrawLine(g, new Pen(Color.White), _originalGripPos, _mousePosInWorld, CSYS.Model);
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Layer/AddLayerCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | using SharpCAD.DatabaseServices;
6 | using SharpCAD.Windows;
7 |
8 | namespace SharpCAD.Commands
9 | {
10 | ///
11 | /// 新增图层命令
12 | ///
13 | internal class AddLayerCmd : Command
14 | {
15 | private Layer _layer = null;
16 |
17 | public override void Initialize()
18 | {
19 | LayerItemForm dlg = new LayerItemForm(LayerItemForm.Mode.Add, null, this.database);
20 | dlg.StartPosition = FormStartPosition.CenterParent;
21 | DialogResult dlgRet = dlg.ShowDialog();
22 | if (dlgRet == DialogResult.OK)
23 | {
24 | _layer = dlg.layer;
25 | _mgr.FinishCurrentCommand();
26 | }
27 | else
28 | {
29 | _mgr.CancelCurrentCommand();
30 | }
31 | }
32 |
33 | public override void Undo()
34 | {
35 | base.Undo();
36 |
37 | if (_layer != null)
38 | {
39 | this.database.layerTable.Remove(_layer);
40 | }
41 | }
42 |
43 | public override void Redo()
44 | {
45 | base.Redo();
46 |
47 | this.CommitToDatabase();
48 | }
49 |
50 | private void CommitToDatabase()
51 | {
52 | if (_layer != null)
53 | {
54 | this.database.layerTable.Add(_layer);
55 | }
56 | }
57 |
58 | public override void Finish()
59 | {
60 | this.CommitToDatabase();
61 |
62 | base.Finish();
63 | }
64 |
65 | public override void Cancel()
66 | {
67 | base.Cancel();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Layer/ModifyLayerCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | using SharpCAD.DatabaseServices;
6 | using SharpCAD.Windows;
7 |
8 | namespace SharpCAD.Commands
9 | {
10 | ///
11 | /// 修改图层命令
12 | ///
13 | internal class ModifyLayerCmd : Command
14 | {
15 | private readonly Layer _layer = null;
16 | private Layer _originalLayerCopy = null;
17 | private Layer _resultLayer = null;
18 |
19 | public ModifyLayerCmd(Layer layer)
20 | {
21 | _layer = layer;
22 | _originalLayerCopy = _layer.Clone() as Layer;
23 | _resultLayer = _layer.Clone() as Layer;
24 | }
25 |
26 | public override void Initialize()
27 | {
28 | LayerItemForm dlg = new LayerItemForm(LayerItemForm.Mode.Modify, _layer, this.database);
29 | dlg.StartPosition = FormStartPosition.CenterParent;
30 | DialogResult dlgRet = dlg.ShowDialog();
31 | if (dlgRet == DialogResult.OK)
32 | {
33 | _resultLayer = dlg.layer;
34 | if (_resultLayer.name == _layer.name
35 | && _resultLayer.description == _layer.description
36 | && _resultLayer.color == _layer.color)
37 | {
38 | _mgr.CancelCurrentCommand();
39 | }
40 | else
41 | {
42 | _mgr.FinishCurrentCommand();
43 | }
44 | }
45 | else
46 | {
47 | _mgr.CancelCurrentCommand();
48 | }
49 | }
50 |
51 | public override void Undo()
52 | {
53 | _layer.name = _originalLayerCopy.name;
54 | _layer.color = _originalLayerCopy.color;
55 | _layer.description = _originalLayerCopy.description;
56 | }
57 |
58 | public override void Redo()
59 | {
60 | this.Commit();
61 | }
62 |
63 | private void Commit()
64 | {
65 | _layer.name = _resultLayer.name;
66 | _layer.color = _resultLayer.color;
67 | _layer.description = _resultLayer.description;
68 | }
69 |
70 | public override void Finish()
71 | {
72 | this.Commit();
73 |
74 | base.Finish();
75 | }
76 |
77 | public override void Cancel()
78 | {
79 | base.Cancel();
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Layer/RemoveLayersCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | using SharpCAD.ApplicationServices;
6 | using SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD.Commands
9 | {
10 | ///
11 | /// 删除图层命令
12 | ///
13 | internal class RemoveLayersCmd : Command
14 | {
15 | private List _layers = new List();
16 | private List _layersToDelete = new List();
17 |
18 | public RemoveLayersCmd(List layers)
19 | {
20 | _layers.AddRange(layers);
21 | }
22 |
23 | public override void Initialize()
24 | {
25 | DBUtils.DatabaseUtils dbUtils = new DBUtils.DatabaseUtils(this.database);
26 |
27 | foreach (Layer layer in _layers)
28 | {
29 | if (dbUtils.IsLayerCanDelete(layer.id))
30 | {
31 | _layersToDelete.Add(layer);
32 | }
33 | }
34 |
35 | int cntCanNotToDelete = _layers.Count - _layersToDelete.Count;
36 | if (cntCanNotToDelete > 0)
37 | {
38 | string message = string.Format(
39 | "有 {0} 个选定图层无法删除 (共 {1} 个选定图层)",
40 | cntCanNotToDelete,
41 | _layers.Count);
42 | MessageBox.Show(message);
43 | }
44 |
45 | if (_layersToDelete.Count > 0)
46 | {
47 | _mgr.FinishCurrentCommand();
48 | }
49 | else
50 | {
51 | _mgr.CancelCurrentCommand();
52 | }
53 | }
54 |
55 | public override void Undo()
56 | {
57 | foreach (Layer layer in _layersToDelete)
58 | {
59 | this.database.layerTable.Add(layer);
60 | }
61 | }
62 |
63 | public override void Redo()
64 | {
65 | this.Commit();
66 | }
67 |
68 | private void Commit()
69 | {
70 | foreach (Layer layer in _layersToDelete)
71 | {
72 | layer.Erase();
73 | }
74 | }
75 |
76 | public override void Finish()
77 | {
78 | this.Commit();
79 |
80 | base.Finish();
81 | }
82 |
83 | public override void Cancel()
84 | {
85 | base.Cancel();
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/DeleteCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.ApplicationServices;
7 | using SharpCAD.DatabaseServices;
8 | using SharpCAD.UI;
9 |
10 | namespace SharpCAD.Commands.Modify
11 | {
12 | ///
13 | /// 删除命令
14 | ///
15 | internal class DeleteCmd : ModifyCmd
16 | {
17 | ///
18 | /// 操作的图元
19 | ///
20 | private List _items = new List();
21 | private void InitializeItemsToDelete()
22 | {
23 | Document doc = _mgr.presenter.document as Document;
24 | foreach (Selection sel in _mgr.presenter.selections)
25 | {
26 | DBObject dbobj = doc.database.GetObject(sel.objectId);
27 | if (dbobj != null && dbobj is Entity)
28 | {
29 | Entity entity = dbobj as Entity;
30 | _items.Add(entity);
31 | }
32 | }
33 | }
34 |
35 | public override void Initialize()
36 | {
37 | base.Initialize();
38 |
39 | //
40 | if (_mgr.presenter.selections.Count > 0)
41 | {
42 | InitializeItemsToDelete();
43 | _mgr.FinishCurrentCommand();
44 | }
45 | else
46 | {
47 | this.pointer.mode = Pointer.Mode.Select;
48 | }
49 | }
50 |
51 | ///
52 | /// 提交到数据库
53 | ///
54 | protected override void Commit()
55 | {
56 | foreach (Entity item in _items)
57 | {
58 | item.Erase();
59 | }
60 | }
61 |
62 | ///
63 | /// 回滚撤销
64 | ///
65 | protected override void Rollback()
66 | {
67 | foreach (Entity item in _items)
68 | {
69 | _mgr.presenter.AppendEntity(item);
70 | }
71 | }
72 |
73 | public override EventResult OnMouseDown(MouseEventArgs e)
74 | {
75 | return EventResult.Handled;
76 | }
77 |
78 | public override EventResult OnMouseUp(MouseEventArgs e)
79 | {
80 | if (e.Button == MouseButtons.Right)
81 | {
82 | if (_mgr.presenter.selections.Count > 0)
83 | {
84 | InitializeItemsToDelete();
85 | _mgr.FinishCurrentCommand();
86 | }
87 | else
88 | {
89 | _mgr.CancelCurrentCommand();
90 | }
91 | }
92 |
93 | return EventResult.Handled;
94 | }
95 |
96 | public override EventResult OnMouseMove(MouseEventArgs e)
97 | {
98 | return EventResult.Handled;
99 | }
100 |
101 | public override EventResult OnKeyDown(KeyEventArgs e)
102 | {
103 | if (e.KeyCode == Keys.Escape)
104 | {
105 | _mgr.CancelCurrentCommand();
106 | }
107 |
108 | return EventResult.Handled;
109 | }
110 |
111 | public override EventResult OnKeyUp(KeyEventArgs e)
112 | {
113 | return EventResult.Handled;
114 | }
115 |
116 | public override void OnPaint(Graphics g)
117 | {
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/Offset/OffsetArc.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.Commands.Modify.Offset
6 | {
7 | internal class OffsetArc : _OffsetOperation
8 | {
9 | private Arc _arc = null;
10 | private Arc _result = null;
11 |
12 | public override Entity result
13 | {
14 | get { return _result; }
15 | }
16 |
17 | public OffsetArc(Entity entity)
18 | : base()
19 | {
20 | _arc = entity as Arc;
21 | if (_arc != null)
22 | {
23 | _result = _arc.Clone() as Arc;
24 | }
25 | }
26 |
27 | public override bool Do(double value, LitMath.Vector2 refPoint)
28 | {
29 | if (_arc == null
30 | || _result == null)
31 | {
32 | return false;
33 | }
34 |
35 | double dis = (_arc.center - refPoint).length;
36 | if (dis > _arc.radius)
37 | {
38 | _result.radius = _arc.radius + Math.Abs(value);
39 | }
40 | else
41 | {
42 | if (_arc.radius <= Math.Abs(value))
43 | {
44 | _result.radius = _arc.radius;
45 | return false;
46 | }
47 | else
48 | {
49 | _result.radius = _arc.radius - Math.Abs(value);
50 | }
51 | }
52 |
53 | return true;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/Offset/OffsetCircle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.Commands.Modify.Offset
6 | {
7 | internal class OffsetCircle : _OffsetOperation
8 | {
9 | private Circle _circle = null;
10 | private Circle _result = null;
11 |
12 | public override Entity result
13 | {
14 | get { return _result; }
15 | }
16 |
17 | public OffsetCircle(Entity entity)
18 | : base()
19 | {
20 | _circle = entity as Circle;
21 | if (_circle != null)
22 | {
23 | _result = _circle.Clone() as Circle;
24 | }
25 | }
26 |
27 | public override bool Do(double value, LitMath.Vector2 refPoint)
28 | {
29 | if (_circle == null
30 | || _result == null)
31 | {
32 | return false;
33 | }
34 |
35 | double dis = (_circle.center - refPoint).length;
36 | if (dis > _circle.radius)
37 | {
38 | _result.radius = _circle.radius + Math.Abs(value);
39 | }
40 | else
41 | {
42 | if (_circle.radius <= Math.Abs(value))
43 | {
44 | _result.radius = _circle.radius;
45 | return false;
46 | }
47 | else
48 | {
49 | _result.radius = _circle.radius - Math.Abs(value);
50 | }
51 | }
52 |
53 | return true;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/Offset/OffsetLine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.Commands.Modify.Offset
6 | {
7 | internal class OffsetLine : _OffsetOperation
8 | {
9 | private Line _line = null;
10 | private Line _result = null;
11 |
12 | private LitMath.Vector2 _lineDir = new LitMath.Vector2(0, 0);
13 | private LitMath.Vector2 _lineN1 = new LitMath.Vector2(0, 0);
14 | private LitMath.Vector2 _lineN2 = new LitMath.Vector2(0, 0);
15 | private double _crossDirN1 = 0.0;
16 |
17 | public override Entity result
18 | {
19 | get { return _result; }
20 | }
21 |
22 | public OffsetLine(Entity entity)
23 | : base()
24 | {
25 | _line = entity as Line;
26 | if (_line != null)
27 | {
28 | _result = _line.Clone() as Line;
29 | _lineDir = (_line.endPoint - _line.startPoint).normalized;
30 | _lineN1 = new LitMath.Vector2(_lineDir.y, -_lineDir.x);
31 | _lineN2 = new LitMath.Vector2(-_lineDir.y, _lineDir.x);
32 | _crossDirN1 = LitMath.Vector2.Cross(_lineDir, _lineN1);
33 | }
34 | }
35 |
36 | public override bool Do(double value, LitMath.Vector2 refPoint)
37 | {
38 | if (_line == null
39 | || _result == null)
40 | {
41 | return false;
42 | }
43 |
44 | if (_crossDirN1 * LitMath.Vector2.Cross(_lineDir, refPoint - _line.startPoint) > 0)
45 | {
46 | _result.startPoint = _line.startPoint + _lineN1 * Math.Abs(value);
47 | _result.endPoint = _line.endPoint + _lineN1 * Math.Abs(value);
48 | }
49 | else
50 | {
51 | _result.startPoint = _line.startPoint + _lineN2 * Math.Abs(value);
52 | _result.endPoint = _line.endPoint + _lineN2 * Math.Abs(value);
53 | }
54 |
55 | return true;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/Offset/_OffsetOperation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.Commands.Modify.Offset
6 | {
7 | internal abstract class _OffsetOperation
8 | {
9 | public abstract Entity result { get; }
10 |
11 | public abstract bool Do(double value, LitMath.Vector2 refPoint);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/Offset/_OffsetOpsMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD.Commands.Modify.Offset
7 | {
8 | internal class _OffsetOpsMgr
9 | {
10 | ///
11 | /// 单例
12 | ///
13 | private static _OffsetOpsMgr _instance = null;
14 | public static _OffsetOpsMgr Instance
15 | {
16 | get
17 | {
18 | if (_instance == null)
19 | {
20 | _instance = new _OffsetOpsMgr();
21 | }
22 | return _instance;
23 | }
24 | }
25 |
26 | ///
27 | /// 图元类型<>Offset操作类型
28 | ///
29 | private Dictionary _entType2OffsetOpType = new Dictionary();
30 |
31 | ///
32 | /// 构造函数
33 | ///
34 | private _OffsetOpsMgr()
35 | {
36 | RegisterOffsetOpType(typeof(Line), typeof(OffsetLine));
37 | RegisterOffsetOpType(typeof(Circle), typeof(OffsetCircle));
38 | RegisterOffsetOpType(typeof(Arc), typeof(OffsetArc));
39 | }
40 |
41 | ///
42 | /// 注册Offset操作类型
43 | ///
44 | private void RegisterOffsetOpType(Type entType, Type offsetOpType)
45 | {
46 | _entType2OffsetOpType[entType] = offsetOpType;
47 | }
48 |
49 | ///
50 | /// 新建图元Offset操作对象
51 | ///
52 | public _OffsetOperation NewOffsetOperation(Entity entity)
53 | {
54 | Type entType = entity.GetType();
55 | if (_entType2OffsetOpType.ContainsKey(entType))
56 | {
57 | Type offsetOpType = _entType2OffsetOpType[entType];
58 |
59 | object[] parameters = new object[1];
60 | parameters[0] = entity;
61 | return Activator.CreateInstance(offsetOpType, parameters) as _OffsetOperation;
62 | }
63 | else
64 | {
65 | return null;
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Modify/_ModifyCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.ApplicationServices;
5 | using SharpCAD.DatabaseServices;
6 | using SharpCAD.UI;
7 |
8 | namespace SharpCAD.Commands.Modify
9 | {
10 | internal abstract class ModifyCmd : Command
11 | {
12 | ///
13 | /// 初始化
14 | ///
15 | public override void Initialize()
16 | {
17 | base.Initialize();
18 |
19 | this.pointer.isShowAnchor = false;
20 | }
21 |
22 | ///
23 | /// 结束
24 | ///
25 | public override void Terminate()
26 | {
27 | _mgr.presenter.selections.Clear();
28 |
29 | base.Terminate();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/SharpCAD/Commands/Text/EditCmd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using db = SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD.Commands.Text
9 | {
10 | ///
11 | /// 文本编辑命令
12 | ///
13 | internal class EditCmd : Command
14 | {
15 | ///
16 | /// 文本
17 | ///
18 | private db.Text _text = null;
19 | private db.Text _original = null;
20 | private db.Text _result = null;
21 |
22 | internal db.Text text
23 | {
24 | set
25 | {
26 | _text = value;
27 | _original = _text.Clone() as db.Text;
28 | _result = _text.Clone() as db.Text;
29 | }
30 | }
31 |
32 | ///
33 | /// 初始化
34 | ///
35 | public override void Initialize()
36 | {
37 | base.Initialize();
38 |
39 | _mgr.presenter.selections.Clear();
40 | this.pointer.isShowAnchor = false;
41 | }
42 |
43 | ///
44 | /// 结束
45 | ///
46 | public override void Terminate()
47 | {
48 | _mgr.presenter.selections.Clear();
49 |
50 | base.Terminate();
51 | }
52 |
53 | ///
54 | /// 提交到数据库
55 | ///
56 | protected override void Commit()
57 | {
58 | _text.text = _result.text;
59 | _text.font = _result.font;
60 | _text.height = _result.height;
61 | _text.alignment = _result.alignment;
62 | }
63 |
64 | ///
65 | /// 回滚撤销
66 | ///
67 | protected override void Rollback()
68 | {
69 | _text.text = _original.text;
70 | _text.font = _original.font;
71 | _text.height = _original.height;
72 | _text.alignment = _original.alignment;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/SharpCAD/DatabaseUtils/ArcUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.DBUtils
6 | {
7 | internal class ArcUtils
8 | {
9 | public static LitMath.Vector2 ArcMiddlePoint(Arc arc)
10 | {
11 | double angle = 0;
12 | if (arc.endAngle >= arc.startAngle)
13 | {
14 | angle = (arc.startAngle + arc.endAngle) / 2;
15 | }
16 | else
17 | {
18 | angle = (arc.startAngle + arc.endAngle + LitMath.Utils.PI * 2) / 2;
19 | }
20 | return arc.center + LitMath.Vector2.RotateInRadian(
21 | new LitMath.Vector2(arc.radius, 0), angle);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/SharpCAD/DatabaseUtils/DatabaseUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD.DBUtils
7 | {
8 | internal class DatabaseUtils
9 | {
10 | private Database _db;
11 |
12 | internal DatabaseUtils(Database db)
13 | {
14 | _db = db;
15 | }
16 |
17 | internal bool IsLayerCanDelete(ObjectId layerId)
18 | {
19 | if (layerId == _db.layerTable.layerZeroId)
20 | {
21 | return false;
22 | }
23 |
24 | foreach (Block block in _db.blockTable)
25 | {
26 | foreach (Entity entity in block)
27 | {
28 | if (entity.layerId == layerId)
29 | {
30 | return false;
31 | }
32 | }
33 | }
34 |
35 | return true;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/SharpCAD/Languages/Chinese.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 文件
4 | 新建...
5 | 打开...
6 | 保存...
7 | 另存为...
8 | 编辑
9 | 撤销
10 | 重做
11 | 格式
12 | 图层
13 | 绘图
14 | 点
15 | 直线
16 | 射线
17 | 构造线
18 | 多段线
19 | 正多边形
20 | 矩形
21 | 圆
22 | 椭圆
23 | 圆弧
24 | 修改
25 | 删除
26 | 复制
27 | 镜像
28 | 偏移
29 | 移动
30 | 新建
31 | 图层特性管理器
32 | 名称
33 | 描述
34 | 颜色
35 | 线型
36 | 层锁定
37 | 创建图层
38 | 图层名称
39 | 描述
40 | 颜色
41 | SharpCAD文件(*.scad)|*.scad
42 | 红
43 | 黄
44 | 绿
45 | 青
46 | 蓝
47 | 洋红
48 | 白
49 | 选择颜色...
50 | 修改
51 | 新增
52 | 删除
53 | 工具
54 | 帮助
55 |
56 |
--------------------------------------------------------------------------------
/src/SharpCAD/Languages/English.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | File
4 | New...
5 | Open...
6 | Save...
7 | Save As...
8 | Edit
9 | Undo
10 | Redo
11 | Format
12 | Layer
13 | Draw
14 | Point
15 | Line
16 | Ray
17 | Xline
18 | Polyline
19 | Polygon
20 | Rectangle
21 | Circle
22 | Ellipse
23 | Arc
24 | Modify
25 | Erase
26 | Copy
27 | Mirror
28 | Offset
29 | Move
30 | new
31 | Layer Feature Manager
32 | Name
33 | Description
34 | Color
35 | Line Type
36 | Lock
37 | Create Layer
38 | Layer Name
39 | Description
40 | Color
41 | SharpCAD File(*.scad)|*.scad
42 | Red
43 | Yellow
44 | Green
45 | Cyan
46 | Blue
47 | Magenta
48 | White
49 | Choose Color...
50 | Modify
51 | Add
52 | Delete
53 | Tool
54 | Help
55 |
56 |
--------------------------------------------------------------------------------
/src/SharpCAD/Languages/GlobalData.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Configuration;
6 |
7 | namespace SharpCAD
8 | {
9 | public class GlobalData
10 | {
11 | ///
12 | /// System Language (Chinese, English...)
13 | ///
14 | public static string SystemLanguage = ConfigurationManager.AppSettings["Language"];
15 |
16 | private static Language globalLanguage;
17 | public static Language GlobalLanguage
18 | {
19 | get
20 | {
21 | if (globalLanguage == null)
22 | {
23 | globalLanguage = new Language();
24 | return globalLanguage;
25 | }
26 | return globalLanguage;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/Anchor/AnchorsMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.ApplicationServices;
7 | using SharpCAD.DatabaseServices;
8 |
9 | namespace SharpCAD
10 | {
11 | internal class AnchorsMgr
12 | {
13 | private Presenter _presenter = null;
14 |
15 | private Dictionary> _gripPnts = new Dictionary>();
16 | private GripPoint _currGripPoint = null;
17 | internal GripPoint currentGripPoint
18 | {
19 | get { return _currGripPoint; }
20 | }
21 | private ObjectId _currGripEntityId = ObjectId.Null;
22 | internal ObjectId currentGripEntityId
23 | {
24 | get { return _currGripEntityId; }
25 | }
26 | private int _currGripPointIndex = -1;
27 | internal int currentGripPointIndex
28 | {
29 | get { return _currGripPointIndex; }
30 | }
31 |
32 | public AnchorsMgr(Presenter presenter)
33 | {
34 | _presenter = presenter;
35 | }
36 |
37 | internal void Update()
38 | {
39 | Document doc = _presenter.document as Document;
40 | if (doc.selections.Count == 0)
41 | {
42 | _gripPnts.Clear();
43 | return;
44 | }
45 |
46 | Dictionary> oldGripPnts = _gripPnts;
47 | _gripPnts = new Dictionary>();
48 | foreach (Selection sel in doc.selections)
49 | {
50 | if (sel.objectId == ObjectId.Null)
51 | {
52 | continue;
53 | }
54 | if (oldGripPnts.ContainsKey(sel.objectId))
55 | {
56 | _gripPnts[sel.objectId] = oldGripPnts[sel.objectId];
57 | continue;
58 | }
59 |
60 | DBObject dbobj = doc.database.GetObject(sel.objectId);
61 | if (dbobj == null)
62 | {
63 | continue;
64 | }
65 | Entity entity = dbobj as Entity;
66 | if (entity == null)
67 | {
68 | continue;
69 | }
70 |
71 | List entGripPnts = entity.GetGripPoints();
72 | if (entGripPnts != null && entGripPnts.Count > 0)
73 | {
74 | _gripPnts[sel.objectId] = entGripPnts;
75 | }
76 | }
77 | }
78 |
79 | internal void Clear()
80 | {
81 | _gripPnts.Clear();
82 | }
83 |
84 | internal void OnPaint(Graphics graphics)
85 | {
86 | foreach (KeyValuePair> kvp in _gripPnts)
87 | {
88 | foreach (GripPoint gripPnt in kvp.Value)
89 | {
90 | double width = 10;
91 | double height = 10;
92 | LitMath.Vector2 posInCanvas = _presenter.ModelToCanvas(gripPnt.position);
93 | posInCanvas.x -= width / 2;
94 | posInCanvas.y -= height / 2;
95 | _presenter.FillRectangle(graphics, GDIResMgr.Instance.GetBrush(Color.Blue), posInCanvas, width, height, CSYS.Canvas);
96 | }
97 | }
98 | }
99 |
100 | internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas)
101 | {
102 | LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas);
103 |
104 | foreach (KeyValuePair> kvp in _gripPnts)
105 | {
106 | int index = -1;
107 | foreach (GripPoint gripPnt in kvp.Value)
108 | {
109 | ++index;
110 | double width = 10;
111 | double height = 10;
112 | LitMath.Vector2 gripPosInCanvas = _presenter.ModelToCanvas(gripPnt.position);
113 | gripPosInCanvas.x -= width / 2;
114 | gripPosInCanvas.y -= height / 2;
115 | LitMath.Rectangle2 rect = new LitMath.Rectangle2(gripPosInCanvas, width, height);
116 |
117 | if (MathUtils.IsPointInRectangle(posInCanvas, rect))
118 | {
119 | _currGripPoint = gripPnt;
120 | _currGripEntityId = kvp.Key;
121 | _currGripPointIndex = index;
122 | return gripPnt.position;
123 | }
124 | }
125 | }
126 |
127 | _currGripPoint = null;
128 | _currGripEntityId = ObjectId.Null;
129 | _currGripPointIndex = -1;
130 | return posInModel;
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/CSYS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD
4 | {
5 | ///
6 | /// 坐标系
7 | ///
8 | internal enum CSYS
9 | {
10 | Model = 1,
11 | Canvas = 2,
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputCtrl/DynInputCtrl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | namespace SharpCAD.UI
7 | {
8 | ///
9 | /// 动态输入控件
10 | ///
11 | internal abstract class DynInputCtrl
12 | {
13 | protected Presenter _presenter = null;
14 | protected List _winControls = new List();
15 | protected Label _tipLabel = null;
16 |
17 | ///
18 | /// 独占
19 | ///
20 | private bool _exclusive = false;
21 | public bool exclusive
22 | {
23 | get { return _exclusive; }
24 | set { _exclusive = value; }
25 | }
26 |
27 | ///
28 | /// 位置
29 | ///
30 | protected LitMath.Vector2 _position = new LitMath.Vector2(0, 0);
31 | public virtual LitMath.Vector2 position
32 | {
33 | get { return _position; }
34 | set
35 | {
36 | _position = value;
37 | this.UpdatePosition();
38 | }
39 | }
40 | public abstract void UpdatePosition();
41 |
42 | ///
43 | /// 提示消息
44 | ///
45 | public string Message
46 | {
47 | set { _tipLabel.Text = value; }
48 | }
49 |
50 | ///
51 | /// 事件
52 | ///
53 | public delegate void Handler(DynInputCtrl sender, DynInputResult result);
54 | public event Handler finish;
55 | public event Handler cancel;
56 |
57 | ///
58 | /// 构造函数
59 | ///
60 | public DynInputCtrl(Presenter presenter)
61 | {
62 | _presenter = presenter;
63 |
64 | _tipLabel = new Label();
65 | _tipLabel.BackColor = Color.FromArgb(153, 153, 153);
66 | _tipLabel.ForeColor = Color.Black;
67 | _tipLabel.TextAlign = ContentAlignment.MiddleLeft;
68 | _tipLabel.Padding = new Padding(3, 3, 3, 3);
69 | _tipLabel.AutoSize = true;
70 | _winControls.Add(_tipLabel);
71 | }
72 |
73 | ///
74 | /// 初始化
75 | ///
76 | protected virtual void Initialize()
77 | {
78 | foreach (Control ctrl in _winControls)
79 | {
80 | _presenter.canvas.AddChild(ctrl);
81 | }
82 | }
83 |
84 | ///
85 | /// 结束
86 | ///
87 | protected virtual void Terminate()
88 | {
89 | foreach (Control ctrl in _winControls)
90 | {
91 | _presenter.canvas.RemoveChild(ctrl);
92 | }
93 | }
94 |
95 | ///
96 | /// 开始
97 | ///
98 | public virtual void Start()
99 | {
100 | this.Initialize();
101 | }
102 |
103 | ///
104 | /// 完成
105 | ///
106 | public virtual void Finish()
107 | {
108 | this.Terminate();
109 |
110 | if (finish != null)
111 | {
112 | finish.Invoke(this, this.finishResult);
113 | }
114 | }
115 |
116 | protected abstract DynInputResult finishResult
117 | {
118 | get;
119 | }
120 |
121 | ///
122 | /// 取消
123 | ///
124 | public virtual void Cancel()
125 | {
126 | this.Terminate();
127 |
128 | if (cancel != null)
129 | {
130 | cancel.Invoke(this, this.cancelResult);
131 | }
132 | }
133 |
134 | protected abstract DynInputResult cancelResult
135 | {
136 | get;
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputCtrl/DynInputDouble.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | internal class DynInputDouble : DynInputTextBoxOne
6 | {
7 | ///
8 | /// 更新值
9 | ///
10 | protected override bool UpdateValue()
11 | {
12 | return double.TryParse(_textBox.Text, out _value);
13 | }
14 |
15 | ///
16 | /// 构造函数
17 | ///
18 | public DynInputDouble(Presenter presenter, double value)
19 | : base(presenter, value.ToString())
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputCtrl/DynInputInteger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | internal class DynInputInteger : DynInputTextBoxOne
6 | {
7 | ///
8 | /// 更新值
9 | ///
10 | protected override bool UpdateValue()
11 | {
12 | return int.TryParse(_textBox.Text, out _value);
13 | }
14 |
15 | ///
16 | /// 构造函数
17 | ///
18 | public DynInputInteger(Presenter presenter, int value)
19 | : base(presenter, value.ToString())
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputCtrl/DynInputString.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | ///
6 | /// 命令输入控件
7 | ///
8 | internal class DynInputString : DynInputTextBoxOne
9 | {
10 | ///
11 | /// 更新值
12 | ///
13 | protected override bool UpdateValue()
14 | {
15 | _value = _textBox.Text;
16 | return true;
17 | }
18 |
19 | ///
20 | /// 构造函数
21 | ///
22 | public DynInputString(Presenter presenter, string value)
23 | : base(presenter, value)
24 | {
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputCtrl/DynInputTextBoxOne.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.Windows.Controls;
7 |
8 | namespace SharpCAD.UI
9 | {
10 | internal abstract class DynInputTextBoxOne : DynInputCtrl
11 | {
12 | protected DynamicInputTextBox _textBox = null;
13 | protected T _value;
14 |
15 | public string text
16 | {
17 | get { return _textBox.Text; }
18 | set { _textBox.Text = value; }
19 | }
20 |
21 | public Size size
22 | {
23 | get { return _textBox.Size; }
24 | set { _textBox.Size = value; }
25 | }
26 |
27 | ///
28 | /// 构造函数
29 | ///
30 | public DynInputTextBoxOne(Presenter presenter, string text)
31 | : base(presenter)
32 | {
33 | _textBox = new DynamicInputTextBox();
34 | _textBox.Size = new Size(60, 30);
35 | _textBox.Text = text;
36 | _textBox.Hide();
37 |
38 | _winControls.Add(_textBox);
39 | _winControls.Add(_tipLabel);
40 |
41 | _textBox.keyEscDown += this.OnEscDown;
42 | _textBox.keySpaceDown += this.OnSpaceDown;
43 | _textBox.keyEnterDown += this.OnEnterDown;
44 | _textBox.keyTabDown += this.OnTabDown;
45 | }
46 |
47 | ///
48 | /// 更新位置
49 | ///
50 | public override void UpdatePosition()
51 | {
52 | _textBox.Location = new Point((int)_position.x + 10, (int)_position.y + 10);
53 | _tipLabel.Location = new Point(_textBox.Location.X, _textBox.Location.Y + _textBox.Size.Height + 10);
54 | }
55 |
56 | ///
57 | /// 更新值
58 | ///
59 | protected abstract bool UpdateValue();
60 |
61 | ///
62 | /// 开始
63 | ///
64 | public override void Start()
65 | {
66 | base.Start();
67 |
68 | _textBox.Show();
69 | _textBox.Focus();
70 | _textBox.Select(_textBox.Text.Length, 0);
71 | }
72 |
73 | ///
74 | /// 完成
75 | ///
76 | public override void Finish()
77 | {
78 | if (!UpdateValue())
79 | {
80 | return;
81 | }
82 |
83 | base.Finish();
84 | }
85 |
86 | ///
87 | /// 完成结果
88 | ///
89 | protected override DynInputResult finishResult
90 | {
91 | get
92 | {
93 | return new DynInputResult(DynInputStatus.OK, _value);
94 | }
95 | }
96 |
97 | ///
98 | /// 取消
99 | ///
100 | public override void Cancel()
101 | {
102 | base.Cancel();
103 | }
104 |
105 | ///
106 | /// 取消结果
107 | ///
108 | protected override DynInputResult cancelResult
109 | {
110 | get
111 | {
112 | return new DynInputResult(DynInputStatus.Cancel, _value);
113 | }
114 | }
115 |
116 | ///
117 | /// ESC 键响应
118 | ///
119 | protected virtual void OnEscDown(object sender)
120 | {
121 | this.Cancel();
122 | }
123 |
124 | ///
125 | /// Space 键响应
126 | ///
127 | protected virtual void OnSpaceDown(object sender)
128 | {
129 | this.Finish();
130 | }
131 |
132 | ///
133 | /// Enter 键响应
134 | ///
135 | protected virtual void OnEnterDown(object sender)
136 | {
137 | this.Finish();
138 | }
139 |
140 | ///
141 | /// Tab 键响应
142 | ///
143 | protected virtual void OnTabDown(object sender)
144 | {
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputResult/DynInputResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | ///
6 | /// 动态输入返回结果
7 | ///
8 | internal abstract class DynInputResult
9 | {
10 | protected DynInputStatus _status = DynInputStatus.OK;
11 | public DynInputStatus status
12 | {
13 | get { return _status; }
14 | }
15 |
16 | public DynInputResult(DynInputStatus status)
17 | {
18 | _status = status;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputResult/DynInputResultT.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | ///
6 | /// 动态输入结果
7 | ///
8 | ///
9 | internal class DynInputResult : DynInputResult
10 | {
11 | ///
12 | /// 值
13 | ///
14 | protected T _value;
15 | public T value
16 | {
17 | get { return _value; }
18 | }
19 |
20 | public DynInputResult(DynInputStatus status, T value)
21 | : base(status)
22 | {
23 | _value = value;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynInputResult/DynInputStatus.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.UI
4 | {
5 | internal enum DynInputStatus
6 | {
7 | OK = 0,
8 | Cancel = 1,
9 | Error = 2,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/DynamicInputer/DynamicInputer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 | using System.Runtime.InteropServices;
6 |
7 | using SharpCAD.ApplicationServices;
8 | using SharpCAD.DatabaseServices;
9 |
10 | namespace SharpCAD.UI
11 | {
12 | internal class DynamicInputer
13 | {
14 | private Presenter _presenter = null;
15 |
16 | ///
17 | /// 是否激活
18 | ///
19 | public bool active
20 | {
21 | get
22 | {
23 | return _currInputCtrl != null;
24 | }
25 | }
26 |
27 | ///
28 | /// 是否独占
29 | ///
30 | public bool exclusive
31 | {
32 | get
33 | {
34 | return _currInputCtrl != null ? _currInputCtrl.exclusive : false;
35 | }
36 | }
37 |
38 | ///
39 | /// 位置
40 | ///
41 | private LitMath.Vector2 _position = new LitMath.Vector2();
42 | public LitMath.Vector2 position
43 | {
44 | get { return _position; }
45 | set
46 | {
47 | _position = value;
48 | if (_currInputCtrl != null)
49 | {
50 | _currInputCtrl.position = _position;
51 | }
52 | }
53 | }
54 |
55 | ///
56 | /// 动态输入控件
57 | ///
58 | private DynInputCtrl _currInputCtrl = null;
59 | private DynInputString _cmdInput = null;
60 | public DynInputString cmdInput
61 | {
62 | get { return _cmdInput; }
63 | }
64 |
65 | ///
66 | /// 构造函数
67 | ///
68 | ///
69 | public DynamicInputer(Presenter presenter)
70 | {
71 | _presenter = presenter;
72 |
73 | _cmdInput = new DynInputString(_presenter, "");
74 | }
75 |
76 | ///
77 | /// 启动命令动态输入
78 | ///
79 | public bool StartCmd(KeyEventArgs e)
80 | {
81 | // 非字符则返回false
82 | if ((uint)e.KeyCode < 65
83 | || (uint)e.KeyCode > 90)
84 | {
85 | return false;
86 | }
87 |
88 | //
89 | _currInputCtrl = _cmdInput;
90 | _cmdInput.position = _position;
91 | _cmdInput.text = KeyDataToString(e.KeyData);
92 | _cmdInput.Start();
93 |
94 | return true;
95 | }
96 |
97 | public bool StartInput(DynInputCtrl inputCtrl)
98 | {
99 | _currInputCtrl = inputCtrl;
100 | _currInputCtrl.position = _position;
101 | _currInputCtrl.Start();
102 |
103 | return true;
104 | }
105 |
106 | public void OnMouseMove(MouseEventArgs e)
107 | {
108 | this.position = new LitMath.Vector2(e.X, e.Y);
109 | }
110 |
111 | ///
112 | /// 键值转换为字符串
113 | ///
114 | #region
115 | [DllImport("user32.dll")]
116 | static extern int MapVirtualKey(uint uCode, uint uMapType);
117 |
118 | public static string KeyDataToString(Keys keydata)
119 | {
120 | int nonVirtualKey = MapVirtualKey((uint)keydata, 2);
121 | char mappedChar = Convert.ToChar(nonVirtualKey);
122 |
123 | return mappedChar.ToString();
124 | }
125 | #endregion
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/GDIResMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Drawing.Drawing2D;
5 |
6 | using SharpCAD.DatabaseServices;
7 |
8 | namespace SharpCAD
9 | {
10 | ///
11 | /// GDI资源管理类
12 | ///
13 | internal class GDIResMgr
14 | {
15 | private Pen _pen = null;
16 | private Pen _entitySelectedPen = null;
17 | private SolidBrush _brush = null;
18 | private HatchBrush _entitySelectedBrush = null;
19 |
20 | ///
21 | /// 选择矩形画笔
22 | ///
23 | private IntPtr _selectWindowPen = IntPtr.Zero;
24 | private IntPtr _selectCrossPen = IntPtr.Zero;
25 |
26 | internal IntPtr selectWindowPen
27 | {
28 | get
29 | {
30 | if (_selectWindowPen == IntPtr.Zero)
31 | {
32 | _selectWindowPen = XorGDI.CreatePen(
33 | XorGDI.PenStyles.PS_SOLID, 1, XorGDI.RGB(0, 0, 255));
34 | }
35 | return _selectWindowPen;
36 | }
37 | }
38 |
39 | internal IntPtr selectCrossPen
40 | {
41 | get
42 | {
43 | if (_selectCrossPen == IntPtr.Zero)
44 | {
45 | _selectCrossPen = XorGDI.CreatePen(
46 | XorGDI.PenStyles.PS_DOT, 1, XorGDI.RGB(0, 255, 0));
47 | }
48 | return _selectCrossPen;
49 | }
50 | }
51 |
52 | ///
53 | /// 单例
54 | ///
55 | private static GDIResMgr _instance = null;
56 | public static GDIResMgr Instance
57 | {
58 | get
59 | {
60 | if (_instance == null)
61 | {
62 | _instance = new GDIResMgr();
63 | }
64 | return _instance;
65 | }
66 | }
67 |
68 | private GDIResMgr()
69 | {
70 | _pen = new Pen(Color.White, 1);
71 | _entitySelectedPen = new Pen(Color.White, 1);
72 | _entitySelectedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
73 | _entitySelectedPen.DashPattern = new float[] { 3, 3 };
74 | _brush = new SolidBrush(Color.White);
75 | _entitySelectedBrush = new HatchBrush(
76 | HatchStyle.DiagonalCross, Color.FromArgb(33, 40, 48), Color.White);
77 | }
78 |
79 | public Pen GetPen(Color color, double width)
80 | {
81 | _pen.Color = color;
82 | _pen.Width = (float)width;
83 | return _pen;
84 | }
85 |
86 | public Pen GetEntitySelectedPen(Entity entity)
87 | {
88 | _entitySelectedPen.Color = entity.colorValue;
89 | return _entitySelectedPen;
90 | }
91 |
92 | public Brush GetBrush(Color color)
93 | {
94 | _brush.Color = color;
95 | return _brush;
96 | }
97 |
98 | public Brush GetEntitySelectedBrush(Entity entity)
99 | {
100 | _entitySelectedBrush = new HatchBrush(HatchStyle.DiagonalCross, Color.FromArgb(33, 40, 48), entity.colorValue);
101 | return _entitySelectedBrush;
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/LocateCross.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 |
5 | namespace SharpCAD.UI
6 | {
7 | internal class LocateCross
8 | {
9 | private Presenter _presenter = null;
10 |
11 | ///
12 | /// 长度
13 | ///
14 | private int _length = 20;
15 | internal int length
16 | {
17 | get { return _length; }
18 | set { _length = value; }
19 | }
20 |
21 | internal LocateCross(Presenter presenter)
22 | {
23 | _presenter = presenter;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/Origin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Windows.Forms;
4 |
5 | namespace SharpCAD
6 | {
7 | internal class Origin
8 | {
9 | private Presenter _presenter = null;
10 | private LitMath.Vector2 _origin = new LitMath.Vector2(0, 0);
11 | private Bitmap _bitmap = null;
12 | private int _xAxisLength = 50;
13 | private int _yAxisLength = 50;
14 | private int _offsetX = 2;
15 | private int _offsetY = 2;
16 |
17 | internal Origin(Presenter presenter)
18 | {
19 | _presenter = presenter;
20 | _bitmap = new Bitmap(_xAxisLength + 22, _yAxisLength + 22);
21 |
22 | Font font = new Font("Arial", 10);
23 | Color xColor = Color.FromArgb(127, 0, 0);
24 | Color yColor = Color.FromArgb(0, 127, 0);
25 |
26 | Graphics graphics = Graphics.FromImage(_bitmap);
27 | //graphics.Clear(Color.FromArgb(33, 40, 48));
28 | graphics.Clear(Color.Transparent);
29 |
30 | // X Axis
31 | int xAxisStartX = _offsetX;
32 | int xAxisStartY = _bitmap.Height - _offsetY;
33 | int xAxisEndX = xAxisStartX + _xAxisLength;
34 | int xAxisEndY = xAxisStartY;
35 | graphics.DrawLine(GDIResMgr.Instance.GetPen(xColor, 0),
36 | xAxisStartX, xAxisStartY, xAxisEndX, xAxisEndY);
37 | graphics.DrawString("X", font, GDIResMgr.Instance.GetBrush(xColor),
38 | xAxisEndX, xAxisEndY - font.Height);
39 |
40 | // Y Axis
41 | int yAxisStartX = xAxisStartX;
42 | int yAxisStartY = xAxisStartY;
43 | int yAxisEndX = yAxisStartX;
44 | int yAxisEndY = yAxisStartY - _yAxisLength;
45 | graphics.DrawLine(GDIResMgr.Instance.GetPen(yColor, 0),
46 | yAxisStartX, yAxisStartY, yAxisEndX, yAxisEndY);
47 | graphics.DrawString("Y", font, GDIResMgr.Instance.GetBrush(yColor),
48 | yAxisEndX, yAxisEndY - font.Height);
49 |
50 | graphics.Dispose();
51 | }
52 |
53 |
54 | internal void OnPaint(Graphics graphics)
55 | {
56 | LitMath.Vector2 originInCanvas = _presenter.ModelToCanvas(_origin);
57 | graphics.DrawImage(_bitmap,
58 | (float)originInCanvas.x - _offsetX, (float)originInCanvas .y - _bitmap.Height + _offsetY,
59 | new RectangleF(0, 0, _bitmap.Width, _bitmap.Height),
60 | GraphicsUnit.Pixel);
61 | }
62 |
63 | //internal void OnPaint(Graphics graphics)
64 | //{
65 | // LitMath.Vector2 originInCanvas = _presenter.ModelToCanvas(new LitMath.Vector2(0, 0));
66 | // graphics.DrawLine(GDIResMgr.Instance.GetPen(Color.FromArgb(127, 0, 0), 0),
67 | // (float)originInCanvas.x, (float)originInCanvas.y, 50 + (float)originInCanvas.x, (float)originInCanvas.y);
68 | // graphics.DrawLine(GDIResMgr.Instance.GetPen(Color.FromArgb(0, 127, 0), 0),
69 | // (float)originInCanvas.x, (float)originInCanvas.y, (float)originInCanvas.x, (float)originInCanvas.y - 50);
70 |
71 | // Font font = new Font("Arial", 10);
72 | // graphics.DrawString("X", font, GDIResMgr.Instance.GetBrush(Color.FromArgb(127, 0, 0)),
73 | // 50 + (float)originInCanvas.x,
74 | // (float)originInCanvas.y - font.Height);
75 | // graphics.DrawString("Y", font, GDIResMgr.Instance.GetBrush(Color.FromArgb(0, 127, 0)),
76 | // (float)originInCanvas.x,
77 | // (float)originInCanvas.y - 50 - font.Height);
78 | //}
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/ArcHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 | using SharpCAD.UI;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class ArcHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | Arc arc = entity as Arc;
14 | if (arc == null)
15 | return false;
16 |
17 | ArcRS arcRS = new ArcRS();
18 | return arcRS.Cross(pkbox.reservedBounding, arc);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/CircleHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 | using SharpCAD.UI;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class CircleHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | Circle circle = entity as Circle;
14 | if (circle == null)
15 | return false;
16 |
17 | return MathUtils.BoundingCross(pkbox.reservedBounding, circle);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/EllipseHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class EllipseHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | Ellipse ellipse = entity as Ellipse;
14 | if (ellipse == null)
15 | return false;
16 |
17 | return MathUtils.BoundingCross(pkbox.reservedBounding, ellipse);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/EntityHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.UI
6 | {
7 | internal abstract class EntityHitter
8 | {
9 | internal abstract bool Hit(PickupBox pkbox, Entity entity);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/LineHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.UI
6 | {
7 | internal class LineHitter : EntityHitter
8 | {
9 | internal override bool Hit(PickupBox pkbox, Entity entity)
10 | {
11 | Line line = entity as Line;
12 | if (line == null)
13 | return false;
14 |
15 | Bounding pkBounding = pkbox.reservedBounding;
16 | return LineHitter.BoundingIntersectWithLine(
17 | pkBounding,
18 | new LitMath.Line2(line.startPoint, line.endPoint));
19 | }
20 |
21 | internal static bool BoundingIntersectWithLine(Bounding bounding, LitMath.Line2 line)
22 | {
23 | Bounding lineBound = new Bounding(line.startPoint, line.endPoint);
24 | if (!bounding.IntersectWith(lineBound))
25 | {
26 | return false;
27 | }
28 |
29 | if (bounding.Contains(line.startPoint)
30 | || bounding.Contains(line.endPoint))
31 | {
32 | return true;
33 | }
34 |
35 | LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
36 | LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
37 | LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
38 | LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);
39 |
40 | double d1 = LitMath.Vector2.Cross(line.startPoint - pkPnt1, line.endPoint - pkPnt1);
41 | double d2 = LitMath.Vector2.Cross(line.startPoint - pkPnt2, line.endPoint - pkPnt2);
42 | double d3 = LitMath.Vector2.Cross(line.startPoint - pkPnt3, line.endPoint - pkPnt3);
43 | double d4 = LitMath.Vector2.Cross(line.startPoint - pkPnt4, line.endPoint - pkPnt4);
44 |
45 | if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
46 | {
47 | return true;
48 | }
49 | else
50 | {
51 | return false;
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/PolylineHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 | using SharpCAD.UI;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class PolylineHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | Polyline polyline = entity as Polyline;
14 | if (polyline == null)
15 | return false;
16 |
17 | Bounding pkBounding = pkbox.reservedBounding;
18 | for (int i = 1; i < polyline.NumberOfVertices; ++i)
19 | {
20 | LitMath.Line2 line = new LitMath.Line2(
21 | polyline.GetPointAt(i - 1),
22 | polyline.GetPointAt(i));
23 |
24 | if (LineHitter.BoundingIntersectWithLine(pkBounding, line))
25 | {
26 | return true;
27 | }
28 | }
29 |
30 | return false;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/RayHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.UI
6 | {
7 | internal class RayHitter : EntityHitter
8 | {
9 | internal override bool Hit(PickupBox pkbox, Entity entity)
10 | {
11 | Ray ray = entity as Ray;
12 | if (ray == null)
13 | return false;
14 |
15 | Bounding bounding = pkbox.reservedBounding;
16 | return BoundingIntersectWithRay(bounding, ray);
17 | }
18 |
19 | internal static bool BoundingIntersectWithRay(Bounding bounding, Ray ray)
20 | {
21 | if (!ray.bounding.IntersectWith(bounding))
22 | {
23 | return false;
24 | }
25 |
26 | LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
27 | LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
28 | LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
29 | LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);
30 |
31 | double d1 = LitMath.Vector2.Cross(pkPnt1 - ray.basePoint, ray.direction);
32 | double d2 = LitMath.Vector2.Cross(pkPnt2 - ray.basePoint, ray.direction);
33 | double d3 = LitMath.Vector2.Cross(pkPnt3 - ray.basePoint, ray.direction);
34 | double d4 = LitMath.Vector2.Cross(pkPnt4 - ray.basePoint, ray.direction);
35 |
36 | if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
37 | {
38 | return true;
39 | }
40 | else
41 | {
42 | return false;
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/TextHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 | using SharpCAD.UI;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class TextHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | Text text = entity as Text;
14 | if (text == null)
15 | return false;
16 |
17 | TextRS textRS = new TextRS();
18 | return textRS.Cross(pkbox.reservedBounding, text);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/XPointHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD.UI
8 | {
9 | internal class XPointHitter : EntityHitter
10 | {
11 | internal override bool Hit(PickupBox pkbox, Entity entity)
12 | {
13 | XPoint xPoint = entity as XPoint;
14 | if (xPoint == null)
15 | return false;
16 |
17 | XPointRS xPointRS = new XPointRS();
18 | return xPointRS.Cross(pkbox.reservedBounding, xPoint);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/PickupBox/XlineHitter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD.UI
6 | {
7 | internal class XlineHitter : EntityHitter
8 | {
9 | internal override bool Hit(PickupBox pkbox, Entity entity)
10 | {
11 | Xline xline = entity as Xline;
12 | if (xline == null)
13 | return false;
14 |
15 | Bounding bounding = pkbox.reservedBounding;
16 | return BoundingIntersectWithXline(bounding, xline);
17 | }
18 |
19 | internal static bool BoundingIntersectWithXline(Bounding bounding, Xline xline)
20 | {
21 | LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
22 | LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
23 | LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
24 | LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);
25 |
26 | double d1 = LitMath.Vector2.Cross(pkPnt1 - xline.basePoint, xline.direction);
27 | double d2 = LitMath.Vector2.Cross(pkPnt2 - xline.basePoint, xline.direction);
28 | double d3 = LitMath.Vector2.Cross(pkPnt3 - xline.basePoint, xline.direction);
29 | double d4 = LitMath.Vector2.Cross(pkPnt4 - xline.basePoint, xline.direction);
30 |
31 | if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
32 | {
33 | return true;
34 | }
35 | else
36 | {
37 | return false;
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/ArcRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class ArcRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Arc arc = entity as Arc;
13 | if (arc == null)
14 | {
15 | return false;
16 | }
17 |
18 | Bounding arcBounding = arc.bounding;
19 | if (selectBound.Contains(arcBounding))
20 | {
21 | return true;
22 | }
23 |
24 | if (!selectBound.IntersectWith(arcBounding))
25 | return false;
26 |
27 | Circle circle = new Circle(arc.center, arc.radius);
28 | LitMath.Vector2 nearestPntOnBound = new LitMath.Vector2(
29 | Math.Max(selectBound.left, Math.Min(circle.center.x, selectBound.right)),
30 | Math.Max(selectBound.bottom, Math.Min(circle.center.y, selectBound.top)));
31 |
32 | if (LitMath.Vector2.Distance(nearestPntOnBound, circle.center) <= circle.radius)
33 | {
34 | double bdLeft = selectBound.left;
35 | double bdRight = selectBound.right;
36 | double bdTop = selectBound.top;
37 | double bdBottom = selectBound.bottom;
38 |
39 | List pnts = new List();
40 | pnts.Add(new LitMath.Vector2(bdLeft, bdTop));
41 | pnts.Add(new LitMath.Vector2(bdLeft, bdBottom));
42 | pnts.Add(new LitMath.Vector2(bdRight, bdTop));
43 | pnts.Add(new LitMath.Vector2(bdRight, bdBottom));
44 | LitMath.Vector2 xp = new LitMath.Vector2(1, 0);
45 | foreach (LitMath.Vector2 pnt in pnts)
46 | {
47 | if (LitMath.Vector2.Distance(pnt, circle.center) >= circle.radius)
48 | {
49 | LitMath.Vector2 v = pnt - circle.center;
50 | double rad = LitMath.Vector2.AngleInRadian(xp, v);
51 | if (LitMath.Vector2.Cross(xp, v) < 0)
52 | rad = Math.PI * 2 - rad;
53 |
54 | if (AngleInRange(rad, arc.startAngle, arc.endAngle))
55 | {
56 | return true;
57 | }
58 | }
59 | }
60 |
61 | return false;
62 | }
63 | else
64 | {
65 | return false;
66 | }
67 | }
68 |
69 | private bool AngleInRange(double angle, double startAngle, double endAngle)
70 | {
71 | if (endAngle >= startAngle)
72 | {
73 | return angle >= startAngle
74 | && angle <= endAngle;
75 | }
76 | else
77 | {
78 | return angle >= startAngle
79 | || angle <= endAngle;
80 | }
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/CircleRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.DatabaseServices;
4 |
5 | namespace SharpCAD
6 | {
7 | internal class CircleRS : EntityRS
8 | {
9 | internal override bool Cross(Bounding selectBound, Entity entity)
10 | {
11 | Circle circle = entity as Circle;
12 | if (circle == null)
13 | {
14 | return false;
15 | }
16 |
17 | return MathUtils.BoundingCross(selectBound, circle);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/EllipseRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD
8 | {
9 | internal class EllipseRS : EntityRS
10 | {
11 | internal override bool Cross(Bounding selectBound, Entity entity)
12 | {
13 | Ellipse ellipse = entity as Ellipse;
14 | if (ellipse == null)
15 | {
16 | return false;
17 | }
18 |
19 | return MathUtils.BoundingCross(selectBound, ellipse);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/EntityRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.ApplicationServices;
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal abstract class EntityRS
9 | {
10 | internal abstract bool Cross(Bounding bounding, Entity entity);
11 | internal virtual bool Window(Bounding bounding, Entity entity)
12 | {
13 | return bounding.Contains(entity.bounding);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/EntityRSMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.ApplicationServices;
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD
8 | {
9 | internal class EntityRSMgr
10 | {
11 | ///
12 | /// Singleton
13 | ///
14 | private static EntityRSMgr _instance = null;
15 | internal static EntityRSMgr Instance
16 | {
17 | get
18 | {
19 | if (_instance == null)
20 | {
21 | _instance = new EntityRSMgr();
22 | }
23 |
24 | return _instance;
25 | }
26 | }
27 |
28 | ///
29 | /// Constructor
30 | ///
31 | private Dictionary _type2EntityRS = new Dictionary();
32 |
33 | private EntityRSMgr()
34 | {
35 | Initialize();
36 | }
37 |
38 | private void Initialize()
39 | {
40 | RegisterEntityRS(typeof(XPoint), new XPointRS());
41 | RegisterEntityRS(typeof(Line), new LineRS());
42 | RegisterEntityRS(typeof(Xline), new XlineRS());
43 | RegisterEntityRS(typeof(Ray), new RayRS());
44 | RegisterEntityRS(typeof(Polyline), new PolylineRS());
45 | RegisterEntityRS(typeof(Circle), new CircleRS());
46 | RegisterEntityRS(typeof(Ellipse), new EllipseRS());
47 | RegisterEntityRS(typeof(Arc), new ArcRS());
48 | RegisterEntityRS(typeof(Text), new TextRS());
49 | }
50 |
51 | private void RegisterEntityRS(Type type, EntityRS entityRS)
52 | {
53 | _type2EntityRS[type] = entityRS;
54 | }
55 |
56 | ///
57 | /// Select
58 | ///
59 | internal bool Cross(Bounding selectBound, Entity entity)
60 | {
61 | if (_type2EntityRS.ContainsKey(entity.GetType()))
62 | {
63 | return _type2EntityRS[entity.GetType()].Cross(selectBound, entity);
64 | }
65 |
66 | return false;
67 | }
68 |
69 | internal bool Window(Bounding selectBound, Entity entity)
70 | {
71 | if (_type2EntityRS.ContainsKey(entity.GetType()))
72 | {
73 | return _type2EntityRS[entity.GetType()].Window(selectBound, entity);
74 | }
75 |
76 | return false;
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/LineRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.ApplicationServices;
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class LineRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Line line = entity as Line;
13 | if (line == null)
14 | {
15 | return false;
16 | }
17 |
18 | Bounding lineBound = line.bounding;
19 | if (selectBound.Contains(lineBound))
20 | {
21 | return true;
22 | }
23 |
24 | LitMath.Rectangle2 selRect = new LitMath.Rectangle2(
25 | new LitMath.Vector2(selectBound.left, selectBound.bottom),
26 | new LitMath.Vector2(selectBound.right, selectBound.top));
27 |
28 | LitMath.Line2 rectLine1 = new LitMath.Line2(selRect.leftBottom, selRect.leftTop);
29 | LitMath.Line2 rectLine2 = new LitMath.Line2(selRect.leftTop, selRect.rightTop);
30 | LitMath.Line2 rectLine3 = new LitMath.Line2(selRect.rightTop, selRect.rightBottom);
31 | LitMath.Line2 rectLine4 = new LitMath.Line2(selRect.rightBottom, selRect.leftBottom);
32 | LitMath.Line2 line2 = new LitMath.Line2(line.startPoint, line.endPoint);
33 |
34 | LitMath.Vector2 intersection = new LitMath.Vector2();
35 | if (LitMath.Line2.Intersect(rectLine1, line2, ref intersection)
36 | || LitMath.Line2.Intersect(rectLine2, line2, ref intersection)
37 | || LitMath.Line2.Intersect(rectLine3, line2, ref intersection)
38 | || LitMath.Line2.Intersect(rectLine4, line2, ref intersection))
39 | {
40 | return true;
41 | }
42 | else
43 | {
44 | return false;
45 | }
46 | }
47 |
48 | //internal override bool Window(Bounding selectBound, Entity entity)
49 | //{
50 | // Line line = entity as Line;
51 | // if (line == null)
52 | // {
53 | // return false;
54 | // }
55 |
56 | // LitMath.Rectangle2 selRect = new LitMath.Rectangle2(
57 | // new LitMath.Vector2(selectBound.left, selectBound.bottom),
58 | // new LitMath.Vector2(selectBound.right, selectBound.top));
59 |
60 | // if (MathUtils.IsPointInRectangle(line.startPoint, selRect)
61 | // && MathUtils.IsPointInRectangle(line.endPoint, selRect))
62 | // {
63 | // return true;
64 | // }
65 | // else
66 | // {
67 | // return false;
68 | // }
69 | //}
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/PolylineRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.ApplicationServices;
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class PolylineRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Polyline polyline = entity as Polyline;
13 | if (polyline == null)
14 | {
15 | return false;
16 | }
17 |
18 | Bounding polylineBound = polyline.bounding;
19 | if (selectBound.Contains(polylineBound))
20 | {
21 | return true;
22 | }
23 |
24 | LitMath.Rectangle2 selRect = new LitMath.Rectangle2(
25 | new LitMath.Vector2(selectBound.left, selectBound.bottom),
26 | new LitMath.Vector2(selectBound.right, selectBound.top));
27 |
28 | LitMath.Line2 rectLine1 = new LitMath.Line2(selRect.leftBottom, selRect.leftTop);
29 | LitMath.Line2 rectLine2 = new LitMath.Line2(selRect.leftTop, selRect.rightTop);
30 | LitMath.Line2 rectLine3 = new LitMath.Line2(selRect.rightTop, selRect.rightBottom);
31 | LitMath.Line2 rectLine4 = new LitMath.Line2(selRect.rightBottom, selRect.leftBottom);
32 |
33 | for (int i = 1; i < polyline.NumberOfVertices; ++i)
34 | {
35 | LitMath.Vector2 spnt = polyline.GetPointAt(i - 1);
36 | LitMath.Vector2 epnt = polyline.GetPointAt(i);
37 | LitMath.Line2 line2 = new LitMath.Line2(spnt, epnt);
38 | LitMath.Vector2 intersection = new LitMath.Vector2();
39 | if (LitMath.Line2.Intersect(rectLine1, line2, ref intersection)
40 | || LitMath.Line2.Intersect(rectLine2, line2, ref intersection)
41 | || LitMath.Line2.Intersect(rectLine3, line2, ref intersection)
42 | || LitMath.Line2.Intersect(rectLine4, line2, ref intersection))
43 | {
44 | return true;
45 | }
46 | }
47 |
48 | return false;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/RayRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.ApplicationServices;
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class RayRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Ray ray = entity as Ray;
13 | if (ray == null)
14 | {
15 | return false;
16 | }
17 |
18 | return SharpCAD.UI.RayHitter.BoundingIntersectWithRay(selectBound, ray);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/TextRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class TextRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Text text = entity as Text;
13 | if (text == null)
14 | {
15 | return false;
16 | }
17 |
18 | Bounding textBound = text.bounding;
19 | if (selectBound.Contains(textBound))
20 | {
21 | return true;
22 | }
23 |
24 | if (textBound.IntersectWith(selectBound))
25 | {
26 | return true;
27 | }
28 | else
29 | {
30 | return false;
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/XPointRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using SharpCAD.DatabaseServices;
6 |
7 | namespace SharpCAD
8 | {
9 | internal class XPointRS : EntityRS
10 | {
11 | internal override bool Cross(Bounding selectBound, Entity entity)
12 | {
13 | XPoint xPoint = entity as XPoint;
14 | if (xPoint == null) return false;
15 |
16 | Bounding xPointBound = xPoint.bounding;
17 | return selectBound.Contains(xPointBound) || xPointBound.IntersectWith(selectBound);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SelectRectangle/XlineRS.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using SharpCAD.ApplicationServices;
4 | using SharpCAD.DatabaseServices;
5 |
6 | namespace SharpCAD
7 | {
8 | internal class XlineRS : EntityRS
9 | {
10 | internal override bool Cross(Bounding selectBound, Entity entity)
11 | {
12 | Xline xline = entity as Xline;
13 | if (xline == null)
14 | {
15 | return false;
16 | }
17 |
18 | return SharpCAD.UI.XlineHitter.BoundingIntersectWithXline(selectBound, xline);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/SharpCAD/Presenter/SnapNodesMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | using SharpCAD.ApplicationServices;
7 | using SharpCAD.DatabaseServices;
8 |
9 | namespace SharpCAD
10 | {
11 | ///
12 | /// 捕捉节点管理器
13 | ///
14 | internal class SnapNodesMgr
15 | {
16 | private Presenter _presenter = null;
17 |
18 | private ObjectSnapPoint _currObjectSnapPoint = null;
19 | internal ObjectSnapPoint currentObjectSnapPoint
20 | {
21 | get { return _currObjectSnapPoint; }
22 | }
23 |
24 | public SnapNodesMgr(Presenter presenter)
25 | {
26 | _presenter = presenter;
27 | }
28 |
29 | public LitMath.Vector2 Snap(double x, double y)
30 | {
31 | return this.Snap(new LitMath.Vector2(x, y));
32 | }
33 |
34 | internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas)
35 | {
36 | LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas);
37 |
38 | foreach (Entity entity in _presenter.currentBlock)
39 | {
40 | List snapPnts = entity.GetSnapPoints();
41 | if (snapPnts == null || snapPnts.Count == 0)
42 | {
43 | continue;
44 | }
45 | foreach (ObjectSnapPoint snapPnt in snapPnts)
46 | {
47 | double dis = (snapPnt.position - posInModel).length;
48 | double disInCanvas = _presenter.ModelToCanvas(dis);
49 | if (disInCanvas <= _threshold)
50 | {
51 | _currObjectSnapPoint = snapPnt;
52 | return snapPnt.position;
53 | }
54 | }
55 | }
56 |
57 | _currObjectSnapPoint = null;
58 | return posInModel;
59 | }
60 |
61 | public void Clear()
62 | {
63 | _currObjectSnapPoint = null;
64 | }
65 |
66 | private double _threshold = 8;
67 | public void OnPaint(IGraphicsDraw canvasDraw)
68 | {
69 | if (_currObjectSnapPoint != null)
70 | {
71 | CanvasDraw gd = canvasDraw as CanvasDraw;
72 | Pen pen = GDIResMgr.Instance.GetPen(Color.Yellow, 2);
73 | gd.pen = pen;
74 | LitMath.Vector2 posInCanvas = _presenter.ModelToCanvas(_currObjectSnapPoint.position);
75 |
76 | switch (_currObjectSnapPoint.type)
77 | {
78 | case ObjectSnapMode.End:
79 | {
80 | gd.DrawRectangle(new LitMath.Vector2(posInCanvas.x - _threshold, posInCanvas.y - _threshold),
81 | _threshold * 2, _threshold * 2);
82 | }
83 | break;
84 |
85 | case ObjectSnapMode.Mid:
86 | {
87 | LitMath.Vector2 offset = new LitMath.Vector2(0, -_threshold * 1.2);
88 | LitMath.Vector2 point1 = posInCanvas + offset;
89 | offset = LitMath.Vector2.Rotate(offset, 120);
90 | LitMath.Vector2 point2 = posInCanvas + offset;
91 | offset = LitMath.Vector2.Rotate(offset, 120);
92 | LitMath.Vector2 point3 = posInCanvas + offset;
93 |
94 | gd.DrawLine(point1, point2);
95 | gd.DrawLine(point2, point3);
96 | gd.DrawLine(point3, point1);
97 | }
98 | break;
99 |
100 | case ObjectSnapMode.Center:
101 | {
102 | gd.DrawCircle(posInCanvas, _threshold);
103 | }
104 | break;
105 |
106 | default:
107 | {
108 | gd.DrawRectangle(new LitMath.Vector2(posInCanvas.x - _threshold, posInCanvas.y - _threshold),
109 | _threshold * 2, _threshold * 2);
110 | }
111 | break;
112 | }
113 | }
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/SharpCAD/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Forms;
4 |
5 | namespace SharpCAD.ApplicationServices
6 | {
7 | internal static class Program
8 | {
9 | ///
10 | /// 应用程序的主入口点。
11 | ///
12 | [STAThread]
13 | static void Main()
14 | {
15 | Application.EnableVisualStyles();
16 | Application.SetCompatibleTextRenderingDefault(false);
17 | Application.Run(Windows.MainWin.Instance);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SharpCAD/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("SharpCAD")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SharpCAD")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("4b83ef4c-ec9b-475b-b486-bc3e9111c4c3")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 内部版本号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/SharpCAD/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SharpCAD.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpCAD.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/SharpCAD/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SharpCAD.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/SharpCAD/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_arc_cse.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_arc_cse.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_circle_cr.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_circle_cr.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_ellipse_cenax.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_ellipse_cenax.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_line.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_line.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_point.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_point.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_polygon.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_polygon.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_polyline.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_polyline.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_ray.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_ray.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_rectangle.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_rectangle.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Resources/draw_xline.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/Resources/draw_xline.bmp
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/Canvas.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SharpCAD.Windows
2 | {
3 | partial class Canvas
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region 组件设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // SharpCadCanvas
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.BackColor = System.Drawing.Color.Black;
38 | this.Name = "ShapCadCanvas";
39 | this.Size = new System.Drawing.Size(464, 150);
40 | this.ResumeLayout(false);
41 |
42 | }
43 |
44 | #endregion
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/Canvas.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Data;
6 | using System.Text;
7 | using System.Windows.Forms;
8 |
9 | namespace SharpCAD.Windows
10 | {
11 | internal partial class Canvas : UserControl, ICanvas, SharpCAD.DatabaseServices.IDatabaseObserver
12 | {
13 | private IPresenter _presenter = null;
14 |
15 | public Canvas()
16 | {
17 | InitializeComponent();
18 |
19 | this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
20 | this.SetStyle(ControlStyles.UserPaint, true);
21 | this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
22 | }
23 |
24 | // 画布宽
25 | public double width
26 | {
27 | get { return this.ClientRectangle.Width; }
28 | }
29 | // 画布高
30 | public double height
31 | {
32 | get { return this.ClientRectangle.Height; }
33 | }
34 |
35 | public void AddChild(object child)
36 | {
37 | this.Controls.Add((Control)child);
38 | }
39 |
40 | public void RemoveChild(object child)
41 | {
42 | this.Controls.Remove((Control)child);
43 | }
44 |
45 | ///
46 | /// 获取鼠标位置
47 | ///
48 | public LitMath.Vector2 GetMousePosition()
49 | {
50 | Point point = this.PointToClient(Control.MousePosition);
51 | return new LitMath.Vector2(point.X, point.Y);
52 | }
53 |
54 | ///
55 | /// 设置鼠标位置
56 | ///
57 | public void SetMousePosition(LitMath.Vector2 postion)
58 | {
59 | Cursor.Position = this.PointToScreen(new Point((int)postion.x, (int)postion.y));
60 | }
61 |
62 | public void Repaint()
63 | {
64 | Invalidate();
65 | }
66 |
67 | public void Repaint(double x, double y, double width, double height)
68 | {
69 | Invalidate(new Rectangle((int)x, (int)y, (int)width, (int)height));
70 | }
71 |
72 | public void SetPresenter(IPresenter presenter)
73 | {
74 | _presenter = presenter;
75 | }
76 |
77 | protected override void OnPaint(PaintEventArgs e)
78 | {
79 | _presenter.OnPaintCanvas(e);
80 | }
81 |
82 | protected override void OnResize(EventArgs e)
83 | {
84 | base.OnResize(e);
85 | if (_presenter != null)
86 | {
87 | _presenter.OnResize(e);
88 | }
89 | }
90 |
91 | protected override void OnMouseDown(MouseEventArgs e)
92 | {
93 | base.OnMouseDown(e);
94 | _presenter.OnMouseDown(e);
95 | }
96 |
97 | protected override void OnMouseUp(MouseEventArgs e)
98 | {
99 | base.OnMouseUp(e);
100 | _presenter.OnMouseUp(e);
101 | }
102 |
103 | protected override void OnMouseMove(MouseEventArgs e)
104 | {
105 | base.OnMouseMove(e);
106 | _presenter.OnMouseMove(e);
107 | }
108 |
109 | protected override void OnMouseDoubleClick(MouseEventArgs e)
110 | {
111 | base.OnMouseDoubleClick(e);
112 | _presenter.OnMouseDoubleClick(e);
113 | }
114 |
115 | protected override void OnMouseWheel(MouseEventArgs e)
116 | {
117 | base.OnMouseWheel(e);
118 | _presenter.OnMouseWheel(e);
119 | }
120 |
121 | protected override void OnKeyDown(KeyEventArgs e)
122 | {
123 | base.OnKeyDown(e);
124 | _presenter.OnKeyDown(e);
125 | }
126 |
127 | protected override void OnKeyUp(KeyEventArgs e)
128 | {
129 | base.OnKeyUp(e);
130 | _presenter.OnKeyUp(e);
131 | }
132 |
133 | protected override void OnMouseEnter(EventArgs e)
134 | {
135 | base.OnMouseEnter(e);
136 |
137 | Cursor.Hide();
138 | }
139 |
140 | protected override void OnMouseLeave(EventArgs e)
141 | {
142 | base.OnMouseLeave(e);
143 |
144 | Cursor.Show();
145 | }
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/DocumentForm.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SharpCAD.Windows
2 | {
3 | partial class DocumentForm
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // DocumentForm
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.ClientSize = new System.Drawing.Size(617, 301);
38 | this.Name = "DocumentForm";
39 | this.Text = "DocumentForm";
40 | this.ResumeLayout(false);
41 |
42 | }
43 |
44 | #endregion
45 | }
46 | }
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/DynamicInputTextBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Windows.Forms;
5 |
6 | namespace SharpCAD.Windows.Controls
7 | {
8 | internal class DynamicInputTextBox : TextBox
9 | {
10 | public delegate void MessageHandler(object sender);
11 | public event MessageHandler keyEscDown;
12 | public event MessageHandler keySpaceDown;
13 | public event MessageHandler keyEnterDown;
14 | public event MessageHandler keyTabDown;
15 |
16 | protected override void OnKeyDown(KeyEventArgs e)
17 | {
18 | switch (e.KeyCode)
19 | {
20 | case Keys.Escape:
21 | if (keyEscDown != null)
22 | {
23 | keyEscDown.Invoke(this);
24 | }
25 | break;
26 |
27 | case Keys.Space:
28 | if (keySpaceDown != null)
29 | {
30 | keySpaceDown.Invoke(this);
31 | }
32 | break;
33 |
34 | case Keys.Enter:
35 | if (keyEnterDown != null)
36 | {
37 | keyEnterDown.Invoke(this);
38 | }
39 | break;
40 |
41 | case Keys.Tab:
42 | if (keyTabDown != null)
43 | {
44 | keyTabDown.Invoke(this);
45 | }
46 | break;
47 |
48 | default:
49 | base.OnKeyDown(e);
50 | break;
51 | }
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/MainWin.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace SharpCAD.Windows
2 | {
3 | partial class MainWin
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // MainWin
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.ClientSize = new System.Drawing.Size(1064, 530);
38 | this.IsMdiContainer = true;
39 | this.Name = "MainWin";
40 | this.Text = "SharpCAD";
41 | this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
42 | this.ResumeLayout(false);
43 |
44 | }
45 |
46 | #endregion
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/src/SharpCAD/Windows/MenuNames.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD.Windows
6 | {
7 | class MenuNames
8 | {
9 | const string MenuFile = "File";
10 | const string MenuFileNew = "New";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/SharpCAD/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/SharpCAD/res/common_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/common_plus.png
--------------------------------------------------------------------------------
/src/SharpCAD/res/common_subtract.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/common_subtract.png
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_arc_3pnts.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_arc_3pnts.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_arc_cse.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_arc_cse.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_circle_cr.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_circle_cr.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_line.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_line.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_polygon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_polygon.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_polyline.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_polyline.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_ray.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_ray.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_rectangle.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_rectangle.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/draw/draw_xline.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/draw/draw_xline.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/edit/edit_redo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/edit/edit_redo.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/edit/edit_undo.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/edit/edit_undo.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/file/file_new.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/file/file_new.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/file/file_open.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/file/file_open.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/file/file_save.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/file/file_save.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/file/file_saveas.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/file/file_saveas.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/format_layer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/format_layer.png
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_array.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_array.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_copy.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_copy.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_erase.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_erase.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_extemd.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_extemd.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_mirror.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_mirror.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_move.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_move.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_offset.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_offset.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_rotate.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_rotate.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_scale.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_scale.ico
--------------------------------------------------------------------------------
/src/SharpCAD/res/modify/modify_trim.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zhudaijie/SharpCAD/a5e443659b314101386f5f2d15d0b5cda4bd6284/src/SharpCAD/res/modify/modify_trim.ico
--------------------------------------------------------------------------------
/src/lcdb/Colors/ColorMethod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.Colors
4 | {
5 | public enum ColorMethod
6 | {
7 | None = 0,
8 | ByColor = 1,
9 | ByLayer = 2,
10 | ByBlock = 3,
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/lcdb/DBObject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Xml;
5 |
6 | namespace SharpCAD.DatabaseServices
7 | {
8 | public abstract class DBObject : ICloneable
9 | {
10 | ///
11 | /// 类名
12 | ///
13 | public virtual string className
14 | {
15 | get { return "DBObject"; }
16 | }
17 |
18 | ///
19 | /// ID
20 | ///
21 | protected ObjectId _id = ObjectId.Null;
22 | public ObjectId id
23 | {
24 | get { return _id; }
25 | }
26 |
27 | internal void SetId(ObjectId newId)
28 | {
29 | _id = newId;
30 | }
31 |
32 | ///
33 | /// 数据库
34 | ///
35 | public virtual Database database
36 | {
37 | get
38 | {
39 | if (dbtable != null)
40 | {
41 | return dbtable.database;
42 | }
43 |
44 | return null;
45 | }
46 | }
47 |
48 | ///
49 | /// 数据表
50 | ///
51 | public virtual DBTable dbtable
52 | {
53 | get
54 | {
55 | if (_parent == null)
56 | return null;
57 |
58 | DBObject parentObj = _parent;
59 | while (parentObj != null)
60 | {
61 | if (parentObj is DBTableRecord)
62 | {
63 | DBTableRecord tblRec = parentObj as DBTableRecord;
64 | return tblRec.dbtable;
65 | }
66 |
67 | parentObj = parentObj.parent;
68 | }
69 |
70 | return null;
71 | }
72 | }
73 |
74 | ///
75 | /// 父物体
76 | ///
77 | protected DBObject _parent = null;
78 | public DBObject parent
79 | {
80 | get { return _parent; }
81 | }
82 |
83 | public ObjectId parentId
84 | {
85 | get
86 | {
87 | if (_parent == null)
88 | return ObjectId.Null;
89 | return _parent.id;
90 | }
91 | }
92 |
93 | internal void SetParent(DBObject parent)
94 | {
95 | _parent = parent;
96 | }
97 |
98 | ///
99 | /// 构造函数
100 | ///
101 | public DBObject()
102 | {
103 | }
104 |
105 | ///
106 | /// 克隆函数
107 | ///
108 | public virtual object Clone()
109 | {
110 | DBObject dbobj = this.CreateInstance();
111 | dbobj._id = ObjectId.Null;
112 | dbobj._parent = null;
113 | return dbobj;
114 | }
115 |
116 | ///
117 | /// 创建实例
118 | ///
119 | protected abstract DBObject CreateInstance();
120 |
121 | ///
122 | /// 移除
123 | ///
124 | public void Erase()
125 | {
126 | Database db = this.database;
127 | if (db != null)
128 | {
129 | db.UnmapObject(this);
130 | _Erase();
131 | this._id = ObjectId.Null;
132 | }
133 | }
134 |
135 | protected virtual void _Erase()
136 | {
137 | }
138 |
139 | ///
140 | /// 写XML
141 | ///
142 | public virtual void XmlOut(Filer.XmlFiler filer)
143 | {
144 | filer.Write("id", _id);
145 | }
146 |
147 | ///
148 | /// 读XML
149 | ///
150 | public virtual void XmlIn(Filer.XmlFiler filer)
151 | {
152 | filer.Read("id", out _id);
153 | }
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/src/lcdb/Entity/BlockReference.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | ///
6 | /// 块参照
7 | ///
8 | public class BlockReference : Entity
9 | {
10 | ///
11 | /// 类名
12 | ///
13 | public override string className
14 | {
15 | get { return "BlockReference"; }
16 | }
17 |
18 | ///
19 | /// 外围边框
20 | ///
21 | public override Bounding bounding
22 | {
23 | get
24 | {
25 | return new Bounding();
26 | }
27 | }
28 |
29 | ///
30 | /// 克隆函数
31 | ///
32 | public override object Clone()
33 | {
34 | BlockReference blkRef = base.Clone() as BlockReference;
35 | return blkRef;
36 | }
37 |
38 | protected override DBObject CreateInstance()
39 | {
40 | return new BlockReference();
41 | }
42 |
43 | ///
44 | /// 平移
45 | ///
46 | public override void Translate(LitMath.Vector2 translation)
47 | {
48 | }
49 |
50 | ///
51 | /// Transform
52 | ///
53 | public override void TransformBy(LitMath.Matrix3 transform)
54 | {
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/lcdb/Entity/Line.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | ///
7 | /// 线段
8 | ///
9 | public class Line : Entity
10 | {
11 | ///
12 | /// 类名
13 | ///
14 | public override string className
15 | {
16 | get { return "Line"; }
17 | }
18 |
19 | ///
20 | /// 起点
21 | ///
22 | private LitMath.Vector2 _startPoint = new LitMath.Vector2();
23 | public LitMath.Vector2 startPoint
24 | {
25 | get { return _startPoint; }
26 | set { _startPoint = value; }
27 | }
28 |
29 | ///
30 | /// 终点
31 | ///
32 | private LitMath.Vector2 _endPoint = new LitMath.Vector2();
33 | public LitMath.Vector2 endPoint
34 | {
35 | get { return _endPoint; }
36 | set { _endPoint = value; }
37 | }
38 |
39 | ///
40 | /// 外围边框
41 | ///
42 | public override Bounding bounding
43 | {
44 | get
45 | {
46 | return new Bounding(_startPoint, _endPoint);
47 | }
48 | }
49 |
50 | ///
51 | /// 构造函数
52 | ///
53 | public Line()
54 | {
55 | }
56 |
57 | public Line(LitMath.Vector2 startPnt, LitMath.Vector2 endPnt)
58 | {
59 | _startPoint = startPnt;
60 | _endPoint = endPnt;
61 | }
62 |
63 | ///
64 | /// 绘制函数
65 | ///
66 | public override void Draw(IGraphicsDraw gd)
67 | {
68 | gd.DrawLine(_startPoint, _endPoint);
69 | }
70 |
71 | ///
72 | /// 克隆函数
73 | ///
74 | public override object Clone()
75 | {
76 | Line line = base.Clone() as Line;
77 | line._startPoint = _startPoint;
78 | line._endPoint = _endPoint;
79 | return line;
80 | }
81 |
82 | protected override DBObject CreateInstance()
83 | {
84 | return new Line();
85 | }
86 |
87 | ///
88 | /// 平移
89 | ///
90 | public override void Translate(LitMath.Vector2 translation)
91 | {
92 | _startPoint += translation;
93 | _endPoint += translation;
94 | }
95 |
96 | ///
97 | /// Transform
98 | ///
99 | public override void TransformBy(LitMath.Matrix3 transform)
100 | {
101 | _startPoint = transform * _startPoint;
102 | _endPoint = transform * _endPoint;
103 | }
104 |
105 | ///
106 | /// 对象捕捉点
107 | ///
108 | public override List GetSnapPoints()
109 | {
110 | List snapPnts = new List();
111 | snapPnts.Add(new ObjectSnapPoint(ObjectSnapMode.End, _startPoint));
112 | snapPnts.Add(new ObjectSnapPoint(ObjectSnapMode.End, _endPoint));
113 | snapPnts.Add(new ObjectSnapPoint(ObjectSnapMode.Mid, (_startPoint + _endPoint) / 2));
114 |
115 | return snapPnts;
116 | }
117 |
118 | ///
119 | /// 获取夹点
120 | ///
121 | public override List GetGripPoints()
122 | {
123 | List gripPnts = new List();
124 | gripPnts.Add(new GripPoint(GripPointType.End, _startPoint));
125 | gripPnts.Add(new GripPoint(GripPointType.End, _endPoint));
126 |
127 | return gripPnts;
128 | }
129 |
130 | ///
131 | /// 设置夹点
132 | ///
133 | public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
134 | {
135 | if (index == 0)
136 | {
137 | _startPoint = newPosition;
138 | }
139 | else if (index == 1)
140 | {
141 | _endPoint = newPosition;
142 | }
143 | }
144 |
145 | ///
146 | /// 写XML
147 | ///
148 | public override void XmlOut(Filer.XmlFiler filer)
149 | {
150 | base.XmlOut(filer);
151 |
152 | filer.Write("startPoint", _startPoint);
153 | filer.Write("endPoint", _endPoint);
154 | }
155 |
156 | ///
157 | /// 读XML
158 | ///
159 | public override void XmlIn(Filer.XmlFiler filer)
160 | {
161 | base.XmlIn(filer);
162 |
163 | filer.Read("startPoint", out _startPoint);
164 | filer.Read("endPoint", out _endPoint);
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/src/lcdb/Entity/TextAlignment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | public enum TextAlignment
6 | {
7 | LeftBottom = 0,
8 | LeftMiddle = 1,
9 | LeftTop = 2,
10 | CenterBottom = 3,
11 | CenterMiddle = 4,
12 | CenterTop = 5,
13 | RightBottom = 6,
14 | RightMiddle = 7,
15 | RightTop = 8,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/lcdb/Entity/XPoint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD.DatabaseServices
6 | {
7 | ///
8 | /// 点
9 | ///
10 | public class XPoint : Entity
11 | {
12 | ///
13 | /// 类名
14 | ///
15 | public override string className
16 | {
17 | get { return "XPoint"; }
18 | }
19 |
20 | ///
21 | /// 终点
22 | ///
23 | private LitMath.Vector2 _endPoint = new LitMath.Vector2();
24 | public LitMath.Vector2 endPoint
25 | {
26 | get { return _endPoint; }
27 | set { _endPoint = value; }
28 | }
29 |
30 | ///
31 | /// 外围边框
32 | ///
33 | public override Bounding bounding
34 | {
35 | get
36 | {
37 | return new Bounding(_endPoint, 0, 0);
38 | }
39 | }
40 |
41 | ///
42 | /// 构造函数
43 | ///
44 | public XPoint()
45 | {
46 | }
47 |
48 | public XPoint(LitMath.Vector2 endPnt)
49 | {
50 | _endPoint = endPnt;
51 | }
52 |
53 | ///
54 | /// 绘制函数
55 | ///
56 | public override void Draw(IGraphicsDraw gd)
57 | {
58 | gd.DrawPoint(_endPoint);
59 | }
60 |
61 | ///
62 | /// 克隆函数
63 | ///
64 | public override object Clone()
65 | {
66 | XPoint xPoint = base.Clone() as XPoint;
67 | xPoint._endPoint = _endPoint;
68 | return xPoint;
69 | }
70 |
71 | protected override DBObject CreateInstance()
72 | {
73 | return new XPoint();
74 | }
75 |
76 | public override void Translate(LitMath.Vector2 translation)
77 | {
78 | _endPoint += translation;
79 | }
80 |
81 | public override void TransformBy(LitMath.Matrix3 transform)
82 | {
83 | _endPoint = transform * _endPoint;
84 | }
85 |
86 | ///
87 | /// 对象捕捉点
88 | ///
89 | public override List GetSnapPoints()
90 | {
91 | List snapPnts = new List();
92 | snapPnts.Add(new ObjectSnapPoint(ObjectSnapMode.End, _endPoint));
93 |
94 | return snapPnts;
95 | }
96 |
97 | ///
98 | /// 获取夹点
99 | ///
100 | public override List GetGripPoints()
101 | {
102 | List gripPnts = new List();
103 | gripPnts.Add(new GripPoint(GripPointType.End, _endPoint));
104 |
105 | return gripPnts;
106 | }
107 |
108 | ///
109 | /// 设置夹点
110 | ///
111 | public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
112 | {
113 | if (index == 0)
114 | {
115 | _endPoint = newPosition;
116 | }
117 | }
118 |
119 | ///
120 | /// 写XML
121 | ///
122 | public override void XmlOut(Filer.XmlFiler filer)
123 | {
124 | base.XmlOut(filer);
125 |
126 | filer.Write("endPoint", _endPoint);
127 | }
128 |
129 | ///
130 | /// 读XML
131 | ///
132 | public override void XmlIn(Filer.XmlFiler filer)
133 | {
134 | base.XmlIn(filer);
135 |
136 | filer.Read("endPoint", out _endPoint);
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/lcdb/Entity/Xline.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | ///
7 | /// 构造线
8 | ///
9 | public class Xline : Entity
10 | {
11 | ///
12 | /// 类名
13 | ///
14 | public override string className
15 | {
16 | get { return "Xline"; }
17 | }
18 |
19 | ///
20 | /// 基点
21 | ///
22 | private LitMath.Vector2 _basePoint = new LitMath.Vector2(0, 0);
23 | public LitMath.Vector2 basePoint
24 | {
25 | get { return _basePoint; }
26 | set { _basePoint = value; }
27 | }
28 |
29 | ///
30 | /// 方向
31 | ///
32 | private LitMath.Vector2 _direction = new LitMath.Vector2(1, 0);
33 | public LitMath.Vector2 direction
34 | {
35 | get { return _direction; }
36 | set { _direction = value.normalized; }
37 | }
38 |
39 | ///
40 | /// 外围边框
41 | ///
42 | public override Bounding bounding
43 | {
44 | get
45 | {
46 | return new Bounding(
47 | new LitMath.Vector2(double.MinValue, double.MinValue),
48 | new LitMath.Vector2(double.MaxValue, double.MaxValue));
49 | }
50 | }
51 |
52 | ///
53 | /// 构造函数
54 | ///
55 | public Xline()
56 | {
57 | }
58 |
59 | public Xline(LitMath.Vector2 basePoint, LitMath.Vector2 direction)
60 | {
61 | _basePoint = basePoint;
62 | _direction = direction;
63 | }
64 |
65 | ///
66 | /// 绘制函数
67 | ///
68 | public override void Draw(IGraphicsDraw gd)
69 | {
70 | gd.DrawXLine(_basePoint, _direction);
71 | }
72 |
73 | ///
74 | /// 克隆函数
75 | ///
76 | public override object Clone()
77 | {
78 | Xline xline = base.Clone() as Xline;
79 | xline._basePoint = _basePoint;
80 | xline._direction = _direction;
81 | return xline;
82 | }
83 |
84 | protected override DBObject CreateInstance()
85 | {
86 | return new Xline();
87 | }
88 |
89 | ///
90 | /// 平移
91 | ///
92 | public override void Translate(LitMath.Vector2 translation)
93 | {
94 | _basePoint += translation;
95 | }
96 |
97 | ///
98 | /// Transform
99 | ///
100 | public override void TransformBy(LitMath.Matrix3 transform)
101 | {
102 | LitMath.Vector2 refPnt = _basePoint + _direction;
103 | _basePoint = transform * _basePoint;
104 | refPnt = transform * refPnt;
105 | _direction = (refPnt - _basePoint).normalized;
106 | }
107 |
108 | ///
109 | /// 对象捕捉点
110 | ///
111 | public override List GetSnapPoints()
112 | {
113 | return null;
114 | }
115 |
116 | ///
117 | /// 获取夹点
118 | ///
119 | public override List GetGripPoints()
120 | {
121 | List gripPnts = new List();
122 | gripPnts.Add(new GripPoint(GripPointType.End, _basePoint));
123 | gripPnts.Add(new GripPoint(GripPointType.End, _basePoint + 10 * _direction));
124 | gripPnts.Add(new GripPoint(GripPointType.End, _basePoint - 10 * _direction));
125 |
126 | return gripPnts;
127 | }
128 |
129 | ///
130 | /// 设置夹点
131 | ///
132 | public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
133 | {
134 | if (index == 0)
135 | {
136 | _basePoint = newPosition;
137 | }
138 | else if (index == 1 || index == 2)
139 | {
140 | LitMath.Vector2 dir = (newPosition - _basePoint).normalized;
141 | if (!dir.Equals(new LitMath.Vector2(0, 0)))
142 | {
143 | _direction = dir;
144 | }
145 | }
146 | }
147 |
148 | ///
149 | /// 写XML
150 | ///
151 | public override void XmlOut(Filer.XmlFiler filer)
152 | {
153 | base.XmlOut(filer);
154 |
155 | filer.Write("basePoint", _basePoint);
156 | filer.Write("direction", _direction);
157 | }
158 |
159 | ///
160 | /// 读XML
161 | ///
162 | public override void XmlIn(Filer.XmlFiler filer)
163 | {
164 | base.XmlIn(filer);
165 |
166 | filer.Read("basePoint", out _basePoint);
167 | filer.Read("direction", out _direction);
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/src/lcdb/Filer/XmlFiler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml;
4 |
5 | namespace SharpCAD.DatabaseServices.Filer
6 | {
7 | ///
8 | /// SharpCAD XML 文件读写接口类
9 | ///
10 | public abstract class XmlFiler
11 | {
12 | ///
13 | /// 写文件
14 | ///
15 | /// 键名称
16 | /// 键值
17 | ///
18 | /// 成功则返回true
19 | /// 失败则返回false
20 | ///
21 | public abstract bool Write(string name, string value);
22 | public abstract bool Write(string name, bool value);
23 | public abstract bool Write(string name, byte value);
24 | public abstract bool Write(string name, uint value);
25 | public abstract bool Write(string name, int value);
26 | public abstract bool Write(string name, double value);
27 | public abstract bool Write(string name, LitMath.Vector2 value);
28 | public abstract bool Write(string name, SharpCAD.Colors.Color color);
29 | public abstract bool Write(string name, ObjectId value);
30 | public abstract bool Write(string name, SharpCAD.DatabaseServices.LineWeight value);
31 | public abstract bool Write(string name, SharpCAD.DatabaseServices.LineType value);
32 |
33 | ///
34 | /// 读文件
35 | ///
36 | /// 键名称
37 | /// 读取的键值
38 | ///
39 | /// 成功则返回true
40 | /// 失败则返回false
41 | ///
42 | public abstract bool Read(string name, out string value);
43 | public abstract bool Read(string name, out bool value);
44 | public abstract bool Read(string name, out byte value);
45 | public abstract bool Read(string name, out uint value);
46 | public abstract bool Read(string name, out int value);
47 | public abstract bool Read(string name, out double value);
48 | public abstract bool Read(string name, out LitMath.Vector2 value);
49 | public abstract bool Read(string name, out SharpCAD.Colors.Color color);
50 | public abstract bool Read(string name, out ObjectId value);
51 | public abstract bool Read(string name, out SharpCAD.DatabaseServices.LineWeight value);
52 | public abstract bool Read(string name, out SharpCAD.DatabaseServices.LineType value);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/lcdb/GripPoint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | ///
6 | /// 夹点
7 | ///
8 | public class GripPoint
9 | {
10 | ///
11 | /// 夹点类型
12 | ///
13 | public GripPointType type
14 | {
15 | get { return _type; }
16 | set { _type = value; }
17 | }
18 | private GripPointType _type = GripPointType.Undefined;
19 |
20 | ///
21 | /// 位置
22 | ///
23 | public LitMath.Vector2 position
24 | {
25 | get { return _position; }
26 | set { _position = value; }
27 | }
28 | private LitMath.Vector2 _position = new LitMath.Vector2(0, 0);
29 |
30 | ///
31 | /// 扩展数据1
32 | ///
33 | public object xData1
34 | {
35 | get { return _xdata1; }
36 | set { _xdata1 = value; }
37 | }
38 | private object _xdata1 = null;
39 |
40 | ///
41 | /// 扩展数据2
42 | ///
43 | public object xData2
44 | {
45 | get { return _xdata2; }
46 | set { _xdata2 = value; }
47 | }
48 | private object _xdata2 = null;
49 |
50 | ///
51 | /// 构造函数
52 | ///
53 | public GripPoint(GripPointType type, LitMath.Vector2 position)
54 | {
55 | _type = type;
56 | _position = position;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/lcdb/GripPointType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | ///
6 | /// 夹点类型
7 | ///
8 | public enum GripPointType
9 | {
10 | // 未定义
11 | Undefined = 0,
12 | // 端点
13 | End = 1,
14 | // 中点
15 | Mid = 2,
16 | // 中心点
17 | Center = 3,
18 | // 节点
19 | Node = 4,
20 | // 象限点
21 | Quad = 5,
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/lcdb/IDatabaseObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | public interface IDatabaseObserver
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/lcdb/LineType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD.DatabaseServices
6 | {
7 | public enum LineType
8 | {
9 | ByLineTypeDefault = -3,
10 | ByBlock = -2,
11 | ByLayer = -1,
12 |
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/lcdb/LineWeight.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | public enum LineWeight
6 | {
7 | ByLineWeightDefault = -3,
8 | ByBlock = -2,
9 | ByLayer = -1,
10 | LineWeight000 = 0,
11 | LineWeight005 = 5,
12 | LineWeight009 = 9,
13 | LineWeight013 = 13,
14 | LineWeight015 = 15,
15 | LineWeight018 = 18,
16 | LineWeight020 = 20,
17 | LineWeight025 = 25,
18 | LineWeight030 = 30,
19 | LineWeight035 = 35,
20 | LineWeight040 = 40,
21 | LineWeight050 = 50,
22 | LineWeight053 = 53,
23 | LineWeight060 = 60,
24 | LineWeight070 = 70,
25 | LineWeight080 = 80,
26 | LineWeight090 = 90,
27 | LineWeight100 = 100,
28 | LineWeight106 = 106,
29 | LineWeight120 = 120,
30 | LineWeight140 = 140,
31 | LineWeight158 = 158,
32 | LineWeight200 = 200,
33 | LineWeight211 = 211,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/lcdb/MathUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | internal class MathUtils
6 | {
7 | internal static double NormalizeRadianAngle(double angleInRadian)
8 | {
9 | double value = angleInRadian % (2 * Math.PI);
10 | if (value < 0)
11 | value += 2 * Math.PI;
12 | return value;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/lcdb/ObjectId.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | public struct ObjectId : IComparable, IEquatable
7 | {
8 | private uint _id;
9 | public uint id
10 | {
11 | get { return _id; }
12 | }
13 |
14 | internal ObjectId(uint id = 0)
15 | {
16 | _id = id;
17 | }
18 |
19 | public static ObjectId Null
20 | {
21 | get
22 | {
23 | return new ObjectId(0);
24 | }
25 | }
26 |
27 | public bool isNull
28 | {
29 | get { return _id == 0; }
30 | }
31 |
32 | public override string ToString()
33 | {
34 | return _id.ToString();
35 | }
36 |
37 | internal static bool TryParse(string s, out ObjectId result)
38 | {
39 | uint uid = 0;
40 | if (uint.TryParse(s, out uid))
41 | {
42 | result = new ObjectId(uid);
43 | return true;
44 | }
45 | else
46 | {
47 | result = ObjectId.Null;
48 | return false;
49 | }
50 | }
51 |
52 | #region IEquatable
53 | public override bool Equals(object obj)
54 | {
55 | if (!(obj is ObjectId))
56 | return false;
57 |
58 | return Equals((ObjectId)obj);
59 | }
60 |
61 | public bool Equals(ObjectId other)
62 | {
63 | return _id == other._id;
64 | }
65 |
66 | public override int GetHashCode()
67 | {
68 | return _id.GetHashCode();
69 | }
70 | #endregion
71 |
72 | #region IComparable
73 | public int CompareTo(ObjectId other)
74 | {
75 | return this._id.CompareTo(other._id);
76 | }
77 | #endregion
78 |
79 | public static bool operator ==(ObjectId lhs, ObjectId rhs)
80 | {
81 | return lhs.Equals(rhs);
82 | }
83 |
84 | public static bool operator !=(ObjectId lhs, ObjectId rhs)
85 | {
86 | return !(lhs == rhs);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/lcdb/ObjectIdMgr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | internal class ObjectIdMgr
7 | {
8 | private Database _database;
9 | private uint _currentId = 10000;
10 |
11 | internal ObjectIdMgr(Database db)
12 | {
13 | _database = db;
14 | }
15 |
16 | internal void reset()
17 | {
18 | if (_database != null)
19 | {
20 | ObjectId max = _database.currentMaxId;
21 | if (max.id > 10000)
22 | {
23 | _currentId = max.id;
24 | }
25 | }
26 | }
27 |
28 | internal ObjectId NextId
29 | {
30 | get { return new ObjectId(++_currentId); }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/lcdb/ObjectSnapMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | ///
6 | /// 对象捕捉模式
7 | ///
8 | public enum ObjectSnapMode
9 | {
10 | // 未定义
11 | Undefined = 0,
12 | // 端点
13 | End = 1,
14 | // 中点
15 | Mid = 2,
16 | // 中心点
17 | Center = 4,
18 | // 节点
19 | Node = 8,
20 | // 象限点
21 | Quad = 16,
22 | // 插入点
23 | Ins = 32,
24 | // 垂足
25 | Perpendicular = 64,
26 | // 切点
27 | Tangent = 128,
28 | // 最近点
29 | Near = 256,
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/lcdb/ObjectSnapPoint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | ///
6 | /// 对象捕捉点
7 | ///
8 | public class ObjectSnapPoint
9 | {
10 | ///
11 | /// 类型
12 | ///
13 | public ObjectSnapMode type
14 | {
15 | get { return _type; }
16 | set { _type = value; }
17 | }
18 | private ObjectSnapMode _type = ObjectSnapMode.Undefined;
19 |
20 | ///
21 | /// 点坐标
22 | ///
23 | private LitMath.Vector2 _position = new LitMath.Vector2(0, 0);
24 | public LitMath.Vector2 position
25 | {
26 | get { return _position; }
27 | set { _position = value; }
28 | }
29 |
30 | ///
31 | /// 构造函数
32 | ///
33 | public ObjectSnapPoint(ObjectSnapMode type, LitMath.Vector2 pos)
34 | {
35 | _type = type;
36 | _position = pos;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/lcdb/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("lcdb")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("lcdb")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("354a5293-ffaf-4549-9dd6-1a686b215e92")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 内部版本号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/lcdb/Table/BlockTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml;
4 |
5 | namespace SharpCAD.DatabaseServices
6 | {
7 | public class BlockTable : DBTable
8 | {
9 | ///
10 | /// 类名
11 | ///
12 | public override string className
13 | {
14 | get { return "BlockTable"; }
15 | }
16 |
17 | ///
18 | /// 构造函数
19 | ///
20 | internal BlockTable(Database db)
21 | : base(db, Database.BlockTableId)
22 | {
23 | }
24 |
25 | ///
26 | /// 读XML
27 | ///
28 | public override void XmlIn(Filer.XmlFiler filer)
29 | {
30 | Filer.XmlFilerImpl filerImpl = filer as Filer.XmlFilerImpl;
31 |
32 | base.XmlIn(filer);
33 |
34 | XmlNode curXmlNode = filerImpl.curXmlNode;
35 | XmlNodeList blocks = curXmlNode.SelectNodes("Block");
36 | foreach (XmlNode blockNode in blocks)
37 | {
38 | Block block = new Block();
39 | block._dbtable = this;
40 | filerImpl.curXmlNode = blockNode;
41 | block.XmlIn(filerImpl);
42 | this._Add(block);
43 | }
44 | filerImpl.curXmlNode = curXmlNode;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/lcdb/Table/LayerTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml;
4 |
5 | namespace SharpCAD.DatabaseServices
6 | {
7 | public class LayerTable : DBTable
8 | {
9 | ///
10 | /// 类名
11 | ///
12 | public override string className
13 | {
14 | get { return "LayerTable"; }
15 | }
16 |
17 | ///
18 | ///
19 | ///
20 | private ObjectId _layerZeroId = ObjectId.Null;
21 | public ObjectId layerZeroId
22 | {
23 | get { return _layerZeroId; }
24 | }
25 |
26 | ///
27 | /// 构造函数
28 | ///
29 | internal LayerTable(Database db)
30 | : base(db, Database.LayerTableId)
31 | {
32 | Layer layerZero = new Layer("0");
33 | this.Add(layerZero);
34 |
35 | _layerZeroId = layerZero.id;
36 | }
37 |
38 | ///
39 | /// 读XML
40 | ///
41 | public override void XmlIn(Filer.XmlFiler filer)
42 | {
43 | Filer.XmlFilerImpl filerImpl = filer as Filer.XmlFilerImpl;
44 |
45 | base.XmlIn(filer);
46 |
47 | XmlNode curXmlNode = filerImpl.curXmlNode;
48 | XmlNodeList layers = curXmlNode.SelectNodes("Layer");
49 | foreach (XmlNode layerNode in layers)
50 | {
51 | Layer layer = new Layer();
52 | filerImpl.curXmlNode = layerNode;
53 | layer.XmlIn(filerImpl);
54 | this._Add(layer);
55 | }
56 | filerImpl.curXmlNode = curXmlNode;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/lcdb/Table/TableIds.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD.DatabaseServices
4 | {
5 | internal class TableIds
6 | {
7 | internal static uint BlockTableId = 1;
8 | internal static uint LayerTableId = 2;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/lcdb/TableRecord/Block.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml;
4 | using System.Reflection;
5 |
6 | namespace SharpCAD.DatabaseServices
7 | {
8 | public class Block : DBTableRecord, IEnumerable
9 | {
10 | ///
11 | /// 类名
12 | ///
13 | public override string className
14 | {
15 | get { return "Block"; }
16 | }
17 |
18 | private List _items = new List();
19 |
20 | ///
21 | /// 克隆函数
22 | ///
23 | public override object Clone()
24 | {
25 | Block block = base.Clone() as Block;
26 | foreach (Entity item in _items)
27 | {
28 | Entity itemCopy = item.Clone() as Entity;
29 | block.AppendEntity(itemCopy);
30 | }
31 |
32 | return block;
33 | }
34 |
35 | protected override DBObject CreateInstance()
36 | {
37 | return new Block();
38 | }
39 |
40 | ///
41 | /// 添加图元
42 | ///
43 | public ObjectId AppendEntity(Entity entity)
44 | {
45 | if (entity.id != ObjectId.Null)
46 | {
47 | throw new System.Exception("entity is not newly created");
48 | }
49 | return _AppendEntity(entity);
50 | }
51 |
52 | private ObjectId _AppendEntity(Entity entity)
53 | {
54 | if (_id == ObjectId.Null)
55 | {
56 | _items.Add(entity);
57 | entity.SetParent(this);
58 | }
59 | else
60 | {
61 | _items.Add(entity);
62 | entity.SetParent(this);
63 | this.database.IdentifyObject(entity);
64 | }
65 |
66 | return entity.id;
67 | }
68 |
69 | ///
70 | /// 删除图元
71 | ///
72 | internal void RemoveEntity(Entity entity)
73 | {
74 | _items.Remove(entity);
75 | }
76 |
77 | ///
78 | /// 清空图元
79 | ///
80 | internal void Clear()
81 | {
82 | _items.Clear();
83 | }
84 |
85 | ///
86 | /// 写XML
87 | ///
88 | public override void XmlOut(Filer.XmlFiler filer)
89 | {
90 | Filer.XmlFilerImpl filerImpl = filer as Filer.XmlFilerImpl;
91 |
92 | //
93 | base.XmlOut(filer);
94 |
95 | //
96 | filerImpl.NewSubNodeAndInsert("entities");
97 | foreach (Entity item in _items)
98 | {
99 | filerImpl.NewSubNodeAndInsert(item.className);
100 | item.XmlOut(filer);
101 | filerImpl.Pop();
102 | }
103 | filerImpl.Pop();
104 | }
105 |
106 | ///
107 | /// 读XML
108 | ///
109 | public override void XmlIn(Filer.XmlFiler filer)
110 | {
111 | Filer.XmlFilerImpl filerImpl = filer as Filer.XmlFilerImpl;
112 |
113 | base.XmlIn(filerImpl);
114 |
115 | XmlNode curXmlNode = filerImpl.curXmlNode;
116 | XmlNode entitiesNode = curXmlNode.SelectSingleNode("entities");
117 | if (entitiesNode != null && entitiesNode.ChildNodes != null)
118 | {
119 | foreach (XmlNode entityNode in entitiesNode.ChildNodes)
120 | {
121 | Type type = Type.GetType("SharpCAD.DatabaseServices." + entityNode.Name);
122 | if (type == null)
123 | {
124 | continue;
125 | }
126 | Entity ent = Activator.CreateInstance(type) as Entity;
127 | if (ent == null)
128 | {
129 | continue;
130 | }
131 | filerImpl.curXmlNode = entityNode;
132 | ent.XmlIn(filerImpl);
133 | this._AppendEntity(ent);
134 | }
135 | }
136 | filerImpl.curXmlNode = curXmlNode;
137 | }
138 |
139 | #region IDBObjectContainer
140 | public IEnumerator GetEnumerator()
141 | {
142 | return _items.GetEnumerator();
143 | }
144 |
145 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
146 | {
147 | return this.GetEnumerator();
148 | }
149 | #endregion
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/src/lcdb/TableRecord/DBTableRecord.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace SharpCAD.DatabaseServices
5 | {
6 | ///
7 | /// 命名的数据库对象
8 | ///
9 | public abstract class DBTableRecord : DBObject
10 | {
11 | ///
12 | /// 类名
13 | ///
14 | public override string className
15 | {
16 | get { return "DBTableRecord"; }
17 | }
18 |
19 | ///
20 | /// 名称
21 | ///
22 | protected string _name = "";
23 | public string name
24 | {
25 | get { return _name; }
26 | set { _name = value; }
27 | }
28 |
29 | ///
30 | /// 数据表
31 | ///
32 | internal DBTable _dbtable = null;
33 | public override DBTable dbtable
34 | {
35 | get { return _dbtable; }
36 | }
37 |
38 | ///
39 | /// 克隆函数
40 | ///
41 | public override object Clone()
42 | {
43 | DBTableRecord tblRec = base.Clone() as DBTableRecord;
44 | tblRec._name = _name;
45 | tblRec._dbtable = null;
46 | return tblRec;
47 | }
48 |
49 | ///
50 | /// 删除
51 | ///
52 | protected override void _Erase()
53 | {
54 | if (_dbtable != null)
55 | {
56 | _dbtable.Remove(this);
57 | }
58 | }
59 |
60 | ///
61 | /// 写XML
62 | ///
63 | public override void XmlOut(Filer.XmlFiler filer)
64 | {
65 | base.XmlOut(filer);
66 |
67 | filer.Write("name", _name);
68 | }
69 |
70 | ///
71 | /// 读XML
72 | ///
73 | public override void XmlIn(Filer.XmlFiler filer)
74 | {
75 | base.XmlIn(filer);
76 |
77 | filer.Read("name", out _name);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/lcdb/TableRecord/Layer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using SharpCAD.Colors;
5 |
6 | namespace SharpCAD.DatabaseServices
7 | {
8 | ///
9 | /// 图层
10 | ///
11 | public class Layer : DBTableRecord
12 | {
13 | ///
14 | /// 类名
15 | ///
16 | public override string className
17 | {
18 | get { return "Layer"; }
19 | }
20 |
21 | ///
22 | /// 颜色
23 | ///
24 | private Color _color = Color.FromRGB(255, 255, 255);
25 | public Color color
26 | {
27 | get { return _color; }
28 | set
29 | {
30 | if (value.colorMethod == ColorMethod.ByColor)
31 | {
32 | _color = value;
33 | }
34 | else
35 | {
36 | throw new System.Exception("Layer set color exception.");
37 | }
38 | }
39 | }
40 |
41 | public System.Drawing.Color colorValue
42 | {
43 | get
44 | {
45 | return System.Drawing.Color.FromArgb(_color.r, _color.g, _color.b);
46 | }
47 | }
48 |
49 | ///
50 | /// 描述
51 | ///
52 | private string _description = string.Empty;
53 | public string description
54 | {
55 | get { return _description; }
56 | set { _description = value; }
57 | }
58 |
59 | ///
60 | /// 线宽
61 | ///
62 | private LineWeight _lineWeight = LineWeight.ByLineWeightDefault;
63 | public LineWeight lineWeight
64 | {
65 | get { return _lineWeight; }
66 | set { _lineWeight = value; }
67 | }
68 |
69 | ///
70 | /// 线型
71 | ///
72 | private LineType _lineType = LineType.ByLineTypeDefault;
73 | public LineType lineType
74 | {
75 | get { return _lineType; }
76 | set { _lineType = value; }
77 | }
78 |
79 | ///
80 | /// 构造函数
81 | ///
82 | public Layer(string name = "")
83 | {
84 | _name = name;
85 | }
86 |
87 | ///
88 | /// 克隆函数
89 | ///
90 | public override object Clone()
91 | {
92 | Layer layer = base.Clone() as Layer;
93 | layer._color = _color;
94 | layer._lineWeight = _lineWeight;
95 | layer._lineType = _lineType;
96 | layer._description = _description;
97 |
98 | return layer;
99 | }
100 |
101 | protected override DBObject CreateInstance()
102 | {
103 | return new Layer();
104 | }
105 |
106 | ///
107 | /// 写XML
108 | ///
109 | public override void XmlOut(Filer.XmlFiler filer)
110 | {
111 | base.XmlOut(filer);
112 |
113 | filer.Write("color", _color);
114 | filer.Write("lineWeight", _lineWeight);
115 | filer.Write("lineType", _lineType);
116 | filer.Write("description", _description);
117 | }
118 |
119 | ///
120 | /// 读XML
121 | ///
122 | public override void XmlIn(Filer.XmlFiler filer)
123 | {
124 | base.XmlIn(filer);
125 |
126 | filer.Read("color", out _color);
127 | filer.Read("lineWeight", out _lineWeight);
128 | filer.Read("lineType", out _lineType);
129 | filer.Read("_description", out _description);
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/ICanvas.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SharpCAD
6 | {
7 | ///
8 | /// 画布接口
9 | ///
10 | public interface ICanvas
11 | {
12 | // 画布宽
13 | double width { get; }
14 | // 画布高
15 | double height { get; }
16 |
17 | ///
18 | /// 设置Presenter
19 | ///
20 | void SetPresenter(IPresenter controller);
21 |
22 | ///
23 | /// 添加子元素
24 | ///
25 | void AddChild(object child);
26 |
27 | ///
28 | /// 删除子元素
29 | ///
30 | void RemoveChild(object child);
31 |
32 | ///
33 | /// 重绘
34 | ///
35 | void Repaint();
36 | void Repaint(double x, double y, double width, double height);
37 |
38 | ///
39 | /// 获取与设置鼠标位置
40 | ///
41 | LitMath.Vector2 GetMousePosition();
42 | void SetMousePosition(LitMath.Vector2 postion);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/ICommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD
4 | {
5 | ///
6 | /// 命令接口
7 | ///
8 | public interface ICommand
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/IDocument.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD
4 | {
5 | ///
6 | /// 文档接口
7 | ///
8 | public interface IDocument
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/IGraphicsContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD
4 | {
5 | ///
6 | /// 绘图上下文
7 | ///
8 | public interface IGraphicsContext
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/IGraphicsDraw.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SharpCAD
4 | {
5 | public enum TextAlignment
6 | {
7 | LeftBottom = 0,
8 | LeftMiddle = 1,
9 | LeftTop = 2,
10 | CenterBottom = 3,
11 | CenterMiddle = 4,
12 | CenterTop = 5,
13 | RightBottom = 6,
14 | RightMiddle = 7,
15 | RightTop = 8,
16 | }
17 |
18 | public interface IGraphicsDraw
19 | {
20 | void DrawPoint(LitMath.Vector2 endPoint);
21 |
22 | void DrawLine(LitMath.Vector2 startPoint, LitMath.Vector2 endPoint);
23 |
24 | void DrawXLine(LitMath.Vector2 basePoint, LitMath.Vector2 direction);
25 |
26 | void DrawRay(LitMath.Vector2 basePoint, LitMath.Vector2 direction);
27 |
28 | void DrawCircle(LitMath.Vector2 center, double radius);
29 |
30 | void DrawEllipse(LitMath.Vector2 center, double radiusX, double radiusY);
31 |
32 | ///
33 | /// 绘制圆弧
34 | /// 以逆时针方式绘制
35 | ///
36 | /// 圆弧中心
37 | /// 圆弧半径
38 | /// 起始角度(弧度)
39 | /// 结束角度(弧度)
40 | void DrawArc(LitMath.Vector2 center, double radius, double startAngle, double endAngle);
41 |
42 | void DrawRectangle(LitMath.Vector2 position, double width, double height);
43 |
44 | LitMath.Vector2 DrawText(LitMath.Vector2 position, string text, double height, string font, TextAlignment textAlign);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/lcinterface/Interface/IPresenter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Windows.Forms;
5 |
6 | namespace SharpCAD
7 | {
8 | public interface IPresenter
9 | {
10 | IDocument document { get; }
11 | ICanvas canvas { get; }
12 |
13 | void OnPaintCanvas(PaintEventArgs e);
14 | void OnResize(EventArgs e);
15 | void OnMouseDown(MouseEventArgs e);
16 | void OnMouseUp(MouseEventArgs e);
17 | void OnMouseMove(MouseEventArgs e);
18 | void OnMouseDoubleClick(MouseEventArgs e);
19 | void OnMouseWheel(MouseEventArgs e);
20 |
21 | void OnKeyDown(KeyEventArgs e);
22 | void OnKeyUp(KeyEventArgs e);
23 |
24 | void OnCommand(ICommand cmd);
25 |
26 | double ModelToCanvas(double value);
27 | LitMath.Vector2 ModelToCanvas(LitMath.Vector2 pointInModel);
28 | double CanvasToModel(double value);
29 | LitMath.Vector2 CanvasToModel(LitMath.Vector2 pointInCanvas);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/lcinterface/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("lcinterface")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("lcinterface")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("6cd550de-2856-4ec5-b79b-59c63813c5d2")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 内部版本号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/lcinterface/lcinterface.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {39C4BCAF-8AAE-4410-9BC4-B586B18E964A}
9 | Library
10 | Properties
11 | lcinterface
12 | lcinterface
13 | v2.0
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | ..\bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | ..\bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | False
36 | ..\3rdlib\LitMath.dll
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
61 |
--------------------------------------------------------------------------------
/test/test.scad:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 | 10001
6 | ModelSpace
7 |
8 |
9 | 10003
10 | ByColor:0,128,0
11 | ByLayer
12 | 0
13 | 0;0
14 | 100;100
15 |
16 |
17 | 10004
18 | ByColor:0,0,255
19 | ByLayer
20 | 0
21 | 0;0
22 | 20
23 |
24 |
25 | 10005
26 | ByColor:255,255,0
27 | ByLayer
28 | 0
29 | False
30 | 0;0|10;20|20;5|30;25
31 |
32 |
33 | 10006
34 | ByColor:0,0,255
35 | ByLayer
36 | 0
37 | 20;20
38 | 6
39 | 0.785398163397448
40 | 4.3982296401243
41 |
42 |
43 | 10007
44 | ByLayer:255,255,255
45 | ByLayer
46 | 0
47 | 0;50
48 | -0.707106781186547;-0.707106781186547
49 |
50 |
51 | 10008
52 | ByLayer:255,255,255
53 | ByLayer
54 | 0
55 | -10;20
56 | 0.371390676354104;-0.928476690885259
57 |
58 |
59 |
60 |
61 |
62 | 2
63 |
64 | 10002
65 | 0
66 | ByColor:255,255,255
67 | ByLineWeightDefault
68 |
69 |
70 |
--------------------------------------------------------------------------------