private void axMxDrawX1_CustomEntity_Explode(object sender, AxMxDrawXLib._DMxDrawXEvents_CustomEntity_ExplodeEvent e) { MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pCustomEntity; var sGuid = pCustomEntity.Guid; MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pDraw; if (sGuid == "DrawCustEntity" ) { MyDrawMline(pWorldDraw, pCustomEntity, null ); e.pRet = 1; } } private void MyDrawMline(MxDrawWorldDraw pWorldDraw, MxDrawCustomEntity pCustomEntity, MxDrawPoint curPt) { // 取自定义实体的端点数目,属性。 if (!pCustomEntity.IsHave( "Count" )) return ; long lCount = pCustomEntity.GetLong("Count"); MxDrawPolyline tmpPl = new MxDrawPolyline(); for (long i = 0; i < lCount; i++) { String sName; sName = "Point" + (i + 1).ToString(); if (!pCustomEntity.IsHave(sName)) break ; // 取自定义实体的端点坐标。 MxDrawPoint pt = pCustomEntity.GetPoint(sName); // 把端点坐标,传给pl线,用于生成双线。 tmpPl.AddVertexAt(pt); } if (curPt != null ) tmpPl.AddVertexAt(curPt); if (tmpPl.NumVerts < 2) { // 端点数少于2就,不构成直线,就不需要显示。 return ; } // 求pl线,开始点的导数. MxDrawVector3d vecFx; if (!tmpPl.GetFirstDeriv(tmpPl.GetStartParam(), out vecFx)) return ; if (vecFx.IsZeroLength()) return ; // 把向量旋转90度. vecFx.RotateByXyPlan(3.14159265 / 2.0); vecFx.Normalize(); // 得到双线的宽度属性。 double dWidth = pCustomEntity.GetDouble("Width"); vecFx.Mult(dWidth); MxDrawPoint startPt = tmpPl.GetStartPoint(); // 向pl线,两个方向偏移, MxDrawPoint offsetPt1 = new MxDrawPoint(); offsetPt1.x = startPt.x; offsetPt1.y = startPt.y; offsetPt1.Add(vecFx); MxDrawPoint offsetPt2 = new MxDrawPoint(); offsetPt2.x = startPt.x; offsetPt2.y = startPt.y; offsetPt2.Sum(vecFx); MxDrawText text = new MxDrawText(); text.TextString = "Test"; text.Height = 100; text.Position = startPt; text.AlignmentPoint = startPt; MxDrawPoint pt1, pt2; text.GetBoundingBox(out pt1, out pt2); MxDrawPoint pt3 = new MxDrawPoint(); pt3.x = pt1.x; pt3.y = pt2.y; MxDrawPoint pt4 = new MxDrawPoint(); pt4.x = pt2.x; pt4.y = pt1.y; MxDrawPoints pts = new MxDrawPoints(); pts.Add(pt1.x, pt1.y, 0); pts.Add(pt3.x, pt3.y, 0); pts.Add(pt2.x, pt2.y, 0); pts.Add(pt4.x, pt4.y, 0); Int32 lDraworder = pWorldDraw.Draworder; pWorldDraw.Draworder = lDraworder + 1; pWorldDraw.DrawWipeout(pts); pWorldDraw.Draworder = lDraworder + 2; pWorldDraw.DrawEntity((MxDrawEntity)text); pWorldDraw.Draworder = lDraworder; // pWorldDraw-> { MxDrawResbuf newobj; if (tmpPl.OffsetCurves(dWidth, offsetPt1, out newobj)) { for (Int32 j = 0; j < newobj.Count; j++) { MxDrawEntity tmpObj = (MxDrawEntity)newobj.AtObject(j); if (tmpObj == null ) continue ; pWorldDraw.DrawEntity(tmpObj); } newobj.RemoveAll(); } } { MxDrawResbuf newobj; if (tmpPl.OffsetCurves(dWidth, offsetPt2, out newobj)) { for (Int32 j = 0; j < newobj.Count; j++) { MxDrawEntity tmpObj = (MxDrawEntity)newobj.AtObject(j); if (tmpObj == null ) continue ; pWorldDraw.DrawEntity(tmpObj); } // 这不使用newobj,需要显示调用RemoveAll函数清楚内存。 // 不然这个可能就会程序退出时才释放,这时它会去释放控件对象指针,有可能会出错。 newobj.RemoveAll(); } } } |