public void CreateCableTraysFromIntersectionPoints( List <CableTrayAndMassIntersectionModel> cableTrayAndMassFormIntersectionList, ExternalCommandData commandData) { foreach (var cableTrayAndMassInt in cableTrayAndMassFormIntersectionList) { //Выбираем точки, по которым будем создавать трубы var pointsToCreateCableTrays = new List <XYZ>(); pointsToCreateCableTrays.Add(cableTrayAndMassInt.CableTray.StarPoint); pointsToCreateCableTrays.AddRange(cableTrayAndMassInt.IntersectionPoints .OrderBy(p => p.DistanceTo(cableTrayAndMassInt.CableTray.StarPoint)).ToList()); pointsToCreateCableTrays.Add(cableTrayAndMassInt.CableTray.EndPoint); bool isNewCableTrayCreated = false; for (int i = 0; i < pointsToCreateCableTrays.Count; i++) { if (i == 0) { continue; } var currentPoint = pointsToCreateCableTrays[i]; var prevPoint = pointsToCreateCableTrays[i - 1]; if (currentPoint.IsEqualByXYZ(prevPoint, 5)) { continue; } //Создаём новую трубу по новым точкам, но присваивая свойства прошлой трубы var newCableTray = CableTraysUtils.CreateNewCableTrayByTypeOfExisted( cableTrayAndMassInt.CableTray.Model, currentPoint, prevPoint, commandData); if (newCableTray == null) { continue; } var newCableTrayModel = CableTrayModel.Create(newCableTray); if (newCableTrayModel != null) { CableTrays.Add(newCableTrayModel); isNewCableTrayCreated = true; } } //если создавался новый элемент на основе старого, то старый удаляем. if (isNewCableTrayCreated) { DeleteUtils.DeleteElements(commandData, new List <Element> { cableTrayAndMassInt.CableTray.Model }); } } }
public void CreatePipesFromIntersectionPoints( List <PipeAndMassIntersectionModel> pipeAndMassFormIntersectionList, List <List <XYZ> > pipePointsToCheckList, ExternalCommandData commandData) { #region Создаём трубы из точек пересечения foreach (var pipeAndMassInt in pipeAndMassFormIntersectionList) { //Выбираем точки, по которым будем создавать трубы var pointsToCreatePipes = new List <XYZ>(); pointsToCreatePipes.Add(pipeAndMassInt.Pipe.StarPoint); pointsToCreatePipes.AddRange(pipeAndMassInt.IntersectionPoints .OrderBy(p => p.DistanceTo(pipeAndMassInt.Pipe.StarPoint)).ToList()); pointsToCreatePipes.Add(pipeAndMassInt.Pipe.EndPoint); bool isNewPipeCreated = false; for (int i = 0; i < pointsToCreatePipes.Count; i++) { if (i == 0) { continue; } var currentPoint = pointsToCreatePipes[i]; var prevPoint = pointsToCreatePipes[i - 1]; //Проверяем, совпадают ли точки новой трубы с точками труб из модели bool areNewAndOldPipePointsMatch = false; foreach (var pointsCheck in pipePointsToCheckList) { if (pointsCheck.Count < 2) { continue; } if (pointsCheck[0].IsEqualByXYZ(currentPoint, 5) && pointsCheck[1].IsEqualByXYZ(prevPoint, 5)) { areNewAndOldPipePointsMatch = true; } else if (pointsCheck[0].IsEqualByXYZ(prevPoint, 5) && pointsCheck[1].IsEqualByXYZ(currentPoint, 5)) { areNewAndOldPipePointsMatch = true; } } if (areNewAndOldPipePointsMatch) { continue; } if (currentPoint.IsEqualByXYZ(prevPoint, 5)) { continue; } //Создаём новую трубу по новым точкам, но присваивая свойства прошлой трубы var newPipe = PipesUtils.CreateNewPipeByTypeOfExisted( pipeAndMassInt.Pipe.Model, currentPoint, prevPoint, commandData); if (newPipe == null) { continue; } var newPipeModel = PipeModel.Create(newPipe); if (newPipeModel != null) { Pipes.Add(newPipeModel); isNewPipeCreated = true; } } //если создавался новый элемент на основе старого, то старый удаляем. if (isNewPipeCreated) { DeleteUtils.DeleteElements(commandData, new List <Element> { pipeAndMassInt.Pipe.Model }); } } #endregion #region Соединяем новые трубы, соединения которых разорваны foreach (var oPipeFirst in Pipes) { foreach (var oPipeSecond in Pipes) { oPipeFirst.Model.ConnectToWithUnionFitting(oPipeSecond.Model, commandData); } } #endregion }
public void CreateDuctsFromIntersectionPoints( List <DuctAndMassIntersectionModel> ductAndMassFormIntersectionList, List <List <XYZ> > ductPointsToCheckList, ExternalCommandData commandData) { foreach (var ductAndMassInt in ductAndMassFormIntersectionList) { //Выбираем точки, по которым будем создавать трубы var pointsToCreatePipes = new List <XYZ>(); pointsToCreatePipes.Add(ductAndMassInt.Duct.StarPoint); pointsToCreatePipes.AddRange(ductAndMassInt.IntersectionPoints .OrderBy(p => p.DistanceTo(ductAndMassInt.Duct.StarPoint)).ToList()); pointsToCreatePipes.Add(ductAndMassInt.Duct.EndPoint); bool isNewPipeCreated = false; for (int i = 0; i < pointsToCreatePipes.Count; i++) { if (i == 0) { continue; } var currentPoint = pointsToCreatePipes[i]; var prevPoint = pointsToCreatePipes[i - 1]; //Проверяем, совпадают ли точки новой трубы с точками труб из модели bool areNewAndOldPipePointsMatch = false; foreach (var pointsCheck in ductPointsToCheckList) { if (pointsCheck.Count < 2) { continue; } if (pointsCheck[0].IsEqualByXYZ(currentPoint, 5) && pointsCheck[1].IsEqualByXYZ(prevPoint, 5)) { areNewAndOldPipePointsMatch = true; } else if (pointsCheck[0].IsEqualByXYZ(prevPoint, 5) && pointsCheck[1].IsEqualByXYZ(currentPoint, 5)) { areNewAndOldPipePointsMatch = true; } } if (areNewAndOldPipePointsMatch) { continue; } if (currentPoint.IsEqualByXYZ(prevPoint, 5)) { continue; } //Создаём новую трубу по новым точкам, но присваивая свойства прошлой трубы var newDuct = DuctsUtils.CreateNewDuctByTypeOfExisted( ductAndMassInt.Duct.Model, currentPoint, prevPoint, commandData); if (newDuct == null) { continue; } var newDuctModel = DuctModel.Create(newDuct); if (newDuctModel != null) { isNewPipeCreated = true; Ducts.Add(newDuctModel); } } foreach (var oDuctFirst in Ducts) { foreach (var oDuctSecond in Ducts) { oDuctFirst.Model.ConnectToWithUnionFitting(oDuctSecond.Model, commandData); } } if (isNewPipeCreated) { DeleteUtils.DeleteElements(commandData, new List <Element> { ductAndMassInt.Duct.Model }); } } }