Example #1
0
        /// <summary>
        /// set up IfcRelSequence for the task
        /// </summary>
        /// <param name="row">COBieJobRow holding the data</param>
        private void SetPriors(COBieJobRow row)
        {
            IEnumerable <IfcTask> ifcTaskFound = IfcTasks.Where(task => task.Name == row.Name && task.TaskId == row.TaskNumber);

            if (ifcTaskFound.Count() == 1) //should equal one
            {
                IfcTask ifcTask = ifcTaskFound.First();
                if (ValidateString(row.Priors))
                {
                    string   priors      = row.Priors.ToString();
                    char     splitKey    = GetSplitChar(priors);
                    string[] priorsArray = row.Priors.ToString().Split(splitKey);
                    foreach (string prior in priorsArray)
                    {
                        string name     = row.Name.ToLower().Trim();
                        string testName = prior.ToLower().Trim();
                        IEnumerable <IfcTask> ifcTaskRelating      = IfcTasks.Where(task => (ifcTask.EntityLabel != task.EntityLabel) && (task.TaskId.ToString().ToLower().Trim() == testName) && (task.Name.ToString().ToLower().Trim() == name));
                        List <IfcTask>        ifcTaskRelatingTasks = ifcTaskRelating.ToList(); //avoids crash of foreach loop, Steve to fix then this can be removed
                        foreach (IfcTask ifcTaskitem in ifcTaskRelatingTasks)
                        {
                            IfcRelSequence relSequence = Model.Instances.New <IfcRelSequence>();
                            relSequence.RelatedProcess  = ifcTask;
                            relSequence.RelatingProcess = ifcTaskitem;
                        }
                    }
                }
            }
            //throw new Exception("COBieXBimJob.SetPriors(): did not find a single task matching name and task number");
        }
Example #2
0
        /// <summary>
        /// Get the IfcTask object for the passed name
        /// </summary>
        /// <param name="name">IfcTask name</param>
        /// <returns>IfcTask Object</returns>
        private IfcTask GetTask(string name)
        {
            IfcTask ifcTask = null;

            if (IfcTasks == null)
            {
                IfcTasks = Model.Instances.OfType <IfcTask>();
            }

            name    = name.ToLower().Trim();
            ifcTask = IfcTasks.Where(t => t.Name.ToString().ToLower().Trim() == name).FirstOrDefault();


            return(ifcTask);
        }
Example #3
0
        /// <summary>
        /// Get required resources for the task
        /// </summary>
        /// <param name="ifcTask">IfcTask object to get resources for</param>
        /// <returns>delimited string of the resources</returns>
        private string GetResources(IfcTask ifcTask)
        {
            IEnumerable <IfcConstructionEquipmentResource> ifcConstructionEquipmentResources = ifcTask.OperatesOn.SelectMany(ratp => ratp.RelatedObjects.OfType <IfcConstructionEquipmentResource>());
            List <string> strList = new List <string>();

            foreach (IfcConstructionEquipmentResource ifcConstructionEquipmentResource in ifcConstructionEquipmentResources)
            {
                if ((ifcConstructionEquipmentResource != null) && (!string.IsNullOrEmpty(ifcConstructionEquipmentResource.Name.ToString())))
                {
                    if (!strList.Contains(ifcConstructionEquipmentResource.Name.ToString()))
                    {
                        strList.Add(ifcConstructionEquipmentResource.Name.ToString());
                    }
                }
            }
            return((strList.Count > 0) ? (string.Join(", ", strList) + ".") : DEFAULT_STRING);
        }
Example #4
0
        /// <summary>
        /// Get the number of tasks before this task
        /// </summary>
        /// <param name="ifcTask">IfcTask object</param>
        /// <returns>string holding predecessor name of last task(s)</returns>
        private string GetPriors(IfcTask ifcTask)
        {
            IEnumerable <IfcRelSequence> isSuccessorFrom = ifcTask.IsSuccessorFrom;
            List <string> relatingTasks = new List <string>();

            foreach (IfcRelSequence ifcRelSequence in isSuccessorFrom)
            {
                IfcTask relatingIfcTask = ifcRelSequence.RelatingProcess as IfcTask;
                if (relatingIfcTask != null)
                {
                    relatingTasks.Add(relatingIfcTask.TaskId.ToString().Trim());
                }
            }

            if (relatingTasks.Count > 0)
            {
                return(string.Join(":", relatingTasks));
            }
            else
            {
                return(ifcTask.TaskId.ToString().Trim()); //if no priors, reference itself
            }
        }
