/// <summary> /// Create a new intance of TaitBryan. /// </summary> /// <param name="xform">Transformation matrix.</param> public clsMatrix(Matrix3d xform) { try { if (!xform.IsUniscaledOrtho()) { throw new ArgumentException("Non uniscaled ortho matrix."); } Transform = xform; Beta = -Math.Asin(xform[2, 0] / xform.GetScale()) * -1; if (Abs(Beta - PI * 0.5) < 1e-7) { Beta = PI * 0.5; Alpha = Atan2(xform[1, 2], xform[1, 1]); Gamma = 0.0; } else if (Abs(Beta + PI * 0.5) < 1e-7) { Beta = -PI * 0.5; Alpha = Atan2(-xform[1, 2], xform[1, 1]); Gamma = 0.0; } else { Alpha = Atan2(xform[1, 0], xform[0, 0]); Gamma = Atan2(xform[2, 1], xform[2, 2]); } Yaw = Matrix3d.Rotation(Alpha, Vector3d.ZAxis, Point3d.Origin); Pitch = Matrix3d.Rotation(Beta, Vector3d.YAxis, Point3d.Origin); Roll = Matrix3d.Rotation(Gamma, Vector3d.XAxis, Point3d.Origin); Alpha = Math.Round(Alpha * 180.0 / Math.PI, 8); Beta = Math.Round(Beta * 180.0 / Math.PI, 8); Gamma = Math.Round(Gamma * 180.0 / Math.PI, 8); } catch (Exception) { Alpha = 999; Beta = 999; Gamma = 999; } }
convertBubble() { ObjectId idWO = ObjectId.Null; //wipeout ObjectId idSM = ObjectId.Null; //symbol ObjectId idTX = ObjectId.Null; //text ObjectId idLDR = ObjectId.Null; //leader Point3d pnt3d = Pub.pnt3dO; Object osMode = SnapMode.getOSnap(); int scale = Misc.getCurrAnnoScale(); TypedValue[] tvs = new TypedValue[2]; tvs.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0); tvs.SetValue(new TypedValue((int)DxfCode.LayerName, "BUBBLE"), 1); SelectionSet ss = Select.buildSSet(tvs); ObjectId[] idsBR = ss.GetObjectIds(); ObjectId idLayer = Layer.manageLayers("BUBBLE"); double angleView = -(double)Application.GetSystemVariable("VIEWTWIST"); Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = BaseObjs.startTransactionDb()) { DBDictionary groups = (DBDictionary)db.GroupDictionaryId.GetObject(OpenMode.ForRead); BlockTableRecord ms = Blocks.getBlockTableRecordMS(); foreach (ObjectId idBR in idsBR) { BlockReference br = (BlockReference)tr.GetObject(idBR, OpenMode.ForWrite); if (br.Name == "CWP") { br.ObjectId.delete(); continue; } Scale3d scaleFactor = br.ScaleFactors; Matrix3d m3d = scaleFactor.GetMatrix(); double scaleBR = m3d.GetScale(); double rotation = br.Rotation; Point3d pnt3dPos = br.Position; string name = br.Name; string value = string.Empty; Entity ent = null; AttributeCollection atts = br.AttributeCollection; foreach (ObjectId id in atts) { ent = id.getEnt(); AttributeReference attDef = (AttributeReference)ent; value = attDef.TextString; } Vector3d v3d = new Vector3d(scaleBR * 1.35, scaleBR * 1.35, 0); v3d = v3d * 1.1; Point3d pnt3dLL = pnt3dPos - v3d; Point3d pnt3dUR = pnt3dPos + v3d; Point3d pnt3dLR = new Point3d(pnt3dUR.X, pnt3dLL.Y, 0.0); Point3d pnt3dUL = new Point3d(pnt3dLL.X, pnt3dUR.Y, 0.0); Point3dCollection pnts3d = new Point3dCollection { pnt3dLL, pnt3dLR, pnt3dUR, pnt3dUL, pnt3dLL }; tvs = new TypedValue[2]; tvs.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 0); tvs.SetValue(new TypedValue((int)DxfCode.LayerName, "BUBBLE"), 1); Point3d pnt3dBeg = Pub.pnt3dO; Point3d pnt3dEnd = Pub.pnt3dO; Point3d pnt3dMid = Pub.pnt3dO; double bulge = 0.0, delta0 = 0.0; double dirChord, dirTarget, disChord, disTarget; Polyline poly; ObjectIdCollection idsLdr = new ObjectIdCollection(); ss = Select.buildSSet(tvs, pnts3d); if (ss != null && ss.Count > 0) { ObjectId[] ids = ss.GetObjectIds(); foreach (ObjectId id in ids) { poly = (Polyline)id.getEnt(); if (poly != null) { pnt3dBeg = poly.StartPoint; pnt3dMid = poly.GetPoint3dAt(1); pnt3dEnd = poly.EndPoint; bulge = poly.GetBulgeAt(1); delta0 = Geom.getDelta(bulge); disChord = pnt3dMid.getDistance(pnt3dEnd); disTarget = (0.5 * disChord) / System.Math.Cos(delta0 / 4); dirChord = pnt3dMid.getDirection(pnt3dEnd); dirTarget = dirChord - delta0 / 4; pnt3dMid = pnt3dMid.traverse(dirTarget, disTarget); //dirTarget = pnt3dEnd.getDirection(pnt3dPos); //direction towards center of circle //disTarget = pnt3dEnd.getDistance(pnt3dPos); //distance from original end point to center //disTarget = disTarget - Pub.radius * scale * 0.85; //0.85 per addSymbolAndWipeout - factors to adjust symbols for best fit. //pnt3dEnd = pnt3dEnd.traverse(dirTarget, disTarget); pnt3dEnd = pnt3dPos; pnts3d = new Point3dCollection { pnt3dBeg, pnt3dMid, pnt3dEnd }; ObjectId idLdr = Ldr.addLdr(pnts3d, idLayer, 0.09 * scale, 0, clr.byl, ObjectId.Null, spline: true); idsLdr.Add(idLdr); poly.ObjectId.delete(); } } } idSM = Base_Tools45.Draw.addSymbolAndWipeout(pnt3dPos, angleView, out idWO, Pub.radius, 1024, true); idSM.moveToTop(); idSM.moveBelow(new ObjectIdCollection { idWO }); if (idsLdr.Count > 0) { idWO.moveBelow(idsLdr); } Color color = new Color(); color = Color.FromColorIndex(ColorMethod.ByLayer, 256); idTX = Txt.addMText(value, pnt3dPos, angleView, 0.8, 0.09, AttachmentPoint.MiddleCenter, "Annotative", "BUBBLE", color, Pub.JUSTIFYCENTER); br.ObjectId.delete(); Draw.addXData(idSM, scale, idTX, idsLdr, idWO, 1024, "0".stringToHandle(), ""); //DBObjectCollection dbObjs = new DBObjectCollection(); //ent = (Entity)br; //ent.Explode(dbObjs); //foreach(Autodesk.AutoCAD.DatabaseServices.DBObject dbObj in dbObjs){ // Autodesk.AutoCAD.DatabaseServices.Entity e = (Autodesk.AutoCAD.DatabaseServices.Entity)dbObj; // ms.AppendEntity(e); // tr.AddNewlyCreatedDBObject(e, true); // if(e.GetType() == typeof(Circle)){ // foreach (DBDictionaryEntry entry in groups) // { // ObjectId idGrp = entry.Value; // Group group = (Group)tr.GetObject(idGrp, (OpenMode.ForRead)); // ObjectId[] ids = group.GetAllEntityIds(); // List<ObjectId> lstIDs = new List<ObjectId>(); // foreach (ObjectId id in ids) // lstIDs.Add(id); // if (lstIDs.Contains(idBR)) // { // group.UpgradeOpen(); // foreach (ObjectId idEnt in lstIDs) // { // group.Remove(idEnt); // idEnt.delete(); // } // group.Erase(); // break; // } // } // } // e.ObjectId.delete(); //} } tr.Commit(); } SnapMode.setOSnap((int)osMode); }