private bool SwManipulatorHandler2_OnDoubleValueChanged(object pManipulator, int Id, ref double Value) { doneonce = doneonce + 1; Debug.Print("SwManipulatorHandler2_OnDoubleValueChanged"); Debug.Print(" ID = " + Id); Debug.Print(" Value = " + Value); DragArrowManipulator swTmpManipulator = default(DragArrowManipulator); swTmpManipulator = (DragArrowManipulator)pManipulator; //Update origin MathPoint swMathPoint = default(MathPoint); swMathPoint = swTmpManipulator.Origin; double[] varMathPt = null; varMathPt = (double[])swMathPoint.ArrayData; varMathPt[1] = varMathPt[1] + lenFact / 1000; swMathPoint.ArrayData = varMathPt; if ((doneonce == 1)) { swTmpManipulator.FixedLength = true; } swTmpManipulator.Origin = swMathPoint; swTmpManipulator.Update(); return(true); }
public virtual bool OnDoubleValueChanged(object pManipulator, int handleIndex, ref double Value) { doneonce = doneonce + 1; DragArrowManipulator swTmpManipulator = default(DragArrowManipulator); swTmpManipulator = (DragArrowManipulator)pManipulator; //Update origin MathPoint swMathPoint = default(MathPoint); swMathPoint = swTmpManipulator.Origin; double[] varMathPt = null; varMathPt = (double[])swMathPoint.ArrayData; varMathPt[1] = varMathPt[1] + lenFact / 1000; swMathPoint.ArrayData = varMathPt; if ((doneonce == 1)) { swTmpManipulator.FixedLength = true; } swTmpManipulator.Origin = swMathPoint; swTmpManipulator.Update(); return(true); return(DoubelValueChanged?.Invoke(pManipulator as DragArrowManipulator, handleIndex.CastObj <swDragArrowManipulatorOptions_e>(), Value) == false ? false : true); }
public GeomVue(View vue, Sketch esquisse) { MathUtility SwMath = App.Sw.GetMathUtility(); gPoint ptCentreVue = new gPoint(vue.Position); gPoint ptMin = new gPoint(Double.PositiveInfinity, Double.PositiveInfinity, 0); gPoint ptMax = new gPoint(Double.NegativeInfinity, Double.NegativeInfinity, 0); foreach (SketchPoint s in esquisse.GetSketchPoints2()) { MathPoint swStartPoint = SwMath.CreatePoint(new Double[3] { s.X, s.Y, s.Z }); MathTransform SketchXform = esquisse.ModelToSketchTransform; SketchXform = SketchXform.Inverse(); swStartPoint = swStartPoint.MultiplyTransform(SketchXform); MathTransform ViewXform = vue.ModelToViewTransform; swStartPoint = swStartPoint.MultiplyTransform(ViewXform); gPoint swViewStartPt = new gPoint(swStartPoint); ptMin.Min(swViewStartPt); ptMax.Max(swViewStartPt); } ptMinX = ptMin.X; ptMinY = ptMin.Y; ptMaxX = ptMax.X; ptMaxY = ptMax.Y; MajCentreRectangle(); ptCentreVueX = ptCentreVue.X; ptCentreVueY = ptCentreVue.Y; }
/// <summary> /// 创建箭头 /// </summary> /// <param name="swN"></param> /// <param name="swPickPt"></param> /// <param name="length"></param> /// <returns></returns> private Manipulator CreateNewDrag(MathVector swN, MathPoint swPickPt, double length) { var swModel = (ModelDoc2)swApp.ActiveDoc; var swModViewMgr = swModel.ModelViewManager; SwManHandler2 swDragHdlr = new SwManHandler2(); Manipulator swManip = swModViewMgr.CreateManipulator((int)swManipulatorType_e.swDragArrowManipulator, swDragHdlr); DragArrowManipulator swDrag = (DragArrowManipulator)swManip.GetSpecificManipulator(); swDrag.AllowFlip = false; swDrag.ShowRuler = false; swDrag.ShowOppositeDirection = false; swDrag.Length = length; swDrag.Direction = swN; //swDrag.LengthOppositeDirection = 0.01; swDrag.Origin = swPickPt; swManip.Show(swModel); swDrag.Update(); return(swManip); }
public gPoint(MathPoint pt) { Double[] Pt = (Double[])pt.ArrayData; X = Pt[0]; Y = Pt[1]; Z = Pt[2]; }
/// <summary> /// Calcualtes if the two vectors intersect /// </summary> /// <param name="axis1Dir">The direction of the first axis</param> /// <param name="axis1Point">a point on the first axis</param> /// <param name="axis2Dir">The direction of the second axis</param> /// <param name="axis2Point">a point on the second axis</param> /// <returns></returns> public static bool AxisIntersect(MathVector axis1Dir, MathPoint axis1Point, MathVector axis2Dir, MathPoint axis2Point) { MathVector pointVect = GetVectorBetweenPoints(axis1Point, axis2Point); if (pointVect.GetLength() < VectorCalcs.errorVal || VectorCalcs.IsParallel(pointVect.Cross(axis1Dir), pointVect.Cross(axis2Dir))) return true; else return false; }
private static void Destructure(MathPoint p, out double x, out double y, out double z) { var arrayData = (double[])p.ArrayData; x = arrayData[0]; y = arrayData[1]; z = arrayData[2]; }
private Double AngleCubeDeVisualisation(View vue, Sketch esquisse) { MathUtility SwMath = App.Sw.GetMathUtility(); List <gPoint> LstPt = new List <gPoint>(); foreach (SketchPoint s in esquisse.GetSketchPoints2()) { MathPoint point = SwMath.CreatePoint(new Double[3] { s.X, s.Y, s.Z }); MathTransform SketchXform = esquisse.ModelToSketchTransform; SketchXform = SketchXform.Inverse(); point = point.MultiplyTransform(SketchXform); MathTransform ViewXform = vue.ModelToViewTransform; point = point.MultiplyTransform(ViewXform); gPoint swViewStartPt = new gPoint(point); LstPt.Add(swViewStartPt); } // On recherche le point le point le plus à droite puis le plus haut LstPt.Sort(new gPointComparer(ListSortDirection.Descending, p => p.X)); LstPt.Sort(new gPointComparer(ListSortDirection.Descending, p => p.Y)); // On le supprime LstPt.RemoveAt(0); // On recherche le point le point le plus à gauche puis le plus bas LstPt.Sort(new gPointComparer(ListSortDirection.Ascending, p => p.X)); LstPt.Sort(new gPointComparer(ListSortDirection.Ascending, p => p.Y)); // C'est le point de rotation gPoint pt1 = LstPt[0]; // On recherche le plus loin gPoint pt2; Double d1 = pt1.Distance(LstPt[1]); Double d2 = pt1.Distance(LstPt[2]); if (d1 > d2) { pt2 = LstPt[1]; } // En cas d'égalité, on renvoi le point le plus à gauche else if (d1 == d2) { pt2 = (LstPt[1].X < LstPt[2].X) ? LstPt[1] : LstPt[2]; } else { pt2 = LstPt[2]; } gVecteur v = new gVecteur(pt1, pt2); return(Math.Atan2(v.Y, v.X)); }
public ReflectionPoint(MathUtility mathUtils, double[] xyz, double[] nxnynz, Component2 component) { this.xyz = xyz; this.nxnynz = nxnynz; this.component = component; location = mathUtils.CreatePoint(xyz); normal = mathUtils.CreateVector(nxnynz); }
// GET: TrendLine public ActionResult Trendlines() { FlexChartModal model = new FlexChartModal(); model.Settings = CreateIndexSettings(); model.MathPoints10 = MathPoint.GetMathPointList(10); model.MathPoints40 = MathPoint.GetMathPointList(40); model.MonthSales = MonthSale.GetData(); return(View(model)); }
public void MultiplyTransfom(MathTransform trans) { MathUtility Mu = App.Sw.GetMathUtility(); MathPoint mp = Mu.CreatePoint(new double[] { X, Y, Z }); mp = mp.MultiplyTransform(trans); Double[] pt = (Double[])mp.ArrayData; X = pt[0]; Y = pt[1]; Z = pt[2]; }
private TriangleNet.Geometry.Point TransformPt(TriangleNet.Geometry.Point Pt) { double[] arr = new double[3]; arr[0] = Pt.X; arr[1] = Pt.Y; arr[2] = 0; MathPoint swPt = (MathPoint)Mu.CreatePoint(arr); swPt = swPt.MultiplyTransform(xForm); arr = swPt.ArrayData; return(new TriangleNet.Geometry.Point(arr[0], arr[1])); }
private bool IsPointZero(MathPoint mathpoint) { double sum = 0; Double[] DoubleArray = (Double[])mathpoint.ArrayData; foreach (double d in DoubleArray) { sum = sum + d; } if (sum > 0.0001) { return false; } return true; }
public static PointParamWithRayProjection ClosestPointToRay(this ICurve curve, PointDirection3 ray, double tol = 1e-9) { var bound = curve.Domain(); int numOfRadius = 0; double[] radius = null; MathPoint location = null; var radiusResult = curve.FindMinimumRadius(); var domain = new RangeDouble(curve.Domain()); var tessTol = radiusResult.Radius / 10; var closestPointOnEdge = Vector3.Zero; for (var i = 0; i < 1; i++) { var tessPoints = Sequences .LinSpace(domain.Min, domain.Max, 100) .Select(curve.PointParamAt).ToList(); var edges = tessPoints.Buffer(2, 1).Where(buf => buf.Count == 2) .ToList(); var closestEdge = edges .Select(edge => new { edge, connection = MakeEdge(edge).ShortestEdgeJoining(ray, tol) }) .MinBy(o => o.connection.LengthSquared)[0]; var a = closestEdge.edge[0].T; var b = closestEdge.edge[1].T; domain = new RangeDouble(a, b); tessTol = tessTol / 10; } Func <Vector3, Vector3> projectOnRay = p => (p - ray.Point).ProjectOn(ray.Direction) + ray.Point; var solver = new BrentSearch(t => { var p = curve.PointAt(t); var proj = projectOnRay(p); return((p - proj).LengthSquared()); }, domain.Min, domain.Max); solver.Minimize(); var minT = solver.Solution; var pointParam = curve.PointParamAt(minT); return(new PointParamWithRayProjection(pointParam, projectOnRay(pointParam.Point))); }
private void button5_Click(object sender, EventArgs e) { //Given two line segements and find whether these two lines interesect //Each line consist of two MathPoints start and end //so given four MathPoints where p1 and q1 form a line and p2 and q2 form another line MathPoint p1 = new MathPoint(10, 0); MathPoint q1 = new MathPoint(0, 10); MathPoint p2 = new MathPoint(0, 0); MathPoint q2 = new MathPoint(10, 0); //bool result = DoLinesIntersect(p1, q1, p2, q2); PointIntersection pi = new PointIntersection(); bool result = pi.DoLinesIntersect(p1, q1, p2, q2); }
public static double[] whereRayHitsComponent(Component2 component, MathPoint rayOrigin, MathVector rayDirection) { List <IBody2> bodies = new List <IBody2>(); object vBodyInfo; object[] componentBodies = (object[])component.GetBodies3((int)swBodyType_e.swSolidBody, out vBodyInfo); for (int i = 0; i < componentBodies.Length; i++) { IBody2 tempBody = ((Body2)componentBodies[i]).ICopy(); tempBody.ApplyTransform(component.Transform2); bodies.Add(tempBody); } int numIntersectionsFound = (int)swDoc.RayIntersections((object)bodies.ToArray(), (object)rayOrigin.ArrayData, (object)rayDirection.ArrayData, (int)(swRayPtsOpts_e.swRayPtsOptsTOPOLS | swRayPtsOpts_e.swRayPtsOptsNORMALS), (double).0000001, (double).0000001); if (numIntersectionsFound == 0) { return(null); } double[] horrifyingReturn = (double[])swDoc.GetRayIntersectionsPoints(); int lengthOfOneReturn = 9; for (int i = 0; i < numIntersectionsFound; i++) { double x = horrifyingReturn[i * lengthOfOneReturn + 3]; double y = horrifyingReturn[i * lengthOfOneReturn + 4]; double z = horrifyingReturn[i * lengthOfOneReturn + 5]; double[] hitPoint = new double[] { x, y, z }; if (!hitMainBodyBefore(rayOrigin.ArrayData, rayDirection.ArrayData, hitPoint)) { return(hitPoint); } } return(null); }
private void button7_Click(object sender, EventArgs e) { MathPoint p1 = new MathPoint(1, 1); MathPoint p2 = new MathPoint(4, 4); MathPoint p3 = new MathPoint(5, 5); MathPoint p4 = new MathPoint(2, 5); MathPoint p5 = new MathPoint(6, 3); List <MathPoint> points = new List <MathPoint>(); points.Add(p1); points.Add(p2); points.Add(p3); points.Add(p4); points.Add(p5); MathPoint[] pointsarray = points.ToArray(); PointIntersection obj = new PointIntersection(); Line bestline = obj.FindBestLine(pointsarray); }
private void button12_Click(object sender, EventArgs e) { //Given two line segements and find whether these two lines interesect //Gayle 6th edition page 464 //so given four MathPoints where p1 and q1 form a line and p2 and q2 form another line MathPoint p1 = new MathPoint(10, 0); MathPoint q1 = new MathPoint(0, 10); MathPoint p2 = new MathPoint(0, 0); MathPoint q2 = new MathPoint(10, 0); PointIntersection pi = new PointIntersection(); MathPoint result = pi.GetIntersectionPointUsingSlopes(p1, q1, p2, q2); if (result != null) { //we found intersction point } }
public void drawInitalRay() { centreOfVision = (MathPoint)Camera.getCentreOfVision(fieldOfView, swDoc, swSelectionMgr, mathUtils); if (centreOfVision == null) { Utilities.alert("you need to insert the camera first!"); return; } IMathPoint otherReference = Camera.getDirectionReference(fieldOfView, swDoc, swSelectionMgr, mathUtils); double[] centreData = (double[])centreOfVision.ArrayData; double[] otherData = (double[])otherReference.ArrayData; double[] cameraDir = { otherData[0] - centreData[0], otherData[1] - centreData[1], otherData[2] - centreData[2] }; cameraDirection = mathUtils.CreateVector(cameraDir); Camera.drawRayForCamera(cameraDirection, centreOfVision, swDoc, swSelectionMgr); castRayCentres = null; castRayVectors = null; }
public void changePois(ISldWorks swApp) //将点变为绝对坐标下 { MathUtility mathUtil = (MathUtility)swApp.GetMathUtility(); for (int i = 0; i < pois.Count; i++) { double[] vPnt = new double[3]; vPnt[0] = pois[i].x; vPnt[1] = pois[i].y; vPnt[2] = pois[i].z; MathPoint mp = (MathPoint)mathUtil.CreatePoint(vPnt); //double[] temPoi = mp.ArrayData; //MathTransform trans = sket.ModelToSketchTransform; MathTransform trans = sket.ModelToSketchTransform.Inverse(); mp = mp.MultiplyTransform(trans); double[] temPoi = mp.ArrayData; pois[i].setLocation(temPoi[0], temPoi[1], temPoi[2]); Debug.Print("Point " + i + ": " + pois[i].ox + ", " + pois[i].oy + ", " + pois[i].oz); } }
private static double LinePlaneIntersection(MathPoint origin, MathVector axis0, MathVector axis1, MathPoint lineOrigin, MathVector lineVector) { double x1, y1, z1; double x2, y2, z2; double x3, y3, z3; double x4, y4, z4; double x5, y5, z5; double t; var p0 = (MathPoint)origin.AddVector(axis0); var p1 = (MathPoint)origin.AddVector(axis1); Destructure(origin, out x1, out y1, out z1); Destructure(p0, out x2, out y2, out z2); Destructure(p1, out x3, out y3, out z3); var p2 = (MathPoint)origin.AddVector(lineVector); Destructure(lineOrigin, out x4, out y4, out z4); Destructure(p2, out x5, out y5, out z5); Matrix a = new DenseMatrix(4, 4, new double[] { 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 1, x4, y4, z4 }); Matrix b = new DenseMatrix(4, 4, new double[] { 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 0, x5 - x4, y5 - y4, z5 - z4 }); var da = a.Determinant(); var db = b.Determinant(); t = da / db; return(t); }
// Thickness is in mm public bool Thickness(double Thickness) { DisplayDimension swDisplayDimension = (DisplayDimension)swFeat.GetFirstDisplayDimension(); while (swDisplayDimension != null) { // the display dimension of the thickness is not radial or diametric if (swDisplayDimension.GetType() != (int)swDimensionType_e.swRadialDimension && swDisplayDimension.GetType() != (int)swDimensionType_e.swDiameterDimension) { Dimension swDimension = (Dimension)swDisplayDimension.GetDimension(); // thickness dimension has reference points and a direction if (swDimension.ReferencePoints != null) { object[] swMathPointsObj = (object[])swDimension.ReferencePoints; foreach (object swMathPointObj in swMathPointsObj) { MathPoint swMathPoint = (MathPoint)swMathPointObj; if (!IsPointZero(swMathPoint)) { int retval = swDimension.SetSystemValue2(Thickness / 1000.0, 0); if (retval == 0) return true; return false; } } } } // Get next dimension swDisplayDimension = (DisplayDimension)swFeat.GetNextDisplayDimension(swDisplayDimension); } return false; }
private static double LinePlaneIntersection(MathPoint origin, MathVector axis0, MathVector axis1, MathPoint lineOrigin, MathVector lineVector) { throw new NotImplementedException(); //double x1, y1, z1; //double x2, y2, z2; //double x3, y3, z3; //double x4, y4, z4; //double x5, y5, z5; //double t; //var p0 = (MathPoint)origin.AddVector(axis0); //var p1 = (MathPoint)origin.AddVector(axis1); //Destructure(origin, out x1, out y1, out z1); //Destructure(p0, out x2, out y2, out z2); //Destructure(p1, out x3, out y3, out z3); //var p2 = (MathPoint)origin.AddVector(lineVector); //Destructure(lineOrigin, out x4, out y4, out z4); //Destructure(p2, out x5, out y5, out z5); //Matrix a = new DenseMatrix(4, 4, new double[] //{ // 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 1, x4, y4, z4 //}); //Matrix b = new DenseMatrix(4, 4, new double[] //{ // 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 0, x5 - x4, y5 - y4, z5 - z4 //}); //var da = a.Determinant(); //var db = b.Determinant(); //t = da / db; //return t; }
/// <summary> /// Selects the axis and origin if one has already been selected /// </summary> public void SelectOrigin() { modelDoc.ClearSelection2(true); if (currentAttachment.OriginPoint != null) { originSelectionbox.SetSelectionFocus(); SelectData data = ((SelectionMgr)modelDoc.SelectionManager).CreateSelectData(); data.Mark = 2; ((IEntity)currentAttachment.OriginPoint).Select4(false, data); MathTransform originTransform = null; if (((IEntity)currentAttachment.OriginPoint).GetComponent() != null) { originTransform = ((IEntity)currentAttachment.OriginPoint).GetComponent().Transform2; } if (currentAttachment.OriginPoint is IVertex) { originPt = swApp.GetMathUtility().CreatePoint(((IVertex)currentAttachment.OriginPoint).GetPoint()).MultiplyTransform(originTransform); } else if (currentAttachment.OriginPoint is IFeature) { if (originTransform != null) { originPt = ((IFeature)currentAttachment.OriginPoint).GetSpecificFeature2().GetRefPoint().MultiplyTransform(originTransform); } else { originPt = ((IFeature)currentAttachment.OriginPoint).GetSpecificFeature2().GetRefPoint(); } } /*rotManipulator.Origin = ((IMathUtility)swApp.GetMathUtility()).CreatePoint(new double[]{currentAttachment.OriginX, currentAttachment.OriginY, currentAttachment.OriginZ}); //convert current rotations to transforms and apply them to the triad IMathUtility mathUtil = (IMathUtility)swApp.GetMathUtility(); MathTransform transR = mathUtil.CreateTransform(new double[] { 1, 0, 0, 0, Math.Cos(currentAttachment.RotR), Math.Sin(currentAttachment.RotR), 0, -Math.Sin(currentAttachment.RotR), Math.Cos(currentAttachment.RotR), 0, 0, 0, 1, 0, 0, 0 }); MathTransform transP = mathUtil.CreateTransform(new double[] { Math.Cos(currentAttachment.RotP), 0, -Math.Sin(currentAttachment.RotP), 0, 1, 0, Math.Sin(currentAttachment.RotP), 0, Math.Cos(currentAttachment.RotP), 0, 0, 0, 1, 0, 0, 0 }); MathTransform transY = mathUtil.CreateTransform(new double[] { Math.Cos(currentAttachment.RotY),Math.Sin(currentAttachment.RotY),0, -Math.Sin(currentAttachment.RotY),Math.Cos(currentAttachment.RotY),0, 0,0,1, 0,0,0,1,0,0,0 }); MathTransform rotMatrix = transR.Multiply(transP).Multiply(transY); MathVector xAxis = mathUtil.CreateVector(new double[] { 1, 0, 0 }); xAxis = xAxis.MultiplyTransform(rotMatrix); MathVector yAxis = mathUtil.CreateVector(new double[] { 0, 1, 0 }); yAxis = yAxis.MultiplyTransform(rotMatrix); MathVector zAxis = mathUtil.CreateVector(new double[] { 0, 0, 1 }); zAxis = zAxis.MultiplyTransform(rotMatrix); rotManipulator.XAxis = xAxis; rotManipulator.YAxis = yAxis; rotManipulator.ZAxis = zAxis; rotManipulator.UpdatePosition(); swManip.Show(modelDoc);*/ } if (currentAttachment.DirectionAxis!=null) { //modelDoc.ClearSelection2(false); axisSelectionbox.SetSelectionFocus(); SelectData data = ((SelectionMgr)modelDoc.SelectionManager).CreateSelectData(); data.Mark = 4; ((IEntity)currentAttachment.DirectionAxis).Select4(true, data); originSelectionbox.SetSelectionFocus(); } }
/// <summary> /// saves all the attachment data /// </summary> public void SaveAttachment() { object originObj =((SelectionMgr)modelDoc.SelectionManager).GetSelectedObject6(1, 2); currentAttachment.OriginPoint = originObj; if (originObj is IVertex) { MathTransform vertTransform = ((IEntity)originObj).GetComponent().Transform2; double[] tempPoint = ((IVertex)originObj).GetPoint(); double[] originPt = swApp.GetMathUtility().CreatePoint(tempPoint).MultiplyTransform(vertTransform).ArrayData; currentAttachment.OriginX = originPt[0]; currentAttachment.OriginY = originPt[1]; currentAttachment.OriginZ = originPt[2]; } else if (originObj is IFeature) { MathPoint tempPoint = ((IFeature)originObj).GetSpecificFeature2().GetRefPoint(); double[] originPt; if(((IEntity)originObj).GetComponent() != null) { MathTransform vertTransform = ((IEntity)originObj).GetComponent().Transform2; originPt = swApp.GetMathUtility().CreatePoint(tempPoint).MultiplyTransform(vertTransform).ArrayData; } else { originPt = tempPoint.ArrayData; } currentAttachment.OriginX = originPt[0]; currentAttachment.OriginY = originPt[1]; currentAttachment.OriginZ = originPt[2]; } currentAttachment.DirectionAxis = ((SelectionMgr)modelDoc.SelectionManager).GetSelectedObject6(1, 4); double num; if (Double.TryParse(rollTextbox.Text, out num)) { currentAttachment.RotRoll = num * Math.PI / 180; } if (Double.TryParse(pitchTextbox.Text, out num)) { currentAttachment.RotPitch = num * Math.PI / 180; } if (Double.TryParse(yawTextbox.Text, out num)) { currentAttachment.RotYaw = num * Math.PI / 180; } }
/// <summary> /// Called to verify whether to submit a newly selected item into a selection box on attachment property manager page /// </summary> /// <param name="Id">Id of selection box in focus</param> /// <param name="Selection">Item selected</param> /// <param name="SelType">Type of item selected</param> /// <param name="ItemText">Text to enter into selectionbox for this item</param> /// <returns>true if valid selection</returns> public bool OnSubmitSelection(int Id, object Selection, int SelType, ref string ItemText) { MathTransform componentTransform = null; if ((Component2)((IEntity)Selection).GetComponent() != null)//gets the component transform if one exists. this allows for conversion between the components local space and the global space { componentTransform = ((Component2)((IEntity)Selection).GetComponent()).Transform2; } MathUtility matUtil = swApp.GetMathUtility(); switch (Id) { case originSelectionboxID: MathTransform originTransform = null; if (((IEntity)Selection).GetComponent() != null) { originTransform = ((IEntity)Selection).GetComponent().Transform2; } if (Selection is IVertex) { originPt = matUtil.CreatePoint(((IVertex)Selection).GetPoint()).MultiplyTransform(originTransform); } else if (Selection is IFeature) { if (originTransform != null) { originPt = ((IFeature)Selection).GetSpecificFeature2().GetRefPoint().MultiplyTransform(originTransform); } else { originPt = ((IFeature)Selection).GetSpecificFeature2().GetRefPoint(); } } break; case axisSelectionboxID: if (SelType == (int)swSelectType_e.swSelDATUMAXES) { IRefAxis tempAxis = ((IFeature)Selection).GetSpecificFeature2(); double[] refPoints = tempAxis.GetRefAxisParams(); double[] axis; if (currentAttachment.FlipAxis) { axis = new double[] { refPoints[0] - refPoints[3], refPoints[1] - refPoints[4], refPoints[2] - refPoints[5] }; } else { axis = new double[] { refPoints[3] - refPoints[0], refPoints[4] - refPoints[1], refPoints[5] - refPoints[2] }; } if (componentTransform != null) { MathVector transformedAxis = matUtil.CreateVector(axis).MultiplyTransform(componentTransform); this.axis = transformedAxis.Normalise().ArrayData; featureAxis = this.axis; } else { this.axis=matUtil.CreateVector(axis).Normalise().ArrayData; featureAxis = this.axis; } } else if (SelType == (int)swSelectType_e.swSelEDGES) { if (((IEdge)Selection).GetCurve().LineParams is DBNull) { return false; } double[] tempArr = ((IEdge)Selection).GetCurve().LineParams; double[] axis; if (currentAttachment.FlipAxis) { axis = new double[] { -tempArr[3], -tempArr[4], -tempArr[5] }; } else { axis = new double[] { tempArr[3], tempArr[4], tempArr[5] }; } MathVector transformedAxis = matUtil.CreateVector(axis).MultiplyTransform(componentTransform); this.axis=transformedAxis.ArrayData; featureAxis = this.axis; } break; } CalcRotations(); DrawViewPreview(); return true; }
public static MathPoint Origin(this IMathUtility m) => _Origin ??(_Origin = m.Point(_OriginArray));
public void OnEndDrag(object pManipulator, int handleIndex) { startOrigin = ((TriadManipulator)pManipulator).Origin; double[] originPt = ((TriadManipulator)pManipulator).Origin.ArrayData; ComXTextbox.Text = originPt[0].ToString(); ComYTextbox.Text = originPt[1].ToString(); ComZTextbox.Text = originPt[2].ToString(); currentLink.ComX = originPt[0]; currentLink.ComY = originPt[1]; currentLink.ComZ = originPt[2]; updateStartOrigin = true; }
/// <summary> /// Updates the center of mass (z) value when it changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ComZTextbox_TextChanged(object sender, EventArgs e) { double num; if (Double.TryParse(ComZTextbox.Text, out num)) { currentLink.ComZ = num; if (triadManip != null) { double[] newPoint = triadManip.Origin.ArrayData; newPoint[2] = num; triadManip.Origin = currentLink.swApp.GetMathUtility().CreatePoint(newPoint); if(updateStartOrigin) startOrigin = triadManip.Origin; triadManip.UpdatePosition(); } } }
/// <summary> /// Gets the nonnormalised vector between the 2 points /// </summary> /// <param name="p1">Thefirst point</param> /// <param name="p2">The second point</param> /// <returns>returns the vector from point 1 to point 2</returns> public static MathVector GetVectorBetweenPoints(MathPoint p1, MathPoint p2) { double[] point1 = p1.ArrayData; double[] point2 = p2.ArrayData; double[] pointDisp = { point2[0] - point1[0], point2[1] - point1[1], point2[2] - point1[2] }; return RobotInfo.mathUtil.CreateVector(pointDisp); }
public static ICurve CreateTrimmedLine(this IModeler modeler, MathPoint p0, MathPoint p1) { return CreateTrimmedLine( modeler, p0.ArrayData.CastArray<double>().ToVector3(), p1.ArrayData.CastArray<double>().ToVector3()); }
private static void AddTextBlock(ModelDoc2 swModel, DrawingDoc swDraw, string txt, double tX, double tY, double tZ, double tHeight, double tAngle,MathPoint mp,bool needToExplode) { swModel.SetAddToDB(true); swDraw.ICreateText2(txt, tX, tY, tZ, tHeight, tAngle); swModel.Extension.SelectByID2("", "NOTE", tX, tY, tZ, true, 0, null, 0); //if (!needToExplode) swModel.SketchManager.MakeSketchBlockFromSelected(mp); swModel.SetAddToDB(false); swModel.ClearUndoList(); }
public static MathPoint Origin(this IMathUtility m) => _Origin ?? (_Origin = m.Point(_OriginArray));
/// <summary> /// Finds if the given point lies on the given line /// </summary> /// <param name="dir">The direction of the line</param> /// <param name="pointOnLine">A point somewhere on the line</param> /// <param name="otherPoint">The point that is being checked</param> /// <returns>Returns true if the point is is on the line</returns> public static bool IsPointOnLine(MathVector dir, MathPoint pointOnLine, MathPoint otherPoint) { MathVector PointVector = GetVectorBetweenPoints(pointOnLine, otherPoint).Normalise(); return (IsParallel(dir, PointVector)); }
public static bool rayHitsComponent(Component2 component, MathPoint rayOrigin, MathVector rayDirection) { return(whereRayHitsComponent(component, rayOrigin, rayDirection) != null); }
public void Main() { //ADD THESE LINES OF CODE double holeRadius; double holeDepth; //Create an instance of the user form frmCutExtrude myForm = new frmCutExtrude(); //Set the title for the form myForm.Text = "Size of Cut-Extrude in Millimeters"; //Display the user form and retrieve radius and //depth values typed by the user; divide those values //by 1000 to change millimeters to meters myForm.ShowDialog(); holeRadius = myForm.radius / 1000; holeDepth = myForm.depth / 1000; //Dispose of the user form and remove it from //memory because it's no longer needed myForm.Dispose(); ModelDoc2 swDoc = null; //bool boolstatus = false; //var COSMOSWORKSObj = null; swDoc = ((ModelDoc2)(swApp.ActiveDoc)); //COSMOSWORKSObj COSMOSWORKSObj = null; //CWAddinCallBackObj CWAddinCallBackObj = null; //CWAddinCallBackObj = swApp.GetAddInObject("CosmosWorks.CosmosWorks"); //COSMOSWORKSObj = CWAddinCallBackObj.COSMOSWORKS; ModelView myModelView = null; myModelView = ((ModelView)(swDoc.ActiveView)); myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized)); //boolstatus = swDoc.Extension.SelectByRay(0.00053592862681739462, 0.2199999999999136, -0.0045118054006820785, -0.18724816575405859, -0.66456615869841951, -0.723387824845406, 0.0010862903128070283, 2, false, 0, 0); //ADD THESE LINES OF CODE //Get coordinates of selection point SelectionMgr swSelectionMgr = null; swSelectionMgr = (SelectionMgr)swDoc.SelectionManager; double[] SelectCoordinates; SelectCoordinates = (double[])swSelectionMgr.GetSelectionPoint2(1, -1); //If face is selected, then open a sketch; //otherwise, stop execution object SelectedObject = null; SelectedObject = (object)swSelectionMgr.GetSelectedObject6(1, 0); int objtype; objtype = (int)swSelectionMgr.GetSelectedObjectType3(1, -1); if (objtype == (int)swSelectType_e.swSelFACES) { swDoc.SketchManager.InsertSketch(true); } //swDoc.ClearSelection2(true); SketchSegment skSegment = null; skSegment = ((SketchSegment)(swDoc.SketchManager.CreateCircle(0, 0, 0, 0.010505, -0.007509, 0))); Feature myFeature = null; myFeature = ((Feature)(swDoc.FeatureManager.FeatureCut4(true, false, false, 0, 0, 0.02, 0.01, true, false, false, false, 0.26179938779914946, 0.017453292519943334, false, false, false, false, false, true, true, true, true, false, 0, 0, false, false))); swDoc.ISelectionManager.EnableContourSelection = false; //StudyManagerObj = null; //ActiveDocObj = null; //CWAddinCallBackObj = null; //COSMOSWORKSObj = null; //ADD THESE LINES OF CODE //Get IMathPoint to use when transforming //from model space to sketch space MathUtility swMathUtility = null; MathPoint swMathPoint = null; Sketch swSketch = null; double dx; double dy; double dz; swMathUtility = (MathUtility)swApp.GetMathUtility(); swMathPoint = (MathPoint)swMathUtility.CreatePoint(SelectCoordinates); //Get reference to sketch swSketch = (Sketch)swDoc.SketchManager.ActiveSketch; //Translate sketch point into sketch space MathTransform swMathTransform = null; swMathTransform = (MathTransform)swSketch.ModelToSketchTransform; swMathPoint = (MathPoint)swMathPoint.MultiplyTransform(swMathTransform); //Retrieve coordinates of the sketch point double[] darray; darray = (double[])swMathPoint.ArrayData; dx = darray[0]; dy = darray[1]; dz = darray[2]; //Use swDoc.SketchManager.CreateCircleByRadius instead of //swDoc.SketchManager.CreateCircle because //swDoc.SketchManager.CreateCircleByRadius sketches a //circle centered on a sketch point and lets you //specify a radius double radius = 0.015; SketchSegment swSketchSegment = null; swSketchSegment = (SketchSegment)swDoc.SketchManager.CreateCircleByRadius(dx, dy, dz, radius); //Create the cut extrude feature Feature swFeature = null; swFeature = (Feature)swDoc.FeatureManager.FeatureCut3(true, false, false, 0, 0, 0.025, 0.01, true, false, false, false, 0, 0, false, false, false, false, false, true, true, false, false, false, (int)swStartConditions_e.swStartSketchPlane, 0, false); }
public string CreateBlock(ISldWorks swApp, int type, out MathPoint instancePosition, double x = 0, double y = 0 ) { var objPoint1 = new double[3]; objPoint1[0] = 0; objPoint1[1] = 0; objPoint1[2] = 0; var swMathUtil1 = swApp.IGetMathUtility(); instancePosition = (MathPoint)swMathUtil1.CreatePoint(objPoint1); int i = 0; switch (type) { case 0: i = 4; break; case 1: i = 6; break; case 2: i = 2; break; case 3: i = 3; break; case 4: i = 6; break; } double blScale = 0.05; var swModel = (ModelDoc2)swApp.ActiveDoc; var swSkSeg = new ISketchSegment[i]; swModel.SetAddToDB(true); switch (type) { case 0: // 5 through swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, 0.0, 0.0, 0.0, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(0.0, 0.04, 0.0, 0.04, 0.0, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, 0.0, 0.0, 0.0, -0.04, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateLine2(0.0, -0.04, 0.0, -0.04, 0.0, 0.0); break; case 1: // 5 H 12 swSkSeg[0] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.003, 0.0, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.0045, 0.0, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.006, 0.0, 0.0); swSkSeg[4] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.0075, 0.0, 0.0); swSkSeg[5] = (SketchSegment)swModel.CreateCircle2(0.0, 0.0, 0.0, 0.009, 0.0, 0.0); blScale = 0.075; break; case 2: // 8 swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, -0.04, 0.0); blScale = 0.06; break; case 3: //8 through swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.0293, 0.0, 0.0, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(0.0, 0.04, 0.0, 0.04, -0.0293, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, -0.0293, 0.0, -0.04, -0.0293, 0.0); break; case 4: //811 swSkSeg[0] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, -0.04, 0.04, 0.0); swSkSeg[1] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[2] = (SketchSegment)swModel.CreateLine2(0.04, 0.04, 0.0, 0.04, -0.04, 0.0); swSkSeg[3] = (SketchSegment)swModel.CreateLine2(0.04, -0.04, 0.0, -0.04, -0.04, 0.0); swSkSeg[4] = (SketchSegment)swModel.CreateLine2(-0.04, -0.04, 0.0, 0.04, 0.04, 0.0); swSkSeg[5] = (SketchSegment)swModel.CreateLine2(-0.04, 0.04, 0.0, 0.04, -0.04, 0.0); blScale = 0.03; break; } object vSkSeg = swSkSeg; swModel.Extension.MultiSelect(vSkSeg, true, null); SketchBlockDefinition swSketchBlockDef = swModel.SketchManager.MakeSketchBlockFromSelected(null); var swInst = swSketchBlockDef.IGetInstances(1); swInst.Scale = blScale; if (x != 0 && y != 0) { var objPoint = new double[3]; objPoint[0] = x+0.01; objPoint[1] = y; objPoint[2] = 0; var swMathUtil = swApp.IGetMathUtility(); var swMathPoint = (MathPoint)swMathUtil.CreatePoint(objPoint); swInst.InstancePosition = swMathPoint; instancePosition = swMathPoint; } swModel.SetAddToDB(false); swModel.GraphicsRedraw2(); swModel.ClearSelection(); return swInst.Name; }
private static double LinePlaneIntersection(MathPoint origin, MathVector axis0, MathVector axis1, MathPoint lineOrigin, MathVector lineVector) { double x1, y1, z1; double x2, y2, z2; double x3, y3, z3; double x4, y4, z4; double x5, y5, z5; double t; var p0 = (MathPoint) origin.AddVector(axis0); var p1 = (MathPoint) origin.AddVector(axis1); Destructure(origin, out x1, out y1, out z1); Destructure(p0, out x2, out y2, out z2); Destructure(p1, out x3, out y3, out z3); var p2 = (MathPoint) origin.AddVector(lineVector); Destructure(lineOrigin, out x4, out y4, out z4); Destructure(p2, out x5, out y5, out z5); Matrix a = new DenseMatrix(4, 4, new double[] { 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 1, x4, y4, z4 }); Matrix b = new DenseMatrix(4, 4, new double[] { 1, x1, y1, z1, 1, x2, y2, z2, 1, x3, y3, z3, 0, x5 - x4, y5 - y4, z5 - z4 }); var da = a.Determinant(); var db = b.Determinant(); t = da/db; return t; }
/// <summary> /// 创建直线 /// </summary> /// <param name="modeler">造型接口</param> /// <param name="p0">起点</param> /// <param name="p1">终点</param> /// <returns></returns> public static ICurve CreateTrimmedLine(this IModeler modeler, MathPoint p0, MathPoint p1) { return(CreateTrimmedLine(modeler, new Edge3(((double[])p0.ArrayData).ToVector3(), ((double[])p1.ArrayData).ToVector3()))); }
private static void Destructure(MathPoint p, out double x, out double y, out double z) { var arrayData = (double[]) p.ArrayData; x = arrayData[0]; y = arrayData[1]; z = arrayData[2]; }
/// <summary> /// Gets the axis vector for a line or edge. Assumes the edge is linear /// </summary> /// <param name="axisVector">The calculated axis vector</param> /// <param name="axisPoint">The calculated point on the line</param> /// <param name="obj">The axis object</param> /// <param name="objType">The typeof the object</param> protected void GetAxisFromObject(out MathVector axisVector, out MathPoint axisPoint, object obj, int objType) { MathTransform componentTransform = null; if ((Component2)((IEntity)obj).GetComponent() != null)//gets the component transform if one exists. this allows for conversion between the components local space and the global space { componentTransform = ((Component2)((IEntity)obj).GetComponent()).Transform2; } double[] tempArray; if (objType == (int)swSelectType_e.swSelEDGES) { double[] edgeCurveParams = ((IEdge)obj).GetCurve().LineParams; tempArray = new double[] { edgeCurveParams[3], edgeCurveParams[4], edgeCurveParams[5] }; axisVector = VectorCalcs.CreateVector(componentTransform, tempArray);//creates a vector representing the linear edge tempArray = new double[] { edgeCurveParams[0], edgeCurveParams[1], edgeCurveParams[2] };//point on line axisPoint = VectorCalcs.CreatePoint(componentTransform, tempArray); // point transformed to global space } else if (objType == (int)swSelectType_e.swSelFACES) { axisVector = VectorCalcs.CreateVector(componentTransform,((IFace)obj).Normal); axisPoint = VectorCalcs.CreatePoint(componentTransform, ((IFace)obj).GetClosestPointOn(0, 0, 0)); } else if (objType == (int)swSelectType_e.swSelDATUMAXES) { double[] points = ((IRefAxis)((IFeature)obj).GetSpecificFeature2()).GetRefAxisParams(); tempArray = new double[] { points[3] - points[0], points[4] - points[1], points[5] - points[2] }; axisVector = VectorCalcs.CreateVector(componentTransform, tempArray);//creates a vector between the 2 points on the reference axis and transforms to global space if nessacary tempArray = new double[] { points[0], points[1], points[2] };//point on line axisPoint = VectorCalcs.CreatePoint(componentTransform, tempArray); // point transformed to global space } else if (objType == (int)swSelectType_e.swSelDATUMPLANES) { MathVector tempVector = RobotInfo.mathUtil.CreateVector(new double[] { 0, 0, 1 }); MathPoint tempPoint = RobotInfo.mathUtil.CreatePoint(new double[] { 0, 0, 0 }); MathTransform tempTransform = ((IRefPlane)((IFeature)obj).GetSpecificFeature2()).Transform; axisVector = tempVector.MultiplyTransform(tempTransform).MultiplyTransform(componentTransform); axisPoint = tempPoint.MultiplyTransform(tempTransform).MultiplyTransform(componentTransform); } else { axisPoint = null; axisVector = null; } }
private Feature EsquisseRepere(ModelDoc2 mdl, Boolean creer = true) { // On recherche l'esquisse contenant les parametres Feature Esquisse = mdl.eChercherFonction(fc => { return(fc.Name == CONSTANTES.NOM_ESQUISSE_NUMEROTER); }); if (Esquisse.IsNull() && creer) { var SM = mdl.SketchManager; // On recherche le chemin du bloc String cheminbloc = CheminBlocEsquisseNumeroter(); if (String.IsNullOrWhiteSpace(cheminbloc)) { return(null); } // On supprime la definition du bloc SupprimerDefBloc(mdl, cheminbloc); // On recherche le plan de dessus, le deuxième dans la liste des plans de référence Feature Plan = mdl.eListeFonctions(fc => { return(fc.GetTypeName2() == FeatureType.swTnRefPlane); })[1]; // Selection du plan et création de l'esquisse Plan.eSelect(); SM.InsertSketch(true); SM.AddToDB = false; SM.DisplayWhenAdded = true; mdl.eEffacerSelection(); // On récupère la fonction de l'esquisse Esquisse = mdl.Extension.GetLastFeatureAdded(); // On insère le bloc MathUtility Mu = App.Sw.GetMathUtility(); MathPoint Origine = Mu.CreatePoint(new double[] { 0, 0, 0 }); var def = SM.MakeSketchBlockFromFile(Origine, cheminbloc, false, 1, 0); // On récupère la première instance // et on l'explose var Tab = (Object[])def.GetInstances(); var ins = (SketchBlockInstance)Tab[0]; SM.ExplodeSketchBlockInstance(ins); // Fermeture de l'esquisse SM.AddToDB = false; SM.DisplayWhenAdded = true; SM.InsertSketch(true); //// On supprime la definition du bloc //SupprimerDefBloc(mdl, cheminbloc); // On renomme l'esquisse Esquisse.Name = CONSTANTES.NOM_ESQUISSE_NUMEROTER; mdl.eEffacerSelection(); // On l'active dans toutes les configurations Esquisse.SetSuppression2((int)swFeatureSuppressionAction_e.swUnSuppressFeature, (int)swInConfigurationOpts_e.swAllConfiguration, null); } if (Esquisse.IsRef()) { // On selectionne l'esquisse, on la cache // et on la masque dans le FeatureMgr // elle ne sera pas du tout acessible par l'utilisateur Esquisse.eSelect(); mdl.BlankSketch(); Esquisse.SetUIState((int)swUIStates_e.swIsHiddenInFeatureMgr, true); mdl.eEffacerSelection(); mdl.EditRebuild3(); } return(Esquisse); }
/// <summary> /// 转换到Vector3 /// </summary> /// <param name="mathPoint"></param> /// <returns></returns> public static Vector3 ToVector3(this MathPoint mathPoint) { return(new Vector3((double[])mathPoint.ArrayData)); }
public static ICurve CreateTrimmedLine(this IModeler modeler, MathPoint p0, MathPoint p1) { return(CreateTrimmedLine(modeler, p0.ArrayData.CastArray <double>().ToVector3(), p1.ArrayData.CastArray <double>().ToVector3())); }
/// <summary> /// Toggles custom value textboxes when checkbox changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CustomMassValCheckbox_CheckedChanged(object sender, EventArgs e) { currentLink.UseCustomInertial = CustomMassValCheckbox.Checked; PhysicalButton.Enabled = !CustomMassValCheckbox.Checked; toggleCOMTextboxes(); if (CustomMassValCheckbox.Checked) { swManip = currentLink.modelDoc.ModelViewManager.CreateManipulator((int)swManipulatorType_e.swTriadManipulator, this); triadManip = swManip.GetSpecificManipulator(); triadManip.DoNotShow = (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXRING | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowXYPlane | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowYZPlane | (int)swTriadManipulatorDoNotShow_e.swTriadManipulatorDoNotShowZXPlane; triadManip.Origin = currentLink.swApp.GetMathUtility().CreatePoint(new double[] { currentLink.ComX, currentLink.ComY, currentLink.ComZ }); startOrigin = triadManip.Origin; triadManip.UpdatePosition(); swManip.Show(currentLink.modelDoc); } else { InertiaButton_Click(null, null); HideProperty(); } }
public void OnSelectionboxListChanged(int Id, int Count) { if(Count == 0) switch (Id) { case originSelectionboxID: currentAttachment.OriginPoint = null; originPt = null; DrawViewPreview(); break; case axisSelectionboxID: currentAttachment.DirectionAxis = null; axis = new double[] { 1, 0, 0 }; CalcRotations(); DrawViewPreview(); break; } }
internal static bool processModel(SldWorks swApp, string file, string targetFile, string calcFile, CancellationToken cancellationToken) { // Initiate variables Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); StreamWriter toFile = new StreamWriter(targetFile); toFile.AutoFlush = true; StreamWriter toCalc = new StreamWriter(calcFile); toCalc.AutoFlush = true; MathUtility swMathUtil = default(MathUtility); ModelDoc2 swModel = default(ModelDoc2); Feature swFeat = default(Feature); Feature swMateFeat = null; Feature swSubFeat = default(Feature); Mate2 swMate = default(Mate2); Component2 swComp = default(Component2); MateEntity2[] swMateEnt = new MateEntity2[3]; MathTransform swTrans = default(MathTransform); MathPoint swOrig = default(MathPoint); AssemblyDoc swAssembly = default(AssemblyDoc); double[] corners = new double[6]; int[] swAssyDir = new int[6]; double[] nPt = new double[3]; object vPt = null; double height = 0; double width = 0; double depth = 0; int Warning = 0; int Error = 0; int i = 0; double[] entityParameters = new double[8]; // Start function try { if (cancellationToken.IsCancellationRequested) { return(false); } string extention = Path.GetExtension(file); int type = 0; if (extention.ToLower().Contains("sldprt")) { type = (int)swDocumentTypes_e.swDocPART; } else { type = (int)swDocumentTypes_e.swDocASSEMBLY; } // Get assembly model swModel = swApp.OpenDoc6(file, type, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref Error, ref Warning) as ModelDoc2; if (Error != 0) { return(false); } if (swModel == null) { return(false); } swModel.Visible = true; // Get first assembly feature swFeat = (Feature)swModel.FirstFeature(); // Iterate over features in FeatureManager design tree while ((swFeat != null)) { if ("MateGroup" == swFeat.GetTypeName()) { swMateFeat = swFeat; break; } swFeat = swFeat = swFeat.GetNextFeature(); } toFile.WriteLine(" " + swMateFeat.Name); toFile.WriteLine(""); // Get first mate, which is a subfeature swSubFeat = (Feature)swMateFeat.GetFirstSubFeature(); while ((swSubFeat != null)) { swMate = (Mate2)swSubFeat.GetSpecificFeature2(); if ((swMate != null)) { for (i = 0; i <= 1; i++) { swMateEnt[i] = swMate.MateEntity(i); swComp = swMateEnt[i].ReferenceComponent; // Initate point nPt[0] = 0.0; nPt[1] = 0.0; nPt[2] = 0.0; vPt = nPt; // Get component origin point swTrans = swComp.Transform2; swMathUtil = (MathUtility)swApp.GetMathUtility(); swOrig = (MathPoint)swMathUtil.CreatePoint(vPt); swOrig = (MathPoint)swOrig.MultiplyTransform(swTrans); // Write parameters to readable ASCII file toFile.WriteLine(" " + swSubFeat.Name); toFile.WriteLine(" Type = " + swMate.Type); toFile.WriteLine(" Alignment = " + swMate.Alignment); toFile.WriteLine(" Can be flipped = " + swMate.CanBeFlipped); toFile.WriteLine(""); toFile.WriteLine(" Component = " + swComp.Name2); toFile.WriteLine(" Origin = (" + ((double[])swOrig.ArrayData)[0] * 1000.0 + ", " + ((double[])swOrig.ArrayData)[1] * 1000.0 + ", " + ((double[])swOrig.ArrayData)[2] * 1000.0 + ")"); toFile.WriteLine(" Mate enity type = " + swMateEnt[i].ReferenceType); entityParameters = (double[])swMateEnt[i].EntityParams; toFile.WriteLine(" (x,y,z) = (" + entityParameters[0] * 1000 + ", " + entityParameters[1] * 1000 + ", " + entityParameters[2] * 1000 + ")"); toFile.WriteLine(" (i,j,k) = (" + entityParameters[3] + ", " + entityParameters[4] + ", " + entityParameters[5] + ")"); toFile.WriteLine(" Radius 1 = " + entityParameters[6] * 1000); toFile.WriteLine(" Radius 2 = " + entityParameters[7] * 1000); toFile.WriteLine(""); // Write parameters to a simplified ASCII file for computation toCalc.Write(swSubFeat.Name); toCalc.Write(" " + swMate.Type); toCalc.Write(" " + swMate.Alignment); toCalc.Write(" " + swMate.CanBeFlipped); toCalc.Write(" " + swComp.Name2); toCalc.Write(" " + ((double[])swOrig.ArrayData)[0] * 1000.0 + "," + ((double[])swOrig.ArrayData)[1] * 1000.0 + "," + ((double[])swOrig.ArrayData)[2] * 1000.0); toCalc.Write(" " + swMateEnt[i].ReferenceType); toCalc.Write(" " + entityParameters[0] * 1000.0 + "," + entityParameters[1] * 1000.0 + "," + entityParameters[2] * 1000.0); toCalc.Write(" " + entityParameters[3] + "," + entityParameters[4] + "," + entityParameters[5]); toCalc.Write(" " + entityParameters[6] * 1000.0); toCalc.WriteLine(" " + entityParameters[7] * 1000.0); } toFile.WriteLine(" "); } // Get the next mate in MateGroup swSubFeat = (Feature)swSubFeat.GetNextSubFeature(); } // Get bounding box around assembly swAssembly = (AssemblyDoc)swModel; corners = swAssembly.GetBox(1); height = (corners[4] - corners[1]) * 1000.0; width = (corners[3] - corners[0]) * 1000.0; depth = (corners[5] - corners[2]) * 1000.0; // Write to file toFile.WriteLine("Aprx. assembly dimensions"); toFile.WriteLine("(Height, Width, Depth) = (" + height + ", " + width + ", " + depth + ")"); toFile.WriteLine(" "); toCalc.WriteLine("dims(hwd) " + height + " " + width + " " + depth); // Get Possible Assembly Directions with interferenceDir function interference inter = new interference(); swAssyDir = inter.interferenceDir(swApp, swModel, swMateFeat, swMateEnt); // Write swAssyDir to file toFile.WriteLine("(x+, x-, y+, y-, z+, z-) = (" + swAssyDir[0] + ", " + swAssyDir[1] + ", " + swAssyDir[2] + ", " + swAssyDir[3] + ", " + swAssyDir[4] + ", " + swAssyDir[5] + ") "); toFile.WriteLine("1 is possible, 0 is not possible"); toFile.WriteLine(""); toFile.WriteLine("All dimensions are in mm"); toCalc.Write("dir " + swAssyDir[0] + " " + swAssyDir[1] + " " + swAssyDir[2] + " " + swAssyDir[3] + " " + swAssyDir[4] + " " + swAssyDir[5]); return(true); } catch (Exception) { return(false); } }
/// <summary> /// Sets an arrow to the give locations /// </summary> /// <param name="point">Origin point of the arrow</param> /// <param name="vector">Direction Vector of the arrow</param> /// <param name="length">length of the arrow</param> /// <param name="arrow">The arrow to be edited</param> protected void SetArrowAtLoc(MathPoint point, MathVector vector, double length, DragArrowManipulator arrow) { arrow.ShowRuler = false; arrow.FixedLength = true; arrow.ShowOppositeDirection = false; arrow.AllowFlip = false; arrow.Length = length; arrow.Direction = vector; arrow.Origin = point; }