Ejemplo n.º 1
0
        public ILibraryItem GetFrom(string Name, Database from)
        {
            CivilDocumentStore sourceStore = from.GetDocumentStore <CivilDocumentStore>();
            PlotType           source      = (from pt in sourceStore.PlotTypes where pt.PlotTypeName == Name select pt).First();

            return(source);
        }
Ejemplo n.º 2
0
        private void Transfer(Database to, Database from, CivilDocumentStore destinationStore)
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                ObjectIdCollection collection = new ObjectIdCollection();

                //Generate list of objects to transfer

                /*collection.Add(BackgroundBlockID);
                 * collection.Add(BasepointID);*/
                collection.Add(BlockID);

                /*foreach (ObjectId accessPointLocation in AccessPointLocations.Collection)
                 * {
                 *  collection.Add(accessPointLocation);
                 * }
                 *
                 * foreach (WallSegment wallSegment in Segments)
                 * {
                 *  collection.Add(wallSegment.PerimeterLine);
                 * }*/

                IdMapping acMapping = new IdMapping();

                to.WblockCloneObjects(collection, to.BlockTableId, acMapping, DuplicateRecordCloning.Ignore, false);

                PlotType destination = (PlotType)this.Clone();

                destination.BackgroundBlockID = TranslateMapping(BackgroundBlockID, acMapping);
                destination.BasepointID       = TranslateMapping(BasepointID, acMapping);
                destination.BlockID           = TranslateMapping(BlockID, acMapping);

                for (int i = 0; i < destination.AccessPointLocations.Count; i++)
                {
                    destination.AccessPointLocations[i] = TranslateMapping(AccessPointLocations[i], acMapping);
                }

                foreach (WallSegment wallSegment in destination.Segments)
                {
                    wallSegment.PerimeterLine = TranslateMapping(wallSegment.PerimeterLine, acMapping);
                }

                destinationStore.PlotTypes.Add(destination);
                destinationStore.Save();

                tr.Commit();
            }
        }
Ejemplo n.º 3
0
        public static void Finalise()
        {
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);

                ObjectId         newBlockId = bt[PlotType.CurrentOpen.PlotTypeName];
                BlockTableRecord btr        = tr.GetObject(newBlockId, OpenMode.ForWrite) as BlockTableRecord;
                foreach (ObjectId e in btr)
                {
                    Entity temp = tr.GetObject(e, OpenMode.ForWrite) as Entity;
                    temp.Erase();
                }

                ObjectIdCollection plotObjects = new ObjectIdCollection();

                plotObjects.Add(PlotType.CurrentOpen.BackgroundBlockID);
                plotObjects.Add(PlotType.CurrentOpen.BasepointID);

                foreach (WallSegment ws in PlotType.CurrentOpen.Segments)
                {
                    plotObjects.Add(ws.PerimeterLine);
                }

                foreach (ObjectId c in PlotType.CurrentOpen.AccessPointLocations.Collection)
                {
                    plotObjects.Add(c);
                }

                btr.AssumeOwnershipOf(plotObjects);

                tr.Commit();
            }

            //Triggeer regen to update blocks display
            //alternatively http://adndevblog.typepad.com/autocad/2012/05/redefining-a-block.html
            Application.DocumentManager.CurrentDocument.Editor.Regen();

            //Add to the document store
            CivilDocumentStore cds = acDoc.GetDocumentStore <CivilDocumentStore>();

            cds.PlotTypes.Add(PlotType.CurrentOpen);

            PlotType.CurrentOpen = null;
            OnCurrentOpenChanged?.Invoke();
        }
Ejemplo n.º 4
0
        private void saveButton_Click(object sender, RoutedEventArgs e)
        {
            PlotType instance = plotTypeGrid.SelectedItem as PlotType;

            Civils.Main.PtLibrary.SaveLeafEntity(instance.PlotTypeName, instance, (libraryTree.SelectedItem as Branch));
        }
