private void BuildAndEnterSketch(Document document) { var sketchCreator = new SketchCreator(document); var currentSketch = sketchCreator.CurrentSketch; var sketchNodeBuilder = new NodeBuilder(currentSketch); Document.Transact(); Log.InfoFormat("StartSketch - Command line input"); var firstvector = new gpDir(Points[1].GpPnt.X - Points[0].GpPnt.X, Points[1].GpPnt.Y - Points[0].GpPnt.Y, Points[1].GpPnt.Z - Points[0].GpPnt.Z); var secondvector = new gpDir(Points[2].GpPnt.X - Points[0].GpPnt.X, Points[2].GpPnt.Y - Points[0].GpPnt.Y, Points[2].GpPnt.Z - Points[0].GpPnt.Z); var normal = firstvector.Crossed(secondvector); var _normalOnPlane = new gpAx1(Points[0].GpPnt, normal); var sketchAx2 = new gpAx2(); sketchAx2.Axis = (_normalOnPlane); var plane = new gpPln(new gpAx3(sketchAx2)); Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); sketchNodeBuilder[0].Axis3D = new Axis(sketchNodeBuilder[0].Axis3D.Location, new Point3D(new gpPnt(_normalOnPlane.Direction.XYZ))); HighlightCurrentSketchNodes(sketchNodeBuilder.Node); NodeBuilderUtils.HidePlanes(Document); Document.Commit("sketch created"); AddNodeToTree(sketchNodeBuilder.Node); Document.Transact(); Document.Root.Get <DocumentContextInterpreter>().ActiveSketch = sketchNodeBuilder.Node.Index; _sketchButton.Block(); Document.Commit("Started editing sketch"); }
public ParallelLineMatch(GeometricSolver solver, double precision) : base(solver) { _precision = precision; _oxDir = gp.OX.Direction; _oyDir = gp.OY.Direction; _ozDir = gp.OZ.Direction; }
private bool AxisParallel(Point3D currentPoint, Point3D initialPosition, double angleRange) { if (currentPoint.IsEqual(initialPosition)) { return(false); } var direction = new gpDir(new gpVec(initialPosition.GpPnt, currentPoint.GpPnt)); return(_axisDirection.IsParallel(direction, angleRange)); }
public int Box(double x, double y, double z, double x1, double y1, double z1, double x3, double y3, double z3, double height) { var dir = new gpDir(x1, y1, z1); var axis = new gpAx1(new gpPnt(x, y, z), dir); var point3 = new Point3D(x3, y3, z3); var node = TreeUtils.AddBox(Document, axis, point3, height); return(node.Index); }
public void StartDragging(SceneSelectedEntity handleNode) { IsDragging = true; if (SelectedEntity.ShapeType == TopAbsShapeEnum.TopAbs_FACE) { selectedShape = SelectedEntity.TargetShape(); prevFaceCount = -1; initialDirection = GeomUtils.ExtractDirection(SelectedEntity.TargetShape()); DraggingIndex = 0;// _handles[FunctionNames.AxisHandle]; } }
public override bool Execute() { var position = Dependency[0].TransformedPoint3D; var direction = new gpDir(Dependency[1].TransformedPoint3D.GpPnt.XYZ); var line = new GeomLine(new gpLin(position.GpPnt, direction)); var helperLine = OccShapeCreatorCode.BuildDottedLine(line); Interactive = helperLine; return(true); }
/// <summary> /// Detects paralellism with axis /// </summary> /// <param name = "currentPoint"></param> /// <param name = "initialPosition"></param> /// <returns></returns> public SolverPreviewObject AxisParallel(Point3D currentPoint, Point3D initialPosition) { var direction = new gpDir(new gpVec(initialPosition.GpPnt, currentPoint.GpPnt)); var axisDirection = _oxDir; if (axisDirection.IsParallel(direction, _precision)) { var point = GetOtherPoint(initialPosition, currentPoint, axisDirection); if (point == null) { return(null); } var solverPoint = new SolverEdgeTwoPointsResult(point.Value, initialPosition, Color.Red) { Type = "Parallel X" }; return(solverPoint); } axisDirection = _oyDir; if (axisDirection.IsParallel(direction, _precision)) { //return ProjectPointOnDirection(initialPosition, currentPoint, axisDirection, Color.Green); var point = GetOtherPoint(initialPosition, currentPoint, axisDirection); if (point == null) { return(null); } var solverPoint = new SolverEdgeTwoPointsResult(point.Value, initialPosition, Color.Red) { Type = "Parallel Y" }; return(solverPoint); } axisDirection = _ozDir; if (axisDirection.IsParallel(direction, _precision)) { //return ProjectPointOnDirection(initialPosition, currentPoint, axisDirection, Color.Blue); var point = GetOtherPoint(initialPosition, currentPoint, axisDirection); if (point == null) { return(null); } var solverPoint = new SolverEdgeTwoPointsResult(point.Value, initialPosition, Color.Red) { Type = "Parallel Z" }; return(solverPoint); } return(null); }
private static double GetPreviousMajorRadius(NodeBuilder builder) { bool reversed; gpDir dirX = null; gpDir dirY = null; double previousMinorRadius; double previousMajorRadius; TreeUtils.ComputeEllipseRadiuses(builder[0].TransformedPoint3D, builder[1].TransformedPoint3D, builder[2].TransformedPoint3D, out previousMinorRadius, out previousMajorRadius, out reversed, ref dirX, ref dirY); return(previousMajorRadius); }
/// <summary> /// Detects paralellism with axis /// </summary> /// <param name = "currentPoint"></param> /// <param name = "initialPosition"></param> /// <returns></returns> private SolverPreviewObject AxisParallel(Point3D currentPoint, Point3D initialPosition) { var direction = new gpDir(new gpVec(initialPosition.GpPnt, currentPoint.GpPnt)); foreach (var dir in _directions) { if (dir.IsParallel(direction, _precision)) { return(ParallelLineMatch.ProjectPointOnDirection(initialPosition, currentPoint, dir, Color.Black)); } } return(null); }
private void SetSecondPointDraggingHandle(gpVec vectorV2V1, Mouse3DPosition vertex, Point3D secondPoint) { if (_secondPointProjectionDirection == null) { _secondPointProjectionDirection = new gpDir(vectorV2V1); } var secondPointProjectionPlane = new gpPln(vertex.Point.GpPnt, _secondPointProjectionDirection); var secondProjectedPoint = GeomUtils.ProjectPointOnPlane(secondPoint.GpPnt, secondPointProjectionPlane, Precision.Confusion); Dependency[1].TransformedPoint3D = new Point3D(secondProjectedPoint); Dependency[2].TransformedPoint3D = vertex.Point; }
public static Point3D?ProjectPointOnLine(Point3D firstLinePoint, gpDir lineDirection, Point3D pointToProject) { // Make a parallel line with this line starting from the initial point var projectionLine = new gceMakeLin(firstLinePoint.GpPnt, lineDirection).Value; var geomLine = new GeomLine(projectionLine); var projectionPoint = new GeomAPIProjectPointOnCurve(pointToProject.GpPnt, geomLine); if (projectionPoint.NbPoints > 0) { return(new Point3D(projectionPoint.NearestPoint)); } return(null); }
private Point3D?GetOtherPoint(Point3D firstLinePoint, Point3D secondLinePoint, gpDir direction) { // Make a parallel line with this line starting from the initial point var parallelLine = new gceMakeLin(firstLinePoint.GpPnt, direction).Value; var geomLine = new GeomLine(parallelLine); var projectionPoint = new GeomAPIProjectPointOnCurve(secondLinePoint.GpPnt, geomLine); if (projectionPoint.NbPoints <= 0) { return(null); } return(new Point3D(projectionPoint.NearestPoint)); }
/// <summary> /// Builds a rectangle from 2 points received as parameter. /// Rectangle: /// P2--------P3 /// P1--------P4 /// </summary> /// <param name = "firstPoint"></param> /// <param name = "thirdPoint"></param> /// <param name = "direction"></param> /// <returns></returns> public static TopoDSFace BuildRectangle(gpPnt firstPoint, gpPnt thirdPoint, gpDir direction) { // Check for point coincidence if (firstPoint.IsEqual(thirdPoint, Precision.Confusion)) { return(null); } var secondPoint = new gpPnt(); var fourthPoint = new gpPnt(); GeomUtils.CalculateRectangleVertexes(firstPoint, thirdPoint, direction, ref secondPoint, ref fourthPoint); return(BuildRectangle(new Point3D(firstPoint), new Point3D(secondPoint), new Point3D(fourthPoint))); }
private static gpPln BuildNormalPlane(gpDir dir, Axis gravityAxis) { var gravityCenter = gravityAxis.Location; var plane = new gpPln(gravityCenter.GpPnt, dir); var newPoint = gravityCenter; newPoint.X += 1; newPoint.Y += 2; newPoint.Z += 3; var result = GeomUtils.ProjectPointOnPlane(newPoint.GpPnt, plane, Precision.Confusion); var resultPlane = GeomUtils.BuildPlane(gravityCenter, new Point3D(result), gravityAxis.Location.AddCoordinate(gravityAxis.Direction)); return(resultPlane); }
public static Node AddSketchNode(Document document, Point3D point1, Point3D point2, Point3D point3) { //var sketchCreator = new SketchCreator(document); //var currentSketch = sketchCreator.CurrentSketch; var sketchNodeBuilder = new NodeBuilder(document, FunctionNames.Sketch); var firstvector = new gpDir(point2.GpPnt.X - point1.GpPnt.X, point2.GpPnt.Y - point1.GpPnt.Y, point2.GpPnt.Z - point1.GpPnt.Z); var secondvector = new gpDir(point3.GpPnt.X - point1.GpPnt.X, point3.GpPnt.Y - point1.GpPnt.Y, point3.GpPnt.Z - point1.GpPnt.Z); var normal = firstvector.Crossed(secondvector); var _normalOnPlane = new gpAx1(point1.GpPnt, normal); var sketchAx2 = new gpAx2(); sketchAx2.Axis = (_normalOnPlane); sketchNodeBuilder[0].TransformedAxis3D = _normalOnPlane; return(!sketchNodeBuilder.ExecuteFunction() ? null : sketchNodeBuilder.Node); }
private double GetPreviousMajorRadius() { bool reversed; gpDir dirX = null; gpDir dirY = null; double previousMinorRadius; double previousMajorRadius; var firstPoint = Builder[0].ReferenceBuilder[1].TransformedPoint3D; var secondPoint = Builder[1].ReferenceBuilder[1].TransformedPoint3D; var thirdPoint = Builder[2].ReferenceBuilder[1].TransformedPoint3D; TreeUtils.ComputeEllipseRadiuses(firstPoint, secondPoint, thirdPoint, out previousMinorRadius, out previousMajorRadius, out reversed, ref dirX, ref dirY); return(previousMajorRadius); }
/// <summary> /// Builds an ellipse from 3 points in space /// </summary> private static TopoDSWire BuildEllipse(Point3D center, Point3D secondPoint, Point3D thirdPoint) { double minorRadius; double majorRadius; bool reversed; gpDir dirX = null; gpDir dirY = null; if (secondPoint.GpPnt.Distance(thirdPoint.GpPnt) < Precision.Confusion) { return(null); } if (!TreeUtils.ComputeEllipseRadiuses(center, secondPoint, thirdPoint, out minorRadius, out majorRadius, out reversed, ref dirX, ref dirY)) { return(null); } // Build a plane from the 3 points var plane = GeomUtils.BuildPlane(center, secondPoint, thirdPoint); var ax1 = plane.Axis; var ax2 = new gpAx2(); ax2.Axis = (ax1); ax2.Location = (center.GpPnt); // If major and minor radius are reversed also their directions arereversed if (!reversed) { ax2.XDirection = (dirX); ax2.YDirection = (dirY); } else { ax2.XDirection = (dirY); ax2.YDirection = (dirX); } var ellipse = new GeomEllipse(ax2, majorRadius, minorRadius); var edge = new BRepBuilderAPIMakeEdge(ellipse).Edge; var wire = new BRepBuilderAPIMakeWire(edge).Wire; return(wire); }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { if (!mouseData.MouseDown) { return; } AddToPointList(mouseData.Point); // Start a line drawing process if (Points.Count == 1) { var face = CurrentFacePicked; if (face != null) { _direction = GeomUtils.ExtractDirection(face); } Log.Info("Line Normal - draw line started"); return; } // The line drawing finished Log.Info("Line Normal - draw line finished"); // Create line var normalPoint = (Point3D)GeomUtils.ProjectPointOnLine(Points[0], _direction, mouseData.Point); if (Points[0].IsEqual(normalPoint)) { return; } InitSession(); var node = TreeUtils.AddLineToNode(Document, Points[0], normalPoint).Node; if (node == null) { Document.Revert(); BackToNeutralModifier(); return; } // Commit CommitFinal("Line Normal"); _temporary = new NodeBuilder(null); }
public static bool BuildFaceDraft(BRepOffsetAPIDraftAngle draft, TopoDSFace draftedFace, gpDir draftDirection, double angle, gpPln neutralPlane) { try { draft.Add(draftedFace, draftDirection, angle, neutralPlane, true); if (!draft.AddDone) { //draft.Remove(draftedFace); return(false); } } catch (Exception) { return(false); } return(true); }
/// <summary> /// Calculates the projection of the second line point on the direction so that the line created from /// [first point, projection] is parallel with direction. /// </summary> /// <param name = "firstLinePoint"></param> /// <param name = "secondLinePoint"></param> /// <param name = "direction"></param> /// <param name = "color"></param> /// <returns></returns> public static SolverPreviewObject ProjectPointOnDirection(Point3D firstLinePoint, Point3D secondLinePoint, gpDir direction, Color color) { // Make a parallel line with this line starting from the initial point var parallelLine = new gceMakeLin(firstLinePoint.GpPnt, direction).Value; var geomLine = new GeomLine(parallelLine); var projectionPoint = new GeomAPIProjectPointOnCurve(secondLinePoint.GpPnt, geomLine); if (projectionPoint.NbPoints <= 0) { return(null); } var firstParallelPoint = new Point3D(projectionPoint.NearestPoint); var secondParallelPoint = firstLinePoint; var solverPoint = new SolverEdgeTwoPointsResult(firstParallelPoint, secondParallelPoint, color) { Type = "Parallel Line" }; return(solverPoint); }
private NodeBuilder BuildFloor(ShapeBoundBox bounding) { var floorRectangle = new NodeBuilder(_mirrorDocument, FunctionNames.Rectangle); var startFloorPoint = new Point3D(bounding.Coordinate.X - _range, bounding.Coordinate.Y - _range, bounding.Coordinate.Z); var dir = new gpDir(0, 0, 1); var endFloorPoint = new Point3D( bounding.Coordinate.X + bounding.Dimensions.X + _range, bounding.Coordinate.Y + bounding.Dimensions.Y + _range, bounding.Coordinate.Z); floorRectangle[0].Axis3D = new Axis(new gpAx1(startFloorPoint.GpPnt, dir)); floorRectangle[1].TransformedPoint3D = endFloorPoint; floorRectangle.Color = Color.White; floorRectangle.Transparency = 0.8; floorRectangle.ExecuteFunction(); _mirrorDocument.Commit("tranparent floor"); return(floorRectangle); }
/// <summary> /// Calculates the computer radiuses knowing the center position and two points located on the two axis /// </summary> public static bool ComputeEllipseRadiuses(Point3D center, Point3D secondPoint, Point3D thirdPoint, out double minorRadius, out double majorRadius, out bool reversed, ref gpDir dirX, ref gpDir dirY) { // Calculate the major radius majorRadius = center.GpPnt.Distance(secondPoint.GpPnt); // Calculate also the axis/direction of the major radus var vecX = new gpVec(center.GpPnt, secondPoint.GpPnt); dirX = new gpDir(vecX); var line = new gpLin(center.GpPnt, dirX); // Calculate the minor radius minorRadius = line.Distance(thirdPoint.GpPnt); reversed = false; if (minorRadius < Precision.Confusion || majorRadius < Precision.Confusion) { return(false); } // Calculate also the axis/direction of the major radus var vecY = new gpVec(center.GpPnt, thirdPoint.GpPnt); // We want the direction to be perpendicular on the direction of the major radius var vecZ = vecX.Crossed(vecY); vecY = vecX.Crossed(vecZ); dirY = new gpDir(vecY); // Major radius must be bigger than minor radius if (minorRadius > majorRadius) { var aux = majorRadius; majorRadius = minorRadius; minorRadius = aux; reversed = true; } return(true); }
private static void SetRadius(NodeBuilder ellipseBuilder, double majorRadius, double minorRadius) { bool reversed; gpDir dirX = null; gpDir dirY = null; double previousMinorRadius; double previousMajorRadius; TreeUtils.ComputeEllipseRadiuses(ellipseBuilder[0].TransformedPoint3D, ellipseBuilder[1].TransformedPoint3D, ellipseBuilder[2].TransformedPoint3D, out previousMinorRadius, out previousMajorRadius, out reversed, ref dirX, ref dirY); // Calculate the ratio needed to scale the radiuses var scaleMajor = majorRadius / previousMajorRadius; var scaleMinor = minorRadius / previousMinorRadius; var center = ellipseBuilder[0].TransformedPoint3D; var translatedPoint = new Point3D(center.X, center.Y, center.Z); var translatedPoint2 = new Point3D(center.X, center.Y, center.Z); // If minor radius is smaller than major radius if (!reversed) { translatedPoint = TreeUtils.ScaleSegment(translatedPoint, ellipseBuilder[1].TransformedPoint3D, scaleMajor); ellipseBuilder[1].TransformedPoint3D = translatedPoint; TreeUtils.ScaleSegment(translatedPoint2, ellipseBuilder[2].TransformedPoint3D, scaleMinor); ellipseBuilder[2].TransformedPoint3D = translatedPoint2; } else { translatedPoint = TreeUtils.ScaleSegment(translatedPoint, ellipseBuilder[1].TransformedPoint3D, scaleMinor); ellipseBuilder[1].TransformedPoint3D = translatedPoint; TreeUtils.ScaleSegment(translatedPoint2, ellipseBuilder[2].TransformedPoint3D, scaleMajor); ellipseBuilder[2].TransformedPoint3D = translatedPoint2; } }
private void SetRadius(Double majorRadius, Double minorRadius) { bool reversed; gpDir dirX = null; gpDir dirY = null; double previousMinorRadius; double previousMajorRadius; var firstPoint = Builder[0].ReferenceBuilder[1].TransformedPoint3D; var secondPoint = Builder[1].ReferenceBuilder[1].TransformedPoint3D; var thirdPoint = Builder[2].ReferenceBuilder[1].TransformedPoint3D; TreeUtils.ComputeEllipseRadiuses(firstPoint, secondPoint, thirdPoint, out previousMinorRadius, out previousMajorRadius, out reversed, ref dirX, ref dirY); // Calculate the ratio needed to scale the radiuses var scaleMajor = majorRadius / previousMajorRadius; var scaleMinor = minorRadius / previousMinorRadius; var center = firstPoint; var translatedPoint = new Point3D(center.X, center.Y, center.Z); var translatedPoint2 = new Point3D(center.X, center.Y, center.Z); // If minor radius is smaller than major radius if (!reversed) { Builder[1].ReferenceBuilder[1].TransformedPoint3D = TreeUtils.ScaleSegment(translatedPoint, secondPoint, scaleMajor); Builder[2].ReferenceBuilder[1].TransformedPoint3D = TreeUtils.ScaleSegment(translatedPoint2, thirdPoint, scaleMinor); } else { Builder[1].ReferenceBuilder[1].TransformedPoint3D = TreeUtils.ScaleSegment(translatedPoint, secondPoint, scaleMinor); Builder[2].ReferenceBuilder[1].TransformedPoint3D = TreeUtils.ScaleSegment(translatedPoint2, thirdPoint, scaleMajor); } NodeBuilderUtils.UpdateSketchesOnFaces(new NodeBuilder(Parent)); }
public GeomLine(gpPnt P, gpDir V) : base(Geom_Line_CtorE13B639C(P.Instance, V.Instance)) { }
protected abstract bool LinesAxisMatch(gpDir axisDir, gpDir direction, double angleRange);
public gceMakeLin(gpPnt P, gpDir V) : base(gce_MakeLin_CtorE13B639C(P.Instance, V.Instance)) { }
protected override bool LinesAxisMatch(gpDir axisDir, gpDir direction, double angleRange) { return(axisDir.IsParallel(direction, angleRange)); }
public bool Orientate(gpDir aNormal) { return(Graphic3d_ArrayOfPrimitives_OrientateCEC711A5(Instance, aNormal.Instance)); }
public int AddVertex(gpPnt aVertice, gpDir aNormal, gpPnt2d aTexel) { return(Graphic3d_ArrayOfPrimitives_AddVertex640114B2(Instance, aVertice.Instance, aNormal.Instance, aTexel.Instance)); }