프로젝트

일반

사용자정보

개정판 74a0c9d6

ID74a0c9d667fc418144d8a7e5bb29999ca9d27586
상위 1c33a480
하위 dc270d65

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #000 : add ui

Change-Id: I2947ecc3f254338c227420f5692b023c27cddf1d

차이점 보기:

DTI_PID/APIDConverter/AVEVA.PID.CustomizationUtility_ACAD2018_x64.csproj
75 75
    <Reference Include="PresentationFramework" />
76 76
    <Reference Include="System" />
77 77
    <Reference Include="System.Core" />
78
    <Reference Include="System.Drawing" />
78 79
    <Reference Include="System.Windows.Forms" />
79 80
    <Reference Include="System.Xaml" />
80 81
    <Reference Include="System.Xml.Linq" />
......
84 85
    <Reference Include="WindowsBase" />
85 86
  </ItemGroup>
86 87
  <ItemGroup>
88
    <Compile Include="Form\APIDConverter.cs">
89
      <SubType>Form</SubType>
90
    </Compile>
91
    <Compile Include="Form\APIDConverter.Designer.cs">
92
      <DependentUpon>APIDConverter.cs</DependentUpon>
93
    </Compile>
87 94
    <Compile Include="AutoModeling.cs" />
88 95
    <Compile Include="Aveva.PID.AssemblyInfo.cs" />
89 96
    <Compile Include="ConverterRibbonUI.cs" />
......
93 100
    <Compile Include="Utilities.cs" />
94 101
    <Compile Include="Utils\GUIUtils.cs" />
95 102
  </ItemGroup>
103
  <ItemGroup>
104
    <EmbeddedResource Include="Form\APIDConverter.resx">
105
      <DependentUpon>APIDConverter.cs</DependentUpon>
106
    </EmbeddedResource>
107
  </ItemGroup>
96 108
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
97 109
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
98 110
       Other similar extension points exist, see Microsoft.Common.targets.
