public List <Vector3D> CreateSteppedCylinder(Vector3D center, double radius1, double radius2, double height, double anglet, double xAngle, double yAngle, double zAngle) { List <Vector3D> pointsTop = new List <Vector3D>(); List <Vector3D> rotPoints = new List <Vector3D>(); List <Vector3D> transPoints = new List <Vector3D>(); List <Vector3D> pointsBottom = new List <Vector3D>(); RefPlane refPlane = RefPlane.XY_PLANE; pointsTop = CreateEllipse(height / 2.0, radius1, radius1, anglet); pointsBottom = CreateEllipse(-height / 2.0, radius2, radius2, anglet); pointsBottom = pointsBottom.Union(pointsTop).ToList(); rotPoints = RotatePoints(xAngle, yAngle, zAngle, pointsBottom); transPoints = TranslatePoints(center.X, center.Y, center.Z, rotPoints); SetNormal(0.0, 0.0, 1.0); _normal = RotateVector(xAngle, yAngle, zAngle, _normal); GetRefPlane(ref refPlane); CalculateAngleAR(ref _AngleR, ref _AngleH, _normal, refPlane); _center = center; return(transPoints); }
public static Camera createCamera(Component2 fieldOfView, SldWorks swApp, ModelDoc2 swDoc, AssemblyDoc swAssembly, SelectionMgr swSelectionMgr, MathUtility mathUtils) { IMathPoint centreOfVision = getCentreOfVision(fieldOfView, swDoc, swSelectionMgr, mathUtils); if (centreOfVision == null) { swApp.SendMsgToUser2("you need to insert the camera first!", 1, 1); return(null); } RefPlane cameraNormalPlane = getCameraNormalPlane(fieldOfView, swDoc, swSelectionMgr); // note that we reverse this transform because our plane normal is pointing the wrong direction :( MathTransform cameraTransform = Camera.reverseTransform(cameraNormalPlane.Transform, mathUtils); MathVector cameraDirection = getCameraDirection(cameraTransform, mathUtils); drawRayForCamera(cameraDirection, centreOfVision, swDoc, swSelectionMgr); Camera camera = new Camera(fieldOfView, mathUtils.CreatePoint((double[])centreOfVision.ArrayData), cameraDirection); camera.swApp = swApp; camera.swDoc = swDoc; camera.swAssembly = swAssembly; camera.swSelectionMgr = swSelectionMgr; camera.mathUtils = mathUtils; return(camera); }
public List <Vector3D> CreatePlane(Vector3D center, double width, double height, double xAngle, double yAngle, double zAngle) { List <Vector3D> points = new List <Vector3D>(); List <Vector3D> rotPoints = new List <Vector3D>(); List <Vector3D> transPoints = new List <Vector3D>(); RefPlane refPlane = RefPlane.XY_PLANE; Vector3D point1 = new Vector3D(0.0 + width / 2.0, 0.0, 0.0); Vector3D point2 = new Vector3D(0.0 - width / 2.0, 0.0, 0.0); Vector3D point3 = new Vector3D(0.0, 0.0 + height / 2.0, 0.0); Vector3D point4 = new Vector3D(0.0, 0.0 - height / 2.0, 0.0); points.Add(point1); points.Add(point2); points.Add(point3); points.Add(point4); rotPoints = RotatePoints(xAngle, yAngle, zAngle, points); transPoints = TranslatePoints(center.X, center.Y, center.Z, rotPoints); SetNormal(0.0, 0.0, 1.0); _normal = RotateVector(xAngle, yAngle, zAngle, _normal); GetRefPlane(ref refPlane); CalculateAngleAR(ref _AngleR, ref _AngleH, _normal, refPlane); _center = center; return(transPoints); }
//creates a cutout private void Create_Cutout(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face, int[] face_norm, string selected_face_normal) { PartDocument _doc = _application.ActiveDocument as PartDocument; RefPlanes refPlanes = null; RefPlane refPlane = null; refPlanes = _doc.RefPlanes; //Adding parallel refplane to the selected face refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false); Relations2d relations2D = null; ProfileSets profileSets = null; ProfileSet profileSet = null; Profiles profiles = null; Profile profile = null; Lines2d lines2D = null; Models models = null; Model model = null; Sketchs sketchs = null; Sketch sketch = null; ExtrudedCutouts extrudedCutouts = null; sketchs = _doc.Sketches; sketch = sketchs.Add(); profileSets = _doc.ProfileSets; profileSet = profileSets.Add(); profiles = sketch.Profiles; profile = profiles.Add(refPlane); lines2D = profile.Lines2d; relations2D = (Relations2d)profile.Relations2d; //adding a 2D profile for the cutout lines2D.AddBy2Points(0.03, -0.055, 0.045, -0.055); lines2D.AddBy2Points(0.045, -0.055, 0.045, -0.04); lines2D.AddBy2Points(0.045, -0.04, 0.03, -0.04); lines2D.AddBy2Points(0.03, -0.04, 0.03, -0.055); profile.End(ProfileValidationType.igProfileClosed); models = _doc.Models; model = models.Item(1); extrudedCutouts = model.ExtrudedCutouts; //adding a new extruded cutout extrudedCutouts.AddThroughNext(Profile: profile, ProfileSide: FeaturePropertyConstants.igLeft, ProfilePlaneSide: FeaturePropertyConstants.igLeft ); }
public Vector3 GetIntersectionPoint(Ray ray) { float distance = 0; bool success = RefPlane.Raycast(ray, out distance); if (success == false) { Debug.LogError("Failed to compute intersection between camera ray and reference plane. Make sure the camera Axes are set up correctly."); } return(ray.origin + ray.direction * distance); }
private static RefPlane getCameraNormalPlane(Component2 fieldOfView, ModelDoc2 swDoc, SelectionMgr swSelectionMgr) { // now figure out the direction the camera points // this is translated from http://help.solidworks.com/2012/English/api/sldworksapi/get_the_normal_and_origin_of_a_reference_plane_using_its_transform_example_vb.htm swDoc.Extension.SelectByID2("Front Plane@" + fieldOfView.GetSelectByIDString(), "PLANE", 0, 0, 0, false, 0, null, 0); IFeature cameraNormalFeature = swSelectionMgr.GetSelectedObject6(1, -1); RefPlane cameraNormalPlane = cameraNormalFeature.GetSpecificFeature2(); return(cameraNormalPlane); }
public void SetRefPlane(Vector3D unit) { if ((unit.Z >= .9999) && (unit.Z <= 1.0001)) { _refPlane = RefPlane.XY_PLANE; } else if ((unit.Y >= .9999) && (unit.Y <= 1.0001)) { _refPlane = RefPlane.ZX_PLANE; } else if ((unit.X >= .9999) && (unit.Z <= 1.0001)) { _refPlane = RefPlane.YZ_PLANE; } }
// Recherche de l'arrete sur laquelle est contrainte la platine. private Edge ArretePlatine(List <Mate2> listeContraintes, Feature planContrainte, Face2 f_Dessus) { Mate2 Contrainte = null; foreach (Mate2 Ct in listeContraintes) { foreach (MateEntity2 Ent in Ct.eListeDesEntitesDeContrainte()) { // Si l'entite est un plan if (Ent.ReferenceType2 == (int)swSelectType_e.swSelDATUMPLANES) { RefPlane P = Ent.Reference; Feature F = (Feature)P; // On vérifie que le plan a le même nom que le plan contrainte if (planContrainte.Name == F.Name) { Contrainte = Ct; break; } } } if (Contrainte.IsRef()) { break; } } foreach (MateEntity2 Ent in Contrainte.eListeDesEntitesDeContrainte()) { // On récupère la face associée à la contrainte if (Ent.ReferenceType2 == (int)swSelectType_e.swSelFACES) { Face2 F = Ent.Reference; // Liste des arrêtes communes, normalement, il n'y en a qu'une List <Edge> L = F.eListeDesArretesCommunes(f_Dessus); // On renvoi la première if (L.Count > 0) { return(L[0]); } } } return(null); }
private void SelectionnerSupportEsquisse() { int TypeRef = 0; Object obj = Esquisse.GetReferenceEntity(ref TypeRef); if (TypeRef == (int)swSelectType_e.swSelFACES) { Entity ent = (Entity)obj; ent.eSelectEntite(); } else { RefPlane plan = (RefPlane)obj; Feature f = (Feature)obj; f.eSelect(); } }
public List <Vector3D> CreateLine(Vector3D center, List <Vector3D> points, double xAngle, double yAngle, double zAngle) { List <Vector3D> rotPoints = new List <Vector3D>(); List <Vector3D> transPoints = new List <Vector3D>(); RefPlane refPlane = RefPlane.XY_PLANE; rotPoints = RotatePoints(xAngle, yAngle, zAngle, points); transPoints = TranslatePoints(center.X, center.Y, center.Z, rotPoints); Vector3D Normal = points[1] - points[0]; Normal.Normalize(); SetNormal(Normal.X, Normal.Y, Normal.Z); _normal = RotateVector(xAngle, yAngle, zAngle, _normal); GetRefPlane(ref refPlane); CalculateAngleAR(ref _AngleR, ref _AngleH, _normal, refPlane); _center = center; return(transPoints); }
public List <Vector3D> CreateEllipse(Vector3D center, double aRadius, double bRadius, double anglet, double xAngle, double yAngle, double zAngle) { // x=a*cos(t) // y=b*sin(t) Vector3D point = new Vector3D(); List <Vector3D> points = new List <Vector3D>(); List <Vector3D> rotPoints = new List <Vector3D>(); List <Vector3D> transPoints = new List <Vector3D>(); RefPlane refPlane = RefPlane.XY_PLANE; double angleRad = 0.0; anglet = anglet * Math.PI / 180.0; for (angleRad = 0.0; angleRad < 2 * Math.PI; angleRad += anglet) { point.X = aRadius * Math.Cos(angleRad); point.Y = bRadius * Math.Sin(angleRad); point.Z = 0.0; points.Add(point); } rotPoints = RotatePoints(xAngle, yAngle, zAngle, points); transPoints = TranslatePoints(center.X, center.Y, center.Z, rotPoints); if (aRadius >= bRadius) { SetMajorAxis(-1.0, 0.0, 0.0); } else { SetMajorAxis(0.0, -1.0, 0.0); } SetNormal(0.0, 0.0, 1.0); _normal = RotateVector(xAngle, yAngle, zAngle, _normal); _majorAxis = RotateVector(xAngle, yAngle, zAngle, _majorAxis); GetRefPlane(ref refPlane); CalculateAngleAR(ref _AngleR, ref _AngleH, _majorAxis, refPlane); _center = center; return(transPoints); }
/// <summary> /// Constructor with a plane. /// </summary> /// <param name="plane">The reference plane that the sketch lies on.</param> public Sketch(RefPlane plane) : this() { Plane = plane; }
public void SetRefPlane(RefPlane refPlane) { _refPlane = refPlane; }
//creates a slot private void Create_Slot(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face, int[] face_norm, string selected_face_normal) { PartDocument _doc = _application.ActiveDocument as PartDocument; RefPlanes refPlanes = null; RefPlane refPlane = null; refPlanes = _doc.RefPlanes; //Adding a parallel refplane to the selected face refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false); ProfileSets profileSets = null; ProfileSet profileSet = null; Profiles profiles = null; Profile profile = null; Lines2d lines2D = null; Models models = null; Model model = null; Sketchs sketchs = null; Sketch sketch = null; Slots slots = null; Slot slot = null; sketchs = _doc.Sketches; sketch = sketchs.Add(); profileSets = _doc.ProfileSets; profileSet = profileSets.Add(); profiles = sketch.Profiles; //Adding the refplane to the profile profile = profiles.Add(refPlane); lines2D = profile.Lines2d; lines2D.AddBy2Points(0.02, 0, 0.02, 0.02); profile.End(ProfileValidationType.igProfileClosed); models = _doc.Models; model = models.Item(1); slots = model.Slots; //Adding a new slot slots.Add(Profile: profile, SlotType: FeaturePropertyConstants.igRegularSlot, SlotEndCondition: FeaturePropertyConstants.igFormedEnd, SlotWidth: 0.005, SlotOffsetWidth: 0, SlotOffsetDepth: 0, ExtentType: FeaturePropertyConstants.igThroughAll, ExtentSide: FeaturePropertyConstants.igLeft, FiniteDistance: 0, KeyPointFlags: KeyPointExtentConstants.igTangentNormal, KeyPointOrTangentFace: null, ExtentType2: FeaturePropertyConstants.igNone, ExtentSide2: FeaturePropertyConstants.igNone, FiniteDistance2: 0, KeyPointFlags2: KeyPointExtentConstants.igTangentNormal, KeyPointOrTangentFace2: null, FromFaceOrPlane: null, FromOffsetSide: OffsetSideConstants.seOffsetNone, FromOffsetDistance: 0, ToFaceOrPlane: null, ToOffsetSide: OffsetSideConstants.seOffsetNone, ToOffsetDistance: 0 ); }
//creates a hole private void create_hole(double PointOnGraphic_X, double PointOnGraphic_Y, double PointOnGraphic_Z, SolidEdgeGeometry.Face selected_face, int[] face_norm, string selected_face_normal) { // var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; PartDocument _doc = _application.ActiveDocument as PartDocument; RefPlanes refPlanes = null; RefPlane refPlane = null; refPlanes = _doc.RefPlanes; //Adding parallel refplane to the selected face refPlane = refPlanes.AddParallelByDistance(selected_face, 0.0, ReferenceElementConstants.igNormalSide, false, false, true, false); //Running windows form application System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.Run(new Form1()); MessageBox.Show("Cancel Hole Dimension?"); Form1 form1 = new Form1(); //Hole diameter from user input double cc = form1.Hole_dia; while (cc < 0.0) { MessageBox.Show("Enter valid dimension"); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.Run(new Form1()); Form1 form2 = new Form1(); double dd = form2.Hole_dia; MessageBox.Show("Cancel diamension?"); if (cc == dd) { MessageBox.Show("invalid argument"); dd = 0.0; } cc = dd; } ProfileSets profileSets = null; ProfileSet profileSet = null; Profiles profiles = null; Profile profile = null; Models models = null; HoleDataCollection holeDataCollection = null; HoleData holeData = null; Holes2d holes2D = null; Holes holes = null; Sketchs sketchs = null; Sketch sketch = null; Array ref_dir = new double[3] as Array; //getting the unit vector of the reference direction refPlane.GetReferenceDirection(ref ref_dir); var Ref_dirX = ref_dir as double[]; Array root_point = new double[3] as Array; refPlane.GetRootPoint(ref root_point); var Root_point = root_point as double[]; //calculating the cross-product between ref_dir and normal vector double[] Ref_dirY = new double[3] { Ref_dirX[2] * face_norm[1] - Ref_dirX[1] * face_norm[2], Ref_dirX[0] * face_norm[2] - Ref_dirX[2] * face_norm[0], Ref_dirX[1] * face_norm[0] - Ref_dirX[0] * face_norm[1] }; double Xcenter = -0.06; //local coordinates double Ycenter = -0.06; //calculating global coordinates from local coordinates double[] X_bar = new double[3] { Xcenter *Ref_dirX[0] + Ycenter * Ref_dirY[0] + Root_point[0], Xcenter *Ref_dirX[1] + Ycenter * Ref_dirY[1] + Root_point[1], Xcenter *Ref_dirX[2] + Ycenter * Ref_dirY[2] + Root_point[2] }; //Calculating the angle between vectors root_point and global double[] OX = new double[3] { PointOnGraphic_X - Root_point[0], PointOnGraphic_Y - Root_point[1], PointOnGraphic_Z - Root_point[2] }; //calculating the modulus of vector OX double OX_Mod = Math.Sqrt(Math.Pow(OX[0], 2) + Math.Pow(OX[1], 2) + Math.Pow(OX[2], 2)); //calculating the modulus of vector Ref_dirX double Ref_dirX_Mod = Math.Sqrt(Math.Pow(Ref_dirX[0], 2) + Math.Pow(Ref_dirX[1], 2) + Math.Pow(Ref_dirX[2], 2)); //calculating the modulus of the vector ReF_dirY double Ref_dirY_Mod = Math.Sqrt(Math.Pow(Ref_dirY[0], 2) + Math.Pow(Ref_dirY[1], 2) + Math.Pow(Ref_dirY[2], 2)); //calculating the dot product between vector OX and Ref_dirY double dotY = (OX[0] * Ref_dirY[0]) + (OX[1] * Ref_dirY[1]) + (OX[2] * Ref_dirY[2]); //calculating the dot product between vector OX and Ref_dirX double dotX = (OX[0] * Ref_dirX[0]) + (OX[1] * Ref_dirX[1]) + (OX[2] * Ref_dirX[2]); //calculating the angle between vector OX and Ref_dirY double angleY = Math.Acos(dotY / (OX_Mod * Ref_dirY_Mod)); //calculating the angle between vector OX and Ref_dirX double angleX = Math.Acos(dotX / (OX_Mod * Ref_dirX_Mod)); double X_dir = 0.0; double Y_dir = 0.0; if (angleY > Math.PI / 2) { X_dir = OX_Mod * Math.Cos(-angleX); Y_dir = OX_Mod * Math.Sin(-angleX); } else { X_dir = OX_Mod * Math.Cos(angleX); Y_dir = OX_Mod * Math.Sin(angleX); } if (OX_Mod == 0.0) { X_dir = 0.0; Y_dir = 0.0; } if (cc > 0.0) { sketchs = _doc.Sketches; sketch = sketchs.Add(); holeDataCollection = _doc.HoleDataCollection; //Defining hole properties holeData = holeDataCollection.Add( HoleType: SolidEdgePart.FeaturePropertyConstants.igRegularHole, HoleDiameter: cc / 1000); profileSets = _doc.ProfileSets; profileSet = profileSets.Add(); //profiles = profileSet.Profiles; profiles = sketch.Profiles; profile = profiles.Add(refPlane); holes2D = profile.Holes2d; var dd = holes2D.Add(X_dir, Y_dir); profile.End(ProfileValidationType.igProfileClosed); // dd.Move(X_dir, Y_dir, 0.0, 0.0); //_application.StartCommand(SolidEdgeConstants.PartCommandConstants.PartViewLookatFace); //getting the hole collection and creating a simple hole Model model = _doc.Models.Item(1); holes = model.Holes; holes.AddThroughNext( Profile: profile, ProfilePlaneSide: SolidEdgePart.FeaturePropertyConstants.igBoth, Data: holeData); } }
async void ISEMouseEvents.MouseClick(short sButton, short sShift, double dX, double dY, double dZ, object pWindowDispatch, int lKeyPointType, object pGraphicDispatch) { if (checkhole) { try { //MessageBox.Show($"dx{1000 * dX}, dy{1000 * dY}, dz{1000 * dZ}"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Holes _holes = _model.Holes; var cc = _holes.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); MessageBox.Show($"PointonGraphic {PointOnGraphicFlag}, {PointOnGraphic_X}, {PointOnGraphic_Y}, {PointOnGraphic_Z}"); // create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); List <HoleInfo> _holeInfos = new List <HoleInfo>(); foreach (Hole hole in _holes) { HoleInfo _holeInfo = default(HoleInfo); SolidEdgePart.HoleData _holedata = hole.HoleData as SolidEdgePart.HoleData; _holeInfo.diameter = 1000 * _holedata.HoleDiameter; Profile profile = hole.Profile as Profile; Holes2d holes2d = profile.Holes2d as Holes2d; Hole2d hole2d = holes2d.Item(1); double x_2d, y_2d, x_3d, y_3d, z_3d; hole2d.GetCenterPoint(out x_2d, out y_2d); profile.Convert2DCoordinate(x_2d, y_2d, out x_3d, out y_3d, out z_3d); _holeInfo.xd = x_2d * 1000; _holeInfo.yd = y_2d * 1000; _holeInfo.x = x_3d * 1000; _holeInfo.y = y_3d * 1000; _holeInfo.z = z_3d * 1000; RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); double[] ns = normals as double[]; _holeInfo.nx = ns[0]; _holeInfo.ny = ns[1]; _holeInfo.nz = ns[2]; _holeInfos.Add(_holeInfo); // MessageBox.Show(string.Format("diam: {0:0.000} x: {1:0.000}, y: {2:0.000}, z: {3:0.000}, nx: {3:0.000}, ny: {3:0.000}, nz: {3:0.000}", // _holeInfo.diameter, _holeInfo.x, _holeInfo.y, _holeInfo.z, _holeInfo.nx, _holeInfo.ny, _holeInfo.nz)); } _holeInfos = _holeInfos.OrderBy(p => p.diameter).ToList(); string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": ["; bool first = true; //adding the hole diameters to query foreach (HoleInfo hi in _holeInfos) { if (!first) { query += ", "; } first = false; string add_v = String.Format("\"{0:0.0}\"", hi.diameter); query += add_v; } query += "], \"e\": ["; double dist_bucket_size = 50; int v_source = 0; first = true; foreach (HoleInfo hi_source in _holeInfos) { int v_dest = 0; string bucket_dir_source = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_source.nx, hi_source.ny, hi_source.nz); // MessageBox.Show($"Source {hi_source.x}, {hi_source.y}, {hi_source.z} --- {hi_source.nx}, {hi_source.ny}, {hi_source.nz} "); // MessageBox.Show($"{bucket_dir_source}"); foreach (HoleInfo hi_dest in _holeInfos) { if (v_dest > v_source) { //MessageBox.Show($"destination {hi_dest.x}, {hi_dest.y}, {hi_dest.z} --- {hi_dest.nx}, {hi_dest.ny}, {hi_dest.nz}"); if (!first) { query += ", "; } first = false; string bucket_dir_dest = string.Format("{0:0.0000}{1:0.0000}{2:0.0000}", hi_dest.nx, hi_dest.ny, hi_dest.nz); double e_dist = Math.Sqrt(Math.Pow(hi_source.x - hi_dest.x, 2) + Math.Pow(hi_source.y - hi_dest.y, 2) + Math.Pow(hi_source.z - hi_dest.z, 2)); //MessageBox.Show($"Bucket_dir_dest {bucket_dir_dest}, e_dist {e_dist}"); double e_dist_bucket = Math.Ceiling(e_dist / dist_bucket_size); //MessageBox.Show($"e_dist_bucket {e_dist_bucket}"); string add_e = string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"{2:0}\"]", hi_source.diameter, hi_dest.diameter, e_dist_bucket); if (bucket_dir_source == bucket_dir_dest) { add_e += string.Format(",[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); //add_e += string.Format("[[\"{0:0.0}\", \"{1:0.0}\"], \"co_dir\"]", hi_source.diameter, hi_dest.diameter); } query += add_e; } v_dest += 1; } v_source += 1; } // query += "]}, \"location\":[[[\"32.0\", \"*\"], \"co_dir\"],"; query += "]}, \"location\": ["; first = true; //Calculating distance from the mouse location to the hole center points foreach (HoleInfo H_dest in _holeInfos) { if (!first) { query += ", "; } first = false; double e_dest = Math.Sqrt(Math.Pow(H_dest.x - (1000 * PointOnGraphic_X), 2) + Math.Pow(H_dest.y - (1000 * PointOnGraphic_Y), 2) + Math.Pow(H_dest.z - (1000 * PointOnGraphic_Z), 2)); double e_dist_bucket = Math.Ceiling(e_dest / dist_bucket_size); string add_e = string.Format("[[\"{0:0.0}\", \"*\"], \"{1:0}\"]", H_dest.diameter, e_dist_bucket); string Hole_Normal_vector = string.Format("{0:0}{1:0}{2:0}", H_dest.nx, H_dest.ny, H_dest.nz); if (Hole_Normal_vector == Face_normal_vector) { add_e += string.Format(", [[\"{0:0.0}\", \"*\"], \"co_dir\"]", H_dest.diameter); //MessageBox.Show($"2D coordinates {H_dest.xd},{H_dest.yd}"); } query += add_e; } query += "]}"; MessageBox.Show($"{query}"); //string query = "http://trapezohedron.shapespace.com:9985/v1/suggestions?query={\"status\": {\"v\": [\"32.0\", \"57.0\"], \"e\": [[[\"32.0\", \"57.0\"], \"co_dir\"]]}, \"location\": [[[\"32.0\", \"*\"], \"co_dir\"]]}"; var values = new Dictionary <string, string> { }; var content = new FormUrlEncodedContent(values); var response = await _client.GetAsync(query); var responseString = await response.Content.ReadAsStringAsync(); MessageBox.Show(responseString); string pattern = @"\d*\.\d"; matchCollection = Regex.Matches(responseString, pattern); count = matchCollection.Count; Match = new double[count]; int i = 0; string match = ""; foreach (Match m in matchCollection) { match += string.Format("{0} ", m.Value); Match[i] = Convert.ToDouble(m.Value); i++; } // MessageBox.Show($"{match}"); create_hole(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); _getting_suggestions = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkcutout) { try { //MessageBox.Show("cutout feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); ExtrudedCutouts _extrudedCutouts = _model.ExtrudedCutouts; int a = _extrudedCutouts.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <CutoutInfo> _Cutoutinfos = new List <CutoutInfo>(); foreach (ExtrudedCutout extrudedCutout in _extrudedCutouts) { CutoutInfo _cutoutInfo = default(CutoutInfo); _cutoutInfo.KeyPoints = new List <double>(); Profile profile = extrudedCutout.Profile as Profile; SolidEdgeFrameworkSupport.Lines2d lines2D = profile.Lines2d; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; SolidEdgeFramework.KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _cutoutInfo.KeyPoints.Add(x_3D * 1000); _cutoutInfo.KeyPoints.Add(y_3D * 1000); _cutoutInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _cutoutInfo.nx = ns[0]; _cutoutInfo.ny = ns[1]; _cutoutInfo.nz = ns[2]; _Cutoutinfos.Add(_cutoutInfo); } var dd = _Cutoutinfos[0].KeyPoints[0]; foreach (CutoutInfo info in _Cutoutinfos) { //MessageBox.Show($"{Math.Round(info.nx)},{Math.Round(info.ny)},{Math.Round(info.nz)}"); string Cutout_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Cutout_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Cutout(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (checkslot) { try { // MessageBox.Show("Slot feature selected"); _getting_suggestions = true; _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(); PartDocument _doc = _application.ActiveDocument as PartDocument; Model _model = _doc.Models.Item(1); Slots slots = _model.Slots; int cc = slots.Count; var selected_face = pGraphicDispatch as SolidEdgeGeometry.Face; Array minparams = new double[2] as Array; Array maxparams = new double[2] as Array; selected_face.GetParamRange(ref minparams, ref maxparams); var mins = minparams as double[]; var maxs = maxparams as double[]; Array u = new double[2] { mins[0] + 0.5 * (maxs[0] - mins[0]), mins[1] + 0.5 * (maxs[1] - mins[1]) }; Array n = new double[3] as Array; //getting the normal vector of the selected face selected_face.GetNormal(1, ref u, ref n); var norm = n as double[]; int x = (int)Math.Round(norm[0]); int y = (int)Math.Round(norm[1]); int z = (int)Math.Round(norm[2]); int[] face_norm = new int[3] { x, y, z }; string Face_normal_vector = string.Format("{0:0}{1:0}{2:0}", x, y, z); //Accessing 3D mouse coordinates _mouse.PointOnGraphic(out int PointOnGraphicFlag, out double PointOnGraphic_X, out double PointOnGraphic_Y, out double PointOnGraphic_Z); List <Slotinfo> _Slotinfos = new List <Slotinfo>(); foreach (Slot slot in slots) { Slotinfo _SlotInfo = default(Slotinfo); _SlotInfo.KeyPoints = new List <double>(); Profile profile = slot.Profile as Profile; Lines2d lines2D = profile.Lines2d; int lincount = lines2D.Count; double x_3d, y_3d, z_3d, x_3D, y_3D, z_3D; int handletype; KeyPointType KeyPointType; int rc = lines2D.Count; for (int j = 1; j <= rc; j++) { var ii = lines2D.Item(j); int keycout = ii.KeyPointCount; for (int i = 0; i < keycout; i++) { ii.GetKeyPoint(i, out x_3d, out y_3d, out z_3d, out KeyPointType, out handletype); profile.Convert2DCoordinate(x_3d, y_3d, out x_3D, out y_3D, out z_3D); _SlotInfo.KeyPoints.Add(x_3D * 1000); _SlotInfo.KeyPoints.Add(y_3D * 1000); _SlotInfo.KeyPoints.Add(z_3D * 1000); } } RefPlane plane = profile.Plane as RefPlane; Array normals = new double[3] as Array; plane.GetNormal(ref normals); //getting the normal vector of the cutout profile double[] ns = normals as double[]; _SlotInfo.nx = ns[0]; _SlotInfo.ny = ns[1]; _SlotInfo.nz = ns[2]; _Slotinfos.Add(_SlotInfo); } var dd = _Slotinfos[0].KeyPoints[0]; foreach (Slotinfo info in _Slotinfos) { //Comparing the normal vector of the face to the slot normal vector string Slot_normal_vector = string.Format("{0:0}{1:0}{2:0}", Math.Round(info.nx), Math.Round(info.ny), Math.Round(info.nz)); if (Face_normal_vector == Slot_normal_vector) { MessageBox.Show("Co-dir"); } } Create_Slot(PointOnGraphic_X, PointOnGraphic_Y, PointOnGraphic_Z, selected_face, face_norm, Face_normal_vector); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public int CalculateAngleAR(ref double arAngle, ref double ahAngle, Vector3D DirectionCos, RefPlane refPlane) { if (refPlane == RefPlane.XY_PLANE) { arAngle = RadianToDegree(Math.Atan(DirectionCos.Y / DirectionCos.X)); ahAngle = RadianToDegree(Math.Acos(DirectionCos.Z)); if ((DirectionCos.X < 0) && (DirectionCos.Y > 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.X < 0) && (DirectionCos.Y < 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.X > 0) && (DirectionCos.Y < 0)) { arAngle = arAngle + 360; } else if ((DirectionCos.X == 0) && (DirectionCos.Y == 0)) { arAngle = 0.0; } else if ((DirectionCos.X == -1) && (DirectionCos.Y == 0.0)) { arAngle = 180.0; } else if ((DirectionCos.X == 0.0) && (DirectionCos.Y == -1.0)) { arAngle = 270.0; } } else if (refPlane == RefPlane.YZ_PLANE) { arAngle = RadianToDegree(Math.Atan(DirectionCos.Z / DirectionCos.Y)); ahAngle = RadianToDegree(Math.Acos(DirectionCos.X)); if ((DirectionCos.Y < 0) && (DirectionCos.Z > 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.Y < 0) && (DirectionCos.Z < 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.Y == 0) && (DirectionCos.Z == 0)) { arAngle = 0.0; } else if ((DirectionCos.Y > 0) && (DirectionCos.Z < 0)) { arAngle = arAngle + 360; } } else if (refPlane == RefPlane.ZX_PLANE) { arAngle = RadianToDegree(Math.Atan(DirectionCos.X / DirectionCos.Z)); ahAngle = RadianToDegree(Math.Acos(DirectionCos.Y)); if ((DirectionCos.Z < 0) && (DirectionCos.X > 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.Z < 0) && (DirectionCos.X < 0)) { arAngle = arAngle + 180.0; } else if ((DirectionCos.Z == 0) && (DirectionCos.X == 0)) { arAngle = 0.0; } else if ((DirectionCos.Z > 0) && (DirectionCos.X < 0)) { arAngle = arAngle + 360; } } return(0); }
public void GetRefPlane(ref RefPlane refPlane) { refPlane = _refPlane; }