Exemplo n.º 1
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 Block[] ImportAll(string filePath)
        {
            string kMethodName = "Block.ImportAll";

            filePath = GeometryExtension.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 <Block> blocks     = new List <Block>();

            foreach (var name in blockNames)
            {
                Block block = new Block(name, filePath);
                blocks.Add(block);
            }
            return(blocks.ToArray());
        }
Exemplo n.º 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 Block Import(string blockName, string filePath)
        {
            string kMethodName = "Block.Import";

            filePath = GeometryExtension.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 Block(blockName, filePath));
        }
Exemplo n.º 3
0
 internal static IGeometryEntity[] ImportFromSAT(ref string fileName)
 {
     if (string.IsNullOrWhiteSpace(fileName))
     {
         throw new System.ArgumentNullException("fileName");
     }
     fileName = GeometryExtension.LocateFile(fileName);
     if (!File.Exists(fileName))
     {
         throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, fileName), "fileName");
     }
     IGeometryEntity[] objects = HostFactory.Factory.LoadSat(fileName);
     return(objects);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an array of Sub Division Mesh from the .Obj file given by the user.
        /// Each Group within the .Obj file is represented by one SubDivsion Mesh.
        /// </summary>
        /// <param name="filePath">The file to be imported</param>
        /// <returns></returns>
        public static SubDivisionMesh[] ImportFromOBJ(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new System.ArgumentNullException("filePath");
            }
            filePath = GeometryExtension.LocateFile(filePath);
            if (!File.Exists(filePath))
            {
                throw new System.ArgumentException(string.Format(Properties.Resources.FileNotFound, filePath), "filePath");
            }
            MeshData result = ObjHandler.Import(filePath);

            return(result.ConvertToSubDivisionMesh());
        }
Exemplo n.º 5
0
        internal static IBlockEntity InsertCore(CoordinateSystem contextCoordinateSystem, ref string fileName, string blockName)
        {
            string kMethodName = "Block.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 = GeometryExtension.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);
        }
Exemplo n.º 6
0
        private HostFactory()
        {
            try
            {
                string factoryFilePath       = null;
                string persistentMgrFilePath = null;

                bool found = GetFactoryFileFromSessionConfig(ref factoryFilePath, ref persistentMgrFilePath);

                if (!found)
                {
                    found = GetFactoryFileFromExeConfig(ref factoryFilePath, ref persistentMgrFilePath);
                }

                // If not set by external applications, use the one in ProtoGeometry.config as a back-up.
                if (!found)
                {
                    found = GetFactoryFileFromGeometryConfig(ref factoryFilePath, ref persistentMgrFilePath);
                }

                if (found)
                {
                    factoryFilePath       = GeometryExtension.LocateFile(factoryFilePath);
                    persistentMgrFilePath = GeometryExtension.LocateFile(persistentMgrFilePath);
                }

                string protoAcadGeometryPath = null;
                //If the configured factory file path is not correct or does not exist, use the default one
                if (string.IsNullOrEmpty(factoryFilePath) || !File.Exists(factoryFilePath))
                {
                    factoryFilePath = GeometryExtension.LocateFile("ProtoAcadGeometry.dll");
                    if (!File.Exists(factoryFilePath))
                    {
                        factoryFilePath = GeometryExtension.LocateFile("DSGeometry.dll"); //For nunit-testing
                        if (!File.Exists(factoryFilePath))
                        {
                            factoryFilePath = null;
                        }
                    }
                    else
                    {
                        protoAcadGeometryPath = factoryFilePath;
                    }
                }

                //If the configured persistent manager file path is not correct or does not exist, use "ProtoAcadGeometry.dll"
                if (string.IsNullOrEmpty(persistentMgrFilePath) || !File.Exists(persistentMgrFilePath))
                {
                    persistentMgrFilePath = protoAcadGeometryPath;
                }

                //Lastly create the factory and persistent manager instance
                if (null == mGeometryFactory && !string.IsNullOrEmpty(factoryFilePath))
                {
                    mGeometryFactory = CreateInstance(typeof(IGeometryFactory), factoryFilePath) as IGeometryFactory;
                }
                if (null == mPersistenceManager && !string.IsNullOrEmpty(persistentMgrFilePath))
                {
                    mPersistenceManager = CreateInstance(typeof(IPersistenceManager), persistentMgrFilePath) as IPersistenceManager;
                }

                //Initialize persistence manager with geometry factory
                if (null != mPersistenceManager && null != mGeometryFactory)
                {
                    mPersistenceManager.GeometryFactory = mGeometryFactory;
                }

                if (!ExtensionApplicationStarted && mExtensionApplications.Count > 0)
                {
                    foreach (IExtensionApplication app in mExtensionApplications)
                    {
                        app.OnBeginExecution(Application.Instance.Session);
                    }
                    ExtensionApplicationStarted = true;
                }
            }
            catch (System.Exception ex)
            {
                if (ex.InnerException != null)
                {
                    System.Diagnostics.Debug.Write(ex.InnerException);
                }
                System.Diagnostics.Debug.Write(ex);
                mErrorString = ex.Message;
            }
        }