public static BaseC3dObject CreateAlignment( string alName, string layerName, string stil, string labelSet, string desc) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; CivilDocument civilDoc = CivilApplication.ActiveDocument; ObjectId al = Alignment.Create(civilDoc, alName, null, layerName, stil, labelSet); BaseC3dObject alObject = new BaseC3dObject(); using (Transaction ts = db.TransactionManager.StartTransaction()) { try { Alignment alignment = al.GetObject(OpenMode.ForWrite) as Alignment; alignment.Layer = layerName; alignment.Description = desc; alObject.Name = alignment.Name; alObject.Id = alignment.ObjectId; ts.Commit(); } catch (System.Exception) { throw; } } return(alObject); }
public void TestConstructor_SqueezeConsecutiveEmptyParts() { var alignment = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 0 }, new char[0]), new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F' }), new AlignedPair <int, char>(new int[0], new [] { 'G' }), new AlignedPair <int, char>(new [] { 3 }, new char[0]), new AlignedPair <int, char>(new [] { 4 }, new [] { 'H', 'I' }), new AlignedPair <int, char>(new [] { 5 }, new [] { 'J' }), new AlignedPair <int, char>(new int[0], new [] { 'K' }), new AlignedPair <int, char>(new int[0], new [] { 'L' }), }); var expected = new Alignment <int, char>(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new char[0]), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new int[0], new [] { 'E', 'F', 'G' }), new AlignedPair <int, char>(new [] { 3 }, new char[0]), new AlignedPair <int, char>(new [] { 4 }, new [] { 'H', 'I' }), new AlignedPair <int, char>(new [] { 5 }, new [] { 'J' }), new AlignedPair <int, char>(new int[0], new [] { 'K', 'L' }), }); Assert.Equal(expected, alignment); }
public void TestConcat() { var left = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new [] { 'A', 'B' }), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new [] { 3, 4 }, new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F' }), }); var right = Alignment.Create(new[] { new AlignedPair <int, char>(new int[0], new [] { 'G' }), new AlignedPair <int, char>(new [] { 5 }, new [] { 'H' }), new AlignedPair <int, char>(new [] { 6, 7 }, new [] { 'I' }), }); var expected = new Alignment <int, char>(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new [] { 'A', 'B' }), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new [] { 3, 4 }, new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F', 'G' }), new AlignedPair <int, char>(new [] { 5 }, new [] { 'H' }), new AlignedPair <int, char>(new [] { 6, 7 }, new [] { 'I' }), }); var concatenated = left.Concat(right); Assert.Equal(expected, concatenated); }
public void TestConstructor_RemoveEmptyPairs() { var alignment = Alignment.Create(new[] { new AlignedPair <int, char>(new int[0], new char[0]), new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new int[0], new char[0]), new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new [] { 3 }, new char[0]), new AlignedPair <int, char>(new int[0], new char[0]), }); var expected = new Alignment <int, char>(new[] { new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new [] { 3 }, new char[0]), }); Assert.Equal(expected, alignment); }
public void Test() { var a1 = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new int[0], new [] { 'E' }), new AlignedPair <int, char>(new [] { 1 }, new char[0]), new AlignedPair <int, char>(new int[0], new [] { 'F' }), new AlignedPair <int, char>(new [] { 3 }, new char[0]), }); Assert.Equal(a1, a1.DetachLeft().AttachLeft(a1.GetRight())); Assert.Equal(a1, a1.DetachRight().AttachRight(a1.GetLeft())); var a2 = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 4 }, new char[0]), new AlignedPair <int, char>(new int[0], new [] { 'G', 'H' }), new AlignedPair <int, char>(new [] { 5, 6 }, new [] { 'I' }), }); var a3 = a1.Concat(a2); Assert.Equal(a3, a1.DetachRight().Join(a2.DetachRight().Translate(a1.GetLeft().Length)).AttachRight(a3.GetLeft())); Assert.Equal(a3, a1.DetachLeft().Join(a2.DetachLeft().Translate(a1.GetRight().Length)).AttachLeft(a3.GetRight())); }
addAlignmentFromPoly(string nameAlign, string nameLayer, ObjectId idPoly, string nameStyle, string nameLabelStyle, bool eraseEx, bool addCurves = false) { Alignment align = null; PolylineOptions opts = new PolylineOptions(); opts.AddCurvesBetweenTangents = addCurves; opts.EraseExistingEntities = eraseEx; opts.PlineId = idPoly; Layer.manageLayers(nameLayer); try { using (BaseObjs._acadDoc.LockDocument()) { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectId id = Alignment.Create(BaseObjs._civDoc, opts, nameAlign, null, nameLayer, nameStyle, nameLabelStyle); align = (Alignment)tr.GetObject(id, OpenMode.ForWrite); align.ReferencePointStation = 1000; tr.Commit(); } } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Align.cs: line: 35", ex.Message)); } return(align); }
public void TestGetLeftAndGetRight() { var alignment = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new [] { 'A', 'B' }), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new [] { 3, 4 }, new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F' }), }); var expectedLeft = new[] { 0, 1, 2, 3, 4 }; Assert.Equal(expectedLeft, alignment.GetLeft()); var expectedRight = new[] { 'A', 'B', 'C', 'D', 'E', 'F' }; Assert.Equal(expectedRight, alignment.GetRight()); }
public Alignment IzradaAlignmenta() { Polyline poly = ElementiAlignmenta(); if (poly != null) { PolylineOptions pOpts = new PolylineOptions(); pOpts.AddCurvesBetweenTangents = false; pOpts.EraseExistingEntities = false; pOpts.PlineId = poly.ObjectId; string ime = "Okomito pero " + brojPera.ToString(); ObjectId peroAlignmentID = Alignment.Create(CivilApplication.ActiveDocument, pOpts, ime, null, "0", "Basic", "_No Labels"); using (Transaction tr = db.TransactionManager.StartTransaction()) { Alignment peroAlignment = tr.GetObject(peroAlignmentID, OpenMode.ForWrite) as Alignment; if (Strana == "Desno") { try { peroAlignment.Reverse(); } catch (System.Exception ex) { ed.WriteMessage("Alignment reverse nije uspio" + ex.Message); throw; } } tr.Commit(); return(peroAlignment); } } else { return(null); } }
public void TestSwap() { var alignment = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new [] { 'A', 'B' }), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new [] { 3, 4 }, new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F' }), }); var expected = new Alignment <char, int>(new[] { new AlignedPair <char, int>(new [] { 'A', 'B' }, new [] { 0, 1 }), new AlignedPair <char, int>(new [] { 'C', 'D' }, new [] { 2 }), new AlignedPair <char, int>(new [] { 'E' }, new [] { 3, 4 }), new AlignedPair <char, int>(new [] { 'F' }, new int[0]), }); var reversed = alignment.Swap(); Assert.Equal(expected, reversed); Assert.Equal(alignment, reversed.Swap()); }
public void TestDetachRight() { var alignment = Alignment.Create(new[] { new AlignedPair <int, char>(new [] { 0, 1 }, new [] { 'A', 'B' }), new AlignedPair <int, char>(new [] { 2 }, new [] { 'C', 'D' }), new AlignedPair <int, char>(new [] { 3, 4 }, new char[0]), new AlignedPair <int, char>(new [] { 5 }, new [] { 'E' }), new AlignedPair <int, char>(new int[0], new [] { 'F' }), }); var expected = new DetachedAlignment <char>(new[] { new Interval <char[]>(0, 2, new [] { 'A', 'B' }), new Interval <char[]>(2, 1, new [] { 'C', 'D' }), new Interval <char[]>(3, 2, new char[0]), new Interval <char[]>(5, 1, new [] { 'E' }), new Interval <char[]>(6, 0, new [] { 'F' }), }); var rightAlignment = alignment.DetachRight(); Assert.Equal(expected, rightAlignment); }
public static void ReadICD() { // CAD指针 CivilDocument civildoc = CivilApplication.ActiveDocument; Document doc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = doc.Database; Editor ed = doc.Editor; PromptOpenFileOptions opt = new PromptOpenFileOptions("\n请选择线型文件."); opt.Filter = "ICD File (*.icd)|*.icd|All files (*.*)|*.*"; PromptFileNameResult res = ed.GetFileNameForOpen(opt); if (res.Status != PromptStatus.OK) { return; } SRBA.PM bill = new SRBA.PM(res.StringResult); // 转化平曲线 ObjectId AlgID = Alignment.Create(civildoc, Path.GetFileNameWithoutExtension(res.StringResult), null, "0", "Basic", "All Labels"); using (Transaction ts = acCurDb.TransactionManager.StartTransaction()) { Alignment myAg = ts.GetObject(AlgID, OpenMode.ForWrite) as Alignment; AddICD(ref myAg, ref bill, ref ed); myAg.ReferencePointStation = bill.StartPK; //ed.WriteMessage("\n{0}读取成功.", res.StringResult); // 竖曲线 PromptKeywordOptions pKeyOpts = new PromptKeywordOptions("\n是否加载竖曲线?"); pKeyOpts.Keywords.Add("Y"); pKeyOpts.Keywords.Add("N"); pKeyOpts.Keywords.Default = "Y"; pKeyOpts.AllowNone = true; PromptResult pKeyRes = doc.Editor.GetKeywords(pKeyOpts); switch (pKeyRes.Status) { case PromptStatus.OK: if (pKeyRes.StringResult == "Y") { SRBA.SQX kitty = new SRBA.SQX(Path.ChangeExtension(res.StringResult, "SQX")); ObjectId layerId = myAg.LayerId; ObjectId styleId = civildoc.Styles.ProfileStyles["Basic"]; ObjectId labelSetId = civildoc.Styles.LabelSetStyles.ProfileLabelSetStyles["Complete Label Set"]; ObjectId oProfileId = Profile.CreateByLayout(myAg.Name + "-Profile", myAg.ObjectId, layerId, styleId, labelSetId); Profile oProfile = ts.GetObject(oProfileId, OpenMode.ForWrite) as Profile; AddSQX(ref oProfile, ref kitty, ref ed); } break; default: break; } // 转化对比JD法 //pKeyOpts = new PromptKeywordOptions("\n是否加载交点法平曲线?"); //pKeyOpts.Keywords.Add("Y"); //pKeyOpts.Keywords.Add("N"); //pKeyOpts.Keywords.Default = "Y"; //pKeyOpts.AllowNone = true; //pKeyRes = doc.Editor.GetKeywords(pKeyOpts); //switch (pKeyRes.Status) //{ // case PromptStatus.OK: // if (pKeyRes.StringResult == "Y") // { // PQXnew kitty = new PQXnew("Test"); // kitty.ReadICDFile(res.StringResult); // ObjectId layerId = myAg.LayerId; // ObjectId styleId = civildoc.Styles.ProfileStyles["Basic"]; // ObjectId labelSetId = civildoc.Styles.LabelSetStyles.ProfileLabelSetStyles["Complete Label Set"]; // ObjectId oProfileId = Profile.CreateByLayout(myAg.Name + "-Profile", myAg.ObjectId, layerId, styleId, labelSetId); // Profile oProfile = ts.GetObject(oProfileId, OpenMode.ForWrite) as Profile; // AddPQX( 0,24000,500, ref acCurDb, ref kitty, ref ed); // } // break; // default: // break; //} ts.Commit(); } }
public static Alignment CreateAlignmentFromIFC(string ifcFile) { Alignment aln = null; Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; CivilDocument Cdoc = CivilApplication.ActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; ObjectId aln_id = ObjectId.Null; ObjectId layerId = ObjectId.Null; ObjectId aln_styleId = ObjectId.Null; ObjectId profStyleId = ObjectId.Null; ObjectId alnLabelSetId = ObjectId.Null; ObjectId profLabelSetId = ObjectId.Null; using (Transaction CADtrans = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)CADtrans.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)CADtrans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); LayerTable acLyrTbl = CADtrans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable; foreach (ObjectId id in acLyrTbl) { layerId = id; break; } AlignmentStyleCollection style_col = Cdoc.Styles.AlignmentStyles; if (style_col.Count > 0) { aln_styleId = style_col[0]; } AlignmentLabelSetStyleCollection alignmentLabelSets = Cdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles; if (alignmentLabelSets.Count > 0) { alnLabelSetId = alignmentLabelSets[0]; } aln_id = Alignment.Create(Cdoc, "Alingment_" + DateTime.Now.ToShortTimeString(), ObjectId.Null, layerId, aln_styleId, alnLabelSetId, AlignmentType.Centerline); aln = CADtrans.GetObject(aln_id, OpenMode.ForRead) as Alignment; int noOfSpiral = 0; string str = string.Empty; using (var model = IfcStore.Open(ifcFile)) { var ifcAlignments = model.Instances.OfType <IfcAlignment>(); try { foreach (IfcAlignment algn in ifcAlignments) { IfcCurve cv = algn.Axis; IfcAlignmentCurve algnCv = cv as IfcAlignmentCurve; if (algnCv != null) { IfcAlignment2DHorizontal algn_hort = algnCv.Horizontal; foreach (IfcAlignment2DHorizontalSegment seg in algn_hort.Segments) { IfcCurveSegment2D seg_2d = seg.CurveGeometry; if (seg_2d.GetType() == typeof(IfcLineSegment2D)) { //get ifc data IfcLineSegment2D line = seg_2d as IfcLineSegment2D; IfcCartesianPoint pt = line.StartPoint; IfcPlaneAngleMeasure dir = line.StartDirection;//this is bearing angle IfcPositiveLengthMeasure len = line.SegmentLength; double angle = bearing2AutocadAngle(dir); ///create civil 3d line entity //create point 1 Point3d pt1 = new Point3d(pt.X, pt.Y, 0); //create point 2 double x = Math.Sin(angle) * len; double y = Math.Cos(angle) * len; Vector3d vector = new Vector3d(x, y, 0); Matrix3d mat = Matrix3d.Displacement(vector); Point3d pt2 = pt1.TransformBy(mat); ed.WriteMessage("Crate line\n"); aln.Entities.AddFixedLine(aln.Entities.Count(), pt1, pt2); } if (seg_2d.GetType() == typeof(IfcTransitionCurveSegment2D)) { noOfSpiral++; IfcTransitionCurveSegment2D tran = seg_2d as IfcTransitionCurveSegment2D; double rad = 0; double startRadius = 0, endRadius = 0; if (tran.StartRadius != null) { startRadius = tran.StartRadius.Value; } if (tran.EndRadius != null) { endRadius = tran.EndRadius.Value; } if (startRadius != 0 && endRadius == 0) { rad = startRadius; } else if (endRadius != 0 && startRadius == 0) { rad = endRadius; } IfcCartesianPoint pt = tran.StartPoint; IfcPositiveLengthMeasure len = tran.SegmentLength; bool IsEndRadiusCCW = false, IsStartRadiusCCW = false, isClockwise = false; if (tran.IsEndRadiusCCW != null) { IsEndRadiusCCW = tran.IsEndRadiusCCW; } if (tran.IsStartRadiusCCW != null) { IsStartRadiusCCW = tran.IsStartRadiusCCW; } if (IsStartRadiusCCW == true) { isClockwise = IsStartRadiusCCW; } double dir = tran.StartDirection; IfcTransitionCurveType tranType = tran.TransitionCurveType; //determine if it in curve or out curve by no? SpiralCurveType spiralCurveType = SpiralCurveType.InCurve; if (noOfSpiral % 2 == 0) { spiralCurveType = SpiralCurveType.OutCurve; } if (tran.TransitionCurveType == IfcTransitionCurveType.CLOTHOIDCURVE) { ed.WriteMessage("Crate Transition Curve\n"); if (rad == 0) { aln.Entities.AddFixedSpiral(aln.Entities.Count(), startRadius, endRadius, len, Autodesk.Civil.SpiralType.Clothoid); } else if (startRadius != 0) { aln.Entities.AddFloatSpiral(aln.Entities.Count(), rad, len, isClockwise, Autodesk.Civil.SpiralType.Clothoid); } //aln.Entities.AddFixedSpiral(aln.Entities.Count(), rad, len, spiralCurveType, Autodesk.Civil.SpiralType.Clothoid); } } if (seg_2d.GetType() == typeof(IfcCircularArcSegment2D)) { IfcCircularArcSegment2D cir = seg_2d as IfcCircularArcSegment2D; IfcPositiveLengthMeasure len = cir.SegmentLength; IfcCartesianPoint pt = cir.StartPoint; IfcPlaneAngleMeasure dir = cir.StartDirection; IfcPositiveLengthMeasure rad = cir.Radius; double angle = bearing2AutocadAngle(dir); bool isCCW = (bool)cir.IsCCW; Point3d startPt = new Point3d(pt.X, pt.Y, 0); double x = Math.Sin(angle) * len; double y = Math.Cos(angle) * len; Vector3d vector = new Vector3d(x, y, 0); //ed.WriteMessage("Crate circle Curve\n"); // aln.Entities.AddFixedCurve(startPt, vector, rad, isCCW); } if (seg_2d.GetType() == typeof(IfcCurveSegment2D)) { IfcCurveSegment2D crv = seg_2d as IfcCurveSegment2D; IfcPositiveLengthMeasure len = crv.SegmentLength; IfcCartesianPoint pt = crv.StartPoint; IfcPlaneAngleMeasure dir = crv.StartDirection; } } #region >>>>=========== Create profile entities // get the standard style and label set // these calls will fail on templates without a style named "Standard" ProfileStyleCollection prof_tyle_col = Cdoc.Styles.ProfileStyles; if (prof_tyle_col.Count > 0) { profStyleId = prof_tyle_col[0]; } ProfileLabelSetStyleCollection profilLabelSets = Cdoc.Styles.LabelSetStyles.ProfileLabelSetStyles; if (profilLabelSets.Count > 0) { profLabelSetId = profilLabelSets[0]; } ObjectId oProfileId = Profile.CreateByLayout("Profile", aln_id, layerId, profStyleId, profLabelSetId); Profile PROF = CADtrans.GetObject(oProfileId, OpenMode.ForWrite) as Profile; //get profile information from ifc IfcAlignment2DVertical algn_vert = algnCv.Vertical; foreach (IfcAlignment2DVerticalSegment seg in algn_vert.Segments) { if (seg.GetType() == typeof(IfcAlignment2DVerSegLine)) { IfcAlignment2DVerSegLine line = seg as IfcAlignment2DVerSegLine; double len = line.HorizontalLength; double z = Convert.ToDouble(line.StartHeight.Value); double slope = Convert.ToDouble(line.StartGradient.Value); } if (seg.GetType() == typeof(IfcAlignment2DVerSegParabolicArc)) { IfcAlignment2DVerSegParabolicArc tran = seg as IfcAlignment2DVerSegParabolicArc; double parabola = Convert.ToDouble(tran.ParabolaConstant); bool isConvex = (bool)tran.IsConvex.Value; double ch = Convert.ToDouble(tran.StartDistAlong); double len = Convert.ToDouble(tran.HorizontalLength); double z = Convert.ToDouble(tran.StartHeight.Value); double slope = Convert.ToDouble(tran.StartGradient.Value); } if (seg.GetType() == typeof(IfcAlignment2DVerSegCircularArc)) { IfcAlignment2DVerSegCircularArc cir = seg as IfcAlignment2DVerSegCircularArc; double radius = Convert.ToDouble(cir.Radius); bool isConvex = (bool)cir.IsConvex.Value; double ch = Convert.ToDouble(cir.StartDistAlong); double len = Convert.ToDouble(cir.HorizontalLength); double z = Convert.ToDouble(cir.StartHeight.Value); double slope = Convert.ToDouble(cir.StartGradient.Value); } //Point2d startPoint = new Point2d(station_start, H_start); //Point2d endPoint = new Point2d(station_end, H_end); //ProfileTangent oTangent = PROF.Entities.AddFixedTangent(startPoint, endPoint); #endregion } } } } catch { } } CADtrans.Commit(); } return(aln); }