예제 #1
0
        /// <summary>
        /// Inserts this instance block as a BlockReference.
        /// </summary>
        /// <param name="doc">The active document.</param>
        /// <param name="tr">The active transaction.</param>
        /// <param name="insPt">The insertion point.</param>
        /// <param name="angle">The block rotation.</param>
        /// <param name="scale">The block scale.</param>
        /// <returns>The Block Reference</returns>
        public BlockReference Insert(Document doc, Transaction tr, Point3d insPt, Double angle = 0, Double scale = 1)
        {
            BlockTable     blockTable = doc.Database.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
            AutoCADBlock   instance = null, content;
            BlockReference blockContent;
            Boolean        is2DBlock = !App.Riviera.Is3DEnabled;

            if (!blockTable.Has(this.InstanceBlockName) && this.LoadBlocks(doc, tr, out instance, out content, is2DBlock))
            {
                this.SetContent(is2DBlock, out blockContent, doc, tr);
            }
            else
            {
                this.LoadBlocks(doc, tr, out instance, out content, is2DBlock);
                instance = new AutoCADBlock(this.InstanceBlockName, tr);
            }
            if (instance != null)
            {
                BlockReference   blkRef     = instance.CreateReference(insPt, angle, scale);
                BlockTableRecord modelSpace = tr.GetModelSpace();
                blkRef.Draw(modelSpace, tr);
                AutoCADLayer lay = new AutoCADLayer(LAYER_RIVIERA_GEOMETRY, tr);
                lay.SetStatus(LayerStatus.EnableStatus, tr);
                blkRef.UpgradeOpen();
                blkRef.Layer = lay.Layername;
                return(blkRef);
            }
            else
            {
                throw new RivieraException(String.Format(ERR_LOADING_BLOCK, this.BlockName));
            }
        }
        /// <summary>
        /// Inserts this instance block as a BlockReference.
        /// </summary>
        /// <param name="doc">The active document.</param>
        /// <param name="tr">The active transaction.</param>
        /// <param name="insPt">The insertion point.</param>
        /// <param name="angle">The block rotation.</param>
        /// <param name="scale">The block scale.</param>
        /// <returns>
        /// The Block Reference
        /// </returns>
        /// <exception cref="RivieraException">Si existe un error al insertar el bloque</exception>
        public BlockReference Insert(Document doc, Transaction tr, LBlockType blockDir, Point3d insPt, double angle = 0, double scale = 1)
        {
            BlockTable   blockTable = doc.Database.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
            AutoCADBlock instance;
            Boolean      is2DBlock    = !App.Riviera.Is3DEnabled;
            String       instanceName = this.GetInstanceName(blockDir);

            if (!blockTable.Has(instanceName))
            {
                instance = this.SetContent(blockDir, is2DBlock, doc, tr);
            }
            else
            {
                Dictionary <LBlockType, AutoCADBlock> blocks2d, blocks3d;
                this.LoadBlocks(doc, tr, out blocks2d, out blocks3d);
                instance = new AutoCADBlock(instanceName, tr);
            }
            //Se realizá la inserción de la instancia
            if (instance != null)
            {
                BlockReference   blkRef     = instance.CreateReference(insPt, angle, scale);
                BlockTableRecord modelSpace = tr.GetModelSpace();
                blkRef.Draw(modelSpace, tr);
                AutoCADLayer lay = new AutoCADLayer(LAYER_RIVIERA_GEOMETRY, tr);
                lay.SetStatus(LayerStatus.EnableStatus, tr);
                blkRef.UpgradeOpen();
                blkRef.Layer = lay.Layername;
                return(blkRef);
            }
            else
            {
                throw new RivieraException(String.Format(ERR_LOADING_BLOCK, this.BlockName));
            }
        }