Example #5
0
        /// <summary>
        /// Get the object IfcTypeObject name from the IfcTask object
        /// </summary>
        /// <param name="ifcTask">IfcTask object</param>
        /// <returns>string holding IfcTypeObject name</returns>
        private string GetObjectType(IfcTask ifcTask)
        {
            //first try
            IEnumerable <IfcTypeObject> ifcTypeObjects = ifcTask.OperatesOn.SelectMany(ratp => ratp.RelatedObjects.OfType <IfcTypeObject>());

            //second try on IsDefinedBy.OfType<IfcRelDefinesByType>
            if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0))
            {
                ifcTypeObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByType>().Select(idb => (idb as IfcRelDefinesByType).RelatingType);
            }

            //third try on IsDefinedBy.OfType<IfcRelDefinesByProperties> for DefinesType
            if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0))
            {
                ifcTypeObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByProperties>().SelectMany(idb => (idb as IfcRelDefinesByProperties).RelatingPropertyDefinition.DefinesType);
            }

            //convert to string and return if all ok
            if ((ifcTypeObjects != null) || (ifcTypeObjects.Count() > 0))
            {
                List <string> strList = new List <string>();
                foreach (IfcTypeObject ifcTypeItem in ifcTypeObjects)
                {
                    if ((ifcTypeItem != null) && (!string.IsNullOrEmpty(ifcTypeItem.Name.ToString())))
                    {
                        if (!strList.Contains(ifcTypeItem.Name.ToString()))
                        {
                            strList.Add(ifcTypeItem.Name.ToString());
                        }
                    }
                }
                return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING);
            }


            //last try on IsDefinedBy.OfType<IfcRelDefinesByProperties> for IfcObject
            if ((ifcTypeObjects == null) || (ifcTypeObjects.Count() == 0))
            {
                IEnumerable <IfcObject> ifcObjects = ifcTask.IsDefinedBy.OfType <IfcRelDefinesByProperties>().SelectMany(idb => idb.RelatedObjects);
                List <string>           strList    = new List <string>();
                foreach (IfcObject ifcObject in ifcObjects)
                {
                    IEnumerable <IfcRelDefinesByType> ifcRelDefinesByTypes = ifcObject.IsDefinedBy.OfType <IfcRelDefinesByType>();
                    foreach (IfcRelDefinesByType ifcRelDefinesByType in ifcRelDefinesByTypes)
                    {
                        if ((ifcRelDefinesByType != null) &&
                            (ifcRelDefinesByType.RelatingType != null) &&
                            (!string.IsNullOrEmpty(ifcRelDefinesByType.RelatingType.Name.ToString()))
                            )
                        {
                            if (!strList.Contains(ifcRelDefinesByType.RelatingType.Name.ToString()))
                            {
                                strList.Add(ifcRelDefinesByType.RelatingType.Name.ToString());
                            }
                        }
                    }
                    return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING);
                }
                return((strList.Count > 0) ? COBieXBim.JoinStrings(':', strList) : DEFAULT_STRING);
            }

            return(DEFAULT_STRING); //fail to get any types
        }
