//-------------------------------------------------------------------------------------------------- public void Write(Ax3 ax3) { var dir = ax3.XDirection; _Writer.Write((float)dir.X); _Writer.Write((float)dir.Y); _Writer.Write((float)dir.Z); _Writer.Write(0.0f); dir = ax3.YDirection; _Writer.Write((float)dir.X); _Writer.Write((float)dir.Y); _Writer.Write((float)dir.Z); _Writer.Write(0.0f); dir = ax3.Direction; _Writer.Write((float)dir.X); _Writer.Write((float)dir.Y); _Writer.Write((float)dir.Z); _Writer.Write(0.0f); var loc = ax3.Location; _Writer.Write((float)loc.X); _Writer.Write((float)loc.Y); _Writer.Write((float)loc.Z); _Writer.Write(1.0f); }
public void Angle() { var p1 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); Assert.AreEqual(Math.PI / 2, p1.Angle(p2)); }
public override bool BindToPlane(Ax3 targetFrame, Entity boundTo, Pln?plane) { if (Operands[0] == null) { return(false); } return(Operands[0].BindToPlane(targetFrame, boundTo, plane)); }
public void Direct() { var p2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); p2.XReverse(); p2.YReverse(); p2.ZReverse(); Assert.IsFalse(p2.Direct()); }
//-------------------------------------------------------------------------------------------------- TopoDS_Shape IShapeOperand.GetBRep(Ax3 targetFrame) { if (Body == null) { return(null); } return(Shape?.GetBRep()?.Moved(_GetCachedLocation(targetFrame))); }
public void Scale() { var res = new Ax3(new Pnt(-1, 0, 5), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(res, p2.Scaled(new Pnt(2, 3, 2), 3)); p2.Scale(new Pnt(2, 3, 2), 3); Assert.AreEqual(res, p2); }
public void TranslateVec() { var res = new Ax3(new Pnt(3, 5, 4), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(res, p2.Translated(new Vec(2, 3, 1))); p2.Translate(new Vec(2, 3, 1)); Assert.AreEqual(res, p2); }
//-------------------------------------------------------------------------------------------------- void _ComputeCoordinateSystem() { TopoDS_Shape ocShape; if ((_TargetBodies.Count == 1) || _Options.HasFlag(Options.MultiBodyUseFirst)) { // Single body, or Multishape using pivot of first shape Body targetBody = _TargetBodies[0]; ocShape = targetBody.Shape?.GetTransformedBRep(); switch (_PivotPoint) { case PivotPoint.BodyPivot: _CoordinateSystem = targetBody.GetCoordinateSystem(); break; case PivotPoint.BoundingCenter: _CoordinateSystem = targetBody.GetCoordinateSystem(); if (ocShape != null) { _CoordinateSystem.Location = ocShape.BoundingBox().Center(); } break; case PivotPoint.MassCenter: _CoordinateSystem = targetBody.GetCoordinateSystem(); if (ocShape != null) { _CoordinateSystem.Location = ocShape.CenterOfMass(); } break; } if (_Options.HasFlag(Options.WorldSpaceOrientation)) { _CoordinateSystem = new Ax3(_CoordinateSystem.Location, Dir.DZ); } } else { // Multiple shapes, use BBox center for all as pivot, and world space axis Bnd_Box bndBox = new Bnd_Box(); foreach (var targetBody in _TargetBodies) { ocShape = targetBody.Shape?.GetTransformedBRep(); if (ocShape != null) { bndBox.Add(ocShape.BoundingBox()); } } _CoordinateSystem = Ax3.XOY; _CoordinateSystem.Location = bndBox.Center(); } }
public void IsCoplanar() { var p1 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); Assert.IsFalse(p1.IsCoplanar(p2, 0.1, 0.1)); Assert.IsFalse(p1.IsCoplanar(p2, 0.1, 2.0)); Assert.IsFalse(p1.IsCoplanar(p2, 0.1, Math.PI / 2)); Assert.IsTrue(p1.IsCoplanar(p2, 1.0, Math.PI / 2)); }
public void MirrorAx1() { var res = new Ax3(new Pnt(1, -2, -3), new Dir(1, 0, 0), new Dir(0, 0, -10)); var a1 = new Ax1(new Pnt(1, 0, 0), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(res, p2.Mirrored(a1)); p2.Mirror(a1); Assert.AreEqual(res, p2); }
public void Rotate() { var res = new Ax3(new Pnt(1, 1, 2), new Dir(1, 0, 0), new Dir(0, -1, 0)); var a1 = new Ax1(new Pnt(2, 2, 2), new Dir(1, 0, 0)); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.IsTrue(res.IsCoplanar(p2.Rotated(a1, Math.PI / 2), 0, 0)); p2.Rotate(a1, Math.PI / 2); Assert.IsTrue(res.IsCoplanar(p2, 0, 0)); }
public void MirrorPnt() { var res = new Ax3(new Pnt(1, -2, -3), new Dir(-1, 0, 0), new Dir(0, 0, -1)); res.YReverse(); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(res, p2.Mirrored(new Pnt(1, 0, 0))); p2.Mirror(new Pnt(1, 0, 0)); Assert.AreEqual(res, p2); }
public void Reverse() { var p2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); p2.XReverse(); Assert.AreEqual(new Dir(0, 0, -1), p2.XDirection); p2.YReverse(); Assert.AreEqual(new Dir(-1, 0, 0), p2.YDirection); p2.ZReverse(); Assert.AreEqual(new Dir(0, -1, 0), p2.Direction); }
//-------------------------------------------------------------------------------------------------- Shape IShapeOperand.Collapse(Ax3 targetFrame) { var collapsedBRep = ((IShapeOperand)this).GetBRep(targetFrame); if (collapsedBRep == null) { return(null); } return(Solid.Create(collapsedBRep)); }
public void MirrorAx2() { var res = new Ax3(new Pnt(1, -2, 3), new Dir(1, 0, 0), new Dir(0, 0, 1)); res.YReverse(); var a2 = new Ax2(new Pnt(1, 0, 0), new Dir(0, 1, 0)); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(res, p2.Mirrored(a2)); p2.Mirror(a2); Assert.AreEqual(res, p2); }
//-------------------------------------------------------------------------------------------------- public TranslateAction(object owner, Ax3 coordinateSystem) : base(owner) { _CoordinateSystem = coordinateSystem; // Create inverse rotation matrix var rotAx3 = _CoordinateSystem; rotAx3.Location = Pnt.Origin; _InverseRotation = new Trsf(rotAx3); _InverseRotation.Invert(); }
//-------------------------------------------------------------------------------------------------- bool DoExport(string filename, IDrawingExporter exporter) { try { var projection = new Ax3(_Viewport.EyePoint, _Viewport.GetViewDirection().Reversed(), _Viewport.GetRightDirection()); var hlrEdgeTypes = HlrEdgeTypes.None; if (Settings.VisibleOutline) { hlrEdgeTypes |= HlrEdgeTypes.VisibleSharp; hlrEdgeTypes |= HlrEdgeTypes.VisibleOutline; } if (Settings.VisibleSmooth) { hlrEdgeTypes |= HlrEdgeTypes.VisibleSmooth; } if (Settings.VisibleSewn) { hlrEdgeTypes |= HlrEdgeTypes.VisibleSewn; } if (Settings.HiddenOutline) { hlrEdgeTypes |= HlrEdgeTypes.HiddenSharp; hlrEdgeTypes |= HlrEdgeTypes.HiddenOutline; } if (Settings.HiddenSmooth) { hlrEdgeTypes |= HlrEdgeTypes.HiddenSmooth; } if (Settings.HiddenSewn) { hlrEdgeTypes |= HlrEdgeTypes.HiddenSewn; } var source = new TopoDSBrepSource(InteractiveContext.Current.WorkspaceController.VisualObjects.GetVisibleBReps().ToArray()); var hlrBrepDrawing = HlrDrawing.Create(projection, hlrEdgeTypes, source); hlrBrepDrawing.UseTriangulation = Settings.UseTriangulation; var drawing = new Drawing(); drawing.Add(hlrBrepDrawing); return(exporter.DoExport(filename, drawing)); } catch (Exception e) { Messages.Exception("Exception while exporting line drawing from viewport.", e); return(false); } }
//-------------------------------------------------------------------------------------------------- bool _MakeSolid(IShapeOperand sourceShape) { var sourceBRep = GetOperandBRep(0); if (sourceBRep == null) { return(false); } // Calculate Parameters Ax3 axis = _CalculateSolidAxis(); var(interval, offset) = _CalculateParameters(); // Build Transformed Shapes TopoDS_Compound resultShape = new TopoDS_Compound(); var builder = new TopoDS_Builder(); builder.MakeCompound(resultShape); for (var index = 0; index < Quantity; index++) { var angle = (interval * index + offset).ToRad(); var transform = Trsf.Identity; if (_KeepOrientation) { // Translation transform transform.SetTranslation(Pnt.Origin.Rotated(axis.Axis, angle).ToVec()); } else { // Rotation transform transform.SetRotation(axis.Axis, angle); } var makeTransform = new BRepBuilderAPI_Transform(sourceBRep, transform); if (!makeTransform.IsDone()) { Messages.Error("Failed transforming shape."); return(false); } builder.Add(resultShape, makeTransform.Shape()); } // Finalize BRep = resultShape; return(true); }
//-------------------------------------------------------------------------------------------------- #region Helper MemoryStream RunExporter(bool useTriangulation, Ax3 projection, DxfVersion version, DxfFlags flags, params Body[] bodies) { var hlrEdgeTypes = HlrEdgeTypes.VisibleSharp | HlrEdgeTypes.VisibleOutline | HlrEdgeTypes.VisibleSmooth | HlrEdgeTypes.HiddenSharp | HlrEdgeTypes.HiddenOutline; IBrepSource[] sources = bodies.Select(body => (IBrepSource) new BodyBrepSource(body)).ToArray(); var hlrBrepDrawing = HlrDrawing.Create(projection, hlrEdgeTypes, sources); hlrBrepDrawing.UseTriangulation = useTriangulation; var drawing = new Drawing(); drawing.Add(hlrBrepDrawing); return(DxfDrawingExporter.Export(drawing, version, flags)); }
public void Transform() { Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); var p2 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var p3 = p2.Transformed(t1); Assert.That(new Pnt(-2, 1, 3).IsEqual(p3.Location, 0.0000001)); Assert.That(new Dir(0, 0, 1).IsEqual(p3.XDirection, 0.0000001)); Assert.That(new Dir(1, 0, 0).IsEqual(p3.YDirection, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p3.Direction, 0.0000001)); p2.Transform(t1); Assert.That(new Pnt(-2, 1, 3).IsEqual(p2.Location, 0.0000001)); Assert.That(new Dir(0, 0, 1).IsEqual(p2.XDirection, 0.0000001)); Assert.That(new Dir(1, 0, 0).IsEqual(p2.YDirection, 0.0000001)); Assert.That(new Dir(0, 1, 0).IsEqual(p2.Direction, 0.0000001)); }
public void Components() { var p1 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); Assert.AreEqual(new Pnt(1, 2, 3), p1.Location); Assert.AreEqual(new Dir(1, 0, 0), p1.Direction); Assert.AreEqual(new Dir(0, 0, 1), p1.XDirection); Assert.AreEqual(new Dir(0, -1, 0), p1.YDirection); p1.Location = new Pnt(3, 2, 1); Assert.AreEqual(new Pnt(3, 2, 1), p1.Location); p1.Direction = new Dir(0, 1, 0); Assert.AreEqual(new Dir(0, 1, 0), p1.Direction); p1.XDirection = new Dir(0, 0, -1); Assert.AreEqual(new Dir(0, 0, -1), p1.XDirection); p1.YDirection = new Dir(1, 0, 0); Assert.AreEqual(new Dir(1, 0, 0), p1.YDirection); }
//-------------------------------------------------------------------------------------------------- #region Helper MemoryStream RunExporter(bool useTriangulation, Ax3 projection, TopoDS_Shape[] shapes) { var helper = new DrawingExportHelper(useTriangulation, projection); helper.IncludeEdgeType(HlrEdgeType.VisibleSharp); helper.IncludeEdgeType(HlrEdgeType.VisibleOutline); helper.IncludeEdgeType(HlrEdgeType.VisibleSmooth); helper.IncludeEdgeType(HlrEdgeType.HiddenSharp); helper.IncludeEdgeType(HlrEdgeType.HiddenOutline); var layers = helper.PrepareExportLayers(shapes); if (layers == null || layers.Length == 0) { return(new MemoryStream("!HLRExporterError!".ToUtf8Bytes())); } return(SvgVectorExporter.Export(VectorExportTemplate.Drawing, layers)); }
//-------------------------------------------------------------------------------------------------- bool DoExport(string filename, IVectorExporter exporter) { try { var projection = new Ax3(_Viewport.EyePoint, _Viewport.GetViewDirection().Reversed(), _Viewport.GetRightDirection()); var exportHelper = new DrawingExportHelper(Settings.UseTriangulation, projection); if (Settings.VisibleOutline) { exportHelper.IncludeEdgeType(HlrEdgeType.VisibleSharp); exportHelper.IncludeEdgeType(HlrEdgeType.VisibleOutline); } if (Settings.VisibleSmooth) { exportHelper.IncludeEdgeType(HlrEdgeType.VisibleSmooth); } if (Settings.VisibleSewn) { exportHelper.IncludeEdgeType(HlrEdgeType.VisibleSewn); } if (Settings.HiddenOutline) { exportHelper.IncludeEdgeType(HlrEdgeType.HiddenSharp); exportHelper.IncludeEdgeType(HlrEdgeType.HiddenOutline); } if (Settings.HiddenSmooth) { exportHelper.IncludeEdgeType(HlrEdgeType.HiddenSmooth); } if (Settings.HiddenSewn) { exportHelper.IncludeEdgeType(HlrEdgeType.HiddenSewn); } return(exportHelper.Export(filename, exporter, InteractiveContext.Current.WorkspaceController.VisualShapes.GetVisibleBReps())); } catch (Exception e) { Messages.Exception("Exception while exporting line drawing from viewport.", e); return(false); } }
TopLoc_Location _GetCachedLocation(Ax3 targetFrame) { if (Body == null) { return(null); } var bodyFrame = Body.GetCoordinateSystem(); if (_CachedLocation.Item1 == bodyFrame && _CachedLocation.Item2 == targetFrame) { return(_CachedLocation.Item3); } var location = new TopLoc_Location(new Trsf(Body.GetCoordinateSystem(), targetFrame)); _CachedLocation = new Tuple <Ax3, Ax3, TopLoc_Location>(bodyFrame, targetFrame, location); return(location); }
//-------------------------------------------------------------------------------------------------- #region IShapeOperator public override bool BindToPlane(Ax3 targetFrame, Entity boundTo, Pln?plane) { if (_BoundTo == null) { _BoundTo = boundTo; } else { if (boundTo != _BoundTo) { return(false); } } if (plane == null) { _BoundTo = null; return(false); } BoundToPlane = plane; return(true); }
//-------------------------------------------------------------------------------------------------- bool IShapeOperand.BindToPlane(Ax3 targetFrame, Entity boundTo, Pln?plane) { if (Body == null) { return(false); } var shape = Shape; if (shape == null) { return(false); } if (plane.HasValue) { return(shape.BindToPlane(Body.GetCoordinateSystem(), boundTo, plane.Value.Transformed(new Trsf(Body.GetCoordinateSystem(), targetFrame)))); } else { return(shape.BindToPlane(Body.GetCoordinateSystem(), boundTo, null)); } }
public void ValueType_Ax3() { var s1 = new Ax3(new Pnt(1, 2, 3), new Dir(1, 0, 0)); var s2 = new Ax3(new Pnt(2, 3, 4), new Dir(0, 1, 0)); Assert.AreEqual(new Pnt(1, 2, 3), s1.Location); Assert.AreEqual(new Dir(1, 0, 0), s1.Direction); Assert.AreEqual(new Dir(0, 0, 1), s1.XDirection); Assert.AreEqual(new Dir(0, -1, 0), s1.YDirection); var p2 = s2; Assert.IsFalse(s1.IsCoplanar(p2, 0.1, 0.1)); Assert.IsFalse(s1.IsCoplanar(p2, 0.1, 2.0)); Assert.IsFalse(s1.IsCoplanar(p2, 0.1, Math.PI / 2)); Assert.IsTrue(s1.IsCoplanar(p2, 1.0, Math.PI / 2)); Assert.AreEqual(Math.PI / 2, s1.Angle(p2)); p2.Location = new Pnt(3, 2, 1); Assert.AreEqual(new Pnt(3, 2, 1), p2.Location); p2.Direction = new Dir(0, 1, 0); Assert.AreEqual(new Dir(0, 1, 0), p2.Direction); p2.XDirection = new Dir(0, 0, -1); Assert.AreEqual(new Dir(0, 0, -1), p2.XDirection); p2.YDirection = new Dir(1, 0, 0); Assert.AreEqual(new Dir(1, 0, 0), p2.YDirection); p2.XReverse(); Assert.AreEqual(new Dir(0, 0, -1), p2.XDirection); p2.YReverse(); Assert.AreEqual(new Dir(-1, 0, 0), p2.YDirection); p2.ZReverse(); Assert.AreEqual(new Dir(0, -1, 0), p2.Direction); Assert.IsFalse(p2.Direct()); var res = new Ax3(new Pnt(1, -2, -3), new Dir(-1, 0, 0), new Dir(0, 0, -1)); res.YReverse(); p2 = s1; Assert.AreEqual(res, p2.Mirrored(new Pnt(1, 0, 0))); p2.Mirror(new Pnt(1, 0, 0)); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, -2, 3), new Dir(1, 0, 0), new Dir(0, 0, 1)); res.YReverse(); var a2 = new Ax2(new Pnt(1, 0, 0), new Dir(0, 1, 0)); p2 = s1; Assert.AreEqual(res, p2.Mirrored(a2)); p2.Mirror(a2); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, -2, -3), new Dir(1, 0, 0), new Dir(0, 0, -10)); var a1 = new Ax1(new Pnt(1, 0, 0), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Mirrored(a1)); p2.Mirror(a1); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(1, 1, 2), new Dir(1, 0, 0), new Dir(0, -1, 0)); a1 = new Ax1(new Pnt(2, 2, 2), new Dir(1, 0, 0)); Assert.IsTrue(res.IsCoplanar(s1.Rotated(a1, Math.PI / 2), 0, 0)); p2 = s1; p2.Rotate(a1, Math.PI / 2); Assert.IsTrue(res.IsCoplanar(p2, 0, 0)); res = new Ax3(new Pnt(-1, 0, 5), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Scaled(new Pnt(2, 3, 2), 3)); p2.Scale(new Pnt(2, 3, 2), 3); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(-1, -1, 2), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Translated(new Pnt(3, 5, 4), new Pnt(1, 2, 3))); p2.Translate(new Pnt(3, 5, 4), new Pnt(1, 2, 3)); Assert.AreEqual(res, p2); res = new Ax3(new Pnt(3, 5, 4), new Dir(1, 0, 0)); p2 = s1; Assert.AreEqual(res, p2.Translated(new Vec(2, 3, 1))); p2.Translate(new Vec(2, 3, 1)); Assert.AreEqual(res, p2); //gp_Trsf gt1 = new gp_Trsf(); //gt1.SetRotation(gp.OZ(), Math.PI / 2); //gp2.Transform(gt1); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, $"({gp2.Location().x},{gp2.Location().y},{gp2.Location().z}),({gp2.XDirection().x},{gp2.XDirection().y},{gp2.XDirection().z}),({gp2.YDirection().x},{gp2.YDirection().y},{gp2.YDirection().z}),({gp2.Direction().x},{gp2.Direction().y},{gp2.Direction().z})")); Trsf t1 = new Trsf(); t1.SetRotation(Ax1.OZ, Math.PI / 2); p2 = s1; Assert.AreEqual("(-2,1,3),(0,0,1),(1,-1.11022302462516E-16,0),(1.11022302462516E-16,1,0)", p2.Transformed(t1).ToString()); p2.Transform(t1); Assert.AreEqual("(-2,1,3),(0,0,1),(1,-1.11022302462516E-16,0),(1.11022302462516E-16,1,0)", p2.ToString()); }
//-------------------------------------------------------------------------------------------------- #endregion #region IShapeOperand TopoDS_Shape IShapeOperand.GetBRep(Ax3 targetFrame) { // We're not transforming if we are referenced directly by another shape // since we have the same body return(GetBRep()); }
//-------------------------------------------------------------------------------------------------- public DrawingExportHelper(bool useTriangulation, Ax3 projection) { _UseTriangulation = useTriangulation; _Projection = projection; }
//-------------------------------------------------------------------------------------------------- public virtual bool BindToPlane(Ax3 targetFrame, Entity boundTo, Pln?plane) { return(false); }