public static LineBasedFamilyCreator_onPlanarFace CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange) { var refDoc = _fi.Document; var refDocId = refDoc.Identifier(); var tarDocId = _tarDoc.Identifier(); var locLine = _fi.LocationLine(); var offsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_fi); var param = _fi.GetAllEditableParams(); DesignOption dop; string dopUid, dopName; OpContext.GetActiveDesignOptionInfo(_tarDoc, out dop, out dopUid, out dopName); var opContext = new OpContext(refDocId, tarDocId, refDoc, _tarDoc, dopUid, dopName, _fi.Id); var hostCat = HostUtils.GetHostCategory(_fi); var hostDir = HostUtils.GetHostDir(_fi); var faceNorm = _fi.GetPlane().Normal; var bb = _fi.GetBoundingBoxInModelCS(null); var bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange); var search = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, faceNorm, dop); Element host; var hostFace = search.FindHostFace(locLine, out host); var ctr = new LineBasedFamilyCreator_onPlanarFace (_fi.Symbol, offsetLocLine, _fi.FacingOrientation, host, hostFace, param, opContext); Methods.GetCutsAndJoins(_fi, out ctr.Cuts, out ctr.CutBy, out ctr.Joins); ctr.CutsHost = HostUtils.CutsHost(_fi); return(ctr); }
public static FamilyCreator CreateSimilar(FamilyInstance _fi, Document _tarDoc, int _hostLevel) { var type = HostUtils.GetHostingType(_fi); if (type == HostingType.FaceBased) { return(FaceBasedFamilyCreator.CreateSimilar(_fi, _tarDoc, _hostLevel)); } else if (type == HostingType.LineBasedOnLevel) { return(LineBasedFamilyCreator_onLevel.CreateSimilar(_fi, _tarDoc, _hostLevel)); } else if (type == HostingType.LineBasedOnFace) { return(LineBasedFamilyCreator_onPlanarFace.CreateSimilar(_fi, _tarDoc, _hostLevel)); } else if (type == HostingType.WallBased) { return(WallBasedFamilyCreator.CreateSimilar(_fi, _tarDoc, _hostLevel)); } else { return(null); } }
public static FaceBasedFamilyCreator CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange) { var refDoc = _fi.Document; var pos = _fi.GetPos(); var hostCat = HostUtils.GetHostCategory(_fi); var bb = _fi.GetBoundingBoxInModelCS(null); var bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange); XYZ faceNorm = null; DesignOption dop; string dopUid, dopName; OpContext.GetActiveDesignOptionInfo(_tarDoc, out dop, out dopUid, out dopName); var hostDir = HostUtils.GetHostDir(_fi); var search = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, faceNorm, dop); Element host; var hostFace = search.FindHostFace(pos, out host); var param = _fi.GetAllEditableParams(); var refDocId = refDoc.Identifier(); var tarDocId = _tarDoc.Identifier(); var opContext = new OpContext(refDocId, tarDocId, refDoc, _tarDoc, dopUid, dopName, _fi.Id); var ctr = new FaceBasedFamilyCreator (_fi.Symbol, _fi.Host, hostFace, pos, _fi.HandOrientation, _fi.FacingOrientation, param, opContext); return(ctr); }
public override void PostProcess() { SetOrientation(this.FI, this.hand, this.facing); HostUtils.CutUncutHost(this.FI, base.cutHost); base.CutAndJoin(); this.OperationFinished = true; }
/// <summary> /// Copy wall-based family instances to multiple levels. /// </summary> /// <param name="_refs">wall-based family instances to be copied.</param> /// <param name="_tarLevels">target levels</param> /// <param name="_baseLevel">base level for calculating height change.</param> /// <param name="_snapShot">snap shot of potential host walls. Need to scan before calling this method.</param> /// <returns>wall-based family creators.</returns> public static List <FamilyCreator> CopyToLevels (FamilyInstance refFI, IEnumerable <Level> _tarLevels, Level _baseLevel, double _searchRange) { var doc = refFI.Document; var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption; var ops = new List <FamilyCreator>(); var refPoints = HostUtils.GetPointsInsideWallHost(refFI); //get params var param = refFI.GetAllEditableParams(); //get orientation var hand = refFI.HandOrientation; var facing = refFI.FacingOrientation; //search cat var bbRef = refFI.GetBoundingBoxForSolidGeometries(); if (bbRef == null) { bbRef = refFI.GetBoundingBoxInModelCS(null); } var hostDir = HostUtils.GetHostDir(refFI); foreach (var tarLevel in _tarLevels) { //skip base level if (tarLevel.Id == _baseLevel.Id) { continue; } var deltaZ = tarLevel.ProjectElevation - _baseLevel.ProjectElevation; var tf = Transform.CreateTranslation(new XYZ(0, 0, deltaZ)); var tarPoints = refPoints.Select(x => tf.OfPoint(x)).ToList(); //search host face var bbTar = bbRef.GetTransformed(tf); var bbFilter = Methods.GetBBIntersectFilter(bbTar, _searchRange); var search = new HostSearchSession(doc, HostCategory.Wall, bbFilter, hostDir, null, dop); var hostWall = search.FindHostWall(tarPoints); if (hostWall == null) { throw new HostNotFoundException(refFI.Id.ToString()); } var tarPos = tf.OfPoint(refFI.GetPos()); var ctr = new WallBasedFamilyCreator (refFI.Symbol, hostWall, tarPos, hand, facing, refFI.StructuralType, param, null); ops.Add(ctr); } return(ops); }
private void calcOffset() { var norm = HostUtils.GetHostNormal(this.NewFI); var p0 = this.NewFI.LocationCurve().GetEndPoint(0); var pOffset = this.OffsetLocLine.GetEndPoint(0); var totalOffset = (pOffset - p0).DotProduct(norm); double symbolOffset = LineBasedFamilyUtils.GetSymbolOffset(this.fs); double profileOffset = LineBasedFamilyUtils.GetProfileOffset(this.fs); double instanceOffset = totalOffset - symbolOffset - profileOffset; this.NewFI.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_OFFSET_PARAM).Set(instanceOffset); }
public FamilyCreator GetSimilarCreator() { var info = new LineBasedFamilyInfo(this.FI); if (info.HostCondition == HostCondition.Level) { var level = this.FI.Host as Level; this.SimilarCreator = new LineBasedFamilyCreator_onLevel (this.FI.Symbol, this.OffsetLocLine, this.facing, level, this.FI.StructuralType, this.paramValues, this.Context); } else { if (this.FI.HostFace != null && this.FI.HostFace.ElementReferenceType != ElementReferenceType.REFERENCE_TYPE_NONE) { this.SimilarCreator = new LineBasedFamilyCreator_onPlanarFace (this.FI.Symbol, this.OffsetLocLine, this.facing, this.FI.HostFace, this.paramValues, this.Context); } else { //search for host face on the run var locLine = this.FI.LocationLine(); var hostCat = HostUtils.GetHostCategory(this.FI); var bbFilter = Methods.GetBBIntersectFilter (this.FI.GetBoundingBoxInModelCS(null), HostSearchSession.HostSearchRange); var hostDir = HostUtils.GetHostDir(this.FI); var faceNorm = this.FI.GetPlane().Normal; var dop = this.FI.DesignOption; var search = new HostSearchSession (this.FI.Document, hostCat, bbFilter, hostDir, faceNorm, dop); Element host; var hostFace = search.FindHostFace(locLine, out host); if (hostFace == null) { throw new goa.Common.Exceptions.HostNotFoundException(this.FI.Id.ToString()); } this.SimilarCreator = new LineBasedFamilyCreator_onPlanarFace (this.FI.Symbol, this.OffsetLocLine, this.facing, host, hostFace, this.paramValues, this.Context); } Methods.GetCutsAndJoins (this.FI, out this.SimilarCreator.Cuts, out this.SimilarCreator.CutBy, out this.SimilarCreator.Joins); } return(this.SimilarCreator); }
public static FamilyCreator Mirror (FamilyInstance refFI, Plane _mirrorPlane, double _hostSearchRange) { var doc = refFI.Document; var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption; var tf = Transform.CreateReflection(_mirrorPlane); var refPoints = HostUtils.GetPointsInsideWallHost(refFI); var tarPoints = refPoints.Select(x => tf.OfPoint(x)).ToList(); //get params var param = refFI.GetAllEditableParams(); //get orientation var hand = tf.OfVector(refFI.HandOrientation); var facing = tf.OfVector(refFI.FacingOrientation); //host search var refHostDir = HostUtils.GetHostDir(refFI); var hostDir = refHostDir == null ? null : tf.OfVector(refHostDir); var bb = refFI.GetBoundingBoxForSolidGeometries(); if (bb == null) { bb = refFI.GetBoundingBoxInModelCS(null); } var bbMr = bb.GetTransformed(tf); var bbFilter = Methods.GetBBIntersectFilter(bbMr, 3.0); var search = new HostSearchSession(doc, HostCategory.Wall, bbFilter, hostDir, null, dop); var hostWall = search.FindHostWall(tarPoints); if (hostWall == null) { throw new HostNotFoundException(refFI.Id.ToString()); } var tarPos = tf.OfPoint(refFI.GetPos()); var ctr = new WallBasedFamilyCreator (refFI.Symbol, hostWall, tarPos, hand, facing, refFI.StructuralType, param, null); return(ctr); }
/// <summary> /// after creation, need to regen doc to get /// corrent orientation info. /// </summary> public override void PostProcess() { if (this.NewFI != null && this.NewFI.IsValidObject) { if (facingRefPoint != null) { adjustFacingByRefPoint(this.NewFI); } FamilyEditor.SetOrientation(this.NewFI, this.Hand, this.Facing); //cuts needs to be inside post process //otherwise face change might affect creation of other new instances. HostUtils.CutUncutHost(this.NewFI, this.CutsHost); base.CutAndJoin(); this.OperationFinished = true; } }
/// <summary> /// TRANSACTION INSIDE. /// </summary> /// <param name="ops"></param> /// <param name="doc"></param> public static void FixHostProblem(IEnumerable <ElementOperator> ops, Document doc) { var newFis = ops.Where(x => x is FamilyCreator) .Cast <FamilyCreator>() .Where(x => x.OperationFinished) .Select(x => x.NewFI); using (Transaction trans = new Transaction(doc, "fix")) { trans.Start(); foreach (var newFI in newFis) { HostUtils.FixInstanceFaceProblem(newFI); } trans.Commit(); } }
public static FamilyCreator MirrorFaceBased (FamilyInstance _fi, Plane _plane, double _hostSearchRange) { var tf = Transform.CreateReflection(_plane); var doc = _fi.Document; var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption; //host search var bb = _fi.GetBoundingBoxForSolidGeometries(); if (bb == null) { bb = _fi.GetBoundingBoxInModelCS(null); } bb = bb.GetTransformed(tf); var filter = Methods.GetBBIntersectFilter(bb, _hostSearchRange); var hostCat = HostUtils.GetHostCategory(_fi); var hostDir = HostUtils.GetHostDir(_fi); if (hostDir != null) { hostDir = tf.OfVector(hostDir); } var refOffsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_fi); var tarOffsetLocLine = refOffsetLocLine.CreateTransformed(tf) as Line; var refLocLine = _fi.LocationLine(); var tarLocLine = refLocLine.CreateTransformed(tf) as Line; var facing = tf.OfVector(_fi.FacingOrientation); var faceNormal = tf.OfVector(_fi.GetPlane().Normal); var search = new HostSearchSession(doc, hostCat, filter, hostDir, faceNormal, dop); Element host; var hostFace = search.FindHostFace(tarLocLine, out host); if (hostFace == null) { throw new HostNotFoundException(_fi.Id.ToString()); } var param = _fi.GetAllEditableParams(); var ctr = new LineBasedFamilyCreator_onPlanarFace (_fi.Symbol, tarOffsetLocLine, facing, host, hostFace, param, null); ctr.CutsHost = HostUtils.CutsHost(_fi); return(ctr); }
public static WallBasedFamilyCreator CreateSimilar(FamilyInstance _fi, Document _tarDoc, double _hostSearchRange) { var refDoc = _fi.Document; var param = _fi.GetAllEditableParams(); var refDocId = refDoc.Identifier(); var tarDocId = _tarDoc.Identifier(); DesignOption dop; string dopUid, dopName; OpContext.GetActiveDesignOptionInfo(_tarDoc, out dop, out dopUid, out dopName); var opContext = new OpContext(refDocId, tarDocId, refDoc, _tarDoc, dopUid, dopName, _fi.Id); var hostCat = HostUtils.GetHostCategory(_fi); var hostDir = HostUtils.GetHostDir(_fi); var bb = _fi.GetBoundingBoxInModelCS(null); var bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange); var posPoints = HostUtils.GetPointsInsideWallHost(_fi); var search = new HostSearchSession(_tarDoc, hostCat, bbFilter, hostDir, null, dop); var hostWall = search.FindHostWall(posPoints); var ctr = new WallBasedFamilyCreator (_fi.Symbol, hostWall, _fi.GetPos(), _fi.HandOrientation, _fi.FacingOrientation, _fi.StructuralType, param, opContext); return(ctr); }
public static void CutUncutHost(FamilyInstance _fi, bool _cut) { if (_fi.Host == null) { return; } bool currCut = HostUtils.CutsHost(_fi); if (_cut == currCut) { return; } var doc = _fi.Document; if (_cut) { InstanceVoidCutUtils.AddInstanceVoidCut(doc, _fi.Host, _fi); } else { InstanceVoidCutUtils.RemoveInstanceVoidCut(doc, _fi.Host, _fi); } }
/// <summary> /// TRANSACTIONS INSIDE. /// Create mirror ONLY FOR vertical host face. /// </summary> public static FamilyCreator Mirror (FamilyInstance fi, Plane _plane, double _hostSearchRange) { var doc = fi.Document; var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption; var tf = Transform.CreateReflection(_plane); var refPos = fi.GetPos(); var tarPos = tf.OfPoint(refPos); var hand = tf.OfVector(fi.HandOrientation); var facing = tf.OfVector(fi.FacingOrientation); var refPlane = fi.GetPlane(); var faceNormal = tf.OfVector(refPlane.Normal); //find host face var bb = fi.GetBoundingBoxForSolidGeometries(); if (bb == null) { bb = fi.GetBoundingBoxInModelCS(null); } bb = bb.GetTransformed(tf); var bbFilter = Methods.GetBBIntersectFilter(bb, _hostSearchRange); var hostCat = HostUtils.GetHostCategory(fi); var hostDir = HostUtils.GetHostDir(fi); var search = new HostSearchSession(doc, hostCat, bbFilter, hostDir, faceNormal, dop); Element host; var hostFace = search.FindHostFace(tarPos, out host); if (hostFace == null) { throw new HostNotFoundException(fi.Id.ToString()); } var param = fi.GetAllEditableParams(); var ctr = new FaceBasedFamilyCreator (fi.Symbol, host, hostFace, tarPos, hand, facing, param, null); return(ctr); }
/// <summary> /// TRANSACTIONS INSIDE. /// Execute all operators in three steps. /// Also checks host problem, if any, fix and prompt user /// to restart operation. /// </summary> public static void Operation123(Document _doc, IEnumerable <ElementOperator> _ops) { var removers = _ops.Where(x => x is ElementRemover); var nonRemovers = _ops.Where(x => x is ElementRemover == false); var ds = new DialogSuppressor(); string errorMsg = "操作未完成。"; using (Transaction trans = new Transaction(_doc, "preprocess")) { ds.UseInTransaction(trans); trans.Start(); foreach (var op in nonRemovers) { op.PreProcess(); } trans.Commit(); if (trans.GetStatus() != TransactionStatus.Committed) { throw new TransactionNotCommitedException(errorMsg); } } execute: using (Transaction trans = new Transaction(_doc, "execute")) { ds.UseInTransaction(trans); trans.Start(); foreach (var op in nonRemovers) { if (!op.Cancel) { op.Execute(); } } if (FamilyCreator.HostsWithInstanceFaceProblem.Count > 0) { trans.RollBack(); } else { trans.Commit(); if (trans.GetStatus() != TransactionStatus.Committed) { throw new TransactionNotCommitedException(errorMsg); } } } //the geometry face retrieved from it might be in one of two states: //A, directly retrieved from instance. The stable reference string does not contain "INSTANCE", or; //B, retrieved from symbol geometry first, then apply instance transform. The stable reference string contains "INSTANCE". //State B might result in failure of creating new instance on face, even when the line stays //perfectly inside face. //To avoid this problem, a face with state A must be ensured. //A join operation of the host will make sure that faces retrieve from it //will always be in state A. if (FamilyCreator.HostsWithInstanceFaceProblem.Count > 0) { UserMessages.ShowMessage("某些主体图元导致本次操作失败。已修复这些图元,请重新进行操作。"); using (Transaction trans = new Transaction(_doc, "fix")) { ds.UseInTransaction(trans); trans.Start(); foreach (var host in FamilyCreator.HostsWithInstanceFaceProblem) { HostUtils.FixInstanceFaceProblem(host); } trans.Commit(); } } FamilyCreator.HostsWithInstanceFaceProblem.Clear(); using (Transaction trans = new Transaction(_doc, "postprocess")) { ds.UseInTransaction(trans); trans.Start(); foreach (var op in nonRemovers) { if (!op.Cancel) { op.PostProcess(); } } trans.Commit(); if (trans.GetStatus() != TransactionStatus.Committed) { throw new TransactionNotCommitedException(errorMsg); } } //hand and facing need second round of set. var ctrs = nonRemovers .Where(x => x is WallBasedFamilyCreator || x is FaceBasedFamilyCreator).ToList(); if (ctrs.Count > 0) { using (Transaction trans = new Transaction(_doc, "postprocess 2")) { ds.UseInTransaction(trans); trans.Start(); foreach (var ctr in ctrs) { if (!ctr.Cancel) { ctr.PostProcess(); } } trans.Commit(); if (trans.GetStatus() != TransactionStatus.Committed) { throw new TransactionNotCommitedException(errorMsg); } } } //delete elements using (Transaction trans = new Transaction(_doc, "delete")) { trans.Start(); foreach (var op in removers) { op.Execute(); } trans.Commit(); } }
/// <summary> /// Copy line-based family instances to multiple levels. /// </summary> /// <param name="_refs">line-based family instances to be copied.</param> /// <param name="_tarLevels">target levels</param> /// <param name="_baseLevel">base level for calculating height change.</param> /// <param name="_snapShot">snap shot of potential host faces. Need to scan before calling this method.</param> /// <returns>Line-based family creators of correct type.</returns> public static List <FamilyCreator> CopyToLevels (FamilyInstance _refFI, IEnumerable <Level> _tarLevels, Level _baseLevel, double _searchRange) { var doc = _refFI.Document; var dop = doc.GetElement(DesignOption.GetActiveDesignOptionId(doc)) as DesignOption; var ops = new List <FamilyCreator>(); var refLocLine = _refFI.LocationLine(); //get params var param = _refFI.GetAllEditableParams(); //get orientation var facing = _refFI.FacingOrientation; var faceNormal = _refFI.GetPlane().Normal; //scan for host face var hostCat = HostUtils.GetHostCategory(_refFI); var hostDir = HostUtils.GetHostDir(_refFI); var bbRef = _refFI.GetBoundingBoxForSolidGeometries(); if (bbRef == null) { bbRef = _refFI.GetBoundingBoxInModelCS(null); } bool cutsHost = HostUtils.CutsHost(_refFI); foreach (var tarLevel in _tarLevels) { //skip base level if (tarLevel.Id == _baseLevel.Id) { continue; } var deltaZ = tarLevel.ProjectElevation - _baseLevel.ProjectElevation; var tf = Transform.CreateTranslation(new XYZ(0, 0, deltaZ)); var tarLocLine = refLocLine.CreateTransformed(tf) as Line; //check host dir FamilyCreator ctr = null; var info = new LineBasedFamilyInfo(_refFI); //host on level if (hostCat == HostCategory.Level) { ctr = new LineBasedFamilyCreator_onLevel (_refFI.Symbol, tarLocLine, _refFI.FacingOrientation, tarLevel, _refFI.StructuralType, param, null); } //host on face else { //search host face var bbTar = bbRef.GetTransformed(tf); var filter = Methods.GetBBIntersectFilter(bbTar, _searchRange); var search = new HostSearchSession(doc, hostCat, filter, hostDir, faceNormal, dop); Element host; var hostFace = search.FindHostFace(tarLocLine, out host); if (hostFace == null) { throw new HostNotFoundException(_refFI.Id.ToString()); } var refOffsetLocLine = LineBasedFamilyUtils.GetOffsetLocLine(_refFI); var tarOffsetLocLine = refOffsetLocLine.CreateTransformed(tf) as Line; var lineBasedCtr = new LineBasedFamilyCreator_onPlanarFace (_refFI.Symbol, tarOffsetLocLine, facing, host, hostFace, param, null); lineBasedCtr.CutsHost = cutsHost; ctr = lineBasedCtr; } ops.Add(ctr); } return(ops); }