private IEnumerable <GeometryObject> Tessellate(Curve curve) { var result = new List <GeometryObject>(); // use the ASM tesselation of the curve var pkg = renderPackageFactory.CreateRenderPackage(); curve.Tessellate(pkg, renderPackageFactory.TessellationParameters); // get necessary info to enumerate and convert the lines //var lineCount = pkg.LineVertexCount * 3 - 3; var verts = pkg.LineStripVertices.ToList(); // we scale the tesselation rather than the curve var conv = UnitConverter.DynamoToHostFactor(UnitType.UT_Length); var scaledXYZs = new List <XYZ>(); for (var i = 0; i < verts.Count; i += 3) { scaledXYZs.Add(new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv)); } result.Add(PolyLine.Create(scaledXYZs)); return(result); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; Selection sel = uiApp.ActiveUIDocument.Selection; //pick a point List <XYZ> points = new List <XYZ>(); for (int i = 0; i < 5; i++) { XYZ point = sel.PickPoint("pick a point inside a room"); points.Add(point); } PolyLine polyline = PolyLine.Create(points); using (Transaction tx = new Transaction(doc)) { tx.Start("create wall section view"); foreach (XYZ point in points) { XYZElement e = new XYZElement(doc, point); } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Tessellate the curve: /// 1). If there are more than 2 points, create a polyline out of the points; /// 2). If there are exactly 2 points, create a line; /// 3). If there's exception thrown during the tessellation process, attempt to create /// a line from start and end points. If that fails, a point will be created instead. /// </summary> /// <param name="curve"></param> /// <returns></returns> private IEnumerable <GeometryObject> Tessellate(Curve curve) { var result = new List <GeometryObject>(); try { // we scale the tesselation rather than the curve var conv = UnitConverter.DynamoToHostFactor(UnitType.UT_Length); // use the ASM tesselation of the curve var pkg = renderPackageFactory.CreateRenderPackage(); curve.Tessellate(pkg, renderPackageFactory.TessellationParameters); // get necessary info to enumerate and convert the lines //var lineCount = pkg.LineVertexCount * 3 - 3; var verts = pkg.LineStripVertices.ToList(); if (verts.Count > 2) { var scaledXYZs = new List <XYZ>(); for (var i = 0; i < verts.Count; i += 3) { scaledXYZs.Add(new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv)); } result.Add(PolyLine.Create(scaledXYZs)); } else if (verts.Count == 2) { result.Add(Line.CreateBound(curve.StartPoint.ToXyz(), curve.EndPoint.ToXyz())); } } catch (Exception) { // Add a red bounding box geometry to identify that some errors occur var bbox = curve.BoundingBox; result.AddRange(ProtoToRevitMesh.CreateBoundingBoxMeshForErrors(bbox.MinPoint, bbox.MaxPoint)); try { result.Add(Line.CreateBound(curve.StartPoint.ToXyz(), curve.EndPoint.ToXyz())); } catch (Exception) { try { result.Add(DocumentManager.Instance.CurrentUIApplication.Application.Create.NewPoint(curve.StartPoint.ToXyz())); } catch (ArgumentException) { //if either the X, Y or Z of the point is infinite, no need to add it for preview } } } return(result); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 //新建一个窗口 Window1 window1 = new Window1(); if (window1.ShowDialog() == true) { //窗口打开并停留,只有点击按键之后,窗口关闭并返回true } //按键会改变window的属性,通过对属性的循环判断来实现对按键的监测 while (!window1.Done) { //选择平曲线 if (window1.FlatCurve) { //因为要对原有模型线进行一个删除是对文件进行一个删除,故要创建一个事件 using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("移动平曲线"); FlatModelLine = moveModelLine(commandData); //2、重置window1.FlatCurve window1.FlatCurve = false; transaction.Commit(); } } if (window1.ShowDialog() == true) { //窗口打开并停留,只有点击按键之后,窗口关闭并返回true } //选择纵曲线 if (window1.VerticalCurve) { //因为要对原有模型线进行一个删除是对文件进行一个删除,故要创建一个事件 using (Transaction transaction = new Transaction(uiDoc.Document)) { transaction.Start("移动纵曲线"); VerticalModelLine = moveModelLine(commandData); //2、重置window1.VerticalCurve window1.VerticalCurve = false; transaction.Commit(); } } if (window1.ShowDialog() == true) { //窗口打开并停留,只有点击按键之后,窗口关闭并返回true } } //获取平曲线上100个点 //计算首尾两点X轴差值以及曲线长度 double FdelX = FlatModelLine.Evaluate(0, true).X - FlatModelLine.Evaluate(1, true).X; double FLength = FlatModelLine.Length; double FY; //选谁的Y最小就选谁 if (FlatModelLine.Evaluate(0, true).Y <= FlatModelLine.Evaluate(1, true).Y) { FY = FlatModelLine.Evaluate(0, true).Y; } else { FY = FlatModelLine.Evaluate(1, true).Y; } List <XYZ> FlatCurvePointList = new List <XYZ>(); for (int i = 0; i < 100; i += 1) { //设置起点和终点,并创建直线,来与原有线段相交 XYZ point1 = new XYZ(FlatModelLine.Evaluate(0, true).X - i * FdelX / 100, FY, FlatModelLine.Evaluate(0, true).Z); XYZ point2 = new XYZ(FlatModelLine.Evaluate(0, true).X - i * FdelX / 100, FY + FLength, FlatModelLine.Evaluate(0, true).Z); Line line = Line.CreateBound(point1, point2); Curve curve = line as Curve; //求交点并把交点放到集里面去 IntersectionResultArray intersectionResultArray; FlatModelLine.Intersect(curve, out intersectionResultArray); XYZ xYZ = intersectionResultArray.get_Item(0).XYZPoint; FlatCurvePointList.Add(xYZ); } //获取纵曲线上100个点 //计算首尾两点X轴差值以及曲线长度 double VdelX = VerticalModelLine.Evaluate(0, true).X - VerticalModelLine.Evaluate(1, true).X; double VLength = VerticalModelLine.Length; double VY; //选谁的Y最小就选谁 if (VerticalModelLine.Evaluate(0, true).Y <= VerticalModelLine.Evaluate(1, true).Y) { VY = VerticalModelLine.Evaluate(0, true).Y; } else { VY = VerticalModelLine.Evaluate(1, true).Y; } List <XYZ> VerticalCurvePointList = new List <XYZ>(); for (int i = 0; i < 100; i += 1) { //设置起点和终点,并创建直线,来与原有线段相交 XYZ point1 = new XYZ(VerticalModelLine.Evaluate(0, true).X - i * VdelX / 100, VY, VerticalModelLine.Evaluate(0, true).Z); XYZ point2 = new XYZ(VerticalModelLine.Evaluate(0, true).X - i * VdelX / 100, VY + VLength, VerticalModelLine.Evaluate(0, true).Z); Line line = Line.CreateBound(point1, point2); Curve curve = line as Curve; //求交点并把交点放到集里面去 IntersectionResultArray intersectionResultArray; VerticalModelLine.Intersect(curve, out intersectionResultArray); XYZ xYZ = intersectionResultArray.get_Item(0).XYZPoint; VerticalCurvePointList.Add(xYZ); } //把平曲线和总曲线上点进行整合生成三维曲线,平曲线的X,Y坐标作为三维曲线X,Y坐标,总曲线Y坐标作为三维曲线Z坐标 List <XYZ> CurvePoint = new List <XYZ>(); for (int i = 0; i < 100; i += 1) { XYZ point = new XYZ(FlatCurvePointList[i].X, FlatCurvePointList[i].Y, VerticalCurvePointList[i].Y); CurvePoint.Add(point); } PolyLine polyLine = PolyLine.Create(CurvePoint); //让这条线以模型线的形式展示一下 using (Transaction tran = new Transaction(uiDoc.Document)) { tran.Start("创建模型线"); for (int i = 0; i < 99; i += 1) { XYZ PointStart = CurvePoint[i]; XYZ PointEnd = CurvePoint[i + 1]; //直线向量 XYZ vector = new XYZ(PointStart.X - PointEnd.X, PointStart.Y - PointEnd.Y, PointStart.Z - PointEnd.Z); //向量和Z向量叉乘,从而获得一个必定与向量垂直的向量,并以此创建一个平面 XYZ normal = vector.CrossProduct(XYZ.BasisZ); Plane plane = Plane.CreateByNormalAndOrigin(normal, PointStart); SketchPlane sketchPlane = SketchPlane.Create(uiDoc.Document, plane); uiDoc.Document.Create.NewModelCurve(Line.CreateBound(PointStart, PointEnd), sketchPlane); } tran.Commit(); } return(Result.Succeeded); }
public MaterialsAMLPaletteRequest(UIApplication uiApp, String text) { RVTDocument doc = uiApp.ActiveUIDocument.Document; MaterialsAMLPalette materialsPalette = BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette; //Get the versioned symbol family FamilySymbol familySymbol = null; string versionedFamily = RVTOperations.GetVersionedFamilyFilePath(uiApp, Properties.Settings.Default.RevitIDAccentMatTag); //Try loading the family symbol Transaction loadSymbolTransaction = new Transaction(doc, "LoadFamilySymbol"); loadSymbolTransaction.Start(); try { try { IFamilyLoadOptions loadOptions = new RVTFamilyLoadOptions(); doc.LoadFamilySymbol(versionedFamily, "Legend Tag (Fake)", loadOptions, out FamilySymbol symb); familySymbol = symb; } catch { MessageBox.Show(String.Format("Could not get the 'Legend Tag (Fake)' type from {0}", versionedFamily), "Family Symbol Load Error"); } loadSymbolTransaction.Commit(); } catch (Exception transactionException) { loadSymbolTransaction.RollBack(); MessageBox.Show(transactionException.ToString()); } //Get the line style to use, or create the default Element lineStyle = null; if (materialsPalette.paletteMaterialComboBox.Text == "Default") { try { lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines).SubCategories.get_Item("6 BA ID ACCENT").GetGraphicsStyle(GraphicsStyleType.Projection); } catch { try { Category linesCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines); Category newLineStyleCategory = doc.Settings.Categories.NewSubcategory(linesCategory, "6 BA ID ACCENT"); newLineStyleCategory.LineColor = new Color(0, 0, 0); newLineStyleCategory.SetLineWeight(6, GraphicsStyleType.Projection); newLineStyleCategory.SetLinePatternId(LinePatternElement.GetSolidPatternId(), GraphicsStyleType.Projection); doc.Regenerate(); lineStyle = newLineStyleCategory.GetGraphicsStyle(GraphicsStyleType.Projection); } catch (Exception e) { MessageBox.Show(e.ToString()); } } } else { lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines).SubCategories.get_Item("ID " + materialsPalette.paletteMaterialComboBox.Text).GetGraphicsStyle(GraphicsStyleType.Projection); } //Assure the view being used is a floor plan if (doc.ActiveView.ViewType != ViewType.FloorPlan) { MessageBox.Show("This tool should be used ina a Floor Plan or Area Plan view"); } else { //Create a loop for picking points. Change the palette background color based on the number of points picked List <XYZ> pickedPoints = new List <XYZ>(); bool breakLoop = false; int pickCount = 0; while (breakLoop == false) { try { //Have the user begin picking points. The number of clicks to start the UI color change is 1 because the first click is usually to activate the window. XYZ point = uiApp.ActiveUIDocument.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.Endpoints, "Click points for the line to follow. Then click once to the side where the lines should be drawn. Hit ESC to finish"); pickedPoints.Add(point); if (pickCount == 1) { materialsPalette.BackColor = System.Drawing.Color.Firebrick; } else if (pickCount == 2) { materialsPalette.BackColor = System.Drawing.Color.Orange; } else if (pickCount > 2) { //After three clicks in the window, the user has made the minimum point selection to generate the lines from the start, end, and positive side points. materialsPalette.BackColor = System.Drawing.Color.GreenYellow; } else { ; } pickCount++; } catch { materialsPalette.BackColor = MaterialsAMLPalette.DefaultBackColor; breakLoop = true; } } //Get rid of the first point from clicking into the Revit view. This point is not needed. pickedPoints.RemoveAt(0); if (pickedPoints.Count > 2) { Transaction createLinesTransaction = new Transaction(doc, "CreateAccentLines"); createLinesTransaction.Start(); try { //These points will be used in determining the start, end, and room points XYZ firstPoint = pickedPoints[0]; XYZ roomPoint = pickedPoints[pickedPoints.Count - 1]; XYZ lastPoint = pickedPoints[pickedPoints.Count - 2]; //Create a list of points for the polyline that excludes the room point List <XYZ> polyLinePoints = new List <XYZ>(); for (int i = 0; i < pickedPoints.Count - 1; i++) { polyLinePoints.Add(pickedPoints[i]); } //Create a polyline from the list of picked points and then get make lines from the points on the poly line PolyLine guidePolyLine = PolyLine.Create(polyLinePoints); IList <XYZ> polyPoints = guidePolyLine.GetCoordinates(); List <Line> guideLines = new List <Line>(); for (int i = 0; i < polyLinePoints.Count - 1; i++) { guideLines.Add(Line.CreateBound(polyLinePoints[i], polyLinePoints[i + 1])); } //Get the direction of the line offset by measuring the first offset for positive and negative values and comparing their distances with the room point bool positiveZ = false; List <Line> offsetLines = new List <Line>(); Line positiveOffsetLine = guideLines.Last().CreateOffset(0.6666666667d, XYZ.BasisZ) as Line; Line negativeOffsetLine = guideLines.Last().CreateOffset(-0.6666666667d, XYZ.BasisZ) as Line; XYZ positiveOffsetMidPoint = positiveOffsetLine.Evaluate(0.5d, true); XYZ negativeOffsetMidPoint = negativeOffsetLine.Evaluate(0.5d, true); Double positiveOffsetDistance = positiveOffsetMidPoint.DistanceTo(roomPoint); Double negativeOffsetDistance = negativeOffsetMidPoint.DistanceTo(roomPoint); //If the positive offset side resulted in a shorter distance to the point inside the room, then the offset should have a positive Z normal. if (positiveOffsetDistance < negativeOffsetDistance) { positiveZ = true; } //Knowing whether or not to use a positive or negative offset, begin creating offset lines for each guide line foreach (Line guideLine in guideLines) { if (positiveZ) { offsetLines.Add(guideLine.CreateOffset(0.6666666667d, XYZ.BasisZ) as Line); } else { offsetLines.Add(guideLine.CreateOffset(-0.6666666667d, XYZ.BasisZ) as Line); } } //Determine if the number of line segments is 1 or more Line firstLine = offsetLines.First(); Line lastLine = null; if (offsetLines.Count > 1) { lastLine = offsetLines.Last(); } //If there is only one line segment, both end operations must be performed on it if (lastLine == null) { double lineLength = firstLine.Length; double fractionOfLength = 0.6666666667d / lineLength; //Checking fractions to ensure they are not greater than 1 for the normalization if (fractionOfLength > 1) { fractionOfLength = 0.25d; } //Re-evaluating where to place the start and end point of the line XYZ shiftedStartPoint = firstLine.Evaluate(fractionOfLength, true); XYZ shiftedEndPoint = firstLine.Evaluate(1 - fractionOfLength, true); firstLine = Line.CreateBound(shiftedStartPoint, shiftedEndPoint); //Creating the angled corner lines Line firstCornerLine = Line.CreateBound(firstPoint, firstLine.GetEndPoint(0)); Line lastCornerLine = Line.CreateBound(lastPoint, firstLine.GetEndPoint(1)); //Create the detail lines from the lines DetailCurve newAccentLine1 = doc.Create.NewDetailCurve(doc.ActiveView, firstCornerLine); DetailCurve newAccentLine2 = doc.Create.NewDetailCurve(doc.ActiveView, firstLine); DetailCurve newAccentLine3 = doc.Create.NewDetailCurve(doc.ActiveView, lastCornerLine); //Assign a line style to the newly created detail lines newAccentLine1.LineStyle = lineStyle; newAccentLine2.LineStyle = lineStyle; newAccentLine3.LineStyle = lineStyle; XYZ tagPlacementPoint = firstLine.Evaluate(0.5d, true); XYZ direction = firstLine.Direction; Line axisLine = Line.CreateUnbound(tagPlacementPoint, XYZ.BasisZ); double rotationAngle = direction.AngleTo(XYZ.BasisX); //Get the midpoint of the line, its direction, and create the rotation and axis if (familySymbol != null) { //Create the tag instance FamilyInstance newTag = doc.Create.NewFamilyInstance(tagPlacementPoint, familySymbol, doc.ActiveView); //Rotate the new tag instance ElementTransformUtils.RotateElement(doc, newTag.Id, axisLine, rotationAngle); } createLinesTransaction.Commit(); } //If there is more than one line segment, an operation must be performed on the start and end of the start and end lines, respectively else { List <Line> linesToDraw = new List <Line>(); // Get the normalized value for 8" relative to the lengths of the start and end lines double firstLineLength = firstLine.Length; double fractionOfFirstLine = 0.6666666667 / firstLineLength; double lastLineLength = lastLine.Length; double fractionOfLastLine = 0.666666667 / lastLineLength; //Checking fractions to ensure they are not greater than 1 for the normalization if (fractionOfFirstLine > 1) { fractionOfFirstLine = 0.25d; } if (fractionOfLastLine > 1) { fractionOfLastLine = 0.25d; } //Shift the ends of the start and end lines by finding the point along the line relative to the normalized 8" value XYZ shiftedStartPoint = firstLine.Evaluate(fractionOfFirstLine, true); XYZ shiftedEndPoint = lastLine.Evaluate(1 - fractionOfLastLine, true); //Reset the start and end lines with the new shifted points firstLine = Line.CreateBound(shiftedStartPoint, firstLine.GetEndPoint(1)); lastLine = Line.CreateBound(lastLine.GetEndPoint(0), shiftedEndPoint); linesToDraw.Add(firstLine); //If there are only 3 offset lines, there will be just one middle segment if (offsetLines.Count == 3) { linesToDraw.Add(offsetLines[1]); } //If there are more than three offset lines, there will be more than one middle line segment else { List <Line> middleLines = offsetLines.GetRange(1, offsetLines.Count - 2); foreach (Line middleLine in middleLines) { linesToDraw.Add(middleLine); } } linesToDraw.Add(lastLine); //For the lines to draw, intersect them with the next line in the list and reset their start and end points to be the intersection for (int i = 0; i < linesToDraw.Count - 1; i++) { Line line1 = linesToDraw[i]; Line scaledLine1 = Line.CreateUnbound(line1.GetEndPoint(1), line1.Direction); Line line2 = linesToDraw[i + 1]; Line scaledLine2 = Line.CreateUnbound(line2.GetEndPoint(0), line2.Direction.Negate()); SetComparisonResult intersectionResult = scaledLine1.Intersect(scaledLine2, out IntersectionResultArray results); if (intersectionResult == SetComparisonResult.Overlap) { IntersectionResult result = results.get_Item(0); Line newLine1 = Line.CreateBound(line1.GetEndPoint(0), result.XYZPoint); Line newLine2 = Line.CreateBound(result.XYZPoint, line2.GetEndPoint(1)); linesToDraw[i] = newLine1; linesToDraw[i + 1] = newLine2; } } //Create the angled corner lines at the start and end of the line chain Line firstCornerLine = Line.CreateBound(firstPoint, firstLine.GetEndPoint(0)); Line lastCornerLine = Line.CreateBound(lastPoint, lastLine.GetEndPoint(1)); linesToDraw.Add(firstCornerLine); linesToDraw.Add(lastCornerLine); //Create each line as a detail line foreach (Line apiLine in linesToDraw) { DetailCurve newAccentLine = doc.Create.NewDetailCurve(doc.ActiveView, apiLine); newAccentLine.LineStyle = lineStyle; } //Declare some stuff for use in the symbol placement Line firstMiddleLine = linesToDraw[0]; Line lastMiddleLine = linesToDraw[linesToDraw.Count - 3]; XYZ firstTagPoint = firstMiddleLine.Evaluate(0.5d, true); XYZ lastTagPoint = lastMiddleLine.Evaluate(0.5d, true); XYZ firstDirection = firstMiddleLine.Direction; XYZ lastDirection = lastMiddleLine.Direction; Line firstAxisLine = Line.CreateUnbound(firstTagPoint, XYZ.BasisZ); Line lastAxisLine = Line.CreateUnbound(lastTagPoint, XYZ.BasisZ); double firstRotation = firstDirection.AngleTo(XYZ.BasisX); double lastRotation = lastDirection.AngleTo(XYZ.BasisX); if (familySymbol != null) { //Create tag at the beginning of the middle lines FamilyInstance firstTag = doc.Create.NewFamilyInstance(firstTagPoint, familySymbol, doc.ActiveView); ElementTransformUtils.RotateElement(doc, firstTag.Id, firstAxisLine, firstRotation); //Create a tag at the end of the middle lines if there are more than 2 middle lines if (linesToDraw.Count > 4) { FamilyInstance lastTag = doc.Create.NewFamilyInstance(lastTagPoint, familySymbol, doc.ActiveView); ElementTransformUtils.RotateElement(doc, lastTag.Id, lastAxisLine, lastRotation); } } createLinesTransaction.Commit(); } } catch (Exception e) { //Suppose the user closed the palette too soon. This will remind them to keep it open. if (BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette == null) { MessageBox.Show("AML Picker was closed prematurely. Please keep the picker open until the lines are drawn."); } else { //Otherwise, if some other error occurred, show the exception MessageBox.Show(e.ToString()); } createLinesTransaction.RollBack(); } } else { ; } } }
public void DrawPolyline(ref Page refPage, DrawPinModel pinModel) { Logger.WriteLine(JsonConvert.SerializeObject(pinModel)); string symbolName = ""; PointD[] PinTextPos = new PointD[2]; PointD DescriptionTextPos = new PointD(); PointD[] PinOutline = new PointD[5]; PointD[] points = new PointD[10]; int index = 0; string[] pinDefs = pinModel.Number.Split(new string[] { "(", ")" }, StringSplitOptions.None); string[] pinName = new string[pinDefs.Length]; string[] pinNum = new string[pinDefs.Length]; string[] pinDescription = pinModel.FunctionDescription.Split(new string[] { "," }, StringSplitOptions.None); foreach (var item in pinDefs) { string[] temp = item.Split(new string[] { "," }, StringSplitOptions.None); if (temp.Length >= 2) { pinName[index] = temp[1]; pinNum[index] = temp[0]; index++; } } int pinMarkSize = (int)pinModel.Font.Size; int offset = Math.Max(pinModel.DimensionX, pinModel.DimensionY) + pinMarkSize; offset = offset + pinModel.PolylineOffset; switch (pinModel.LocationSide) { case EplDrawPosition.Left: symbolName = "LeftConnectionPoint"; PinOutline[0] = new PointD(pinModel.PositionX + pinMarkSize, pinModel.PositionY); PinOutline[1] = new PointD(pinModel.PositionX + pinMarkSize, pinModel.PositionY + pinModel.PinDistance); points[0] = new PointD(PinOutline[0].X, PinOutline[0].Y + pinModel.DimensionY / 2); points[1] = new PointD(PinOutline[0].X + offset, PinOutline[0].Y + pinModel.DimensionY / 2); points[2] = new PointD(PinOutline[0].X + offset, PinOutline[0].Y + pinModel.PinDistance - pinModel.DimensionY / 2);; points[3] = new PointD(PinOutline[0].X, PinOutline[0].Y + pinModel.PinDistance - pinModel.DimensionY / 2); PinTextPos[0] = new PointD(points[0].X, points[0].Y + offset); PinTextPos[1] = new PointD(points[3].X, points[0].Y - offset); DescriptionTextPos = new PointD(points[0].X + 5, points[0].Y + pinModel.PinDistance / 2); break; case EplDrawPosition.Right: symbolName = "RightConnectionPoint"; PinOutline[0] = new PointD(pinModel.PositionX - pinMarkSize, pinModel.PositionY); PinOutline[1] = new PointD(pinModel.PositionX - pinMarkSize, pinModel.PositionY + pinModel.PinDistance); points[0] = new PointD(PinOutline[0].X, PinOutline[0].Y + pinModel.DimensionY / 2); points[1] = new PointD(PinOutline[0].X - offset, PinOutline[0].Y + pinModel.DimensionY / 2); points[2] = new PointD(PinOutline[0].X - offset, PinOutline[0].Y + pinModel.PinDistance - pinModel.DimensionY / 2);; points[3] = new PointD(PinOutline[0].X, PinOutline[0].Y + pinModel.PinDistance - pinModel.DimensionY / 2); PinTextPos[0] = new PointD(points[0].X, points[0].Y + offset); PinTextPos[1] = new PointD(points[3].X, points[0].Y - offset); DescriptionTextPos = new PointD(points[0].X - 5, points[0].Y + pinModel.PinDistance / 2); break; case EplDrawPosition.Bottom: symbolName = "BottomConnectionPoint"; PinOutline[0] = new PointD(pinModel.PositionX, pinModel.PositionY + pinMarkSize); PinOutline[1] = new PointD(pinModel.PositionX + pinModel.PinDistance, pinModel.PositionY + pinMarkSize); points[0] = new PointD(PinOutline[0].X + pinModel.DimensionY / 2, PinOutline[0].Y); points[1] = new PointD(PinOutline[0].X + pinModel.DimensionY / 2, PinOutline[0].Y + offset); points[2] = new PointD(PinOutline[0].X + pinModel.PinDistance - pinModel.DimensionY / 2, PinOutline[0].Y + offset);; points[3] = new PointD(PinOutline[0].X + pinModel.PinDistance - pinModel.DimensionY / 2, PinOutline[0].Y); PinTextPos[0] = new PointD(points[0].X + offset, points[0].Y); PinTextPos[1] = new PointD(points[3].X - offset, points[0].Y); DescriptionTextPos = new PointD(points[0].X + pinModel.PinDistance / 2, points[0].Y + 5); break; case EplDrawPosition.Top: symbolName = "TopConnectionPoint"; PinOutline[0] = new PointD(pinModel.PositionX, pinModel.PositionY - pinMarkSize); PinOutline[1] = new PointD(pinModel.PositionX + pinModel.PinDistance, pinModel.PositionY - pinMarkSize); points[0] = new PointD(PinOutline[0].X + pinModel.DimensionY / 2, PinOutline[0].Y); points[1] = new PointD(PinOutline[0].X + pinModel.DimensionY / 2, PinOutline[0].Y - offset); points[2] = new PointD(PinOutline[0].X + pinModel.PinDistance - pinModel.DimensionY / 2, PinOutline[0].Y - offset); points[3] = new PointD(PinOutline[0].X + pinModel.PinDistance - pinModel.DimensionY / 2, PinOutline[0].Y); PinTextPos[0] = new PointD(points[0].X + offset, points[0].Y); PinTextPos[1] = new PointD(points[3].X - offset, points[0].Y); DescriptionTextPos = new PointD(points[0].X + pinModel.PinDistance / 2, points[0].Y - 5); break; default: break; } Rectangle(ref refPage, pinModel, PinOutline[0]); Rectangle(ref refPage, pinModel, PinOutline[1]); refPage.InsertConnectingPoint("MY_LIB_K", symbolName, PinOutline[0]); refPage.InsertConnectingPoint("MY_LIB_K", symbolName, PinOutline[1]); Text text1 = new Text(); text1.Create(refPage, pinName[0], pinModel.Font.Height); Text text2 = new Text(); text2.Create(refPage, pinName[1], pinModel.Font.Height); text1.Location = PinTextPos[0]; text2.Location = PinTextPos[1]; PolyLine polyLine = new PolyLine(); polyLine.Create(refPage); polyLine.Pen.Width = pinModel.OutlineWidthVal; for (int i = 0; i < 4; i++) { polyLine.SetPointAt(i, ref points[i]); } Text text3 = new Text(); switch (pinModel.Function) { case EplDrawPinFunction.POWER_AC: text3.Create(refPage, "PWR AC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.POWER_DC: text3.Create(refPage, "PWR DC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.SIGNAL_PIN: break; case EplDrawPinFunction.INPUT_AC_V: text3.Create(refPage, "Input\nV-AC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.INPUT_AC_A: text3.Create(refPage, "Input\nA-AC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.INPUT_DC_V: text3.Create(refPage, "Input\nV-DC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.INPUT_DC_A: text3.Create(refPage, "Input\nA-DC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.OUPUT_AC_V: text3.Create(refPage, "Output\nV-AC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.OUPUT_AC_A: text3.Create(refPage, "Output\nV-AC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.OUPUT_DC_V: text3.Create(refPage, "Output\nV-DC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.OUPUT_DC_A: text3.Create(refPage, "Output\nA-DC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.CONTACT_NO: text3.Create(refPage, "NO", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.CONTACT_NC: text3.Create(refPage, "NC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.CONTACT_NOC: text3.Create(refPage, "NO-NC", pinModel.Font.Height); text3.Location = DescriptionTextPos; break; case EplDrawPinFunction.SHILED: break; case EplDrawPinFunction.EARTH: break; case EplDrawPinFunction.RECTANGLE: break; case EplDrawPinFunction.CIRCLE: break; case EplDrawPinFunction.TEXT: break; default: break; } }
private static void CreateTestAnnots(PDFDoc doc) { ElementWriter ew = new ElementWriter(); ElementBuilder eb = new ElementBuilder(); Element element; Page first_page = doc.PageCreate(new Rect(0, 0, 600, 600)); doc.PagePushBack(first_page); ew.Begin(first_page, ElementWriter.WriteMode.e_overlay, false); // begin writing to this page ew.End(); // save changes to the current page // // Test of a free text annotation. // { FreeText txtannot = FreeText.Create(doc, new Rect(10, 400, 160, 570)); txtannot.SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." + "\n\nAha!\n\nAnd there was much rejoicing!"); txtannot.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20)); txtannot.SetQuaddingFormat(0); first_page.AnnotPushBack(txtannot); txtannot.RefreshAppearance(); } { FreeText txtannot = FreeText.Create(doc, new Rect(100, 100, 350, 500)); txtannot.SetContentRect(new Rect(200, 200, 350, 500)); txtannot.SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." + "\n\nAha!\n\nAnd there was much rejoicing!"); txtannot.SetCalloutLinePoints(new Point(200, 300), new Point(150, 290), new Point(110, 110)); txtannot.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20)); txtannot.SetEndingStyle(Line.EndingStyle.e_ClosedArrow); txtannot.SetColor(new ColorPt(0, 1, 0)); txtannot.SetQuaddingFormat(1); first_page.AnnotPushBack(txtannot); txtannot.RefreshAppearance(); } { FreeText txtannot = FreeText.Create(doc, new Rect(400, 10, 550, 400)); txtannot.SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." + "\n\nAha!\n\nAnd there was much rejoicing!"); txtannot.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 1, 10, 20)); txtannot.SetColor(new ColorPt(0, 0, 1)); txtannot.SetOpacity(0.2); txtannot.SetQuaddingFormat(2); first_page.AnnotPushBack(txtannot); txtannot.RefreshAppearance(); } Page page = doc.PageCreate(new Rect(0, 0, 600, 600)); doc.PagePushBack(page); ew.Begin(page, ElementWriter.WriteMode.e_overlay, false); // begin writing to this page eb.Reset(); // Reset the GState to default ew.End(); // save changes to the current page { //Create a Line annotation... Line line = Line.Create(doc, new Rect(250, 250, 400, 400)); line.SetStartPoint(new Point(350, 270)); line.SetEndPoint(new Point(260, 370)); line.SetStartStyle(Line.EndingStyle.e_Square); line.SetEndStyle(Line.EndingStyle.e_Circle); line.SetColor(new ColorPt(.3, .5, 0), 3); line.SetContents("Dashed Captioned"); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); double[] dash = new double[2]; dash[0] = 2; dash[1] = 2.0; line.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_dashed, 2, 0, 0, dash)); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(347, 377, 600, 600)); line.SetStartPoint(new Point(385, 410)); line.SetEndPoint(new Point(540, 555)); line.SetStartStyle(Line.EndingStyle.e_Circle); line.SetEndStyle(Line.EndingStyle.e_OpenArrow); line.SetColor(new ColorPt(1, 0, 0), 3); line.SetInteriorColor(new ColorPt(0, 1, 0), 3); line.SetContents("Inline Caption"); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Inline); line.SetLeaderLineExtensionLength(-4); line.SetLeaderLineLength(-12); line.SetLeaderLineOffset(2); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(10, 400, 200, 600)); line.SetStartPoint(new Point(25, 426)); line.SetEndPoint(new Point(180, 555)); line.SetStartStyle(Line.EndingStyle.e_Circle); line.SetEndStyle(Line.EndingStyle.e_Square); line.SetColor(new ColorPt(0, 0, 1), 3); line.SetInteriorColor(new ColorPt(1, 0, 0), 3); line.SetContents("Offset Caption"); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.SetTextHOffset(-60); line.SetTextVOffset(10); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(200, 10, 400, 70)); line.SetStartPoint(new Point(220, 25)); line.SetEndPoint(new Point(370, 60)); line.SetStartStyle(Line.EndingStyle.e_Butt); line.SetEndStyle(Line.EndingStyle.e_OpenArrow); line.SetColor(new ColorPt(0, 0, 1), 3); line.SetContents("Regular Caption"); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(200, 70, 400, 130)); line.SetStartPoint(new Point(220, 111)); line.SetEndPoint(new Point(370, 78)); line.SetStartStyle(Line.EndingStyle.e_Circle); line.SetEndStyle(Line.EndingStyle.e_Diamond); line.SetContents("Circle to Diamond"); line.SetColor(new ColorPt(0, 0, 1), 3); line.SetInteriorColor(new ColorPt(0, 1, 0), 3); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(10, 100, 160, 200)); line.SetStartPoint(new Point(15, 110)); line.SetEndPoint(new Point(150, 190)); line.SetStartStyle(Line.EndingStyle.e_Slash); line.SetEndStyle(Line.EndingStyle.e_ClosedArrow); line.SetContents("Slash to CArrow"); line.SetColor(new ColorPt(1, 0, 0), 3); line.SetInteriorColor(new ColorPt(0, 1, 1), 3); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(270, 270, 570, 433)); line.SetStartPoint(new Point(300, 400)); line.SetEndPoint(new Point(550, 300)); line.SetStartStyle(Line.EndingStyle.e_RClosedArrow); line.SetEndStyle(Line.EndingStyle.e_ROpenArrow); line.SetContents("ROpen & RClosed arrows"); line.SetColor(new ColorPt(0, 0, 1), 3); line.SetInteriorColor(new ColorPt(0, 1, 0), 3); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(195, 395, 205, 505)); line.SetStartPoint(new Point(200, 400)); line.SetEndPoint(new Point(200, 500)); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(55, 299, 150, 301)); line.SetStartPoint(new Point(55, 300)); line.SetEndPoint(new Point(155, 300)); line.SetStartStyle(Line.EndingStyle.e_Circle); line.SetEndStyle(Line.EndingStyle.e_Circle); line.SetContents("Caption that's longer than its line."); line.SetColor(new ColorPt(1, 0, 1), 3); line.SetInteriorColor(new ColorPt(0, 1, 0), 3); line.SetShowCaption(true); line.SetCaptionPosition(Line.CapPos.e_Top); line.RefreshAppearance(); page.AnnotPushBack(line); } { Line line = Line.Create(doc, new Rect(300, 200, 390, 234)); line.SetStartPoint(new Point(310, 210)); line.SetEndPoint(new Point(380, 220)); line.SetColor(new ColorPt(0, 0, 0), 3); line.RefreshAppearance(); page.AnnotPushBack(line); } Page page3 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page3); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page3); { Circle circle = Circle.Create(doc, new Rect(300, 300, 390, 350)); circle.SetColor(new ColorPt(0, 0, 0), 3); circle.RefreshAppearance(); page3.AnnotPushBack(circle); } { Circle circle = Circle.Create(doc, new Rect(100, 100, 200, 200)); circle.SetColor(new ColorPt(0, 1, 0), 3); circle.SetInteriorColor(new ColorPt(0, 0, 1), 3); double[] dash = new double[2]; dash[0] = 2; dash[1] = 4; circle.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_dashed, 3, 0, 0, dash)); circle.SetPadding(new Rect(2, 2, 2, 2)); circle.RefreshAppearance(); page3.AnnotPushBack(circle); } { Square sq = Square.Create(doc, new Rect(10, 200, 80, 300)); sq.SetColor(new ColorPt(0, 0, 0), 3); sq.RefreshAppearance(); page3.AnnotPushBack(sq); } { Square sq = Square.Create(doc, new Rect(500, 200, 580, 300)); sq.SetColor(new ColorPt(1, 0, 0), 3); sq.SetInteriorColor(new ColorPt(0, 1, 1), 3); double[] dash = new double[2]; dash[0] = 4; dash[1] = 2; sq.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_dashed, 6, 0, 0, dash)); sq.SetPadding(new Rect(4, 4, 4, 4)); sq.RefreshAppearance(); page3.AnnotPushBack(sq); } { Polygon poly = Polygon.Create(doc, new Rect(5, 500, 125, 590)); poly.SetColor(new ColorPt(1, 0, 0), 3); poly.SetInteriorColor(new ColorPt(1, 1, 0), 3); poly.SetVertex(0, new Point(12, 510)); poly.SetVertex(1, new Point(100, 510)); poly.SetVertex(2, new Point(100, 555)); poly.SetVertex(3, new Point(35, 544)); poly.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 4, 0, 0)); poly.SetPadding(new Rect(4, 4, 4, 4)); poly.RefreshAppearance(); page3.AnnotPushBack(poly); } { PolyLine poly = PolyLine.Create(doc, new Rect(400, 10, 500, 90)); poly.SetColor(new ColorPt(1, 0, 0), 3); poly.SetInteriorColor(new ColorPt(0, 1, 0), 3); poly.SetVertex(0, new Point(405, 20)); poly.SetVertex(1, new Point(440, 40)); poly.SetVertex(2, new Point(410, 60)); poly.SetVertex(3, new Point(470, 80)); poly.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 2, 0, 0)); poly.SetPadding(new Rect(4, 4, 4, 4)); poly.SetStartStyle(Line.EndingStyle.e_RClosedArrow); poly.SetEndStyle(Line.EndingStyle.e_ClosedArrow); poly.RefreshAppearance(); page3.AnnotPushBack(poly); } { Link lk = Link.Create(doc, new Rect(5, 5, 55, 24)); //lk.SetColor( ColorPt(0,1,0), 3 ); lk.RefreshAppearance(); page3.AnnotPushBack(lk); } Page page4 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page4); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page4); { ew.Begin(page4); Font font = Font.Create(doc, Font.StandardType1Font.e_helvetica); element = eb.CreateTextBegin(font, 16); element.SetPathFill(true); ew.WriteElement(element); element = eb.CreateTextRun("Some random text on the page", font, 16); element.SetTextMatrix(1, 0, 0, 1, 100, 500); ew.WriteElement(element); ew.WriteElement(eb.CreateTextEnd()); ew.End(); } { Highlight hl = Highlight.Create(doc, new Rect(100, 490, 150, 515)); hl.SetColor(new ColorPt(0, 1, 0), 3); hl.RefreshAppearance(); page4.AnnotPushBack(hl); } { Squiggly sq = Squiggly.Create(doc, new Rect(100, 450, 250, 600)); //sq.SetColor( ColorPt(1,0,0), 3 ); sq.SetQuadPoint(0, new QuadPoint(new Point(122, 455), new Point(240, 545), new Point(230, 595), new Point(101, 500))); sq.RefreshAppearance(); page4.AnnotPushBack(sq); } { Caret cr = Caret.Create(doc, new Rect(100, 40, 129, 69)); cr.SetColor(new ColorPt(0, 0, 1), 3); cr.SetSymbol("P"); cr.RefreshAppearance(); page4.AnnotPushBack(cr); } Page page5 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page5); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page5); Page page6 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page6); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page6); { Text txt = Text.Create(doc, new Rect(10, 20, 30, 40)); txt.SetIcon("UserIcon"); txt.SetContents("User defined icon, unrecognized by appearance generator"); txt.SetColor(new ColorPt(0, 1, 0)); txt.RefreshAppearance(); page6.AnnotPushBack(txt); } { Ink ink = Ink.Create(doc, new Rect(100, 400, 200, 550)); ink.SetColor(new ColorPt(0, 0, 1)); ink.SetPoint(1, 3, new Point(220, 505)); ink.SetPoint(1, 0, new Point(100, 490)); ink.SetPoint(0, 1, new Point(120, 410)); ink.SetPoint(0, 0, new Point(100, 400)); ink.SetPoint(1, 2, new Point(180, 490)); ink.SetPoint(1, 1, new Point(140, 440)); ink.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, 3, 0, 0)); ink.RefreshAppearance(); page6.AnnotPushBack(ink); } Page page7 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page7); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page7); { Sound snd = Sound.Create(doc, new Rect(100, 500, 120, 520)); snd.SetColor(new ColorPt(1, 1, 0)); snd.SetIcon(Sound.Icon.e_Speaker); snd.RefreshAppearance(); page7.AnnotPushBack(snd); } { Sound snd = Sound.Create(doc, new Rect(200, 500, 220, 520)); snd.SetColor(new ColorPt(1, 1, 0)); snd.SetIcon(Sound.Icon.e_Mic); snd.RefreshAppearance(); page7.AnnotPushBack(snd); } Page page8 = doc.PageCreate(new Rect(0, 0, 600, 600)); ew.Begin(page8); // begin writing to the page ew.End(); // save changes to the current page doc.PagePushBack(page8); for (int ipage = 0; ipage < 2; ++ipage) { double px = 5, py = 520; for (RubberStamp.Icon istamp = RubberStamp.Icon.e_Approved; istamp <= RubberStamp.Icon.e_Draft; istamp = (RubberStamp.Icon)((int)(istamp) + 1)) { RubberStamp stmp = RubberStamp.Create(doc, new Rect(1, 1, 100, 100)); stmp.SetIcon(istamp); stmp.SetContents(stmp.GetIconName()); stmp.SetRect(new Rect(px, py, px + 100, py + 25)); py -= 100; if (py < 0) { py = 520; px += 200; } if (ipage == 0) { //page7.AnnotPushBack( st ); ; } else { page8.AnnotPushBack(stmp); stmp.RefreshAppearance(); } } } RubberStamp st = RubberStamp.Create(doc, new Rect(400, 5, 550, 45)); st.SetIcon("UserStamp"); st.SetContents("User defined stamp"); page8.AnnotPushBack(st); st.RefreshAppearance(); }