DTI_PID/APIDConverter/AutoModeling.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Configuration;
4
using System.Data;
5
using System.Data.Common;
6
using System.Data.SqlClient;
7
using System.IO;
8

  
9
using Autodesk.AutoCAD.ApplicationServices;
10
using Autodesk.AutoCAD.ApplicationServices.Core;
11
using Autodesk.AutoCAD.DatabaseServices;
12
using Autodesk.AutoCAD.EditorInput;
13
using Autodesk.AutoCAD.Geometry;
14
using Autodesk.AutoCAD.Interop;
15
using Autodesk.AutoCAD.Interop.Common;
16
using Autodesk.AutoCAD.Runtime;
17
using Autodesk.AutoCAD.Windows;
18

  
19

  
20
namespace AVEVA.PID.CustomizationUtility
21
{
22
    public class AutoModeling
23
    {
24
        Autodesk.Windows.RibbonCombo pipeStyleCombo = null;
25
        Autodesk.Windows.RibbonChecklistButton autoLabelCheckListButton = null;
26

  
27
        private void InitGUI()
28
        {
29
            Autodesk.Windows.RibbonItemCollection items = GUI.RibbonHelper.GetPanelItems("ID_PIPE_PANEL");
30
            object objPipeStyle = GUIUtils.FindItem(items, "PIPESTYLE");
31
            if (objPipeStyle != null)
32
                pipeStyleCombo = objPipeStyle as Autodesk.Windows.RibbonCombo;
33
            object objAutoLabel = GUIUtils.FindItem(items, "Auto Label");
34
            if (objAutoLabel != null)
35
                autoLabelCheckListButton = objAutoLabel as Autodesk.Windows.RibbonChecklistButton;
36

  
37

  
38
        }
39
        private void SetAutoLabelUnCehck()
40
        {
41
            if (autoLabelCheckListButton != null)
42
            {
43
                foreach (var item in autoLabelCheckListButton.Items)
44
                {
45
                    if (item.GetType() == typeof(Autodesk.Windows.RibbonButton))
46
                    {
47
                        Autodesk.Windows.RibbonButton ribbonButton = item as Autodesk.Windows.RibbonButton;
48
                        if (ribbonButton.IsChecked)
49
                            ribbonButton.IsChecked = false;
50
                    }
51
                }
52
            }
53
        }
54

  
55
        private void SetPipeStyle(string style)
56
        {
57
            if (pipeStyleCombo.Current != null)
58
            {
59
                Autodesk.Windows.RibbonButton button = pipeStyleCombo.Current as Autodesk.Windows.RibbonButton;
60
                if (button.AutomationName != style)
61
                {
62
                    foreach (var item in pipeStyleCombo.Items)
63
                    {
64
                        Autodesk.Windows.RibbonButton loop = item as Autodesk.Windows.RibbonButton;
65
                        if (loop.AutomationName == style)
66
                        {
67
                            pipeStyleCombo.Current = loop;
68
                            break;
69
                        }
70
                    }
71
                }
72
            }
73
        }
74

  
75
        private string ReadDrawingLastLine()
76
        {
77
            string sHandle = string.Empty;
78
            SqlConnection connection = null;
79
            try
80
            {
81
                connection = new SqlConnection();
82
                connection.ConnectionString = DB.DB.GetConnectionString();
83
                connection.Open();
84

  
85
                string strQry = string.Format("Select Handle from Pipe Where id = (SELECT MAX(id) FROM Pipe WHERE DrawingId = '{0}')", "Test");
86
                SqlCommand cmd = new SqlCommand();
87
                cmd.Connection = connection;
88
                cmd.CommandText = strQry;
89
                cmd.CommandType = CommandType.Text;
90

  
91
                SqlDataAdapter da = new SqlDataAdapter(cmd);
92
                System.Data.DataTable dt = new System.Data.DataTable();
93
                da.Fill(dt);
94
                if (dt.Rows.Count == 1)
95
                    sHandle = dt.Rows[0][0].ToString();
96

  
97
                dt.Dispose();
98
                da.Dispose();
99
            }
100
            catch (System.Exception)
101
            { }
102
            finally
103
            {
104
                if (connection != null)
105
                    connection.Close();
106
            }
107

  
108
            return sHandle;
109
        }
110

  
111
        #region Drawing Method
112

  
113
        private string DrawPipe(string style, List<string> coordinates)
114
        {
115
            SetPipeStyle(style);
116

  
117
            string prevHandle = ReadDrawingLastLine();
118

  
119
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
120
            Editor editor = acDoc.Editor;
121
            List<object> commandParam = new List<object>();
122
            //command name
123
            commandParam.Add("DRPIPE");
124
            //coordinate
125
            foreach (var item in coordinates)
126
                commandParam.Add(item);
127
            //enter
128
            commandParam.Add(null);
129
            //enter
130
            commandParam.Add(null);
131

  
132
            editor.Command(commandParam.ToArray());
133

  
134
            string newHandle = ReadDrawingLastLine();
135
            if (prevHandle == newHandle)
136
                return string.Empty;
137

  
138
            return newHandle;
139
        }
140
        private void DrawPipe(string style, List<string> coordinates, ObjectId objectId)
141
        {
142
            SetPipeStyle(style);
143

  
144
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
145
            Editor editor = acDoc.Editor;
146
            List<object> commandParam = new List<object>();
147
            //command name
148
            commandParam.Add("DRPIPE");
149
            //coordinate
150
            foreach (var item in coordinates)
151
                commandParam.Add(item);
152
            //enter
153
            commandParam.Add(null);
154

  
155
            //Input Object ID
156
            commandParam.Add(objectId);
157

  
158
            //enter
159
            commandParam.Add(null);
160

  
161
            editor.Command(commandParam.ToArray());
162
        }
163

  
164
        #endregion
165

  
166
        #region Test Source
167

  
168
        public void test()
169
        {
170
            InitGUI();
171

  
172
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
173

  
174
            DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" });
175

  
176
            DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
177
        }
178

  
179
        public static void TEST()
180
        {
181
            AutoModeling auto = new AutoModeling();
182
            auto.test();
183
        }
184
        #endregion
185
    }
186
}
DTI_PID/APIDConverter/ConverterRibbonUI.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
using Autodesk.AutoCAD.ApplicationServices;
8
using Autodesk.AutoCAD.DatabaseServices;
9
using Autodesk.AutoCAD.EditorInput;
10
using Autodesk.AutoCAD.Geometry;
11
using Autodesk.AutoCAD.Interop;
12
using Autodesk.AutoCAD.Interop.Common;
13
using Autodesk.AutoCAD.Runtime;
14
using Autodesk.AutoCAD.Ribbon;
15
using Autodesk.Windows;
16
using Autodesk.Windows.ToolBars;
17
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
18

  
19
namespace AVEVA.PID.CustomizationUtility
20
{
21
    public class ConverterRibbonUI
22
    {
23
        public static void InitUI()
24
        {
25
            RibbonControl ribbon = ComponentManager.Ribbon;
26
            RibbonTab tab = ribbon.FindTab("APIDConverter");
27
            if (tab != null)
28
                ribbon.Tabs.Remove(tab);
29
            else
30
            {
31
                tab = new RibbonTab();
32
                tab.Title = "APID Converter";
33
                tab.Id = "APIDConverter";
34

  
35
                tab.Panels.Add(AddConverterPanel());
36

  
37
                ribbon.Tabs.Insert(0, tab);
38
                ribbon.ActiveTab = tab;
39
            }
40
        }
41

  
42
        public static RibbonPanel AddConverterPanel()
43
        {
44
            RibbonButton rb;
45
            RibbonPanelSource rps = new RibbonPanelSource();
46
            rps.Title = "APID Converter";
47
            RibbonPanel rp = new RibbonPanel();
48
            rp.Source = rps;
49

  
50
            rb = new RibbonButton();
51
            rb.Name = "Converter";
52
            rb.ShowText = true;
53
            rb.Text = "Converter";
54
            rb.CommandHandler = new RibbonCommandHandler();
55
            rb.CommandParameter = "ConverterForm";
56
            rps.Items.Add(rb);
57

  
58
            rb = new RibbonButton();
59
            rb.Name = "Project Setting";
60
            rb.ShowText = true;
61
            rb.Text = "Project\nSetting";
62
            rb.CommandHandler = new RibbonCommandHandler();
63
            rb.CommandParameter = "ProjectForm";
64
            rps.Items.Add(rb);
65
            return rp;
66
        }
67

  
68
        public class RibbonCommandHandler : System.Windows.Input.ICommand
69
        {
70
            public event EventHandler CanExecuteChanged;
71

  
72
            public bool CanExecute(object parameter)
73
            {
74
                RibbonCommandItem btn = parameter as RibbonCommandItem;
75
                if (btn != null)
76
                    return true;
77
                else
78
                    return false;
79
            }
80

  
81
            public void Execute(object parameter)
82
            {
83
                RibbonCommandItem btn = parameter as RibbonCommandItem;
84

  
85
                if (btn != null)
86
                {
87
                    //execute an AutoCAD command, or your custom command defined by [CommandMethod]
88
                    Document dwg = Application.DocumentManager.MdiActiveDocument;
89
                    dwg.SendStringToExecute((string)btn.CommandParameter + " ", true, false, true);
90
                }
91
            }
92
        }
93
    }
94
}
DTI_PID/APIDConverter/DB/DB.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace AVEVA.PID.CustomizationUtility.DB
8
{
9
    public class DB
10
    {
11
        public static string GetConnectionString()
12
        {
13
            string strConn = string.Empty;
14
            if (Utilities.strSQLWinAuthentication.ToUpper() == "YES")
15
            {
16
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Integrated Security=SSPI;Initial Catalog={0};", Utilities.strSQLDatabaseName);
17
            }
18
            else if (Utilities.strSQLWinAuthentication.ToUpper() == "NO")
19
            {
20
                string strAccessString = "User ID=" + Utilities.strSQLUserName + ";Password=" + Utilities.strSQLPassword;
21
                strConn = String.Format("Data Source=" + Utilities.strSQLServerName + ";Initial Catalog=" + Utilities.strSQLDatabaseName + ";" + strAccessString);
22
            }
23

  
24
            return strConn;
25
        }
26
    }
27
}
DTI_PID/APIDConverter/Form/APIDConverter.Designer.cs
1
namespace AVEVA.PID.CustomizationUtility
2
{
3
    partial class APIDConverter
4
    {
5
        /// <summary>
6
        /// Required designer variable.
7
        /// </summary>
8
        private System.ComponentModel.IContainer components = null;
9

  
10
        /// <summary>
11
        /// Clean up any resources being used.
12
        /// </summary>
13
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
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
        /// <summary>
26
        /// Required method for Designer support - do not modify
27
        /// the contents of this method with the code editor.
28
        /// </summary>
29
        private void InitializeComponent()
30
        {
31
            this.button1 = new System.Windows.Forms.Button();
32
            this.SuspendLayout();
33
            // 
34
            // button1
35
            // 
36
            this.button1.Location = new System.Drawing.Point(94, 54);
37
            this.button1.Name = "button1";
38
            this.button1.Size = new System.Drawing.Size(75, 23);
39
            this.button1.TabIndex = 0;
40
            this.button1.Text = "button1";
41
            this.button1.UseVisualStyleBackColor = true;
42
            this.button1.Click += new System.EventHandler(this.button1_Click);
43
            // 
44
            // APIDConverter
45
            // 
46
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
47
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
48
            this.ClientSize = new System.Drawing.Size(979, 516);
49
            this.Controls.Add(this.button1);
50
            this.Name = "APIDConverter";
51
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
52
            this.Text = "APIDConverter";
53
            this.ResumeLayout(false);
54

  
55
        }
56

  
57
        #endregion
58

  
59
        private System.Windows.Forms.Button button1;
60
    }
61
}
DTI_PID/APIDConverter/Form/APIDConverter.cs
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Drawing;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10

  
11
namespace AVEVA.PID.CustomizationUtility
12
{
13
    public partial class APIDConverter : Form
14
    {
15
        public APIDConverter()
16
        {
17
            InitializeComponent();
18
        }
19

  
20
        private void button1_Click(object sender, EventArgs e)
21
        {
22
            APIDConverter aPID = new APIDConverter();
23
            aPID.ShowDialog();
24
        }
25
    }
26
}
DTI_PID/APIDConverter/Form/APIDConverter.resx
1
<?xml version="1.0" encoding="utf-8"?>
2
<root>
3
  <!-- 
