示例#1
0
        /// <summary>
        /// Creates a block with the given name, reference coordinate system and from the
        /// specified geometries
        /// </summary>
        /// <param name="blockName">the block name</param>
        /// <param name="referenceCoordinateSystem">the reference coordinate system</param>
        /// <param name="contents">the geometries contained in the block</param>
        /// <returns></returns>
        public static DSBlock FromGeometry(string blockName, DSCoordinateSystem referenceCoordinateSystem,
                                           DSGeometry[] contents)
        {
            string kMethodName = "DSBlock.FromGeometry";

            if (null == referenceCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IGeometryEntity[] hosts = contents.ConvertAll(DSGeometryExtension.ToEntity <DSGeometry, IGeometryEntity>);
            if (null == hosts || hosts.Length == 0)
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, "geometries", kMethodName), "geometries");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            if (helper.DefineBlock(referenceCoordinateSystem.CSEntity, blockName, hosts))
            {
                return(new DSBlock(blockName));
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Imports a block with the given name from the outside file to the
        /// current drawing
        /// </summary>
        /// <param name="blockName">the given block name</param>
        /// <param name="filePath">the file path for the outside file</param>
        /// <returns></returns>
        public static DSBlock Import(string blockName, string filePath)
        {
            string kMethodName = "DSBlock.Import";

            filePath = DSGeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }

            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            helper.ImportBlockFromFile(filePath, blockName);
            return(new DSBlock(blockName, filePath));
        }
示例#3
0
        /// <summary>
        /// Rename specified block to new name
        /// </summary>
        /// <param name="oldName">
        /// The block to be renamed, must exist in current file</param>
        /// <param name="newName">
        /// New name of the block, must not exist</param>
        /// <returns>Returns true if successfully renamed, else false</returns>
        public bool Rename(string newName)
        {
            string kMethodName = "DSBlock.Rename";

            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "oldName");
            }

            if (string.IsNullOrEmpty(newName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, newName, kMethodName), "newName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            if (helper.RenameBlock(Name, newName))
            {
                Name = newName;
                return(true);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        /// Imports all blocks in the outside file to the current drawing
        /// </summary>
        /// <param name="filePath">the file path for the outside file</param>
        /// <returns></returns>
        public static DSBlock[] ImportAll(string filePath)
        {
            string kMethodName = "DSBlock.ImportAll";

            filePath = DSGeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            string[]       blockNames = helper.ImportAllBlocksFromFile(filePath);
            List <DSBlock> blocks     = new List <DSBlock>();

            foreach (var name in blockNames)
            {
                DSBlock block = new DSBlock(name, filePath);
                blocks.Add(block);
            }
            return(blocks.ToArray());
        }
示例#5
0
文件: Plugins.cs 项目: 15831944/Sheet
 public InvertLineStartPlugin(IServiceLocator serviceLocator)
 {
     _serviceLocator  = serviceLocator;
     _blockController = serviceLocator.GetInstance <IBlockController>();
     _blockFactory    = serviceLocator.GetInstance <IBlockFactory>();
     _blockHelper     = serviceLocator.GetInstance <IBlockHelper>();
 }
示例#6
0
        /// <summary>
        /// Exports the geometries of the block to the outside file.
        /// This is similar to AutoCAD's wblock operation.
        /// </summary>
        /// <param name="filePath">The outside file path</param>
        /// <returns>Returns true if the export operation is successful</returns>
        public bool ExportGeometry(string filePath)
        {
            filePath = DSGeometry.GetFullPath(filePath);

            string kMethodName = "DSBlock.ExportGeometry";

            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, filePath, kMethodName), "filePath");
            }

            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "sourceBlockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            return(helper.ExportBlock(filePath, Name));
        }
示例#7
0
        /// <summary>
        /// Instantiates the specified block by name with the orientation
        /// specified by the coordinate system into the target file.
        /// If the block does not exist in the target file, the block will be exported to the
        /// target file first.
        /// If the block already exists in the target file, the old block will be replaced with
        /// the new one.
        /// </summary>
        /// <param name="contextCoordinateSystem">
        /// Specifies the orientation of the block. Origin is the placement point.
        /// This coordinate system must be orthogonal, can be non-uniformly scaled
        /// </param>
        /// <param name="targetFileName">the outside file name</param>
        /// <returns>If the insertion succeeds, returns true</returns>
        public bool ByCoordinateSystem(DSCoordinateSystem contextCoordinateSystem, string targetFileName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(targetFileName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "blockName");
            }

            targetFileName = DSGeometry.GetFullPath(targetFileName);

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            return(helper.InsertBlockInTargetFile(contextCoordinateSystem.CSEntity, Name, targetFileName));
        }
示例#8
0
 public BlockController(IServiceLocator serviceLocator)
 {
     this._serviceLocator  = serviceLocator;
     this._blockHelper     = serviceLocator.GetInstance <IBlockHelper>();
     this._blockSerializer = serviceLocator.GetInstance <IBlockSerializer>();
     this._pointController = serviceLocator.GetInstance <IPointController>();
 }
示例#9
0
        public SheetEllipseMode(IServiceLocator serviceLocator, SheetState state)
        {
            this._serviceLocator  = serviceLocator;
            this._blockController = serviceLocator.GetInstance <IBlockController>();
            this._blockFactory    = serviceLocator.GetInstance <IBlockFactory>();
            this._blockHelper     = serviceLocator.GetInstance <IBlockHelper>();
            this._itemController  = serviceLocator.GetInstance <IItemController>();
            this._pointController = serviceLocator.GetInstance <IPointController>();

            this._state = state;
        }
