public void CanSetFormula() { var part = new ElementPart(typeof(MappedObject)); part.Formula("formula"); ElementMapping elementMapping = part.GetElementMapping(); elementMapping.Formula.ShouldEqual("formula"); }
public void CanSetLength() { var part = new ElementPart(typeof(MappedObject)); part.Length(50); ElementMapping elementMapping = part.GetElementMapping(); elementMapping.Length.ShouldEqual(50); }
public void CanSetLength() { var part = new ElementPart(typeof(MappedObject)); part.Column("test"); part.Length(50); ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping(); elementMapping.Columns.First().Length.ShouldEqual(50); }
public void CanDeclareColumnNotNullable() { var part = new ElementPart(typeof(MappedObject)); part.Column("nullabilityCheck"); part.Not.Nullable(); ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping(); var columnMappings = elementMapping.Columns.ToList(); columnMappings.First().Nullable.ShouldEqual(false); }
public void CanDeclareColumnNullable() { var part = new ElementPart(typeof(MappedObject)); part.Column("nullabilityCheck"); part.Nullable(); ElementMapping elementMapping = ((IElementMappingProvider)part).GetElementMapping(); var columnMappings = elementMapping.Columns.ToList(); columnMappings.First().Nullable.ShouldEqual(true); }
private static void AssertElementPart(ElementPart expected, ElementPart actual) { if (expected == null) Assert.Null(actual); var attributeExpected = expected as AttributeNode; var dynamicExpected = expected as AttributeStatement; if (attributeExpected != null) { Assert.IsType<AttributeNode>(actual); AssertAttribute(attributeExpected, (AttributeNode) actual); } else if (dynamicExpected != null) { Assert.IsType<AttributeStatement>(actual); AssertExpressionAttribute(dynamicExpected, (AttributeStatement)actual); } else Assert.True(false, "Unknown type"); }
public static LddElement GenererateElement(PaletteDbContext db, SetPartWrapper partWrapper) { if (string.IsNullOrEmpty(partWrapper.ElementID)) { return(null); } var existingElem = db.LddElements.FirstOrDefault(x => x.DesignID == partWrapper.LddPartID); if (existingElem != null) { var newElement = existingElem.Clone(partWrapper.ElementID); newElement.ChangeColor(partWrapper.LddColorID); newElement.RemoveDecorations(); return(newElement); } void AddElementPart(LddElement lddElement, LddPart lddPart, int colorID) { var partConfig = new ElementPart() { PartID = lddPart.DesignID, MaterialID = colorID }; var subMats = lddPart.GetSubMaterials(); if (subMats.Length > 0) { var addedIndices = new List <int>(); for (int i = 0; i < subMats.Length; i++) { if (!addedIndices.Contains(subMats[i]) && subMats[i] != 0) { partConfig.SubMaterials.Add(new ElementMaterial(i, colorID)); addedIndices.Add(subMats[i]); } } } lddElement.Parts.Add(partConfig); } if (!partWrapper.LddPart.IsAssembly) { var newElement = new LddElement() { DesignID = partWrapper.LddPartID, ElementID = partWrapper.ElementID, Flag = 1, IsAssembly = false }; AddElementPart(newElement, partWrapper.LddPart, partWrapper.LddColorID); return(newElement); } else { var newElement = new LddElement() { DesignID = partWrapper.LddPartID, ElementID = partWrapper.ElementID, Flag = 1, IsAssembly = true }; foreach (var assemPart in db.AssemblyParts.Where(x => x.AssemblyID == partWrapper.LddPartID)) { var subPart = db.LddParts.FirstOrDefault(x => x.DesignID == assemPart.PartID); AddElementPart(newElement, subPart, partWrapper.LddColorID); } return(newElement); } }
/// <summary> /// Reader의 내용을 이용하여 부품의 좌표계를 변환 /// </summary> /// <param name="reader"></param> /// <returns></returns> public static Board ConvertBoardData(Reader reader) { List <KY.KYV.JobReader.Component> compList = new List <KY.KYV.JobReader.Component>(); if (reader != null) { #region ComponentInfo if (reader.BoardArrays == null) { return(null); } foreach (ElementBoardArray arr in reader.BoardArrays.Items) { MatrixConverter arrMtx = new MatrixConverter(arr.x, arr.y, arr.rot); foreach (ElementComponent comp in reader.Components.component) { //get part of comp ElementPart part = reader.Parts.ItemDic[comp.part]; //get pack of part ElementPackages.ElementPackage Package; if (!reader.Packages.ItemDic.TryGetValue(part.pkg, out Package)) { continue; } //get rotate of comp float rotate = comp.fAngleByCompItSelf + comp.fAngleForInsp + part.OffsetAngForUsrRefAng;// + Package.fOrgOffsetAng; MatrixConverter compMtx = new MatrixConverter(comp.x, reader.HeadInfo.board.orgH - comp.y, rotate); List <KY.KYV.JobReader.DrawData> drawDataList = new List <KY.KYV.JobReader.DrawData>(); //init data for draw body of comp float angleSum = arr.rot + rotate; float angleAdjust = 0.0F; if (Package != null && Package.pkgbody != null) { foreach (ElementPackages.ElementPackage.ElementPackageBody pkgbody in Package.pkgbody) { ElementShape shape = reader.PackageBodyShapes.ItemDic[pkgbody.shuid]; foreach (ElementRect rect in shape.rc) { float rectrot = (pkgbody.rot + rect.rot); MatrixConverter bodyMtx = new MatrixConverter(pkgbody.x, pkgbody.y, rectrot); PointF ptRect = bodyMtx.TransformPoint(0, 0); ptRect = compMtx.TransformPoint(ptRect); ptRect = arrMtx.TransformPoint(ptRect); drawDataList.Add( new DrawData() { Offset = new System.Drawing.PointF(pkgbody.x, pkgbody.y), Rotate = (pkgbody.rot + rect.rot), Size = new System.Drawing.SizeF(rect.w, rect.h), Type = DrawData.DataType.BODY, AbsLocation = new System.Drawing.PointF(ptRect.X, reader.HeadInfo.board.orgH - ptRect.Y), AbsRoate = (pkgbody.rot + rect.rot + angleSum) }); } } } //init data for draw footprint of comp if (Package != null && Package.pkgpins != null) { foreach (ElementPackages.ElementPackage.ElementPackagePins pkgpins in Package.pkgpins) { foreach (ElementPackages.ElementPackage.ElementPackagePins.ElementPackagePin pkgpin in pkgpins.pkgpin) { ElementShape shape = reader.PackageLeadShapes.ItemDic[pkgpin.shuid]; foreach (ElementRect rect in shape.rc) { float rectrot = (pkgpin.rot + rect.rot); MatrixConverter pinMtx = new MatrixConverter(pkgpin.x, pkgpin.y, rectrot); PointF ptRect = pinMtx.TransformPoint(0, 0); ptRect = compMtx.TransformPoint(ptRect); ptRect = arrMtx.TransformPoint(ptRect); drawDataList.Add( new DrawData() { Offset = new System.Drawing.PointF(pkgpin.x, pkgpin.y), Rotate = (pkgpin.rot + rect.rot), Size = new System.Drawing.SizeF(rect.w, rect.h), Type = DrawData.DataType.LEAD, AbsLocation = new System.Drawing.PointF(ptRect.X, reader.HeadInfo.board.orgH - ptRect.Y), AbsRoate = (pkgpin.rot + rect.rot + angleSum) }); } } } } //if (reader.Footprints.ItemDic.ContainsKey(comp.footprint)) //{ // ElementFootprint footprint = reader.Footprints.ItemDic[comp.footprint]; // foreach (ElementPin pin in footprint.Items) // { // if (reader.FootprintLeadShapes.ItemDic.ContainsKey(pin.shuid)) // { // ElementShape shape = reader.FootprintLeadShapes.ItemDic[pin.shuid]; // foreach (ElementRect rect in shape.rc) // { // System.Drawing.Drawing2D.Matrix mtxRectCenter = new System.Drawing.Drawing2D.Matrix(); // mtxRectCenter.Translate(pin.x, pin.y); // System.Drawing.Drawing2D.Matrix mtxRectRot = new System.Drawing.Drawing2D.Matrix(); // mtxRectRot.RotateAt(-(pin.rot + rect.rot), new PointF(pin.x, pin.y)); // PointF[] ptRect = new PointF[] { new PointF(0F, 0F) }; // mtxRectCenter.TransformPoints(ptRect); // mtxRectRot.TransformPoints(ptRect); // mtxCompCenter.TransformPoints(ptRect); // mtxCompRot.TransformPoints(ptRect); // mtxArrayCenter.TransformPoints(ptRect); // mtxArrayRot.TransformPoints(ptRect); // drawDataList.Add( // new DrawData() // { // Offset = new System.Drawing.PointF(pin.x, pin.y), // Rotate = (pin.rot + rect.rot), // Size = new System.Drawing.SizeF(rect.w, rect.h), // Type = DrawData.DataType.PAD, // AbsLocation = new System.Drawing.PointF(ptRect[0].X, ptRect[0].Y), // AbsRoate = (pin.rot + rect.rot + angleSum) // }); // } // } // } //} //init component list data PointF ptComp = compMtx.TransformPoint(0, 0); ptComp = arrMtx.TransformPoint(ptComp); compList.Add( new KY.KYV.JobReader.Component() { CRD = comp.name, ArrayIndex = arr.num, Location = new System.Drawing.PointF(ptComp.X, reader.HeadInfo.board.orgH - ptComp.Y), Rotate = (comp.fAngleByCompItSelf + comp.fAngleForInsp + angleAdjust + Package.fOrgOffsetAng), DrawDatas = drawDataList.ToArray() }); System.Diagnostics.Debug.WriteLine($"{comp.name}/ {arr.num}"); } } #endregion #region PCBImage string imagefilepath = System.IO.Path.GetDirectoryName(reader.JobfilePath); string[] ImagefileNameList = new string[] { "WholeboardFov.jpg", "WholeBoard.jpg", "WholeBoard.bmp" }; Image boardIamge = null; string boardimagepath = null; foreach (string fileName in ImagefileNameList) { System.Diagnostics.Debug.WriteLine(System.IO.Path.Combine(imagefilepath, fileName)); if (System.IO.File.Exists(System.IO.Path.Combine(imagefilepath, fileName))) { boardimagepath = System.IO.Path.Combine(imagefilepath, fileName); // boardIamge = Image.FromFile(boardimagepath); break; } } List <ImageData> fovimages = new List <ImageData>(); foreach (ElementFov fov in reader.Boardfovs.fovs) { Image fovImage = null; string fovImagepath = null; string path = System.IO.Path.Combine(imagefilepath, string.Format("Board-Fov-{0:D3}_T.jpg", fov.id + 1)); if (System.IO.File.Exists(path)) { fovImagepath = path; } fovimages.Add(new ImageData() { Img = fovImage, ImgFilePath = fovImagepath, Size = new System.Drawing.SizeF(reader.Boardfovs.width, reader.Boardfovs.height), Location = new PointF(fov.left, fov.height) }); } #endregion Board board = new Board() { Size = new System.Drawing.SizeF(reader.HeadInfo.board.w, reader.HeadInfo.board.h), WholeImage = new ImageData() { Img = boardIamge, ImgFilePath = boardimagepath, Size = new System.Drawing.SizeF(reader.HeadInfo.board.w, reader.HeadInfo.board.h), Location = new PointF(reader.HeadInfo.board.w / 2, reader.HeadInfo.board.h / 2) }, FovImages = fovimages.ToArray(), Components = compList.ToArray() }; return(board); } return(null); }