4
    Microsoft ResX Schema 
5
    
6
    Version 2.0
7
    
8
    The primary goals of this format is to allow a simple XML format 
9
    that is mostly human readable. The generation and parsing of the 
10
    various data types are done through the TypeConverter classes 
11
    associated with the data types.
12
    
13
    Example:
14
    
15
    ... ado.net/XML headers & schema ...
16
    <resheader name="resmimetype">text/microsoft-resx</resheader>
17
    <resheader name="version">2.0</resheader>
18
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23
        <value>[base64 mime encoded serialized .NET Framework object]</value>
24
    </data>
25
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26
        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27
        <comment>This is a comment</comment>
28
    </data>
29
                
30
    There are any number of "resheader" rows that contain simple 
31
    name/value pairs.
32
    
33
    Each data row contains a name, and value. The row also contains a 
34
    type or mimetype. Type corresponds to a .NET class that support 
35
    text/value conversion through the TypeConverter architecture. 
36
    Classes that don't support this are serialized and stored with the 
37
    mimetype set.
38
    
39
    The mimetype is used for serialized objects, and tells the 
40
    ResXResourceReader how to depersist the object. This is currently not 
41
    extensible. For a given mimetype the value must be set accordingly:
42
    
43
    Note - application/x-microsoft.net.object.binary.base64 is the format 