示例#10
0
        /// <summary>
        /// Checks if specified block exists in current file
        /// </summary>
        /// <param name="blockName">Name of the block</param>
        /// <returns>Returns true if the block exists else false</returns>
        public static bool Exists(string blockName)
        {
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, "DSBlock.Exists"), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSBlock.Exists"));
            }

            return(helper.BlockExistsInCurrentDocument(blockName));
        }
示例#11
0
        /// <summary>
        /// Removes unused block definitions from current file
        /// </summary>
        /// <param name="blockName">
        /// The name of the block to be purged, the block must exist in current
        /// file</param>
        /// <returns>Returns true if the block-definition could be purged,
        /// else false</returns>
        public static bool Purge(string blockName)
        {
            string kMethodName = "DSBlock.Purge";

            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            return(helper.PurgeBlock(blockName));
        }
示例#12
0
        /// <summary>
        /// Lists the types of geometry in the block
        /// </summary>
        /// <returns>All the type names</returns>
        public string[] ContainedGeometryTypes()
        {
            string kMethodName = "DSBlock.ContainedGeometryTypes";

            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, Name, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            return(helper.ListContentsOfBlock(Name));
        }
示例#13
0
        /// <summary>
        /// Lists all available blocks in the current drawing
        /// </summary>
        /// <returns></returns>
        public static DSBlock[] AvailableBlockDefinitions()
        {
            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "DSBlock.AvailableBlockDefinitions"));
            }

            string[]       blockNames = helper.ListAllBlocksInCurrentDocument();
            List <DSBlock> blocks     = new List <DSBlock>();

            foreach (var name in blockNames)
            {
                DSBlock block = new DSBlock(name);
                blocks.Add(block);
            }
            return(blocks.ToArray());
        }
示例#14
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, ref string fileName, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            fileName = DSGeometryExtension.LocateFile(fileName);
            if (!File.Exists(fileName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }

            IBlockEntity entity = helper.InsertBlockFromFile(contextCoordinateSystem.CSEntity, fileName, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
示例#15
0
        internal static IBlockEntity InsertCore(DSCoordinateSystem contextCoordinateSystem, string blockName)
        {
            string kMethodName = "DSBlock.ByCoordinateSystem ";

            if (null == contextCoordinateSystem)
            {
                throw new ArgumentNullException("contextCoordinateSystem");
            }
            if (contextCoordinateSystem.IsSheared)
            {
                throw new ArgumentException(string.Format(Properties.Resources.Sheared, "contextCoordinateSystem"), "contextCoordinateSystem");
            }
            if (string.IsNullOrEmpty(blockName))
            {
                throw new ArgumentException(string.Format(Properties.Resources.InvalidInput, blockName, kMethodName), "blockName");
            }

            IBlockHelper helper = HostFactory.Factory.GetBlockHelper();

            if (null == helper)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            if (!helper.BlockExistsInCurrentDocument(blockName))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.DoesNotExist, "DSBlock : " + blockName));
            }

            IBlockEntity entity = helper.InsertBlockFromCurrentDocument(contextCoordinateSystem.CSEntity, blockName);

            if (null == entity)
            {
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, kMethodName));
            }
            return(entity);
        }
示例#16
0
 public void Init(IWorldManager world, long seed)
 {
     _Seed        = seed;
     _World       = world;
     _blockHelper = _World.GetServer().GetBlockHelper();
 }
示例#17
0
 public BlockHelperTests()
 {
     this.blockHelper = new BlockHelper();
 }
示例#18
0
 public PointController(IServiceLocator serviceLocator)
 {
     this._serviceLocator = serviceLocator;
     this._blockHelper    = _serviceLocator.GetInstance <IBlockHelper>();
 }
示例#19
0
 public BlockCreator()
 {
     this.blockHelper = new BlockHelper();
 }
示例#20
0
 public static void RegisterHelper(IBlockHelper helper, string helperName = null)
 {
     helperName = helperName ?? helper.GetType().Name;
     Engine.Value.RegisterHelper(helperName, (tw, opts, ctx, args) => helper.Run(tw, opts, ctx, args));
 }
示例#21
0
 public void Init(IWorldManager world, long seed)
 {
     _Seed = seed;
     _World = world;
     _blockHelper = _World.GetServer().GetBlockHelper();
 }
示例#22
0
 public void Init(long seed, IBlockHelper helper)
 {
     _blockHelper = helper;
     _Seed = seed;
 }
示例#23
0
 public static void RegisterHelper(IBlockHelper helper, string helperName = null)
 {
     helperName = helperName ?? helper.GetType().Name;
     Engine.Value.RegisterHelper(helperName, (tw, opts, ctx, args) => helper.Run(tw, opts, ctx, args));
 }
 public ViewModelFactory(IBlockHelper blockHelper, IEpiServerDependencies epiServerDependencies)
 {
     _blockHelper           = blockHelper;
     _epiServerDependencies = epiServerDependencies;
 }
 public ViewModelFactory(IBlockHelper blockHelper, IEpiServerDependencies epiServerDependencies)
 {
     _blockHelper = blockHelper;
     _epiServerDependencies = epiServerDependencies;
 }
示例#26
0
 public void Init(long seed, IBlockHelper helper)
 {
     _blockHelper = helper;
     _Seed        = seed;
 }
示例#27
0
 public BlockSerializer(IServiceLocator serviceLocator)
 {
     this._serviceLocator = serviceLocator;
     this._blockHelper    = serviceLocator.GetInstance <IBlockHelper>();
     this._blockFactory   = serviceLocator.GetInstance <IBlockFactory>();
 }