예제 #3
0
        /// <summary>
        /// Loads the blocks.
        /// </summary>
        /// <param name="doc">The active document.</param>
        /// <param name="tr">The active transaction.</param>
        /// <param name="instance">The instance block</param>
        /// <param name="content">The block content</param>
        /// <param name="is2DBlock">if set to <c>true</c> [is a 2D block] otherwise a 3D block.</param>
        /// <returns></returns>
        public Boolean LoadBlocks(Document doc, Transaction tr, out AutoCADBlock instance, out AutoCADBlock content, Boolean is2DBlock = true)
        {
            BlockTable blockTable = (BlockTable)doc.Database.BlockTableId.GetObject(OpenMode.ForRead);

            instance = null;
            content  = null;
            AutoCADBlock block2d, block3d;

            try
            {
                //Esta línea prueba de manerá local la carga de un bloque
                //this.Block2DName._LoadBlock(this.GetBlockFilePath().FullName, tr);
                instance = new AutoCADBlock(this.InstanceBlockName, tr);
                block2d  = new AutoCADBlock(this.Block2DName, this.GetBlockFilePath(), tr);
                block3d  = new AutoCADBlock(this.Block3DName, this.GetBlockFilePath(false), tr);
                content  = is2DBlock ? block2d : block3d;
            }
            catch (Exception exc)
            {
                string msg = String.Format(ERR_LOADING_BLOCK, this.BlockName);
                msg = NamelessUtils.FormatExceptionMessage(exc, msg);
                App.Riviera.Log.AppendEntry(msg, Protocol.Error, "LoadBlocks", "RivieraBlock");
                throw exc.CreateNamelessException <RivieraException>(msg);
            }
            return(true);
        }
        /// <summary>
        /// Draws the arrow.
        /// </summary>
        /// <param name="arrow">The arrow direction.</param>
        /// <param name="blockDirPath">The Design line bloick directory path.</param>
        /// <param name="insertionPoint">The insertion point.</param>
        /// <param name="rotation">The arrwo rotation.</param>
        /// <param name="tr">The active transaction.</param>
        /// <returns>The drew arrow</returns>
        public static ObjectId DrawArrow(this ArrowDirection arrow, Point3d insertionPoint, Double rotation, String blockDirPath, Transaction tr)
        {
            //Se realiza la selección del archivo.
            String pth = Path.Combine(blockDirPath, FOLDER_MISC);

            FileInfo[] files;
            if (Directory.Exists(pth))
            {
                files = new DirectoryInfo(pth).GetFiles();
            }
            else
            {
                files = new FileInfo[0];
            }
            string   arrowName = arrow.GetArrowDirectionName();
            FileInfo arrowFile = files.FirstOrDefault(x => x.Name.ToUpper() == String.Format("{0}.DWG", arrowName).ToUpper());

            if (arrowFile != null && arrowFile.Exists)
            {
                AutoCADBlock     arrowBlock   = new AutoCADBlock(String.Format(SUFFIX_ARROW, arrowName), arrowFile, tr);
                BlockTableRecord currentSpace = (BlockTableRecord)Application.DocumentManager.MdiActiveDocument.Database.CurrentSpaceId.GetObject(OpenMode.ForWrite);
                BlockReference   blkRef       = arrowBlock.CreateReference(insertionPoint, rotation, 1);
                return(blkRef.Draw(currentSpace, tr));
            }
            else
            {
                throw new RivieraException(String.Format(ERR_MISS_ARROW, arrowName, pth));
            }
        }
 /// <summary>
 /// Draws the in the block record the block reference only if the block record is empty.
 /// </summary>
 /// <param name="tr">The active transaction.</param>
 /// <param name="blockRecord">The block table record.</param>
 /// <param name="blkRef">The block reference.</param>
 /// <param name="is3dBlock">if set to <c>true</c> [is a 3d block].</param>
 private void DrawIn(Transaction tr, AutoCADBlock blockRecord, BlockReference blkRef, Boolean is3dBlock = false)
 {
     blockRecord.Open(tr, OpenMode.ForWrite);
     if (blockRecord.Block.OfType <ObjectId>().Count() == 0)
     {
         blockRecord.Draw(tr, blkRef);
     }
 }
        /// <summary>
        /// Loads the blocks.
        /// </summary>
        /// <param name="doc">The active document.</param>
        /// <param name="tr">The active transaction.</param>
        /// <param name="instance">The instance block</param>
        /// <param name="content">The block content</param>
        /// <param name="is2DBlock">if set to <c>true</c> [is a 2D block] otherwise a 3D block.</param>
        /// <returns></returns>
        public bool LoadBlocks(Document doc, Transaction tr, out Dictionary <LBlockType, AutoCADBlock> blocks2D, out Dictionary <LBlockType, AutoCADBlock> blocks3D)
        {
            AutoCADBlock block2d, block3d, varBlock2d, varBlock3d;

            blocks2D = new Dictionary <LBlockType, AutoCADBlock>();
            blocks3D = new Dictionary <LBlockType, AutoCADBlock>();
            string blockName    = MinSize > MaxSize ? this.VariantBlockName : this.BlockName,
                   varBlockName = MinSize > MaxSize ? this.BlockName : this.VariantBlockName;

            try
            {
                block2d = new AutoCADBlock(String.Format(Block2DName, blockName), this.GetBlockFilePath(blockName), tr);
                block3d = new AutoCADBlock(String.Format(Block3DName, blockName), this.GetBlockFilePath(blockName, false), tr);
                if (this.MinSize != this.MaxSize)
                {
                    varBlock2d = new AutoCADBlock(String.Format(SUFFIX_BLOCK2D, varBlockName), this.GetBlockFilePath(varBlockName), tr);
                    varBlock3d = new AutoCADBlock(String.Format(SUFFIX_BLOCK3D, varBlockName), this.GetBlockFilePath(varBlockName, false), tr);
                    //Registros 2D
                    blocks2D.Add(LBlockType.LEFT_START_MIN_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "2D", BLOCK_DIR_LFT), tr));
                    blocks2D.Add(LBlockType.RIGHT_START_MIN_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "2D", BLOCK_DIR_RGT), tr));
                    blocks2D.Add(LBlockType.LEFT_START_MAX_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_VAR_CONT, varBlockName, "2D", BLOCK_DIR_LFT), tr));
                    blocks2D.Add(LBlockType.RIGHT_START_MAX_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_VAR_CONT, varBlockName, "2D", BLOCK_DIR_RGT), tr));
                    //Registros 3D
                    blocks3D.Add(LBlockType.LEFT_START_MIN_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "3D", BLOCK_DIR_LFT), tr));
                    blocks3D.Add(LBlockType.RIGHT_START_MIN_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "3D", BLOCK_DIR_RGT), tr));
                    blocks3D.Add(LBlockType.LEFT_START_MAX_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_VAR_CONT, varBlockName, "3D", BLOCK_DIR_LFT), tr));
                    blocks3D.Add(LBlockType.RIGHT_START_MAX_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_VAR_CONT, varBlockName, "3D", BLOCK_DIR_RGT), tr));
                    this.InitContent(tr, blocks2D, blocks3D, block2d, block3d, varBlock2d, varBlock3d);
                }
                else
                {
                    //Registros 2D
                    blocks2D.Add(LBlockType.LEFT_SAME_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "2D", BLOCK_DIR_LFT), tr));
                    blocks2D.Add(LBlockType.RIGHT_SAME_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "2D", BLOCK_DIR_RGT), tr));
                    //Registros 3D
                    blocks3D.Add(LBlockType.LEFT_SAME_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "3D", BLOCK_DIR_LFT), tr));
                    blocks3D.Add(LBlockType.RIGHT_SAME_SIZE, new AutoCADBlock(String.Format(PREFIX_BLOCK_CONT, blockName, "3D", BLOCK_DIR_RGT), tr));
                    this.InitContent(tr, blocks2D, blocks3D, block2d, block3d);
                }
            }
            catch (Exception exc)
            {
                string msg = String.Format(ERR_LOADING_BLOCK, blockName);
                msg = NamelessUtils.FormatExceptionMessage(exc, msg);
                App.Riviera.Log.AppendEntry(msg, Protocol.Error, "LoadBlocks", "RivieraLBlock");
                return(false);
            }
            return(true);
        }