Example #6
0
        /// <summary>
        /// Add the data to the IfcTask object
        /// </summary>
        /// <param name="row">COBieJobRow holding the data</param>
        private void AddJob(COBieJobRow row)
        {
            IEnumerable <IfcTypeObject> ifcTypeObjects = Enumerable.Empty <IfcTypeObject>();
            IfcTask ifcTask = null;

            //get the objects in the typeName cell
            if (ValidateString(row.TypeName))
            {
                List <string> typeNames = SplitString(row.TypeName, ':');
                ifcTypeObjects = IfcTypeObjects.Where(to => typeNames.Contains(to.Name.ToString().Trim()));
            }

            //if merging check for existing task
            if (XBimContext.IsMerge)
            {
                string taskNo = string.Empty;
                //get the task ID
                if (ValidateString(row.TaskNumber))
                {
                    taskNo = row.TaskNumber;
                }
                //see if task matches name and task number
                ifcTask = CheckIfObjExistOnMerge <IfcTask>(row.Name).Where(task => task.TaskId == taskNo).FirstOrDefault();
                if (ifcTask != null)
                {
                    IfcRelAssignsToProcess processRel = Model.Instances.Where <IfcRelAssignsToProcess>(rd => rd.RelatingProcess == ifcTask).FirstOrDefault();
                    int matchCount = ifcTypeObjects.Count(to => processRel.RelatedObjects.Contains(to));
                    if (matchCount == ifcTypeObjects.Count()) //task IfcRelAssignsToProcess object hold the correct number of ifcTypeObjects objects so consider a match
                    {
                        return;                               //consider a match so return
                    }
                }
            }

            //no match on task
            ifcTask = Model.Instances.New <IfcTask>();

            //Add Created By, Created On and ExtSystem to Owner History.
            SetUserHistory(ifcTask, row.ExtSystem, row.CreatedBy, row.CreatedOn);

            //using statement will set the Model.OwnerHistoryAddObject to ifcConstructionEquipmentResource.OwnerHistory as OwnerHistoryAddObject is used upon any property changes,
            //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement
            using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcTask.OwnerHistory))
            {
                //Add Name
                if (ValidateString(row.Name))
                {
                    ifcTask.Name = row.Name;
                }

                //Add Category
                if (ValidateString(row.Category))
                {
                    ifcTask.ObjectType = row.Category;
                }

                //AddStatus
                if (ValidateString(row.Status))
                {
                    ifcTask.Status = row.Status;
                }

                //Add Type Relationship
                if (ifcTypeObjects.Any())
                {
                    SetRelAssignsToProcess(ifcTask, ifcTypeObjects);
                }
                //Add GlobalId
                AddGlobalId(row.ExtIdentifier, ifcTask);

                //add Description
                if (ValidateString(row.Description))
                {
                    ifcTask.Description = row.Description;
                }


                //Add Duration and duration Unit
                if (ValidateString(row.Duration))
                {
                    IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", "Job Properties From COBie", "TaskDuration", "Task Duration", new IfcReal(row.Duration));
                    //DurationUnit
                    if (ValidateString(row.DurationUnit))
                    {
                        ifcPropertySingleValue.Unit = GetDurationUnit(row.DurationUnit);
                    }
                }

                //Add start time and start unit
                if (ValidateString(row.Start))
                {
                    IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", null, "TaskStartDate", "Task Start Date", new IfcText(row.Start));
                    //TaskStartUnit
                    if (ValidateString(row.TaskStartUnit))
                    {
                        ifcPropertySingleValue.Unit = GetDurationUnit(row.TaskStartUnit);
                    }
                }

                //Add frequency and frequency unit
                if (ValidateString(row.Frequency))
                {
                    IfcPropertySingleValue ifcPropertySingleValue = AddPropertySingleValue(ifcTask, "Pset_Job_COBie", null, "TaskInterval", "Task Interval", new IfcReal(row.Frequency));
                    //TaskStartUnit
                    if (ValidateString(row.FrequencyUnit))
                    {
                        ifcPropertySingleValue.Unit = GetDurationUnit(row.FrequencyUnit);
                    }
                }

                //Add Task ID
                if (ValidateString(row.TaskNumber))
                {
                    ifcTask.TaskId = row.TaskNumber;
                }

                //Add Priors, done in another loop see above

                //Add Resource names
                if (ValidateString(row.ResourceNames))
                {
                    List <string> Resources = row.ResourceNames.Split(',').ToList <string>(); //did dangerous using , as ',' as user can easily place out of sequence.
                    for (int i = 0; i < Resources.Count; i++)
                    {
                        Resources[i] = Resources[i].ToLower().Trim().Replace(".", string.Empty); //remove full stop
                    }
                    IEnumerable <IfcConstructionEquipmentResource> ifcConstructionEquipmentResource = IfcConstructionEquipmentResources.Where(cer => Resources.Contains(cer.Name.ToString().ToLower().Trim().Replace(".", string.Empty)));
                    if (ifcConstructionEquipmentResource != null)
                    {
                        SetRelAssignsToProcess(ifcTask, ifcConstructionEquipmentResource);
                    }
                }
            }
        }