示例#1
0
        /// <summary>
        /// Read Node File From Database, Fill Out The NODEDWG
        /// Path must be FULL PATH of a DWG from the database
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="path">Note PATH</param>
        public void ReadFromDatabase(SQLiteConnection connection, string pathDwg)
        {
            FixtureBoxSet.Clear();
            InsertPointSet.Clear();
            FixtureDetailSet.Clear();
            TableDataSet.Clear();

            string relPath = GoodiesPath.MakeRelativePath(pathDwg);

            file = DBDwgFile.SelectRow(connection, relPath);
            if (file == null || file.ID == ConstantName.invalidNum)
            {
                MessageBox.Show("NODEDWG -> ReadFromDatabase -> File Not Found");
                return;
            }
            foreach (FixtureBeingUsedAreaModel fixtureBox in DBFixtureBeingUsedArea.SelectRows(connection, file.ID))
            {
                FixtureBeingUsedArea fixtureArea = new FixtureBeingUsedArea(fixtureBox);
                //this line is very important. You have to make sure they have file model in each fixtureArea;
                //this won't complicate the program as we pass the pointer.
                FixtureBoxSet.Add(fixtureArea);
            }

            foreach (FixtureDetailsModel detailModel in DBFixtureDetails.SelectRows(connection, file.ID))
            {
                FixtureDetails fd = new FixtureDetails(detailModel);
                FixtureDetailSet.Add(fd);
            }

            foreach (InsertPointModel insertPointModel in DBInsertPoint.SelectRows(connection, file.ID))
            {
                InsertPoint ip = new InsertPoint(insertPointModel);
                InsertPointSet.Add(ip);
            }

            foreach (TableModel model in DBTable.SelectRows(connection, file.ID))
            {
                TableData table = new TableData(model);
                TableDataSet.Add(table);
            }
        }
示例#2
0
        static private T HandleEditButtons <T>(T values, ref int selected, SplineComponent spline, string insertLabel, InsertPoint <T> insert, string removeLabel, RemovePoint <T> remove)
        {
            if (GUILayout.Button(insertLabel))
            {
                Undo.RecordObject(spline, insertLabel);
                values = insert(values, ref selected);
            }

            if (values != null && selected >= 0)
            {
                if (GUILayout.Button(removeLabel))
                {
                    Undo.RecordObject(spline, removeLabel);
                    values = remove(values, ref selected);
                }
            }

            return(values);
        }
示例#3
0
        private static NODEDWG GetData(Database db, SQLiteConnection connection)
        {
            NODEDWG note = new NODEDWG();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable       bt  = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                foreach (ObjectId id in btr)
                {
                    DBObject obj = tr.GetObject(id, OpenMode.ForRead);
                    if (obj is BlockReference)
                    {
                        BlockReference bref = (BlockReference)obj;
                        if (Goodies.IsBlockInTheDrawing(bref))
                        {
                            if (bref.IsDynamicBlock)
                            {
                                string brefName = Goodies.GetDynamicName(bref);
                                if (brefName.Equals(ConstantName.FixtureInformationArea))
                                {
                                    FixtureBeingUsedArea dbA = new FixtureBeingUsedArea(bref);
                                    if (dbA.model != null)
                                    {
                                        note.FixtureBoxSet.Add(dbA);
                                    }
                                }
                            }
                            else if (bref.Name == ConstantName.FixtureDetailsBox)
                            {
                                FixtureDetails FD = new FixtureDetails(bref, tr);
                                if (FD.model != null)
                                {
                                    note.FixtureDetailSet.Add(FD);
                                }
                            }
                            else if (bref.Name == ConstantName.InsertPoint)
                            {
                                InsertPoint IP = new InsertPoint(bref, tr);
                                if (IP.model != null)
                                {
                                    note.InsertPointSet.Add(IP);
                                }
                            }
                            else if (bref is Table)
                            {
                                TableData tb = new TableData(bref, tr, db);
                                if (tb.model != null)
                                {
                                    note.TableDataSet.Add(tb);
                                }
                            }
                        }
                    }
                }

                List <FixtureDetails> newFixs = new List <FixtureDetails>();

                foreach (FixtureBeingUsedArea fba in note.FixtureBoxSet)
                {
                    foreach (FixtureDetails fd in note.FixtureDetailSet)
                    {
                        if (fba.IsInsideTheBox(fd))
                        {
                            newFixs.Add(fd);
                        }
                    }
                }

                note.FixtureDetailSet.Clear();
                foreach (FixtureDetails fd in newFixs)
                {
                    note.FixtureDetailSet.Add(fd);
                }
            }

            //Write to Database

            string currentdwgPath = db.Filename;
            string dbPath         = GoodiesPath.GetDatabasePathFromDwgPath(currentdwgPath);

            if (string.IsNullOrEmpty(dbPath))
            {
                MessageBox.Show("Could Not Find Database.");
            }

            note.file = DBDwgFile.GetPNote(connection);
            note.file.modifieddate = GoodiesPath.GetModifiedOfFile(GoodiesPath.GetFullPathFromRelativePath(note.file.relativePath, connection)).Ticks;

            if (note.file == null)
            {
                MessageBox.Show($"Can't find this {currentdwgPath} in databse.");
                return(null);
            }
            foreach (FixtureBeingUsedArea fixtureBox in note.FixtureBoxSet)
            {
                fixtureBox.model.file = note.file;
            }

            foreach (FixtureDetails fd in note.FixtureDetailSet)
            {
                fd.model.file = note.file;
            }
            foreach (InsertPoint ip in note.InsertPointSet)
            {
                ip.model.file = note.file;
            }
            foreach (TableData table in note.TableDataSet)
            {
                table.model.file = note.file;
            }

            DBDwgFile.DeleteRow(connection, note.file.relativePath);

            note.WriteToDataBase(connection);

            return(note);
        }