예제 #7
0
        private void InitContent(BordeoL135Panel panel, Transaction tr)
        {
            Dictionary <LBlockType, AutoCADBlock>
            blocks2D                 = new Dictionary <LBlockType, AutoCADBlock>(),
                blocks3D             = new Dictionary <LBlockType, AutoCADBlock>();
            RivieraLBlock rBlock     = (panel.Block as RivieraLBlock);
            AutoCADBlock  block2d    = new AutoCADBlock(String.Format(rBlock.Block2DName, rBlock.BlockName), rBlock.GetBlockFilePath(), tr);
            AutoCADBlock  block3d    = new AutoCADBlock(String.Format(rBlock.Block3DName, rBlock.BlockName), rBlock.GetBlockFilePath(false), tr);
            AutoCADBlock  varBlock2d = new AutoCADBlock(String.Format(SUFFIX_BLOCK2D, rBlock.VariantBlockName), rBlock.GetBlockFilePath(rBlock.VariantBlockName), tr);
            AutoCADBlock  varBlock3d = new AutoCADBlock(String.Format(SUFFIX_BLOCK3D, rBlock.VariantBlockName), rBlock.GetBlockFilePath(rBlock.VariantBlockName, false), tr);

            (panel.Block as RivieraLBlock).LoadBlocks(Application.DocumentManager.MdiActiveDocument, tr, out blocks2D, out blocks3D);
            string blockName        = block2d.Blockname.Substring(0, block2d.Blockname.Length - 2),
                   variantBlockName = varBlock2d != null?varBlock2d.Blockname.Substring(0, varBlock2d.Blockname.Length - 2) : null;

            AutoCADBlock blockRecord = blocks2D[LBlockType.LEFT_SAME_SIZE];

            blockRecord.Open(tr, OpenMode.ForWrite);
            blockRecord.Clear(tr);
            String code           = blockName.Substring(0, 6);
            Double frente1        = 18d.GetPanel135DrawingSize() * Math.Sin(Math.PI / 4),
                   frente2        = 18d.GetPanel135DrawingSize() + 18d.GetPanel135DrawingSize() * Math.Cos(Math.PI / 4);
            BlockReference blkRef = block2d.CreateReference(new Point3d(), 0);

            //Se rota 270°

            blkRef.TransformBy(Matrix3d.Rotation(-3 * Math.PI / 4, Vector3d.ZAxis, new Point3d()));
            Vector3d offset = new Vector3d(frente2, frente1, 0);

            //Offset BR2020
            if (code == CODE_PANEL_90)
            {
                offset = new Vector3d(offset.X + 0.1002d, offset.Y + 0.1002d, 0);
            }
            //Offset BR2030
            else
            {
                offset = new Vector3d(offset.X + 0.0709d, offset.Y + 0.0293d, 0);
            }
            //Se traslada el punto final al punto inicial
            blkRef.TransformBy(Matrix3d.Displacement(new Vector3d(offset.X, offset.Y, 0)));
            blockRecord.Draw(tr, blkRef);
        }
        /// <summary>
        /// Sets the instance content, depending on the if the application view
        /// is on 2D or 3D
        /// </summary>
        /// <param name="is2DBlock">if set to <c>true</c> [is a 2D block] otherwise a 3D block.</param>
        /// <param name="doc">The active document.</param>
        /// <param name="tr">The active transaction.</param>
        public AutoCADBlock SetContent(LBlockType block, Boolean is2DBlock, Document doc, Transaction tr)
        {
            Dictionary <LBlockType, AutoCADBlock> blocks2d, blocks3d;
            AutoCADBlock   instance = null;
            BlockReference blkRef;

            if (LoadBlocks(doc, tr, out blocks2d, out blocks3d))
            {
                instance = new AutoCADBlock(this.GetInstanceName(block), tr);
                instance.Clear(tr);
                if (is2DBlock)
                {
                    blkRef = blocks2d[block].CreateReference(new Point3d(), 0, 1);
                }
                else
                {
                    blkRef = blocks3d[block].CreateReference(new Point3d(), 0, 1);
                }
                instance.Draw(tr, blkRef);
            }
            return(instance);
        }
        /// <summary>
        /// Creates the left reference.
        /// </summary>
        /// <param name="blockName">Name of the block.</param>
        /// <param name="block">The block.</param>
        /// <returns></returns>
        private BlockReference CreateLeftReference(string blockName, AutoCADBlock block)
        {
            String code = blockName.Substring(0, 6);
            double frente1 = int.Parse(blockName.Substring(6, 2)),
                   frente2 = int.Parse(blockName.Substring(8, 2));
            Double         f1, f2;
            Vector3d       offset = new Vector3d();
            BlockReference blkRef = block.CreateReference(new Point3d(), 0);

            if (code == CODE_PANEL_90)//Se rota 270°
            {
                blkRef.TransformBy(Matrix3d.Rotation(3 * Math.PI / 2, Vector3d.ZAxis, new Point3d()));
            }
            else //Se rota 225° para el panel de 135°
            {
                blkRef.TransformBy(Matrix3d.Rotation(-3 * Math.PI / 4, Vector3d.ZAxis, new Point3d()));
            }

            //Offset BR2020
            if (code == CODE_PANEL_90)
            {
                f1     = frente1.GetPanel90DrawingSize();
                f2     = frente2.GetPanel90DrawingSize();
                offset = new Vector3d(f2, f1, 0);
                offset = new Vector3d(offset.X + 0.1002d, offset.Y + 0.1002d, 0);
            }
            //Offset BR2030
            else
            {
                f1     = frente1.GetPanel135DrawingSize() * Math.Sin(Math.PI / 4);
                f2     = frente2.GetPanel135DrawingSize() + frente2.GetPanel135DrawingSize() * Math.Cos(Math.PI / 4);
                offset = new Vector3d(f2, f1, 0);
                offset = new Vector3d(offset.X + 0.07085210d, offset.Y + 0.02934790d, 0);
            }
            //Se desplaza en el punto final al inicial del bloque
            blkRef.TransformBy(Matrix3d.Displacement(new Vector3d(offset.X, offset.Y, 0)));
            return(blkRef);
        }
        /// <summary>
        /// Initializes block content.
        /// </summary>
        /// <param name="blocks2D">The 2D blocks.</param>
        /// <param name="blocks3D">The 3D blocks.</param>
        /// <param name="block2d">The normal 2D block.</param>
        /// <param name="block3d">The normal 3D block</param>
        /// <param name="varBlock2d">The variant 2D block.</param>
        /// <param name="varBlock3d">The variant 3D block</param>
        private void InitContent(Transaction tr, Dictionary <LBlockType, AutoCADBlock> blocks2D, Dictionary <LBlockType, AutoCADBlock> blocks3D, AutoCADBlock block2d, AutoCADBlock block3d, AutoCADBlock varBlock2d = null, AutoCADBlock varBlock3d = null)
        {
            string blockName        = block2d.Blockname.Substring(0, block2d.Blockname.Length - 2),
                   variantBlockName = varBlock2d != null?varBlock2d.Blockname.Substring(0, varBlock2d.Blockname.Length - 2) : null;

            if (variantBlockName != null)
            {
                //Bloques 2D
                this.DrawIn(tr, blocks2D[LBlockType.RIGHT_START_MIN_SIZE], block2d.CreateReference(new Point3d(), 0));
                this.DrawIn(tr, blocks2D[LBlockType.RIGHT_START_MAX_SIZE], varBlock2d.CreateReference(new Point3d(), 0));
                this.DrawIn(tr, blocks2D[LBlockType.LEFT_START_MIN_SIZE], this.CreateLeftReference(variantBlockName, varBlock2d));
                this.DrawIn(tr, blocks2D[LBlockType.LEFT_START_MAX_SIZE], this.CreateLeftReference(blockName, block2d));
                //Bloques 3D
                this.DrawIn(tr, blocks3D[LBlockType.RIGHT_START_MIN_SIZE], block3d.CreateReference(new Point3d(), 0), true);
                this.DrawIn(tr, blocks3D[LBlockType.RIGHT_START_MAX_SIZE], varBlock3d.CreateReference(new Point3d(), 0), true);
                this.DrawIn(tr, blocks3D[LBlockType.LEFT_START_MIN_SIZE], this.CreateLeftReference(variantBlockName, varBlock3d), true);
                this.DrawIn(tr, blocks3D[LBlockType.LEFT_START_MAX_SIZE], this.CreateLeftReference(blockName, block3d), true);
            }
            else
            {
                //Bloques 2D
                this.DrawIn(tr, blocks2D[LBlockType.RIGHT_SAME_SIZE], block2d.CreateReference(new Point3d(), 0));
                this.DrawIn(tr, blocks2D[LBlockType.LEFT_SAME_SIZE], this.CreateLeftReference(blockName, block2d));
                //Bloques 3D
                this.DrawIn(tr, blocks3D[LBlockType.RIGHT_SAME_SIZE], block3d.CreateReference(new Point3d(), 0));
                this.DrawIn(tr, blocks3D[LBlockType.LEFT_SAME_SIZE], this.CreateLeftReference(blockName, block3d));
            }
        }