public void TraverseComponentFeatures(Component2 swComp, long nLevel) { Feature swFeat; swFeat = (Feature)swComp.FirstFeature(); TraverseFeatures(swFeat, nLevel); }
/// <summary> /// 获取组件顶层的所有特征 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static IList <Feature> GetCompTopFeatures(this Component2 comp) { List <Feature> features = new List <Feature>(); var feat = comp.FirstFeature(); while (feat != null) { features.Add(feat); feat = feat.GetNextFeature() as Feature; } return(features); }
/// <summary> /// 用类型名过滤特征--只获取第一级特征 /// </summary> /// <param name="comp"></param> /// <param name="TypeName"></param> /// <returns></returns> public static IList <Feature> GetCompTopFeaturesWithTypeName(this Component2 comp, string TypeName) { List <Feature> features = new List <Feature>(); var feat = comp.FirstFeature(); while (feat != null) { if (feat.GetTypeName2() == TypeName) { features.Add(feat); } feat = feat.GetNextFeature() as Feature; } return(features); }
/// <summary> /// 获取特定的特征 /// </summary> /// <param name="comp"></param> /// <param name="TypeName"></param> /// <returns></returns> public static IList <Feature> TakeCompTopFeaturesWhile(this Component2 comp, Func <Feature, bool> func) { List <Feature> features = new List <Feature>(); var feat = comp.FirstFeature(); while (feat != null) { if (func != null && func(feat)) { features.Add(feat); } feat = feat.GetNextFeature() as Feature; } return(features); }
public static bool quickCheck(Component2 component) { IMathPoint source = Utilities.getNamedPoint("centre of flag top", component); if (source == null) { // then we need to pick some other kind of point... we'll try.... Feature origin = component.FirstFeature(); while (origin != null) { if (origin.GetTypeName().Equals("OriginProfileFeature")) { origin.Select(false); Measure measure = swDoc.Extension.CreateMeasure(); measure.Calculate(null); source = mathUtils.CreatePoint(new double[] { measure.X, measure.Y, measure.Z }); } origin = origin.GetNextFeature(); } } return(camera.isRayWithinFOV(source)); }
public void DumpTraverseComponent(Component2 swComp, long nLevel, ref string asciitext) { // *** SCAN THE COMPONENT FEATURES if (!swComp.IsRoot()) { Feature swFeat; swFeat = (Feature)swComp.FirstFeature(); DumpTraverseFeatures(swFeat, nLevel, ref asciitext); } // *** RECURSIVE SCAN CHILDREN COMPONENTS object[] vChildComp; Component2 swChildComp; string sPadStr = " "; long i = 0; for (i = 0; i <= nLevel - 1; i++) { sPadStr = sPadStr + " "; } vChildComp = (object[])swComp.GetChildren(); for (i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; asciitext += sPadStr + "+" + swChildComp.Name2 + " <" + swChildComp.ReferencedConfiguration + ">" +"\n"; // DumpTraverseComponentFeatures(swChildComp, nLevel, ref asciitext); DumpTraverseComponent(swChildComp, nLevel + 1, ref asciitext); } }
public void PythonTraverseFeatures_for_collshapes(Component2 swComp, long nLevel, ref string asciitext, int nbody, ref MathTransform chbodytransform, ref bool found_collisionshapes, Component2 swCompBase) { CultureInfo bz = new CultureInfo("en-BZ"); Feature swFeat; swFeat = (Feature)swComp.FirstFeature(); String bodyname = "body_" + nbody; MathTransform subcomp_transform = swComp.GetTotalTransform(true); MathTransform invchbody_trasform = (MathTransform)chbodytransform.Inverse(); MathTransform collshape_subcomp_transform = subcomp_transform.IMultiply(invchbody_trasform); // row-ordered transf. -> reverse mult.order! // Export collision shapes if (this.checkBox_collshapes.Checked) { object[] bodies; object bodyInfo; bodies = (object[])swComp.GetBodies3((int)swBodyType_e.swAllBodies, out bodyInfo); if (bodies != null) { // see if it contains some collision shape bool build_collision_model = false; for (int ib = 0; ib < bodies.Length; ib++) { Body2 swBody = (Body2)bodies[ib]; if (swBody.Name.StartsWith("COLL.")) build_collision_model = true; } if (build_collision_model) { if (!found_collisionshapes) { found_collisionshapes = true; // fetch SW attribute with Chrono parameters SolidWorks.Interop.sldworks.Attribute myattr = (SolidWorks.Interop.sldworks.Attribute)swCompBase.FindAttribute(this.mSWintegration.defattr_chbody, 0); if (myattr != null) { asciitext += "\n# Collision parameters \n"; double param_friction = ((Parameter)myattr.GetParameter("friction")).GetDoubleValue(); double param_restitution = ((Parameter)myattr.GetParameter("restitution")).GetDoubleValue(); double param_rolling_friction = ((Parameter)myattr.GetParameter("rolling_friction")).GetDoubleValue(); double param_spinning_friction = ((Parameter)myattr.GetParameter("spinning_friction")).GetDoubleValue(); double param_collision_envelope = ((Parameter)myattr.GetParameter("collision_envelope")).GetDoubleValue(); double param_collision_margin = ((Parameter)myattr.GetParameter("collision_margin")).GetDoubleValue(); int param_collision_family = (int)((Parameter)myattr.GetParameter("collision_family")).GetDoubleValue(); asciitext += String.Format(bz, "{0}.SetFriction({1:g});\n", bodyname, param_friction); if (param_restitution != 0) asciitext += String.Format(bz, "{0}.SetImpactC({1:g});\n", bodyname, param_restitution); if (param_rolling_friction != 0) asciitext += String.Format(bz, "{0}.SetRollingFriction({1:g});\n", bodyname, param_rolling_friction); if (param_spinning_friction != 0) asciitext += String.Format(bz, "{0}.SetSpinningFriction({1:g});\n", bodyname, param_spinning_friction); //if (param_collision_envelope != 0.03) asciitext += String.Format(bz, "{0}.GetCollisionModel().SetEnvelope({1:g});\n", bodyname, param_collision_envelope * ChScale.L); //if (param_collision_margin != 0.01) asciitext += String.Format(bz, "{0}.GetCollisionModel().SetSafeMargin({1:g});\n", bodyname, param_collision_margin * ChScale.L); if (param_collision_family != 0) asciitext += String.Format(bz, "{0}.GetCollisionModel().SetFamily({1});\n", bodyname, param_collision_family); } // clear model only at 1st subcomponent where coll shapes are found in features: asciitext += "\n# Collision shapes \n"; asciitext += String.Format(bz, "{0}.GetCollisionModel().ClearModel()\n", bodyname); } for (int ib = 0; ib < bodies.Length; ib++) { Body2 swBody = (Body2)bodies[ib]; if (swBody.Name.StartsWith("COLL.")) { bool rbody_converted = false; if (ConvertToCollisionShapes.SWbodyToSphere(swBody)) { Point3D center_l = new Point3D(); // in local subcomponent double rad = 0; ConvertToCollisionShapes.SWbodyToSphere(swBody, ref rad, ref center_l); Point3D center = SWTaskpaneHost.PointTransform(center_l, ref collshape_subcomp_transform); asciitext += String.Format(bz, "{0}.GetCollisionModel().AddSphere({1}, chrono.ChVectorD({2},{3},{4}))\n", bodyname, rad * ChScale.L, center.X * ChScale.L, center.Y * ChScale.L, center.Z * ChScale.L); rbody_converted = true; } if (ConvertToCollisionShapes.SWbodyToBox(swBody)) { Point3D vC_l = new Point3D(); Vector3D eX_l = new Vector3D(); Vector3D eY_l = new Vector3D(); Vector3D eZ_l = new Vector3D(); ConvertToCollisionShapes.SWbodyToBox(swBody, ref vC_l, ref eX_l, ref eY_l, ref eZ_l); Point3D vC = SWTaskpaneHost.PointTransform(vC_l, ref collshape_subcomp_transform); Vector3D eX = SWTaskpaneHost.DirTransform(eX_l, ref collshape_subcomp_transform); Vector3D eY = SWTaskpaneHost.DirTransform(eY_l, ref collshape_subcomp_transform); Vector3D eZ = SWTaskpaneHost.DirTransform(eZ_l, ref collshape_subcomp_transform); double hsX = eX.Length * 0.5; double hsY = eY.Length * 0.5; double hsZ = eZ.Length * 0.5; Point3D vO = vC + 0.5 * eX + 0.5 * eY + 0.5 * eZ; Vector3D Dx = eX; Dx.Normalize(); Vector3D Dy = eY; Dy.Normalize(); Vector3D Dz = Vector3D.CrossProduct(Dx, Dy); asciitext += String.Format(bz, "mr = chrono.ChMatrix33D()\n"); asciitext += String.Format(bz, "mr[0,0]={0}; mr[1,0]={1}; mr[2,0]={2} \n", Dx.X, Dx.Y, Dx.Z); asciitext += String.Format(bz, "mr[0,1]={0}; mr[1,1]={1}; mr[2,1]={2} \n", Dy.X, Dy.Y, Dy.Z); asciitext += String.Format(bz, "mr[0,2]={0}; mr[1,2]={1}; mr[2,2]={2} \n", Dz.X, Dz.Y, Dz.Z); asciitext += String.Format(bz, "{0}.GetCollisionModel().AddBox({1},{2},{3},chrono.ChVectorD({4},{5},{6}),mr)\n", bodyname, hsX * ChScale.L, hsY * ChScale.L, hsZ * ChScale.L, vO.X * ChScale.L, vO.Y * ChScale.L, vO.Z * ChScale.L); rbody_converted = true; } if (ConvertToCollisionShapes.SWbodyToCylinder(swBody)) { Point3D p1_l = new Point3D(); Point3D p2_l = new Point3D(); double rad = 0; ConvertToCollisionShapes.SWbodyToCylinder(swBody, ref p1_l, ref p2_l, ref rad); Point3D p1 = SWTaskpaneHost.PointTransform(p1_l, ref collshape_subcomp_transform); Point3D p2 = SWTaskpaneHost.PointTransform(p2_l, ref collshape_subcomp_transform); Vector3D Dy = p1 - p2; Dy.Normalize(); double hsY = (p1 - p2).Length * 0.5; double hsZ = rad; double hsX = rad; Point3D vO = p1 + 0.5 * (p2 - p1); Vector3D Dx = new Vector3D(); if (Dy.X < 0.9) { Vector3D Dtst = new Vector3D(1, 0, 0); Dx = Vector3D.CrossProduct(Dtst, Dy); } else { Vector3D Dtst = new Vector3D(0, 1, 0); Dx = Vector3D.CrossProduct(Dtst, Dy); } Vector3D Dz = Vector3D.CrossProduct(Dx, Dy); asciitext += String.Format(bz, "mr = chrono.ChMatrix33D()\n"); asciitext += String.Format(bz, "mr[0,0]={0}; mr[1,0]={1}; mr[2,0]={2} \n", Dx.X, Dx.Y, Dx.Z); asciitext += String.Format(bz, "mr[0,1]={0}; mr[1,1]={1}; mr[2,1]={2} \n", Dy.X, Dy.Y, Dy.Z); asciitext += String.Format(bz, "mr[0,2]={0}; mr[1,2]={1}; mr[2,2]={2} \n", Dz.X, Dz.Y, Dz.Z); asciitext += String.Format(bz, "{0}.GetCollisionModel().AddCylinder({1},{2},{3},chrono.ChVectorD({4},{5},{6}),mr)\n", bodyname, hsX * ChScale.L, hsZ * ChScale.L, hsY * ChScale.L, vO.X * ChScale.L, vO.Y * ChScale.L, vO.Z * ChScale.L); // note order hsX-Z-Y rbody_converted = true; } if (ConvertToCollisionShapes.SWbodyToConvexHull(swBody, 30) && !rbody_converted) { Point3D[] vertexes = new Point3D[1]; // will be resized by SWbodyToConvexHull ConvertToCollisionShapes.SWbodyToConvexHull(swBody, ref vertexes, 30); if (vertexes.Length > 0) { asciitext += String.Format(bz, "pt_vect = chrono.vector_ChVectorD()\n"); for (int iv = 0; iv < vertexes.Length; iv++) { Point3D vert_l = vertexes[iv]; Point3D vert = SWTaskpaneHost.PointTransform(vert_l, ref collshape_subcomp_transform); asciitext += String.Format(bz, "pt_vect.push_back(chrono.ChVectorD({0},{1},{2}))\n", vert.X * ChScale.L, vert.Y * ChScale.L, vert.Z * ChScale.L); } asciitext += String.Format(bz, "{0}.GetCollisionModel().AddConvexHull(pt_vect)\n", bodyname); } } } // end dealing with a collision shape } // end solid bodies traversal for converting to coll.shapes } // end if build_collision_model } } // end collision shapes export }
// // BODY EXPORTING FUNCTIONS // public void PythonTraverseComponent_for_markers(Component2 swComp, long nLevel, ref string asciitext, int nbody) { // Look if component contains markers Feature swFeat = (Feature)swComp.FirstFeature(); MathTransform swCompTotalTrasf = swComp.GetTotalTransform(true); PythonTraverseFeatures_for_markers(swFeat, nLevel, ref asciitext, nbody, swCompTotalTrasf); // Recursive scan of subcomponents Component2 swChildComp; object[] vChildComp = (object[])swComp.GetChildren(); for (long i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; PythonTraverseComponent_for_markers(swChildComp, nLevel + 1, ref asciitext, nbody); } }
// // LINK EXPORTING FUNCTIONS // public void PythonTraverseComponent_for_links(Component2 swComp, long nLevel, ref string asciitext, ref MathTransform roottrasf) { // Scan assembly features and save mating info if (nLevel > 1) { Feature swFeat = (Feature)swComp.FirstFeature(); PythonTraverseFeatures_for_links(swFeat, nLevel, ref asciitext, ref roottrasf, ref swComp); } // Recursive scan of subassemblies object[] vChildComp; Component2 swChildComp; vChildComp = (object[])swComp.GetChildren(); for (long i = 0; i < vChildComp.Length; i++) { swChildComp = (Component2)vChildComp[i]; if (swChildComp.Solving == (int)swComponentSolvingOption_e.swComponentFlexibleSolving) PythonTraverseComponent_for_links(swChildComp, nLevel + 1, ref asciitext, ref roottrasf); } }
private void CheckBoxIntersectionWithCavities(List<Component2> cutList, Component2 key) { //����� ��� ���� ������������� ���� �� key var swFeat = key.FirstFeature(); while (swFeat != null) { if (swFeat.GetTypeName2() == "ICE") { foreach (var cut in cutList) { if (CheckComponentsIntersection2(cut, swFeat, key)) { //cut.Select(false); swFeat.Select(true); MessageBox.Show("�����������! ������: " + key.GetPathName() + " ����:" + swFeat.Name, "�����������!", MessageBoxButtons.OK); return; } } } swFeat = swFeat.IGetNextFeature(); } }
//private static bool IsCavitiesNew(Component2 comp, out List<Feature> listCavities) //{ // bool ret = false; // listCavities = new List<Feature>(); // var swFeat = comp.FirstFeature(); // while (swFeat != null) // { // if (swFeat.GetTypeName2() == "Cavity") // { // var swFeats = swFeat.GetChildren(); // var a = swFeat.IGetFirstSubFeature(); // var b = swFeat.GetAffectedFaces(); // var c = swFeat.GetBody(); // var d = swFeat.GetParents(); // var e = swFeat.IGetNextSubFeature(); // if (swFeats == null) // { // swFeat = swFeat.IGetNextFeature(); // continue; // } // foreach (var feat in swFeats) // { // listCavities.Add(feat); // ret = true; // } // } // swFeat = swFeat.IGetNextFeature(); // } // return ret; //} private static bool IsCavities(Component2 comp, out List<Feature> listCavities) { bool ret = false; listCavities = new List<Feature>(); var swFeat = comp.FirstFeature(); while (swFeat != null) { if (swFeat.GetTypeName2() == "Cavity") { listCavities.Add(swFeat); ret = true; } swFeat = swFeat.IGetNextFeature(); } return ret; }
public int OnNewSelection() { //var swSelMgr = document.SelectionManager; //var f = swSelMgr.GetSelectedObject6(1, 0); ModelDoc2 swDoc = null; Feature swFeature; swDoc = iSwApp.ActiveDoc; SelectionMgr swSelMgr; swSelMgr = (SelectionMgr)swDoc.SelectionManager; Feature swFeat = default(Feature); ModelDocExtension swModDocExt = default(ModelDocExtension); Component2 swComp = default(Component2); object vModelPathName = null; int selObjType = 0; int nRefCount = 0; selObjType = swSelMgr.GetSelectedObjectType3(1, -1);; if (selObjType == (int)swSelectType_e.swSelBODYFEATURES) { swFeature = swSelMgr.GetSelectedObject6(1, 1); } else if (selObjType == (int)swSelectType_e.swSelCOMPONENTS) { swComp = (Component2)swSelMgr.GetSelectedObjectsComponent3(1, -1); if (swComp == null) { return(0); } //MessageBox.Show(swComp.GetPathName()); swFeat = swComp.FirstFeature(); EventHelper eh = EventHelper.GetInstance(); SelectedEventArgs arg = new SelectedEventArgs(); arg.ComponentName = swComp.GetPathName(); eh.RasieTesting(arg); //display feature's sensor //MessageBox.Show(swFeat.Name); } else if (selObjType == (int)swSelectType_e.swSelSKETCHES) { swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1); nRefCount = swFeat.ListExternalFileReferencesCount(); } //Component2 swComp = null; //swComp = (Component2)swDwgComp.Component; //ModelDoc2 swCompModDoc = null; //swCompModDoc = (ModelDoc2)swComp.GetModelDoc2(); //Debug.Print("dsfasdf"); //var swSelMgr = modelDoc2.SelectionManager; //var swCompEnt = swSelMgr.GetSelectedObject6(1, 0); #region 递归输出Feature.Name //StringBuilder sb = new StringBuilder(); //Feature feature = modelDoc2.FirstFeature(); //Feature nextFeature = null; //sb.Append("名称:" + feature.Name + "----类型:" + feature.GetTypeName()); //while (feature != null) //{ // nextFeature = (Feature)feature.GetNextFeature(); // if (nextFeature == null) { break; } // sb.Append("名称:" + nextFeature.Name + "----类型:" + feature.GetTypeName()); // feature = null; // feature = nextFeature; // nextFeature = null; //} #endregion #region 类型转换出错 //ModelDocExtension swModelDocExt = default(ModelDocExtension); //SelectionMgr swSelMgr = default(SelectionMgr); //Feature swFeat = default(Feature); //string featName = null; //string featType = null; //swSelMgr = (SelectionMgr)document.SelectionManager; //swModelDocExt = (ModelDocExtension)document.Extension; //// Get the selected feature //swFeat = (Feature)swSelMgr.GetSelectedObject6(1, -1); //document.ClearSelection2(true); //// Get the feature's type and name //featName = swFeat.GetNameForSelection(out featType); //swModelDocExt.SelectByID2(featName, featType, 0, 0, 0, true, 0, null, 0); //MessageBox.Show(featName + "" + featType); #endregion return(0); }