示例#4
0
        public static void WriteScheduleTableToNote(SQLiteConnection connection)
        {
            string dwgPath      = Application.DocumentManager.MdiActiveDocument.Name;
            string notePathFull = GoodiesPath.GetNotePathFromADwgPath(dwgPath, connection);
            string notePath     = GoodiesPath.MakeRelativePath(notePathFull);

            if (string.IsNullOrEmpty(notePath))
            {
                MessageBox.Show("WriteScheduleTableToNote -> Can't find P_Note file.");
                return;
            }

            FileStatus fileStatus = Goodies.CanOpenToWrite(notePathFull);

            //Document doc = Goodies.CanOpenToWrite1(notePathFull);
            if (fileStatus == null || fileStatus.db == null)
            {
                return;
            }
            //if (doc == null) return;

            DwgFileModel fileModel = PlumbingDatabaseManager.GetNotePath(connection);

            if (notePath == fileModel.relativePath)
            {
                if (GoodiesPath.IsDateTheSame(notePathFull, connection))
                {
                    NODEDWG note = ReadPNote.ReadDataPNode(connection);


                    InsertPoint ip    = note.InsertPointSet.Where(insertpoint => insertpoint.model.alias == "FS").FirstOrDefault();
                    Table       table = TableSchedule.CreateTable(note.FixtureDetailSet, ip);
                    Document    doc   = Application.DocumentManager.GetDocument(fileStatus.db);
                    using (doc.LockDocument())
                    {
                        using (fileStatus.db)
                        {
                            TableSchedule.DeleteTableSchedule(fileStatus.db, XDataHelperName.tableSchedule);

                            using (Transaction tr = fileStatus.db.TransactionManager.StartTransaction())
                            {
                                BlockTable       bt  = (BlockTable)tr.GetObject(fileStatus.db.BlockTableId, OpenMode.ForRead);
                                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                                Goodies.InsertTable(table, tr, btr);

                                table.Layer = ConstantName.TABLE;
                                XDataHelper.AddTableXData(ref table, tr, fileStatus.db);
                                tr.Commit();
                                tr.Dispose();
                                TableData tableData = new TableData(table, tr, fileStatus.db);
                                tableData.model.file = fileModel;
                                tableData.model.WriteToDatabase(connection);
                            }
                            TableSchedule.AddBlockToTable(table, fileStatus.db, note.FixtureDetailSet);
                            fileStatus.Save();
                        }
                    }
                    fileStatus.ReturnPreviousDocument();
                }
            }
        }