Beispiel #1
0
        private void OnGUI()
        {
            // fixed window size
            GUILayout.ExpandHeight(false);
            GUILayout.ExpandWidth(false);

            SelectBox = new Rect(3, 0, position.width - 6, EditorGUIUtility.singleLineHeight * 4);
            RenderBox = new Rect(3, EditorGUIUtility.singleLineHeight * 4, position.width - 6, EditorGUIUtility.singleLineHeight * 16);

            #region Select Box
            GUILayout.BeginArea(SelectBox);
            GUILayout.Label("- Select object shape file : ", GUILayout.Height(EditorGUIUtility.singleLineHeight));

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Load Shape", GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(EditorGUIUtility.fieldWidth * 2)))
            {
                shpFilePath = EditorUtility.OpenFilePanel("Shape Loader(shx or shp)", "", "shp,shx");
            }
            EditorGUILayout.SelectableLabel(ShpFileName, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Load Dbf", GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(EditorGUIUtility.fieldWidth * 2)))
            {
                dbfFilePath = EditorUtility.OpenFilePanel("Data file Loader", "", "dbf");
            }
            EditorGUILayout.SelectableLabel(DbfFileName, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.EndHorizontal();
            GUILayout.EndArea();
            #endregion

            #region Render Box
            // If Shp file is not selected, shape can't be loaded
            GUILayout.BeginArea(RenderBox);

            // Check file path
            if (shpFilePath.Length == 0)
            {
                GUI.enabled = false;
            }
            else
            {
                GUI.enabled = true;
            }

            if (GUILayout.Button("Load Data"))
            {
                shapeFile = LoadFiles(shpFilePath) as ShpFile;
                dbfFile   = LoadFiles(dbfFilePath) as DbfFile;
            }

            // Check File header Info
            shpFileCode      = (shapeFile != null) ? shapeFile.FileCode : 0;
            shpFileLength    = (shapeFile != null) ? shapeFile.FileLength : 0;
            shpFileVersion   = (shapeFile != null) ? shapeFile.FileVersion : 0;
            shpFileType      = (shapeFile != null) ? shapeFile.ShpType.ToString() : "";
            dbfFileVersion   = (dbfFile != null) ? dbfFile.Version.ToString() : "";
            dbfFileDate      = (dbfFile != null) ? dbfFile.UpdateDate : 0;
            dbfFileRecordCnt = (dbfFile != null) ? dbfFile.NumberOfRecords : 0;

            // Shp File Header Info Field
            GUILayout.Label("- Shp file Description : ", GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.IntField("File Code", shpFileCode, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.IntField("File Length", shpFileLength, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.IntField("File Version", shpFileVersion, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Shape Type", GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            EditorGUILayout.SelectableLabel(shpFileType, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.EndHorizontal();

            // Dbf File Header Info Field
            GUILayout.Label("- Dbf file Description : ", GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.LabelField("Dbf Version", GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(EditorGUIUtility.labelWidth - 4));
            EditorGUILayout.SelectableLabel(dbfFileVersion, EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.IntField("Dbf Date", dbfFileDate, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUILayout.IntField("Record Count", dbfFileRecordCnt, GUILayout.Height(EditorGUIUtility.singleLineHeight));


            // Check file loaded correctly
            if (shapeFile == null)
            {
                GUI.enabled = false;
            }
            else
            {
                GUI.enabled = true;
            }


            // Render Field
            GUILayout.Label("- Render Option : ", GUILayout.Height(EditorGUIUtility.singleLineHeight));

            // Render Data
            shapeColor = EditorGUILayout.ColorField("Color", shapeColor, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            if (GUILayout.Button("Render Data"))
            {
                RenderFiles(shapeColor);
            }
            GUILayout.EndArea();
            #endregion
        }
Beispiel #2
0
 public Shapefile(IShpFile shpFile, IShxFile shxFile) : base()
 {
     ShpFile  = shpFile;
     ShxFile  = shxFile;
     Features = new FeatureList(this);
 }