public ObjectId CreateItem(Point3d insertPointUcs, Matrix3d ucs) { if (_btrId == ObjectId.Null) { _calculate(); } Matrix3d rot = ucs.PreMultiplyBy(Matrix3d.Displacement(_origin - ucs.CoordinateSystem3d.Origin)); ObjectId brId = AcadBlocks.BlockTools.AppendBlockItem(insertPointUcs, _btrId, null, rot); Tools.StartTransaction(() => { var br = brId.GetObjectForRead <BlockReference>(); var ar = br.GetAttributeByTag("Восток"); ar.UpgradeOpen(); ar.TextString = br.Position.X.ToString(_format, _culture); ar = br.GetAttributeByTag("Север"); ar.UpgradeOpen(); ar.TextString = br.Position.Y.ToString(_format, _culture); br.UpgradeOpen(); br.RecordGraphicsModified(true); }); return(brId); }
/// <summary> /// Построить спинку /// </summary> private void BuildHeadboard() { var headboardDisplacement = new Point3d( _parameters.ModelParameters[ParameterType.MainPartLength].Value / 2 + _parameters.ModelParameters[ParameterType.HeadboardThickness] .Value / 2, 0, _parameters.ModelParameters[ParameterType.MainPartHeight].Value / 2) - Point3d.Origin; using (var transaction = _database.TransactionManager.StartTransaction()) { var blockTableRecord = GetBlockTableRecord(transaction); using (var headboardSolid3d = new Solid3d()) { headboardSolid3d.CreateBox( _parameters.ModelParameters[ParameterType.HeadboardThickness] .Value, _parameters.ModelParameters[ParameterType.MainPartWidth].Value, _parameters.ModelParameters[ParameterType.HeadboardHeight].Value); headboardSolid3d.TransformBy( Matrix3d.Displacement(headboardDisplacement)); blockTableRecord.AppendEntity(headboardSolid3d); transaction.AddNewlyCreatedDBObject(headboardSolid3d, true); } transaction.Commit(); } }
protected override bool WorldDraw(WorldDraw _draw) { try { currentPoint = new Point3d(currentPoint.X, basePoint.Y, currentPoint.Z); transform = Matrix3d.Displacement(basePoint.GetVectorTo(currentPoint)); var geometry = _draw.Geometry; if (geometry != null) { geometry.PushModelTransform(transform); foreach (var entity in entities) { geometry.Draw(entity); } geometry.PopModelTransform(); } return(true); } catch (Exception _ex) { CADProxy.Editor.WriteMessage(_ex.Message); return(false); } }
public void RedirectVerticalArrow(Vector3d direction) { double rd = 1; if (IsVerticalRedirected) { rd *= -1; } if (IsVerticalMirrored) { rd *= -1; } if (rd * direction.Y >= 0) { return; } rd = IsVerticalRedirected ? -1 : 1; Point3d destPoint = Point3d.Origin.Add(_verticalTarnsform.CoordinateSystem3d.Yaxis.MultiplyBy(-rd * (_spaceLength * 2d + _length + _arrowLength))); Matrix3d mat = Matrix3d.Displacement(destPoint.GetAsVector()); VerticalTarnsform = mat; IsVerticalRedirected = !IsVerticalRedirected; }
/// <summary> /// Функция построения части лапы мотора /// </summary> /// <param name="database"> База данных</param> /// <param name="trans"> Транзакция</param> /// <param name="width"> Ширина части лапы</param> /// <param name="len"> Длина части лапы</param> /// <param name="coordinateX"> Позиция центра по координате Х </param> /// <param name="coordinateZ"> Позиция центра по координате Z</param> /// <param name="angle"> Угол вращения</param> private void BuildPawsBox(Database database, Transaction trans, double width, double len, double coordinateX, double coordinateZ, double angle) { double r = _diameretBox / 2; double koord = (r * ((Math.Sqrt(2) - 1) / 2) + r) / Math.Sqrt(2); // Открываем таблицу блоков для чтения BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; // Открываем таблицу блоков модели для записи BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Создать новую фигуру Solid3d paw = new Solid3d(); paw.SetDatabaseDefaults(); paw.CreateBox(width, len, 20); paw.ColorIndex = 7; // Позиция центра отрисовки фигуры paw.TransformBy(Matrix3d.Displacement(new Point3d(coordinateX, 0, coordinateZ) - Point3d.Origin)); Vector3d vRotPaw = new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 1, 0)); paw.TransformBy(Matrix3d.Rotation(angle, vRotPaw, new Point3d(coordinateX, 0, coordinateZ))); // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию blockTableRecord.AppendEntity(paw); trans.AddNewlyCreatedDBObject(paw, true); }
void TransformTail(Point3d p1, Point3d p11, double bulge, sbyte flip, ref Polyline tail, out double offset) { double angle = 2 * Math.Atan(bulge); /*угол касательной аналитически получен как 2 вписанных угла. Например, если bulge равно 1, то * имеем дугу с хордой равной двум выпуклостям. Это соответствует углу между хордой и касательной 90 градусов, а угол между хордой * и хордой к середине дуги 45 градусов */ angle *= flip; //чтобы было в нужную сторону на обоих концах Vector3d p1p2v = p1.Subtract(p11.GetAsVector()).GetAsVector(); p1p2v = p1p2v.RotateBy(angle, Vector3d.ZAxis * -1); //-1здесь служит для корректировки направления (по результатам отладки) Point2d first = tail.GetPoint2dAt(0); offset = first.Y * offsetMode * side; //смысл смещения заключается в том, что иногда требуется нарисовать шпильки со смещением от базовой линии //смещение управляется начальной координатой хвоста Matrix3d M = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, p1, p1p2v.DivideBy(p1p2v.Length), p1p2v.GetPerpendicularVector().MultiplyBy(side * flip), Vector3d.ZAxis); M *= Matrix3d.Displacement(Vector3d.YAxis * first.Y * -1 * (offsetMode ^ 1)); tail.TransformBy(M); }
public static void TecTest() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction Tx = db.TransactionManager.StartTransaction()) { BlockTableRecord ms = (BlockTableRecord)Tx.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead); RXObject brClass = RXObject.GetClass(typeof(BlockReference)); Point3d lastrightpt = new Point3d(0, 0, 0); foreach (ObjectId id in ms) { if (id.ObjectClass == brClass) { BlockReference br = (BlockReference)Tx.GetObject(id, OpenMode.ForWrite); ed.WriteMessage("NAME:{0}\n", br.Name); Extents3d bounds = br.GeometricExtents; ed.WriteMessage("BOUNDS: {0}\n", bounds.ToString()); Vector3d vec = (Vector3d)(lastrightpt - bounds.MinPoint); ed.WriteMessage("VECTOR: {0}\n", vec.ToString()); Point3d rightpt = new Point3d(bounds.MaxPoint.X, bounds.MinPoint.Y, 0);; Vector3d newrp = (Vector3d)(vec + rightpt.GetAsVector() + (new Vector3d(50, 0, 0))); lastrightpt = new Point3d(newrp.X, newrp.Y, 0); ed.WriteMessage("NEWLASTRIGHT SET to {0}\n", lastrightpt); Matrix3d mat = Matrix3d.Displacement(vec); br.TransformBy(mat); } } Tx.Commit(); } }
//******************* wstawianie bloku public void wstawblok( Database db, Editor ed, Point3d pnkwstaw, double kat, string attText, double atangle, string blockName, string attTag, string warstwa ) { using (Transaction tr1 = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr1.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); using (BlockReference br = new BlockReference(Point3d.Origin, bt[blockName])) { br.Rotation = RadiansToDegrees(kat); br.Layer = warstwa; br.TransformBy(Matrix3d .Displacement(pnkwstaw - Point3d.Origin) .PreMultiplyBy(ed.CurrentUserCoordinateSystem)); btr.AppendEntity(br); tr1.AddNewlyCreatedDBObject(br, true); InsertAttibuteInBlockRef(br, attTag, attText, atangle, tr1); } tr1.Commit(); } }
// 移动的函数. public static void Move(Entity ent, Point3d sourcePt, Point3d targetPt) { Vector3d vec = targetPt - sourcePt; Matrix3d mt = Matrix3d.Displacement(vec); ent.TransformBy(mt); }
moveSite(this ObjectIdCollection ids, Point3d pnt3dFrom, Point3d pnt3dTo) { Vector3d v3d = pnt3dFrom.GetVectorTo(pnt3dTo); try { using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId id in ids) { Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite); if (ent is CogoPoint) { CogoPoint cgPnt = (CogoPoint)ent; Point3d cgPntLoc = id.getCogoPntCoordinates(); Point3d cgPntNew = cgPntLoc.TransformBy(Matrix3d.Displacement(v3d)); cgPnt.Easting = cgPntNew.X; cgPnt.Northing = cgPntNew.Y; } else { ent.TransformBy(Matrix3d.Displacement(v3d)); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 587"); } }
/// <summary> /// 指定基点与目标点复制实体 /// </summary> /// <param name="ent">实体对象</param> /// <param name="sourcePt">基点</param> /// <param name="targetPt">目标点</param> /// <returns>复制的实体对象</returns> public static Entity CopyTo(this Entity ent, Point3d sourcePt, Point3d targetPt) { Matrix3d mt = Matrix3d.Displacement(targetPt - sourcePt); Entity entCopy = ent.GetTransformedCopy(mt); return(entCopy); }
moveCogoPoint(this ObjectId idCgPnt, Point3d pnt3dTo) { Point3d pnt3dNew = Pub.pnt3dO; try { using (Transaction tr = BaseObjs.startTransactionDb()) { CogoPoint cgPnt = (CogoPoint)tr.GetObject(idCgPnt, OpenMode.ForWrite); Matrix3d matrx3d = BaseObjs._editor.CurrentUserCoordinateSystem; CoordinateSystem3d coordSys = matrx3d.CoordinateSystem3d; Point3d pnt3dFrom = idCgPnt.getCogoPntCoordinates(); Vector3d v3d = new Vector3d(pnt3dTo.X - pnt3dFrom.X, pnt3dTo.Y - pnt3dFrom.Y, 0); pnt3dNew = pnt3dFrom.TransformBy(Matrix3d.Displacement(v3d)); cgPnt.Easting = pnt3dNew.X; cgPnt.Northing = pnt3dNew.Y; } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 554"); } }
moveLdrEndpoint(ObjectId idLDR, Point3d pnt3dFrom, Point3d pnt3dTo, Point3d pnt3dBase) { Point3d pnt3dNew = Pub.pnt3dO; try { using (Transaction tr = BaseObjs.startTransactionDb()) { Leader ldr = (Leader)tr.GetObject(idLDR, OpenMode.ForWrite); Vector3d v3d = new Vector3d(pnt3dTo.X - pnt3dFrom.X, pnt3dTo.Y - pnt3dFrom.Y, 0); pnt3dNew = pnt3dBase.TransformBy(Matrix3d.Displacement(v3d)); try { int x = ldr.NumVertices; ldr.SetVertexAt(x - 1, pnt3dNew); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 520"); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 527"); } return(pnt3dNew); }
// Sampler函数用于检测用户的输入. protected override SamplerStatus Sampler(JigPrompts prompts) { // 定义一个点拖动交互类. JigPromptPointOptions optJig = new JigPromptPointOptions("\n请指定第二点:"); // 设置拖拽光标类型. optJig.Cursor = CursorType.RubberBand; // 设置拖动光标基点. optJig.BasePoint = sourcePt; optJig.UseBasePoint = true; // 用AcquirePoint函数得到用户输入的点. PromptPointResult resJig = prompts.AcquirePoint(optJig); targetPt = resJig.Value; // 如果用户拖拽,则用矩阵变换的方法移动选择集中的全部对象. if (curPt != targetPt) { Matrix3d moveMt = Matrix3d.Displacement(targetPt - curPt); for (int i = 0; i <= ids.Length - 1; i++) { entCopy[i].TransformBy(moveMt); } // 保存当前点. curPt = targetPt; return(SamplerStatus.OK); } else { return(SamplerStatus.NoChange); } }
public void DrawAndSaveAs() { if (File.Exists(filePath)) { throw new Exception("已经存在temp.dwg,请保证已经删除"); } using (Database db = new Database()) using (Transaction acTrans = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)acTrans.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Solid3d solid = new Solid3d(); solid.CreateBox(width, depth, height); //Move the block to the left-behind origin solid.TransformBy(Matrix3d.Displacement(new Vector3d(width / 2, -depth / 2, height / 2))); btr.AppendEntity(solid); acTrans.AddNewlyCreatedDBObject(solid, true); acTrans.Commit(); db.SaveAs(filePath, DwgVersion.Newest); } }
// 复制的函数. public static void Copy(Entity ent, Point3d sourcePt, Point3d targetPt) { Matrix3d mt = Matrix3d.Displacement(targetPt - sourcePt); Entity entCopy = ent.GetTransformedCopy(mt); AppendEntity(entCopy); }
public void DisplaceBlock(BlockReference br) { using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; float Zbottom = (float)(ZOnSurface - Z0); // Position the center of the block br.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Zbottom) - Point3d.Origin)); Matrix3d curUCSMatrix = doc.Editor.CurrentUserCoordinateSystem; CoordinateSystem3d curUCS = curUCSMatrix.CoordinateSystem3d; // Rotate the block around the axis that is defined by the points Vector3d vRot = new Point3d(X1, Y1, Z1). GetVectorTo(new Point3d(X0, Y0, ZOnSurface)); br.TransformBy(Matrix3d.Rotation(Slope, vRot, new Point3d(X0, Y0, ZOnSurface))); // Save the new objects to the database acTrans.Commit(); } }
public void TransformEnties() { Vector3d UserXaxis = db.Ucsxdir; Vector3d WXaxis = new Vector3d(1, 0, 0); Vector3d Zaxis = new Vector3d(0, 0, 1); double Rangle = UserXaxis.GetAngleTo(WXaxis); if (UserXaxis.Y < 0) { Zaxis = Zaxis.Negate(); //1.03版修改,修正角度旋转正负问题 } Matrix3d Rmat = Matrix3d.Rotation(Rangle, Zaxis, mdragPT); //旋转矩阵 if (mdragPT.TransformBy(UCS.Inverse()).X >= mbasePT.TransformBy(UCS.Inverse()).X) { mIsRight = true; Matrix3d mat = Matrix3d.Displacement(mbasePT.GetVectorTo(mdragPT)).PreMultiplyBy(Rmat); //旋转矩阵左乘位移矩阵 foreach (Entity ent in mEntities) { ent.TransformBy(mat); } } else { mIsRight = false; Line L = (Line)mEntitiesL[0]; Vector3d Vt = new Vector3d(L.Length, 0, 0); Matrix3d mat = Matrix3d.Displacement(mbasePT.GetVectorTo(mdragPT) - Vt).PreMultiplyBy(Rmat);//旋转矩阵左乘位移矩阵,然后镜像矩阵左乘前结果 foreach (Entity ent in mEntitiesL) { ent.TransformBy(mat); } } }
private static void SetXDataAndMoveToLocation( Entity ent, ResultBuffer rbdata, Point3d pt ) { Database db = Application.DocumentManager.MdiActiveDocument.Database; Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { ent = tr.GetObject(ent.ObjectId, OpenMode.ForWrite) as Entity; // Let's add our message information as XData, // for later editing RbEncoder.AddRegAppTableRecord(APPLICATION_PREFIX); ResultBuffer rb = rbdata; ent.XData = rb; rb.Dispose(); // Move to the correct location Matrix3d disp = Matrix3d.Displacement(pt.GetAsVector()); ent.TransformBy(disp); tr.Commit(); } }
/// <summary> /// 复制图形 图形已经加入到图形数据库中 /// </summary> /// <param name="entId">图形对象的ObjectId</param> /// <param name="sourcePoint">参考原点</param> /// <param name="targetPoint">参考目标点</param> public static Entity CopyEntity(this ObjectId entId, Point3d sourcePoint, Point3d targetPoint) { // 声明一个图形对象 Entity entR; // 当前图形数据库 Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { // 打开块表 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); // 打开块表记录 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); // Entity ent = (Entity)trans.GetObject(entId, OpenMode.ForWrite); // 打开图形 Entity ent = (Entity)entId.GetObject(OpenMode.ForWrite); // 计算变换矩阵 Vector3d vectoc = sourcePoint.GetVectorTo(targetPoint); Matrix3d mt = Matrix3d.Displacement(vectoc); entR = ent.GetTransformedCopy(mt); // 提交事务处理 trans.Commit(); } return(entR); }
public static Matrix3d GetToLocalTransform(Point3d pointUcs, Matrix3d ucs) { Matrix3d toLocalCs = ucs.Inverse(); toLocalCs = toLocalCs.PostMultiplyBy(Matrix3d.Displacement(Point3d.Origin - pointUcs)); return(toLocalCs); }
/// <summary> /// 矩形阵列 /// </summary> /// <param name="entS">图形对象</param> /// <param name="rowNum">行数</param> /// <param name="columnNum">列数</param> /// <param name="disRow">行间距</param> /// <param name="disColumn">列间距</param> /// <returns>List</returns> 没有加入图形数据库 public static List <Entity> ArrayRectEntity(this Entity entS, int rowNum, int columnNum, double disRow, double disColumn) { if (entS.IsNewObject == true) { // 声明一个Entity类型集合 用于返回 List <Entity> entList = new List <Entity>(); Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { // 打开块表 BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); // 打开块表记录 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); for (int i = 0; i < rowNum; i++) { for (int j = 0; j < columnNum; j++) { Matrix3d mt = Matrix3d.Displacement(new Vector3d(j * disColumn, i * disRow, 0)); Entity entA = entS.GetTransformedCopy(mt); btr.AppendEntity(entA); trans.AddNewlyCreatedDBObject(entA, true); entList.Add(entA); } } trans.Commit(); } return(entList); } else { return(entS.ArrayRectEntity(rowNum, columnNum, disRow, disColumn)); } }
protected override bool WorldDraw(WorldDraw draw) { WorldGeometry geo = draw.Geometry; if (geo != null) { Vector3d vec = basePoint.GetVectorTo(secondPoint); Matrix3d disp = Matrix3d.Displacement(this.basePoint.GetVectorTo(this.secondPoint)); //geo.PushModelTransform(disp); for (int i = 0; i < blockPosition.Count; i++) { Point3d tempPoint = blockPosition[i] + vec; brefs[i].Position = tempPoint; geo.Draw(brefs[i]); } for (int i = 0; i < linesPosition.Count; i++) { Point3d tempStartPoint = linesPosition[i].Item1 + vec; Point3d tempEndPoint = linesPosition[i].Item2 + vec; lines[i].StartPoint = tempStartPoint; lines[i].EndPoint = tempEndPoint; geo.Draw(lines[i]); } //geo.PopModelTransform(); return(true); } return(false); }
public void Cmd_RcAlign() { var acCurDoc = Application.DocumentManager.MdiActiveDocument; var acCurDb = acCurDoc.Database; var acCurEd = acCurDoc.Editor; var objIds = acCurEd.GetAllSelection(false); if (objIds.Length <= 0) { return; } var alId = acCurEd.GetPoint("\nSelect point to align objects to: "); var alignPt = alId.Value; var alignX = alignPt.X; var alignType = acCurEd.GetSimpleKeyword("\nEnter alignment type: ", new[] { "Left", "Center", "Right" }); if (string.IsNullOrEmpty(alignType)) { return; } using (var acTrans = acCurDb.TransactionManager.StartTransaction()) { foreach (var obj in objIds) { var acEnt = acTrans.GetObject(obj, OpenMode.ForWrite) as Entity; if (acEnt == null) { continue; } var geomExt = acEnt.GeometricExtents; var cenPt = geomExt.MinPoint.GetMidPoint(geomExt.MaxPoint); switch (alignType) { case "Left": acEnt.TransformBy(Matrix3d.Displacement( geomExt.MinPoint.GetVectorTo(new Point3d(alignX, geomExt.MinPoint.Y, geomExt.MinPoint.Z)))); break; case "Center": acEnt.TransformBy(Matrix3d.Displacement( cenPt.GetVectorTo(new Point3d(alignX, cenPt.Y, cenPt.Z)))); break; case "Right": acEnt.TransformBy(Matrix3d.Displacement( geomExt.MaxPoint.GetVectorTo(new Point3d(alignX, geomExt.MaxPoint.Y, geomExt.MaxPoint.Z)))); break; } } acTrans.Commit(); } }
/// <summary> /// Функция построения элементов радиаторной решетки /// </summary> /// <param name="database"> База данных</param> /// <param name="trans"> Транзакция</param> /// <param name="coordinateX"> Позиция центра по координате Х</param> /// <param name="coordinateZ"> Позиция центра по координате Z</param> private void BuildRadiator(Database database, Transaction trans, double coordinateX, double coordinateZ) { // Открываем таблицу блоков для чтения BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; // Открываем таблицу блоков модели для записи BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Создать новую фигуру double sizeLenBox = _lenBox * 0.7; double sizeDiameretBox = _diameretBox / 8; Solid3d paw = new Solid3d(); paw.SetDatabaseDefaults(); paw.CreateBox(sizeDiameretBox, sizeLenBox, 5); paw.ColorIndex = 3; // Позиция центра отрисовки фигуры double coordY = -0.1 * _lenBox; paw.TransformBy(Matrix3d.Displacement(new Point3d(coordinateX, coordY, coordinateZ) - Point3d.Origin)); // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию blockTableRecord.AppendEntity(paw); trans.AddNewlyCreatedDBObject(paw, true); }
/// <summary> /// Gets the transformation matrix from the specified model space viewport Display Coordinate System (DCS) /// to the World Coordinate System (WCS). /// </summary> /// <param name="vp">The instance to which this method applies.</param> /// <returns>The DCS to WDCS transformation matrix.</returns> public static Matrix3d Dcs2Wcs(this Viewport vp) { return (Matrix3d.Rotation(-vp.TwistAngle, vp.ViewDirection, vp.ViewTarget) * Matrix3d.Displacement(vp.ViewTarget - Point3d.Origin) * Matrix3d.PlaneToWorld(vp.ViewDirection)); }
/// <summary> /// Returns the transformation matrix from the ViewportTableRecord DCS to WCS. /// </summary> /// <remarks>Borrowed from http://www.acadnetwork.com/index.php?topic=232.msg406#msg406</remarks> /// <param name="view">The ViewportTableRecord instance this method applies to.</param> /// <returns>The DCS to WCS transformation matrix.</returns> public static Matrix3d EyeToWorld(this AbstractViewTableRecord view) { return (Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) * Matrix3d.Displacement(view.Target - Point3d.Origin) * Matrix3d.PlaneToWorld(view.ViewDirection)); }
/// <summary> /// Gets the transformation matrix from the specified paper space viewport Display Coordinate System (DCS) /// to the paper space Display Coordinate System (PSDCS). /// </summary> /// <param name="vp">The instance to which this method applies.</param> /// <returns>The DCS to PSDCS transformation matrix.</returns> public static Matrix3d Dcs2Psdcs(this Viewport vp) { return (Matrix3d.Scaling(vp.CustomScale, vp.CenterPoint) * Matrix3d.Displacement(vp.CenterPoint.GetAsVector()) * Matrix3d.Displacement(vp.ViewCenter.Convert3D().GetAsVector().Negate())); }
private void HorizontalMirroring() { using (var tr = CADProxy.Document.TransactionManager.StartTransaction()) { foreach (var e in entities) { var ent = e.ObjectId.GetObject(OpenMode.ForWrite, true) as Entity; ent.Erase(false); if (ent.GetType() == typeof(DBText)) { ent.TransformBy(Matrix3d.Displacement(new Vector3d(0, (IsHMirror ? 9 : -9) * AppSettings.Get.ScaleFactor, 0))); } else { ent.TransformBy(Matrix3d.Mirroring(new Line3d(basePoint, new Vector3d(1, 0, 0)))); } ent.Erase(); } tr.Commit(); } foreach (var ent in buffer) { if (ent.GetType() == typeof(DBText) || ent.GetType() == typeof(AttributeDefinition)) { ent.TransformBy(Matrix3d.Displacement(new Vector3d(0, (IsHMirror ? 9 : -9), 0))); } else { ent.TransformBy(Matrix3d.Mirroring(new Line3d(new Point3d(0, 0, 0), new Vector3d(1, 0, 0)))); } } IsHMirror = !IsHMirror; }
public void TransformEnties() { Vector3d UserXaxis = db.Ucsxdir; Vector3d WXaxis = new Vector3d(1, 0, 0); Vector3d Zaxis = new Vector3d(0, 0, 1); double Rangle = UserXaxis.GetAngleTo(WXaxis); Matrix3d Rmat = Matrix3d.Rotation(Rangle, Zaxis, mdragPT); //旋转矩阵 Vector3d VT = new Vector3d(1, 1, 1); //插入点转换向量 if (mdragPT.TransformBy(UCS.Inverse()).X >= mbasePT.TransformBy(UCS.Inverse()).X&& mdragPT.TransformBy(UCS.Inverse()).Y >= mbasePT.TransformBy(UCS.Inverse()).Y) { VT = new Vector3d(0, 0, 0); } if (mdragPT.TransformBy(UCS.Inverse()).X < mbasePT.TransformBy(UCS.Inverse()).X&& mdragPT.TransformBy(UCS.Inverse()).Y >= mbasePT.TransformBy(UCS.Inverse()).Y) { VT = new Vector3d(-mtableob.Width, 0, 0); } if (mdragPT.TransformBy(UCS.Inverse()).X < mbasePT.TransformBy(UCS.Inverse()).X&& mdragPT.TransformBy(UCS.Inverse()).Y < mbasePT.TransformBy(UCS.Inverse()).Y) { VT = new Vector3d(-mtableob.Width, -mtableob.Height, 0); } if (mdragPT.TransformBy(UCS.Inverse()).X >= mbasePT.TransformBy(UCS.Inverse()).X&& mdragPT.TransformBy(UCS.Inverse()).Y < mbasePT.TransformBy(UCS.Inverse()).Y) { VT = new Vector3d(0, -mtableob.Height, 0); } Matrix3d mat = Matrix3d.Displacement(mbasePT.GetVectorTo(mdragPT) + VT); //位移矩阵 mtableob.TransformBy(mat.PreMultiplyBy(Rmat)); //位移矩阵左乘旋转矩阵获得变形矩阵 }