private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { int index = (int)treeView1.SelectedNode.Tag; TableItem tmp_node = (TableItem)(MainStorage.TableNode[index]); tableLayoutPanel1.Controls.Clear(); Label label1 = new Label(); label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label1.Text = "StepId:"; Label label2 = new Label(); label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label2.Text = tmp_node.STEPId.ToString(); Label label3 = new Label(); label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label3.Text = "类型:"; Label label4 = new Label(); label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label4.Text = tmp_node.GetTypeName(); Label label5 = new Label(); label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; label5.Text = "属性字段:"; Label label6 = new Label(); label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label7 = new Label(); label7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label8 = new Label(); label8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label9 = new Label(); label9.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label10 = new Label(); label10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label11 = new Label(); label11.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; Label label12 = new Label(); label12.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; //针对不同的节点类型进行处理 switch (tmp_node.TypeFlag) { case 1: { CARTESIAN_POINT struct_tmp = (CARTESIAN_POINT)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "X坐标:"; label8.Text = struct_tmp.x_coord.ToString(); label9.Text = "Y坐标:"; label10.Text = struct_tmp.y_coord.ToString(); label11.Text = "Z坐标:"; label12.Text = struct_tmp.z_coord.ToString(); } ; break; case 2: { DIRECTION struct_tmp = (DIRECTION)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "X投影分量:"; label8.Text = struct_tmp.x_dir.ToString(); label9.Text = "Y投影分量:"; label10.Text = struct_tmp.y_dir.ToString(); label11.Text = "Z投影分量:"; label12.Text = struct_tmp.z_dir.ToString(); } ; break; case 3: { VERTEX_POINT struct_tmp = (VERTEX_POINT)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 4: { CIRCLE struct_tmp = (CIRCLE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "半径:"; label8.Text = struct_tmp.radius.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 5: { EDGE_CURVE struct_tmp = (EDGE_CURVE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "方向:"; label8.Text = struct_tmp.dir.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 6: { ORIENTED_EDGE struct_tmp = (ORIENTED_EDGE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "属性1:"; label8.Text = struct_tmp.flag_1; label9.Text = "属性2:"; label10.Text = struct_tmp.flag_2; label11.Text = "方向:"; label12.Text = struct_tmp.dir.ToString(); } ; break; case 7: { AXIS2_PLACEMENT_3D struct_tmp = (AXIS2_PLACEMENT_3D)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 8: { EDGE_LOOP struct_tmp = (EDGE_LOOP)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 9: { CYLINDRICAL_SURFACE struct_tmp = (CYLINDRICAL_SURFACE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "半径:"; label8.Text = struct_tmp.radius.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 10: { PLANE struct_tmp = (PLANE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 11: { FACE_OUTER_BOUND struct_tmp = (FACE_OUTER_BOUND)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "方向:"; label8.Text = struct_tmp.dir.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 12: { FACE_BOUND struct_tmp = (FACE_BOUND)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "方向:"; label8.Text = struct_tmp.dir.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 13: { ADVANCED_FACE struct_tmp = (ADVANCED_FACE)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = "方向:"; label8.Text = struct_tmp.dir.ToString(); label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 14: { CLOSED_SHELL struct_tmp = (CLOSED_SHELL)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 15: { MANIFOLD_SOLID_BREP struct_tmp = (MANIFOLD_SOLID_BREP)(tmp_node.node); label6.Text = struct_tmp.property; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; case 16: { ADVANCED_BREP_SHAPE_REPRESENTATION struct_tmp = (ADVANCED_BREP_SHAPE_REPRESENTATION)(tmp_node.node); label6.Text = "缺省"; label7.Text = ""; label8.Text = ""; label9.Text = ""; label10.Text = ""; label11.Text = ""; label12.Text = ""; } ; break; } tableLayoutPanel1.Controls.Add(label1, 0, 0); tableLayoutPanel1.Controls.Add(label2, 1, 0); tableLayoutPanel1.Controls.Add(label3, 2, 0); tableLayoutPanel1.Controls.Add(label4, 3, 0); tableLayoutPanel1.Controls.Add(label5, 4, 0); tableLayoutPanel1.Controls.Add(label6, 5, 0); tableLayoutPanel1.Controls.Add(label7, 0, 1); tableLayoutPanel1.Controls.Add(label8, 1, 1); tableLayoutPanel1.Controls.Add(label9, 2, 1); tableLayoutPanel1.Controls.Add(label10, 3, 1); tableLayoutPanel1.Controls.Add(label11, 4, 1); tableLayoutPanel1.Controls.Add(label12, 5, 1); }
public void CreateCylinderMesh(int index)//创建圆柱面网格 { //取出对应元素的索引信息 ArrayList StepIdOfBound = Form1.MainStorage.LookForChildByIndex(index); int StepIdOfLoop1 = Form1.MainStorage.LookForFirstChild((int)StepIdOfBound[0]); int StepIdOfOriented1 = Form1.MainStorage.LookForFirstChild(StepIdOfLoop1); int StepIdOfCurve1 = Form1.MainStorage.LookForFirstChild(StepIdOfOriented1); int StepIdOfCircle1 = Form1.MainStorage.LookForLastChild(StepIdOfCurve1); int IndexOfCircle1 = Form1.MainStorage.LookForNode(StepIdOfCircle1); int StepIdOfCircleAXIS1 = Form1.MainStorage.LookForFirstChild(StepIdOfCircle1); int StepIdOfCirclePoint1 = Form1.MainStorage.LookForFirstChild(StepIdOfCircleAXIS1);//读出圆心1 TableItem temp1 = (TableItem)Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCirclePoint1)]; float Z1_coord = (float)((CARTESIAN_POINT)temp1.node).z_coord; int StepIdOfLoop2 = Form1.MainStorage.LookForFirstChild((int)StepIdOfBound[1]); int StepIdOfOriented2 = Form1.MainStorage.LookForFirstChild(StepIdOfLoop2); int StepIdOfCurve2 = Form1.MainStorage.LookForFirstChild(StepIdOfOriented2); int StepIdOfCircle2 = Form1.MainStorage.LookForLastChild(StepIdOfCurve2); int IndexOfCircle2 = Form1.MainStorage.LookForNode(StepIdOfCircle2); int StepIdOfCircleAXIS2 = Form1.MainStorage.LookForFirstChild(StepIdOfCircle2); int StepIdOfCirclePoint2 = Form1.MainStorage.LookForFirstChild(StepIdOfCircleAXIS2);//读出圆心2 TableItem temp2 = (TableItem)Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCirclePoint2)]; float Z2_coord = (float)((CARTESIAN_POINT)temp2.node).z_coord; float height = (float)Math.Abs(Z1_coord - Z2_coord);//求出圆柱的高度 int StepIdOfAxis3 = Form1.MainStorage.LookForFirstChild((int)StepIdOfBound[2]); ArrayList all_child = Form1.MainStorage.LookForChild(StepIdOfAxis3); int StepIdOfCircleCenter = (int)all_child[0]; //找到底面中心索引 int StepIdOfCylinderDirection = (int)all_child[1]; //找到方向索引 TableItem Cylinder = (TableItem)Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode((int)StepIdOfBound[2])]; CYLINDRICAL_SURFACE Cylinder_obj = (CYLINDRICAL_SURFACE)Cylinder.node; float radius = (float)Cylinder_obj.radius; //读出底面的 //从STEP文件编号中中实例化出信息 TableItem TEMP_CYL = (TableItem)(Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCircleCenter)]); CARTESIAN_POINT Cylinder_center = (CARTESIAN_POINT)TEMP_CYL.node; TableItem TEMP_CYL_DIR = (TableItem)(Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCylinderDirection)]); DIRECTION Cylinder_dir = (DIRECTION)TEMP_CYL_DIR.node; STLDirection dir_temp; STLDirection dir_temp2; STLPoint point1; STLPoint point2; STLPoint point3; STLTriangle temp_tri1; STLPoint point4; STLTriangle temp_tri2; //条件判断,如果符合一定的特殊情况,那么就开始执行三角剖分 if ((Cylinder_dir.x_dir == 0) && (Cylinder_dir.y_dir == 0) && (Cylinder_dir.z_dir > 0)) { for (int i = 0; i < CircleDivision; ++i) { //建立方向 dir_temp = new STLDirection(); dir_temp.x_dir = (float)Cylinder_center.x_coord + radius * (float)Math.Cos(0.5 * (2 * Math.PI * (i / (float)CircleDivision) + 2 * Math.PI * ((i + 1) / (float)CircleDivision))); dir_temp.y_dir = (float)Cylinder_center.y_coord + radius * (float)Math.Sin(0.5 * (2 * Math.PI * (i / (float)CircleDivision) + 2 * Math.PI * ((i + 1) / (float)CircleDivision))); dir_temp.z_dir = (float)Cylinder_center.z_coord; //以下部分建立第一个三角形 //建立第一个点 point1 = new STLPoint(); point1.x = (float)Cylinder_center.x_coord + radius * (float)Math.Cos(2 * Math.PI * (i / (float)CircleDivision)); point1.y = (float)Cylinder_center.y_coord + radius * (float)Math.Sin(2 * Math.PI * (i / (float)CircleDivision)); point1.z = (float)Cylinder_center.z_coord; //建立第二个点 point2 = new STLPoint(); point2.x = (float)Cylinder_center.x_coord + radius * (float)Math.Cos(2 * Math.PI * ((i + 1) / (float)CircleDivision)); point2.y = (float)Cylinder_center.y_coord + radius * (float)Math.Sin(2 * Math.PI * ((i + 1) / (float)CircleDivision)); point2.z = (float)Cylinder_center.z_coord; //建立第三个点 point3 = new STLPoint(); point3.x = (float)Cylinder_center.x_coord + radius * (float)Math.Cos(2 * Math.PI * (i / (float)CircleDivision)); point3.y = (float)Cylinder_center.y_coord + radius * (float)Math.Sin(2 * Math.PI * (i / (float)CircleDivision)); point3.z = (float)Cylinder_center.z_coord + height; //以下部分建立第二个三角形 //前面有两个点可以共用,因此只用建立起一个点 point4 = new STLPoint(); point4.x = (float)Cylinder_center.x_coord + radius * (float)Math.Cos(2 * Math.PI * ((i + 1) / (float)CircleDivision)); point4.y = (float)Cylinder_center.y_coord + radius * (float)Math.Sin(2 * Math.PI * ((i + 1) / (float)CircleDivision)); point4.z = (float)Cylinder_center.z_coord + height; //将点和方向插入到三角形结构体之中 temp_tri1 = new STLTriangle(); temp_tri1.Dir = dir_temp; temp_tri1.Vertex1 = point1; temp_tri1.Vertex2 = point2; temp_tri1.Vertex3 = point3; STL_menber.Add(temp_tri1); temp_tri2 = new STLTriangle(); temp_tri2.Dir = dir_temp; temp_tri2.Vertex1 = point3; temp_tri2.Vertex2 = point4; temp_tri2.Vertex3 = point2; STL_menber.Add(temp_tri2); } } if ((Cylinder_dir.x_dir == 0) && (Cylinder_dir.y_dir > 0) && (Cylinder_dir.z_dir == 0)) //条件判断,如果符合一定的特殊情况,那么就开始执行三角剖分 { // } if ((Cylinder_dir.x_dir > 0) && (Cylinder_dir.y_dir == 0) && (Cylinder_dir.z_dir == 0)) { // } }
public void DecodeCARTESIAN_POINT()//解码笛卡尔点字符串 { //插入笛卡尔点 TableItem temp = new TableItem(); temp.child = new ArrayList(); StringBuilder reg = new StringBuilder(); //存储所有中间字符串 int i = 0; //循环控制变量 //STEPId解码 while (!Char.IsDigit(this.str_temp[i]))//跳过无用的字符,直接找到数字 { ++i; } while (Char.IsDigit(this.str_temp[i])) { reg.Append(this.str_temp[i]); ++i; } temp.STEPId = int.Parse(reg.ToString()); //无孩子结点,无需解码 //TypeFlag解码 temp.TypeFlag = CARTESIAN_POINT_; //信息节点解码 CARTESIAN_POINT struct_tmp = new CARTESIAN_POINT(); //建立结构体,并将指针赋值给共用体 reg.Clear(); //清空字符串 while (this.str_temp[i] != '\'') //跳过前面的字符,直接读取有效信息 { ++i; } ++i; //读取字符串'XX'里的属性 while (this.str_temp[i] != '\'') { reg.Append(this.str_temp[i]); ++i; } struct_tmp.property = reg.ToString(); reg.Clear(); //读取x坐标信息 while (!Char.IsDigit(this.str_temp[i]) && (this.str_temp[i] != '+') && (this.str_temp[i] != '-') && (this.str_temp[i] != '.'))//跳过无用的字符 { ++i; } while (Char.IsDigit(this.str_temp[i]) || (this.str_temp[i] == '+') || (this.str_temp[i] == '-') || (this.str_temp[i] == '.')) { reg.Append(this.str_temp[i]); ++i; } struct_tmp.x_coord = double.Parse(reg.ToString()); reg.Clear(); //读取y坐标信息 while (!Char.IsDigit(this.str_temp[i]) && (this.str_temp[i] != '+') && (this.str_temp[i] != '-') && (this.str_temp[i] != '.'))//跳过无用的字符 { ++i; } while (Char.IsDigit(this.str_temp[i]) || (this.str_temp[i] == '+') || (this.str_temp[i] == '-') || (this.str_temp[i] == '.')) { reg.Append(this.str_temp[i]); ++i; } struct_tmp.y_coord = double.Parse(reg.ToString()); reg.Clear(); //读取z坐标信息 while (!Char.IsDigit(this.str_temp[i]) && (this.str_temp[i] != '+') && (this.str_temp[i] != '-') && (this.str_temp[i] != '.'))//跳过无用的字符 { ++i; } while (Char.IsDigit(this.str_temp[i]) || (this.str_temp[i] == '+') || (this.str_temp[i] == '-') || (this.str_temp[i] == '.')) { reg.Append(this.str_temp[i]); ++i; } struct_tmp.z_coord = double.Parse(reg.ToString()); reg.Clear(); //将结构体插入到向量里 temp.node = struct_tmp; this.TableNode.Add(temp); }
public void CreatePlaneMesh(int index)//创建平面网格 { //取出对应的STEP元素的索引 int StepIdOfBound = Form1.MainStorage.LookForFirstChildByIndex(index); int StepIdOfLoop = Form1.MainStorage.LookForFirstChild(StepIdOfBound); int StepIdOfOriented = Form1.MainStorage.LookForFirstChild(StepIdOfLoop); int StepIdOfCurve = Form1.MainStorage.LookForFirstChild(StepIdOfOriented); int StepIdOfCircle = Form1.MainStorage.LookForLastChild(StepIdOfCurve); int IndexOfCircle = Form1.MainStorage.LookForNode(StepIdOfCircle); TableItem temp = (TableItem)(Form1.MainStorage.TableNode[IndexOfCircle]); float radius = (float)((CIRCLE)(temp.node)).radius; //读出圆的半径 int StepIdOfCircleAXIS = Form1.MainStorage.LookForFirstChild(StepIdOfCircle); int StepIdOfCirclePoint = Form1.MainStorage.LookForFirstChild(StepIdOfCircleAXIS); //读出圆心 int StepIdOfCircleDirection2 = Form1.MainStorage.LookForLastChild(StepIdOfCircleAXIS); //读出平面的方向2 ArrayList child_temp = Form1.MainStorage.LookForChild(StepIdOfCircleAXIS); int StepIdOfCircleDirection1 = (int)(child_temp[1]); //读出平面方向1 //从STEP文件编号中中实例化出信息 TableItem TEMP_CART = (TableItem)(Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCirclePoint)]); CARTESIAN_POINT circle_center_point = (CARTESIAN_POINT)(TEMP_CART.node); TableItem TEMP_DIR1 = (TableItem)(Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCircleDirection1)]); DIRECTION circle_plane_dir1 = (DIRECTION)(TEMP_DIR1.node); TableItem TEMP_DIR2 = (TableItem)(Form1.MainStorage.TableNode[Form1.MainStorage.LookForNode(StepIdOfCircleDirection2)]); DIRECTION circle_plane_dir2 = (DIRECTION)(TEMP_DIR2.node); //条件判断,如果符合一定的特殊情况,那么就开始执行三角剖分 STLPoint point1; STLPoint point2; STLPoint point3; STLDirection dir_temp; STLTriangle temp_tri; if ((circle_plane_dir1.x_dir == 0) && (circle_plane_dir1.y_dir == 0) && (circle_plane_dir1.z_dir > 0)) { //建立方向 dir_temp = new STLDirection(); dir_temp.x_dir = 0; dir_temp.y_dir = 0; dir_temp.z_dir = 1; for (int i = 0; i < CircleDivision; ++i) { //建立第一个点 point1 = new STLPoint(); point1.x = (float)circle_center_point.x_coord; point1.y = (float)circle_center_point.y_coord; point1.z = (float)circle_center_point.z_coord; //建立第二个点 point2 = new STLPoint(); point2.x = (float)circle_center_point.x_coord + (float)(radius * Math.Cos(2 * Math.PI * (i / (float)CircleDivision))); point2.y = (float)circle_center_point.y_coord + (float)(radius * Math.Sin(2 * Math.PI * (i / (float)CircleDivision))); point2.z = (float)circle_center_point.z_coord; //建立第三个点 point3 = new STLPoint(); point3.x = (float)circle_center_point.x_coord + (float)(radius * Math.Cos(2 * Math.PI * ((i + 1) / (float)CircleDivision))); point3.y = (float)circle_center_point.y_coord + (float)(radius * Math.Sin(2 * Math.PI * ((i + 1) / (float)CircleDivision))); point3.z = (float)circle_center_point.z_coord; //将点和方向插入到三角形结构体之中 temp_tri = new STLTriangle(); temp_tri.Dir = dir_temp; temp_tri.Vertex1 = point1; temp_tri.Vertex2 = point2; temp_tri.Vertex3 = point3; STL_menber.Add(temp_tri); } } if ((circle_plane_dir1.x_dir == 0) && (circle_plane_dir1.y_dir == 0) && (circle_plane_dir1.z_dir < 0)) { //建立方向 dir_temp = new STLDirection(); dir_temp.x_dir = 0; dir_temp.y_dir = 0; dir_temp.z_dir = -1; for (int i = 0; i < CircleDivision; ++i) { //建立第一个点 point1 = new STLPoint(); point1.x = (float)circle_center_point.x_coord; point1.y = (float)circle_center_point.y_coord; point1.z = (float)circle_center_point.z_coord; //建立第二个点 point2 = new STLPoint(); point2.x = (float)circle_center_point.x_coord + (float)(radius * Math.Cos(2 * Math.PI * (i / (float)CircleDivision))); point2.y = (float)circle_center_point.y_coord + (float)(radius * Math.Sin(2 * Math.PI * (i / (float)CircleDivision))); point2.z = (float)circle_center_point.z_coord; //建立第三个点 point3 = new STLPoint(); point3.x = (float)circle_center_point.x_coord + (float)(radius * Math.Cos(2 * Math.PI * ((i + 1) / (float)CircleDivision))); point3.y = (float)circle_center_point.y_coord + (float)(radius * Math.Sin(2 * Math.PI * ((i + 1) / (float)CircleDivision))); point3.z = (float)circle_center_point.z_coord; //将点和方向插入到三角形结构体之中 temp_tri = new STLTriangle(); temp_tri.Dir = dir_temp; temp_tri.Vertex1 = point1; temp_tri.Vertex2 = point2; temp_tri.Vertex3 = point3; STL_menber.Add(temp_tri); } } if ((circle_plane_dir1.x_dir == 0) && (circle_plane_dir1.y_dir != 0) && (circle_plane_dir1.z_dir == 0)) { // } if ((circle_plane_dir1.x_dir != 0) && (circle_plane_dir1.y_dir == 0) && (circle_plane_dir1.z_dir == 0)) { // } }