44
    that the ResXResourceWriter will generate, however the reader can 
45
    read any of the formats listed below.
46
    
47
    mimetype: application/x-microsoft.net.object.binary.base64
48
    value   : The object must be serialized with 
49
            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50
            : and then encoded with base64 encoding.
51
    
52
    mimetype: application/x-microsoft.net.object.soap.base64
53
    value   : The object must be serialized with 
54
            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55
            : and then encoded with base64 encoding.
56

  
57
    mimetype: application/x-microsoft.net.object.bytearray.base64
58
    value   : The object must be serialized into a byte array 
59
            : using a System.ComponentModel.TypeConverter
60
            : and then encoded with base64 encoding.
61
    -->
62
  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64
    <xsd:element name="root" msdata:IsDataSet="true">
65
      <xsd:complexType>
66
        <xsd:choice maxOccurs="unbounded">
67
          <xsd:element name="metadata">
68
            <xsd:complexType>
69
              <xsd:sequence>
70
                <xsd:element name="value" type="xsd:string" minOccurs="0" />
71
              </xsd:sequence>
72
              <xsd:attribute name="name" use="required" type="xsd:string" />
73
              <xsd:attribute name="type" type="xsd:string" />
74
              <xsd:attribute name="mimetype" type="xsd:string" />
75
              <xsd:attribute ref="xml:space" />