Ejemplo n.º 5
0
        public static void CreatePlotType()
        {
            Document acDoc    = Application.DocumentManager.MdiActiveDocument;
            Editor   acEditor = acDoc.Editor;
            Database acCurDb  = acDoc.Database;

            if (CurrentOpen == null)
            {
                PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter plot type name: ")
                {
                    AllowSpaces = true
                };
                PromptResult pStrRes = acDoc.Editor.GetString(pStrOpts);

                //Verify input
                if (pStrRes.Status == PromptStatus.OK)
                {
                    //Check the block does not already exist
                    bool exists = false;
                    using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                    {
                        //Create all plot specific layers
                        LayerTable acLayerTable = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable;
                        Core.Utilities.CreateLayer(tr, acLayerTable, Constants.JPP_HS_PlotPerimiter, Constants.JPP_HS_PlotPerimiterColor);

                        //Create the background block
                        BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                        if (bt.Has(pStrRes.StringResult))
                        {
                            exists = true;
                        }
                    }

                    if (!exists)
                    {
                        // Prompt for the start point
                        PromptPointOptions pPtOpts = new PromptPointOptions("")
                        {
                            Message = "\nEnter the base point. Basepoint to be located at bottom left corner of the plot: "
                        };
                        PromptPointResult pPtRes = acDoc.Editor.GetPoint(pPtOpts);

                        if (pPtRes.Status == PromptStatus.OK)
                        {
                            CurrentOpen = new PlotType()
                            {
                                PlotTypeName = pStrRes.StringResult,
                                BasePoint    = pPtRes.Value
                            };

                            using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
                            {
                                Main.AddRegAppTableRecord();

                                //Create all plot specific layers
                                LayerTable acLayerTable = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable;
                                Core.Utilities.CreateLayer(tr, acLayerTable, Constants.JPP_HS_PlotPerimiter, Constants.JPP_HS_PlotPerimiterColor);

                                //Create the background block
                                BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                                bt.UpgradeOpen();

                                BlockTableRecord backgroundBlockRecord = new BlockTableRecord
                                {
                                    Name   = CurrentOpen.PlotTypeName + "Background",
                                    Origin = CurrentOpen.BasePoint
                                };
                                ObjectId objRef = bt.Add(backgroundBlockRecord);
                                tr.AddNewlyCreatedDBObject(backgroundBlockRecord, true);

                                //Prep the block for finalising
                                BlockTableRecord plotTypeBlockRecord = new BlockTableRecord
                                {
                                    Name   = CurrentOpen.PlotTypeName,
                                    Origin = CurrentOpen.BasePoint
                                };
                                ObjectId blockRef = bt.Add(plotTypeBlockRecord);
                                tr.AddNewlyCreatedDBObject(plotTypeBlockRecord, true);

                                //Insert the background block
                                CurrentOpen.BackgroundBlockID = Core.Utilities.InsertBlock(CurrentOpen.BasePoint, 0, objRef);
                                CurrentOpen.BlockID           = blockRef;

                                //Create and add basepoint
                                Circle bp = new Circle
                                {
                                    Center = CurrentOpen.BasePoint,
                                    Radius = 0.5f
                                };
                                BlockTableRecord acBlkTblRec = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                                if (acBlkTblRec != null)
                                {
                                    CurrentOpen.BasepointID = acBlkTblRec.AppendEntity(bp);
                                }
                                else
                                {
                                    //This should never, ever come up but best to handle it
                                    throw new NullReferenceException("Model space not found", null);
                                }

                                tr.AddNewlyCreatedDBObject(bp, true);

                                tr.Commit();
                            }

                            //Inform all event handlers the current plot type has changed
                            OnCurrentOpenChanged?.Invoke();
                        }
                        else
                        {
                            acEditor.WriteMessage("Point selection cancelled\n");
                        }
                    }
                    else
                    {
                        acEditor.WriteMessage("Plot Type Name already exists as block. Please choose a different name or rename exisitng block\n");
                    }
                }
                else
                {
                    acEditor.WriteMessage("No plot type name entered\n");
                }
            }
            else
            {
                acEditor.WriteMessage("Plot Type already open for editing. Please finalise before attempting to create a new plot type.\n");
            }
        }