// 2 Points, 2 Heights private void DrawInsulationOnTwoPointsTwoHeights(PromptPointResult firstPoint) { #region input data var firstPointResult = firstPoint; var secondPointResult = _editorHelper.PromptForPoint("\nSelect SECOND point.", true, true, firstPointResult.Value); if (secondPointResult.Status != PromptStatus.OK) { return; } var thicknessAtFirstPointResult = _editorHelper.PromptForDouble("\nThickness at FIRST point : ", Settings.Default .SInsulationThicknessAtFirstPoint); if (thicknessAtFirstPointResult.Status != PromptStatus.OK) { return; } Settings.Default.SInsulationThicknessAtFirstPoint = thicknessAtFirstPointResult.Value; var thicknessAtSecondPointResult = _editorHelper.PromptForDouble("\nThickness at SECOND point : ", Settings.Default .SInsulationThicknessAtSecondPoint); if (thicknessAtSecondPointResult.Status != PromptStatus.OK) { return; } Settings.Default.SInsulationThicknessAtSecondPoint = thicknessAtSecondPointResult.Value; Settings.Default.Save(); if (Math.Abs(firstPointResult.Value.Z) > 0.00001 || Math.Abs(secondPointResult.Value.Z) > 0.00001) { _editorHelper.WriteMessage("Soft Insulation should be placed in OXY plane !"); _logger.Info("User input is invalid."); return; } #endregion #region preparation var minThickness = (thicknessAtFirstPointResult.Value < thicknessAtSecondPointResult.Value) ? thicknessAtFirstPointResult.Value : thicknessAtSecondPointResult.Value; var segmentsCount = (int)Math.Ceiling((firstPointResult.Value.DistanceTo(secondPointResult.Value) / minThickness) / 0.35); var botLeftPoint = new Complex(0, 0); var botRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value), 0); Complex topLeftPoint, topRightPoint; if (thicknessAtFirstPointResult.Value <= thicknessAtSecondPointResult.Value) { topLeftPoint = new Complex(0, thicknessAtFirstPointResult.Value); topRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value), thicknessAtSecondPointResult.Value); } else { topLeftPoint = new Complex(0, thicknessAtSecondPointResult.Value); topRightPoint = new Complex(firstPointResult.Value.DistanceTo(secondPointResult.Value), thicknessAtFirstPointResult.Value); } var vectorOfBaseLine = new Complex(secondPointResult.Value.X, secondPointResult.Value.Y) - new Complex(firstPointResult.Value.X, firstPointResult.Value.Y); var radiusBotCircle = firstPointResult.Value.DistanceTo(secondPointResult.Value) / (segmentsCount + 0.5); radiusBotCircle /= 2.0; var vectorTopEdge = topRightPoint - topLeftPoint; var vectorTopEdgeOrt = vectorTopEdge / vectorTopEdge.abs(); var vectorNormalOfTopEdge = vectorTopEdgeOrt * (new Complex(0, 1.0)); #endregion #region calculateCenterCircle var centersBotCircles = new List <Complex>(); for (var i = 0; i < segmentsCount + 1; i++) { centersBotCircles.Add(new Complex(i * 2 * radiusBotCircle, radiusBotCircle)); } var centersTopCircles = new List <KeyValuePair <double, Complex> >(); var ordinate = new Line2d(new Complex(radiusBotCircle, 0), new Complex(radiusBotCircle, 100)); var offsetTopEdge = new Line2d(topLeftPoint - vectorNormalOfTopEdge * radiusBotCircle, topRightPoint - vectorNormalOfTopEdge * radiusBotCircle); var centerFirstUpperCircle = offsetTopEdge.IntersectWitch(ordinate); centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusBotCircle, centerFirstUpperCircle)); if (((topRightPoint - topLeftPoint).arg()) * 180.0 / Math.PI <= 5) { for (var i = 1; i < segmentsCount + 1; i++) { var rightVerticalEdge = new Line2d(botRightPoint, topRightPoint); var lineParallelToX = new Line2d(centersTopCircles[i - 1].Value, centersTopCircles[i - 1].Value + new Complex(rightVerticalEdge.A, rightVerticalEdge.B)); var distFromCurrentCircleToRightVertEdge = Math.Abs( (centersTopCircles[i - 1].Value - lineParallelToX.IntersectWitch(rightVerticalEdge)).abs() - centersTopCircles[i - 1].Key); var radiusTopCircle = (distFromCurrentCircleToRightVertEdge / (segmentsCount - i + 0.5)) / 2.0; var rR = centersTopCircles[i - 1].Key + radiusTopCircle; var dR = Math.Abs(radiusTopCircle - centersTopCircles[i - 1].Key); var distBetweenCenters = Math.Sqrt(rR * rR - dR * dR); var centerNextTopCircle = centersTopCircles[i - 1].Value - vectorNormalOfTopEdge * dR + vectorTopEdgeOrt * distBetweenCenters; centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusTopCircle, centerNextTopCircle)); } } else { for (var i = 1; i < segmentsCount + 1; i++) { var tangentPoints = GetTangentPointsOfCommonExternalTanget(centersBotCircles[i], radiusBotCircle, centersTopCircles[i - 1].Value, centersTopCircles[i - 1].Key, true); var vectorCommonTangent = tangentPoints.Value - tangentPoints.Key; var vectorCommonTangentOrt = vectorCommonTangent / vectorCommonTangent.abs(); var vectorTranslationTopCircle = vectorCommonTangentOrt * (new Complex(0, 1.0)); var dL = new Line2d(tangentPoints.Value, tangentPoints.Value + vectorTranslationTopCircle * 100); var rightVerticalEdge = new Line2d(botRightPoint, topRightPoint); var dist = (tangentPoints.Value - dL.IntersectWitch(rightVerticalEdge)).abs(); var radiusTopCircle = (dist / (segmentsCount - i + 0.5)) / 2.0; var hlpLine = new Line2d(tangentPoints.Key - vectorTranslationTopCircle * radiusTopCircle, tangentPoints.Value - vectorTranslationTopCircle * radiusTopCircle); var offsetTopEdgeOnRadiusTopCircle = new Line2d( topLeftPoint - vectorNormalOfTopEdge * radiusTopCircle, topRightPoint - vectorNormalOfTopEdge * radiusTopCircle); centersTopCircles.Add(new KeyValuePair <double, Complex>(radiusTopCircle, offsetTopEdgeOnRadiusTopCircle .IntersectWitch(hlpLine))); } } #endregion #region calculatePointsForPolylineInsulation var insulationPolyline = new Polyline(); insulationPolyline.SetDatabaseDefaults(); insulationPolyline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0); var firstPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[0], radiusBotCircle, centersTopCircles[0].Value, centersTopCircles[0].Key, false); var ang = ((firstPairTangentPoints.Key - centersBotCircles[0]) / -centersBotCircles[0]).arg(); insulationPolyline.AddVertexAt(0, new Point2d(firstPairTangentPoints.Key.real(), firstPairTangentPoints.Key.imag()), -Math.Tan(ang / 4), 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(firstPairTangentPoints.Value.real(), firstPairTangentPoints.Value.imag()), 0, 0, 0); var secondPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[1], radiusBotCircle, centersTopCircles[0].Value, centersTopCircles[0].Key, true); ang = ((centersTopCircles[0].Value - firstPairTangentPoints.Value) / (centersTopCircles[0].Value - secondPairTangentPoints.Value)).arg(); insulationPolyline.AddVertexAt(0, new Point2d(secondPairTangentPoints.Value.real(), secondPairTangentPoints.Value.imag()), Math.Tan(ang / 4), 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(secondPairTangentPoints.Key.real(), secondPairTangentPoints.Key.imag()), 0, 0, 0); var oldPair = secondPairTangentPoints; for (var i = 1; i < segmentsCount; i++) { var pairBotRightTopLeft = GetTangentPointsOfCommonInternalTanget(centersBotCircles[i], radiusBotCircle, centersTopCircles[i].Value, centersTopCircles[i].Key, false); var pairTopRightBotLeft = GetTangentPointsOfCommonInternalTanget(centersBotCircles[i + 1], radiusBotCircle, centersTopCircles[i].Value, centersTopCircles[i].Key, true); ang = ((pairBotRightTopLeft.Key - centersBotCircles[i]) / (oldPair.Key - centersBotCircles[i])).arg(); insulationPolyline.AddVertexAt(0, new Point2d(pairBotRightTopLeft.Key.real(), pairBotRightTopLeft.Key.imag()), -Math.Tan(ang / 4), 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(pairBotRightTopLeft.Value.real(), pairBotRightTopLeft.Value.imag()), 0, 0, 0); ang = ((centersTopCircles[i].Value - pairBotRightTopLeft.Value) / (centersTopCircles[i].Value - pairTopRightBotLeft.Value)).arg(); insulationPolyline.AddVertexAt(0, new Point2d(pairTopRightBotLeft.Value.real(), pairTopRightBotLeft.Value.imag()), Math.Tan(ang / 4), 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(pairTopRightBotLeft.Key.real(), pairTopRightBotLeft.Key.imag()), 0, 0, 0); oldPair = pairTopRightBotLeft; } var lastPairTangentPoints = GetTangentPointsOfCommonInternalTanget(centersBotCircles[segmentsCount], radiusBotCircle, centersTopCircles[segmentsCount] .Value, centersTopCircles[segmentsCount].Key, false); ang = ((lastPairTangentPoints.Key - centersBotCircles[segmentsCount]) / (oldPair.Key - centersBotCircles[segmentsCount])).arg(); insulationPolyline.AddVertexAt(0, new Point2d(lastPairTangentPoints.Key.real(), lastPairTangentPoints.Key.imag()), -Math.Tan(ang / 4), 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(lastPairTangentPoints.Value.real(), lastPairTangentPoints.Value.imag()), 0, 0, 0); var hlpPointForLastBulge = new Complex(centersTopCircles[segmentsCount].Value.real(), centersTopCircles[segmentsCount].Value.imag() + centersTopCircles[segmentsCount].Key); ang = ((centersTopCircles[segmentsCount].Value - lastPairTangentPoints.Value) / (centersTopCircles[segmentsCount].Value - hlpPointForLastBulge)).arg(); insulationPolyline.AddVertexAt(0, new Point2d(hlpPointForLastBulge.real(), hlpPointForLastBulge.imag()), Math.Tan(ang / 4), 0, 0); #endregion #region add contur to poly insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), hlpPointForLastBulge.imag()), 0, 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(botRightPoint.real(), botRightPoint.imag()), 0, 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(botLeftPoint.real(), botLeftPoint.imag()), 0, 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(topLeftPoint.real(), topLeftPoint.imag()), 0, 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), topRightPoint.imag()), 0, 0, 0); insulationPolyline.AddVertexAt(0, new Point2d(topRightPoint.real(), hlpPointForLastBulge.imag()), 0, 0, 0); #endregion #region transforms if (thicknessAtFirstPointResult.Value > thicknessAtSecondPointResult.Value) { var acPtFrom = new Point3d(botRightPoint.x / 2, botRightPoint.y / 2, 0); var acPtTo = new Point3d(botRightPoint.x / 2, 100, 0); var acLine3d = new Line3d(acPtFrom, acPtTo); insulationPolyline.TransformBy(Matrix3d.Mirroring(acLine3d)); } insulationPolyline.TransformBy(Matrix3d.Rotation(vectorOfBaseLine.arg(), new Vector3d(0, 0, 1), Point3d.Origin)); insulationPolyline.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(firstPointResult.Value))); insulationPolyline.TransformBy(_editorHelper.CurrentUcs); #endregion var oldLayer = Application.DocumentManager.MdiActiveDocument.Editor.Document .Database.Clayer; _documentHelper.LayerManipulator.CreateLayer("3-0", System.Drawing.Color.Lime); var softInsulationBlock = new BlockTableRecord(); var nameSalt = DateTime.Now.GetHashCode().ToString(); softInsulationBlock.Name = "SoftInsulation_" + nameSalt; softInsulationBlock.Origin = firstPointResult.Value; insulationPolyline.Layer = "0"; #region addObjectsToDataBase using (var acTrans = _documentHelper.TransactionManager.StartTransaction()) { var blockTable = acTrans.GetObject( Application.DocumentManager.MdiActiveDocument.Editor .Document.Database.BlockTableId, OpenMode.ForWrite) as BlockTable; blockTable.Add(softInsulationBlock); acTrans.AddNewlyCreatedDBObject(softInsulationBlock, true); softInsulationBlock.AppendEntity(insulationPolyline); acTrans.AddNewlyCreatedDBObject(insulationPolyline, true); var rigidInsulationRef = new BlockReference(firstPointResult.Value, softInsulationBlock.ObjectId) { Layer = "3-0" }; var currentSpace = (BlockTableRecord) acTrans.GetObject( Application.DocumentManager.MdiActiveDocument.Editor .Document.Database.CurrentSpaceId, OpenMode.ForWrite); currentSpace.AppendEntity(rigidInsulationRef); acTrans.AddNewlyCreatedDBObject(rigidInsulationRef, true); acTrans.Commit(); } #endregion _documentHelper.LayerManipulator.ChangeLayer(oldLayer); }
public void CodeLine3d(ref Line3d v) { AddValue(v.ToString()); }
public void CodeLine3d(ref Line3d v) { throw new NotImplementedException(); }
public void smooth_append(DCurve3 curve, Vector3f newPos, float fDistThresh) { // empty curve, always append if (curve.VertexCount == 0) { curve.AppendVertex(newPos); last_append = newPos; appended_last_update = true; have_temp_append = false; return; } else if (curve.VertexCount == 1) { curve.AppendVertex(newPos); last_append = newPos; appended_last_update = true; have_temp_append = true; return; } else if (curve.VertexCount <= 3) { curve[curve.VertexCount - 1] = newPos; } double d = (newPos - last_append).Length; if (d < fDistThresh) { // have not gone far enough for a real new vertex! Vector3f usePos = new Vector3f(newPos); bool bValid = false; // do we have enough vertices to do a good job? if (curve.VertexCount > 3) { int nLast = (have_temp_append) ? curve.VertexCount - 2 : curve.VertexCount - 1; Vector3d tan = curve.Tangent(nLast); double fDot = tan.Dot((usePos - curve[nLast]).Normalized); if (fDot > 0.9f) // cos(25) ~= 0.9f // new vtx is aligned with tangent of last "real" vertex { bValid = true; } else { // not aligned, try projection onto tangent Line3d l = new Line3d(curve[nLast], tan); double t = l.Project(newPos); if (t > 0) { // projection of new vtx is 'ahead' so we can use it usePos = (Vector3f)l.PointAt(t); bValid = true; } } } if (bValid) { if (appended_last_update) { curve.AppendVertex(usePos); have_temp_append = true; } else if (have_temp_append) { curve[curve.VertexCount - 1] = usePos; } } appended_last_update = false; } else { // ok we drew far enough, add this position if (have_temp_append) { // re-use temp vertex curve[curve.VertexCount - 1] = newPos; have_temp_append = false; } else { curve.AppendVertex(newPos); } last_append = newPos; appended_last_update = true; // do smoothing pass smoother.End = curve.VertexCount - 1; smoother.Start = MathUtil.Clamp(smoother.End - 5, 0, smoother.End); smoother.UpdateDeformation(2); } }
public void Cmd_DimExtend() { if (!LicensingAgent.Check()) { return; } var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var prEntOpt = new PromptEntityOptions("\nSelect a dimension system to extend: "); prEntOpt.SetRejectMessage("\nOnly linear dimensions may be selected."); prEntOpt.AllowNone = false; prEntOpt.AddAllowedClass(typeof(RotatedDimension), false); var prEntRes = acCurEd.GetEntity(prEntOpt); if (prEntRes.Status != PromptStatus.OK) { return; } var objId = prEntRes.ObjectId; var matrix3d = acCurEd.GetAlignedMatrix(); var eqPoint = CalcTol.ReturnCurrentTolerance(); using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { var acEnt = acTrans.GetObject(objId, OpenMode.ForWrite) as Entity; if (acEnt != null) { acEnt.Unhighlight(); var acRotDim = acEnt as RotatedDimension; if (acRotDim != null) { var dimSys = DimSystem.GetSystem(acRotDim, eqPoint, eqPoint); dimSys.Highlight(); var promptPointOption2 = new PromptPointOptions( "\nSelect a dimension line to extend or press CTRL to start crossing line:"); while (true) { if (dimSys.Count == 0) { break; } dimSys.Highlight(); var nArray = DimSystem.GetActiveViewCount(); var ctManager = TransientManager.CurrentTransientManager; var acCirc = new Circle(); var acLine = new Line(new Point3d(0, 0, 0), new Point3d(0, 0, 0)); acCirc.Color = SettingsUser.DynPreviewColor; acCirc.Normal = acRotDim.Normal; acLine.Color = SettingsUser.DynPreviewColor; var intCol = new IntegerCollection(nArray); ctManager.AddTransient(acCirc, TransientDrawingMode.Highlight, 128, intCol); ctManager.AddTransient(acLine, TransientDrawingMode.Highlight, 128, intCol); var sysPts = dimSys.GetSystemPoints(eqPoint); void Handler(object sender, PointMonitorEventArgs e) { var cPt = dimSys.GetNearest(e.Context.ComputedPoint, eqPoint); var sysPt = sysPts[cPt]; var dlPt = sysPt.DimLinePoint; var scrSize = ScreenReader.GetSreenSize(); acCirc.Radius = scrSize / 200; var point3d = sysPt.Dim1PointIndex != 1 ? sysPt.Dim1.XLine2Point : sysPt.Dim1.XLine1Point; if (Math.Abs(point3d.DistanceTo(dlPt)) <= eqPoint) { acCirc.Center = dlPt; acLine.StartPoint = dlPt; acLine.EndPoint = dlPt; ctManager.UpdateTransient(acCirc, intCol); ctManager.UpdateTransient(acLine, intCol); return; } var point = new Line3d(dlPt, point3d).GetClosestPointTo(e.Context.ComputedPoint).Point; acLine.StartPoint = dlPt; acLine.EndPoint = point; acCirc.Center = point; ctManager.UpdateTransient(acCirc, intCol); ctManager.UpdateTransient(acLine, intCol); } acCurEd.PointMonitor += Handler; PromptPointResult ptRes; try { ptRes = acCurDoc.Editor.GetPoint(promptPointOption2); } finally { acCurEd.PointMonitor -= Handler; ctManager.EraseTransient(acCirc, intCol); ctManager.EraseTransient(acLine, intCol); acCirc.Dispose(); acLine.Dispose(); } var cntrlPressed = (Control.ModifierKeys & Keys.Control) > Keys.None; PromptPointResult ctrlRes = null; if (cntrlPressed) { var promptPointOption3 = new PromptPointOptions("\nSelect second point of crossing line:") { UseBasePoint = true, UseDashedLine = true, BasePoint = ptRes.Value }; ctrlRes = acCurDoc.Editor.GetPoint(promptPointOption3); if (ctrlRes.Status != PromptStatus.OK) { break; } } if (ptRes.Status != PromptStatus.OK) { break; } if (cntrlPressed) { var point3d6 = ptRes.Value.TransformBy(matrix3d); var point3d7 = ctrlRes.Value.TransformBy(matrix3d); var nums = dimSys.GetSystemByLine(point3d6, point3d7, eqPoint); if (nums.Count <= 0) { continue; } var sysPoints2 = dimSys.GetSystemPoints(eqPoint); foreach (var num3 in nums) { var point3d8 = DimSystem.GetCrossing(dimSys, sysPoints2, num3, point3d6, point3d7, eqPoint); if (point3d8.X != -99999 || point3d8.Y != -99999 || point3d8.Z != -99999) { dimSys.Extend(num3, 0, point3d8, eqPoint); } else { acCurEd.WriteMessage("\nCannot extend lines with zero length."); } } acTrans.TransactionManager.QueueForGraphicsFlush(); } else { var point3d9 = ptRes.Value.TransformBy(matrix3d); var num4 = dimSys.GetNearest(point3d9, eqPoint); var sysPoint = dimSys.GetSystemPoints(eqPoint)[num4]; var point3d10 = sysPoint.DimLinePoint; var point3d11 = sysPoint.Dim1PointIndex != 1 ? sysPoint.Dim1.XLine2Point : sysPoint.Dim1.XLine1Point; if (Math.Abs(point3d10.DistanceTo(point3d11)) >= eqPoint) { dimSys.Extend(num4, 0, point3d9, eqPoint); acTrans.TransactionManager.QueueForGraphicsFlush(); } else { acCurEd.WriteMessage("\nCannot extend lines with zero length."); } } } dimSys.Unhighlight(); acTrans.Commit(); } } } }
public void GeneratePlineDoorDWG() { Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; try { List <string> path = IOHelper.GetPath(new Constants().EXCEL__POLY_PATH); if (path != null && path.Count > 0) { List <GateParameter> list = new List <GateParameter>(); foreach (string item5 in path) { List <GateParameter> collection = ExcelOption.ReadPolyDoorExcel(item5); list.AddRange(collection); } exportPath = new Constants().DWG_SAVE_PATH + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "\\"; IOHelper.CreateDirectory(exportPath); foreach (IGrouping <string, GateParameter> gr in from e in list group e by e.DwgName) { string fileName = exportPath + gr.Key + ".dwg"; string a = "否"; double factor = 0.0; Document document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.Add(gr.Key); using (document.LockDocument()) { bool flag = false; List <GateParameter> gpList = new List <GateParameter>(); double borderHeight = 0; double borderWidth = 0; Point3d pBorder = new Point3d(); foreach (GateParameter gp in gr) { if (!flag) { new Border().Generate(document, gp); new Rectangle().Generate(document, gp); flag = true; a = gp.IsMirrored; factor = gp.GateWidth; borderHeight = gp.BorderHeight; borderWidth = gp.BorderWidth; pBorder = new Point3d(gp.BorderBaseX, gp.BorderBaseY, 0); } new CustomBlock().Generate(document, gp); gpList.Add(gp); } new PolyDoor().Generate(document, gpList, borderHeight, borderWidth, pBorder); if (a == "是") { Line3d line = new Line3d(Point3d.Origin + Vector3d.XAxis * factor, Point3d.Origin + Vector3d.XAxis * factor + Vector3d.YAxis); DBHelper.MatrixEntitiesInModelSpace(Matrix3d.Displacement(-Vector3d.XAxis * factor) * Matrix3d.Mirroring(line)); } document.Database.SaveAs(fileName, DwgVersion.AC1021); } } Application.DocumentManager.MdiActiveDocument.SendCommand("CloseAllDwg\n"); } } catch (System.Exception ex) { editor.WriteMessage("生成失败!" + ex?.ToString()); } }
public IntrLine3Box3(Line3d l, Box3d b) { line = l; box = b; }
public void CodeLine3d(ref Line3d v) { CodeV3d(ref v.P0); CodeV3d(ref v.P1); }
public void fOPENVISUAL() { Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor; try { Document doc = acApp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Utils.Utils.Init(); Utils.Utils.ChangeViewStyle("X-Ray"); while (true) { PromptEntityOptions peo = new PromptEntityOptions("\nSelect mesh face:"); peo.SetRejectMessage("\nMust be a 3D solid."); peo.AddAllowedClass(typeof(Solid3d), false); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK || per.Status == PromptStatus.Cancel) { Utils.Utils.End(); break; } Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { Solid3d sol = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Solid3d; if (sol != null) { Brep brp = new Brep(sol); using (brp) { // We're going to check interference between our // solid and a line we're creating between the // picked point and the user (we use the view // direction to decide in which direction to // draw the line) Point3d dir = (Point3d)acApp.GetSystemVariable("VIEWDIR"); Point3d picked = per.PickedPoint, nearerUser = per.PickedPoint - (dir - Point3d.Origin); // Two hits should be enough (in and out) const int numHits = 1; // Create out line Line3d ln = new Line3d(picked, nearerUser); Hit[] hits = brp.GetLineContainment(ln, numHits); ln.Dispose(); if (hits == null || hits.Length < numHits) { Utils.Utils.End(); return; } // Set the shortest distance to something large // and the index to the first item in the list double shortest = (picked - nearerUser).Length; int found = 0; // Loop through and check the distance to the // user (the depth of field). for (int idx = 0; idx < numHits; idx++) { Hit hit = hits[idx]; double dist = (hit.Point - nearerUser).Length; if (dist < shortest) { shortest = dist; found = idx; } } // Once we have the nearest point to the screen, // use that one to get the containing curves //List<Curve3d> curves = new List<Curve3d>(); List <Point3d> faceBoundary = new List <Point3d>(); if (CheckContainment(ed, brp, hits[found].Point, ref faceBoundary)) { Utils.Layers.SetLayer("!FDS_MESH[open]"); if (faceBoundary[0].X == faceBoundary[1].X) { if (faceBoundary[0].X == sol.GeometricExtents.MinPoint.X) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } else if (faceBoundary[0].X == sol.GeometricExtents.MaxPoint.X) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } } else if (faceBoundary[0].Y == faceBoundary[1].Y) { if (faceBoundary[0].Y == sol.GeometricExtents.MinPoint.Y) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } else if (faceBoundary[0].Y == sol.GeometricExtents.MaxPoint.Y) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } } if (faceBoundary[0].Z == faceBoundary[1].Z) { if (faceBoundary[0].Z == sol.GeometricExtents.MinPoint.Z) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } else if (faceBoundary[0].Z == sol.GeometricExtents.MaxPoint.Z) { Utils.Utils.CreateExtrudedSurface(faceBoundary[0], new Point3d(faceBoundary[1].X, faceBoundary[1].Y, faceBoundary[1].Z), "!FDS_MESH[open]", 1, 1); } } } } } tr.Commit(); } } Utils.Utils.End(); Utils.Utils.ChangeViewStyle("2dWireframe"); return; } catch (System.Exception e) { ed.WriteMessage("Program error: " + e.ToString()); Utils.Utils.End(); return; } }
public void UpdateDraw_Spatial(Ray3f ray, Frame3f handFrame, int nStep) { // scene xform may have changed during steps (eg view rotation), so we // need to reconstruct our local frame Frame3f primCurW = scene.ToWorldFrame(primStartS); // step 1: find radius in plane if (nStep == 0) { Vector3f forwardDir = ray.Direction; Vector3f plane_hit = VRUtil.SafeRayPlaneIntersection(ray, forwardDir, primCurW.Origin, primCurW.Y); plane_hit_local = primCurW.ToFrameP(plane_hit); } float fX = MathUtil.SignedClamp(plane_hit_local[0], MinDimension, MaxDimension); float fY = MinDimension; float fZ = MathUtil.SignedClamp(plane_hit_local[2], MinDimension, MaxDimension); float fR_plane = MathUtil.Clamp(plane_hit_local.Length, MinDimension / 2, MaxDimension / 2); // step 2: find height from plane if (nStep == 1) { Vector3f plane_hit = primCurW.FromFrameP(plane_hit_local); Line3d l = new Line3d(plane_hit, primCurW.Y); Vector3f handTip = handFrame.Origin + SceneGraphConfig.HandTipOffset * handFrame.Z; float fHandDist = (float)l.DistanceSquared(handTip); if (fHandDist < fR_plane * 1.5f) { fY = (float)l.Project(handTip); } else { fY = (float)DistLine3Ray3.MinDistanceLineParam(ray, l); } } // figure out possible dimensions, clamp to ranges fY = MathUtil.SignedClamp(fY, MinDimension, MaxDimension); // update frame primitive.Frame = primCurW; // update dimensions bool bIsCorner = (primitive.Center == CenterModes.Corner); float fScale = 1.0f; // object is not in scene coordinates! if (primitive.Type == MeshPrimitivePreview.PrimType.Cylinder) { primitive.Width = (bIsCorner) ? fR_plane * fScale : 2 * fR_plane * fScale; primitive.Depth = primitive.Width; //primitive.Depth = Mathf.Sign(fZ) * primitive.Width; //primitive.Width = Mathf.Sign(fX) * primitive.Width; primitive.Height = fY * fScale; } else if (primitive.Type == MeshPrimitivePreview.PrimType.Box) { primitive.Width = (bIsCorner) ? fX : 2 * fX * fScale; primitive.Depth = (bIsCorner) ? fZ : 2 * fZ * fScale; primitive.Height = fY * fScale; } else if (primitive.Type == MeshPrimitivePreview.PrimType.Sphere) { primitive.Width = (bIsCorner) ? fR_plane * fScale : 2 * fR_plane * fScale; primitive.Depth = primitive.Height = primitive.Width; //primitive.Depth = Mathf.Sign(fZ) * primitive.Width; //primitive.Width = Mathf.Sign(fX) * primitive.Width; //primitive.Height = Mathf.Sign(fY) * primitive.Width; } else { throw new NotImplementedException("DrawPrimitivesTool.UpdateDraw_Ray - type not supported"); } }
public void DrawArrow() { //箭头图形 Polyline pl = MakeArrow(); Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; //插入点 var ppr = ed.GetPoint(new PromptPointOptions("\n指定点")); if (ppr.Status == PromptStatus.OK) { Point3d pt = ppr.Value; //插入角度 var pao = new PromptAngleOptions("\n请输入一个角度"); pao.BasePoint = pt; pao.UseBasePoint = true; var par = ed.GetAngle(pao); if (par.Status == PromptStatus.OK) { var angle = par.Value; //缩放比例 var pdr = ed.GetDouble(new PromptDoubleOptions("\n请输入比例:")); if (pdr.Status == PromptStatus.OK) { var scale = pdr.Value; //是否镜像 var pko = new PromptKeywordOptions("\n是否反向"); pko.Keywords.Add("正向", "Y", "正向(Y)"); pko.Keywords.Add("反向", "N", "反向(N)"); pko.Keywords.Default = "正向"; var pkr = ed.GetKeywords(pko); //旋转、缩放、平移矩阵 var mt = Matrix3d.Displacement(pt.GetAsVector()) * Matrix3d.Scaling(scale, Point3d.Origin) * Matrix3d.Rotation(angle, Vector3d.ZAxis, Point3d.Origin); if (pkr.Status == PromptStatus.OK) { if (pkr.StringResult == "反向") { var v = Vector3d.XAxis.RotateBy(angle + Math.PI / 2, Vector3d.ZAxis); var l3d = new Line3d(Point3d.Origin, v); //旋转、进行、缩放、平移矩阵 mt = Matrix3d.Displacement(pt.GetAsVector()) * Matrix3d.Scaling(scale, Point3d.Origin) * Matrix3d.Mirroring(l3d) * Matrix3d.Rotation(angle, Vector3d.ZAxis, Point3d.Origin); } } //几何变换 pl.TransformBy(mt); Database db = HostApplicationServices.WorkingDatabase; //添加图形 using (var tr = db.TransactionManager.StartTransaction()) { var id = db.AddToCurrentSpace(pl); tr.Commit(); } } } } }
public void GCommand(int gCode, Line3d line3d, bool isRevereseAngle = false) => GCommand(gCode, new Line2d(line3d.PointOnLine.To2d(), line3d.Direction.ToVector2d()), line3d.PointOnLine.Z, isRevereseAngle);
public float AbsAngleBetween(ref Line3d l) { return(Mathf.Abs(Vector3.Angle(m_dir, l.m_dir))); }
public void Bisector() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptEntityOptions peo = new PromptEntityOptions("\nSelect the first line: "); peo.SetRejectMessage("Selected object is not a line !"); peo.AddAllowedClass(typeof(Line), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } Point3d p1 = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem); ObjectId id1 = per.ObjectId; peo.Message = "\nSelect the second line: "; per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } Point3d p2 = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem); ObjectId id2 = per.ObjectId; using (Transaction tr = db.TransactionManager.StartTransaction()) { Line l1 = (Line)tr.GetObject(id1, OpenMode.ForRead); Line l2 = (Line)tr.GetObject(id2, OpenMode.ForRead); // Checks if lines intersect Plane plane; Line3d line1 = new Line3d(l1.StartPoint, l1.EndPoint); Line3d line2 = new Line3d(l2.StartPoint, l2.EndPoint); if (!line1.IsCoplanarWith(line2, out plane) || line1.IsParallelTo(line2)) { return; } // Calculates the bisector Point3d inters = line1.IntersectWith(line2)[0]; Vector3d vec1 = line1.Direction; Vector3d vec2 = line2.Direction; // Corrects the vectors direction according to picked points if (vec1.DotProduct(inters.GetVectorTo(p1)) < 0) { vec1 = vec1.Negate(); } if (vec2.DotProduct(inters.GetVectorTo(p2)) < 0) { vec2 = vec2.Negate(); } Vector3d bisectDir = (vec1 + vec2) / 2.0; // Draws the bisector (XLine) Xline xline = new Xline(); xline.UnitDir = bisectDir.GetNormal(); xline.BasePoint = inters; BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(xline); tr.AddNewlyCreatedDBObject(xline, true); tr.Commit(); } }
public void UpdateDraw_Ray(Ray3f ray, int nStep) { // scene xform may have changed during steps (eg view rotation), so we // need to reconstruct our local frame Frame3f primCurW = scene.ToWorldFrame(primStartS); // try snap points SnapResult snap = Snaps.FindHitSnapPoint(ray); bool bHaveSnap = (snap != null); Frame3f snapF = (bHaveSnap) ? scene.ToWorldFrame(snap.FrameS) : Frame3f.Identity; // step 1: find radius in plane // step 2: find height from plane float fY = MinDimension; if (nStep == 0) { if (bHaveSnap) { plane_hit_local = primCurW.ToFrameP( primCurW.ProjectToPlane(snapF.Origin, 1)); } else { Vector3f forwardDir = ray.Direction; Vector3f plane_hit = VRUtil.SafeRayPlaneIntersection(ray, forwardDir, primCurW.Origin, primCurW.Y); plane_hit_local = primCurW.ToFrameP(plane_hit); } } else if (nStep == 1) { Vector3f plane_hit = primCurW.FromFrameP(plane_hit_local); Line3d l = new Line3d(plane_hit, primCurW.Y); if (bHaveSnap) { fY = (float)l.Project(snapF.Origin); } else { fY = (float)DistLine3Ray3.MinDistanceLineParam(ray, l); } } // figure out possible dimensions, clamp to ranges float planeX = MathUtil.SignedClamp(plane_hit_local[0], MinDimension, MaxDimension); float planeZ = MathUtil.SignedClamp(plane_hit_local[2], MinDimension, MaxDimension); float fR_plane = MathUtil.Clamp(plane_hit_local.Length, MinDimension / 2, MaxDimension / 2); fY = MathUtil.SignedClamp(fY, MinDimension, MaxDimension); // update frame primitive.Frame = primCurW; // update dimensions bool bIsCorner = (primitive.Center == CenterModes.Corner); float fScale = 1.0f; // object is not in scene coordinates! if (primitive.Type == MeshPrimitivePreview.PrimType.Cylinder) { primitive.Width = (bIsCorner) ? fR_plane * fScale : 2 * fR_plane * fScale; primitive.Depth = primitive.Width; primitive.Height = fY * fScale; } else if (primitive.Type == MeshPrimitivePreview.PrimType.Box) { primitive.Width = (bIsCorner) ? planeX * fScale : 2 * planeX * fScale; primitive.Depth = (bIsCorner) ? planeZ * fScale : 2 * planeZ * fScale; primitive.Height = fY * fScale; } else if (primitive.Type == MeshPrimitivePreview.PrimType.Sphere) { primitive.Width = (bIsCorner) ? fR_plane * fScale : 2 * fR_plane * fScale; primitive.Depth = primitive.Width; primitive.Height = Mathf.Sign(fY) * primitive.Width; } else { throw new NotImplementedException("SnapDrawPrimitivesTool.UpdateDraw_Ray - type not supported"); } }
public void smooth_append(CurvePreview preview, Vector3f newPos, float fDistThresh) { // empty curve, always append if (preview.VertexCount == 0) { preview.AppendVertex(newPos); last_append_idx = preview.VertexCount - 1; appended_last_update = true; have_temp_append = false; return; } double d = (newPos - preview[last_append_idx]).Length; if (d < fDistThresh) { // have not gone far enough for a real new vertex! Vector3f usePos = new Vector3f(newPos); bool bValid = false; // do we have enough vertices to do a good job? if (preview.VertexCount > 3) { int nLast = (have_temp_append) ? preview.VertexCount - 2 : preview.VertexCount - 1; Vector3d tan = preview.Tangent(nLast); double fDot = tan.Dot((usePos - preview[nLast]).Normalized); if (fDot > 0.9f) // cos(25) ~= 0.9f // new vtx is aligned with tangent of last "real" vertex { bValid = true; } else { // not aligned, try projection onto tangent Line3d l = new Line3d(preview[nLast], tan); double t = l.Project(newPos); if (t > 0) { // projection of new vtx is 'ahead' so we can use it usePos = (Vector3f)l.PointAt(t); bValid = true; } } } if (bValid) { if (appended_last_update) { preview.AppendVertex(usePos); have_temp_append = true; } else if (have_temp_append) { preview[preview.VertexCount - 1] = usePos; } } appended_last_update = false; } else { // ok we drew far enough, add this position if (have_temp_append) { // re-use temp vertex preview[preview.VertexCount - 1] = newPos; have_temp_append = false; } else { preview.AppendVertex(newPos); } last_append_idx = preview.VertexCount - 1; appended_last_update = true; } }