76
            </xsd:complexType>
77
          </xsd:element>
78
          <xsd:element name="assembly">
79
            <xsd:complexType>
80
              <xsd:attribute name="alias" type="xsd:string" />
81
              <xsd:attribute name="name" type="xsd:string" />
82
            </xsd:complexType>
83
          </xsd:element>
84
          <xsd:element name="data">
85
            <xsd:complexType>
86
              <xsd:sequence>
87
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88
                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89
              </xsd:sequence>
90
              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91
              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92
              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93
              <xsd:attribute ref="xml:space" />
94
            </xsd:complexType>
95
          </xsd:element>
96
          <xsd:element name="resheader">
97
            <xsd:complexType>
98
              <xsd:sequence>
99
                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100
              </xsd:sequence>
101
              <xsd:attribute name="name" type="xsd:string" use="required" />
102
            </xsd:complexType>
103
          </xsd:element>
104
        </xsd:choice>
105
      </xsd:complexType>
106
    </xsd:element>
107
  </xsd:schema>
108
  <resheader name="resmimetype">
109
    <value>text/microsoft-resx</value>
110
  </resheader>
111
  <resheader name="version">
112
    <value>2.0</value>
113
  </resheader>
114
  <resheader name="reader">
115
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116
  </resheader>
117
  <resheader name="writer">
118
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119
  </resheader>
120
</root>
DTI_PID/APIDConverter/PIDCustomization.cs
87 87
        /// <summary>
88 88
        /// This is test command which gives the idea regarding selection of an entity and assigning different color to it
89 89
        /// </summary>
90
        [CommandMethod("TestS")]
91
        public static void TestSelection()
90
        [CommandMethod("APIDConverter")]
91
        public static void APIDConverter()
92 92
        {
93 93
            ConverterRibbonUI.InitUI();
94

  
95
            //AutoModeling.TEST();
96 94
        }
97 95
        [CommandMethod("ConverterForm")]
98
        public static void Test2()
96
        public static void ConverterForm()
99 97
        {
100
            MessageBox.Show("HI");
98
            APIDConverter converter = new APIDConverter();
99
            if (AcadApp.ShowModalDialog(converter) == DialogResult.OK)
100
            {
101

  
102
            }
101 103
        }
102 104
        #region private methods
103 105
        private string SaveBinaryDrawing()

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)