1.通过四个点创建创建模板组件并形成模板定义。
本例所创建模板如下所示:
创建上图中点、约束、模板组件、模板定义的代码及注释如下:
/// <summary> /// 一个四边形的例子 /// </summary> /// <returns></returns> public static Bentley.CifNET.GeometryModel.SDK.Edit.TemplateDefinition Test_TemplateDefinition() { //test_loadTemplate(); TemplatePointConstraint constraint1_1 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint1_2 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint2_1 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint2_2 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint3_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 0.0, "point_Name2"); TemplatePointConstraint constraint3_2 = new TemplatePointConstraint(ConstraintType.Vertical, -3, "point_Name2"); TemplatePointConstraint constraint4_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 4.0, "point_Name3"); TemplatePointConstraint constraint4_2 = new TemplatePointConstraint(ConstraintType.Slope, 0.02, "point_Name3"); string Point_Name1 = "point_Name1"; string featureName1 = ""; string styleName1 = "Linear\\Rail\\Rail_3D_Line"; double x = 2.0; double y = 2.0; string styleConstraintName = ""; string styleConstraintMode = ""; double styleConstraintRange = 0; TemplatePoint point1 = new TemplatePoint(Point_Name1, featureName1, styleName1, false, x, y, 0, styleConstraintName, styleConstraintMode, styleConstraintRange, constraint1_1, constraint1_2); TemplatePoint point2 = new TemplatePoint("point_Name2", "", "Linear\\Rail\\Rail_3D_Line", false, 4.0, 2.4, 0, "", "", 0, constraint2_1, constraint2_2); TemplatePoint point3 = new TemplatePoint("point_Name3", "", "Linear\\Rail\\Rail_3D_Line", false, 1.5, 0.0, 0, "", "", 0, constraint3_1, constraint3_2); TemplatePoint point4 = new TemplatePoint("point_Name4", "", "Linear\\Rail\\Rail_3D_Line", false, 2.5, 0.0, 0, "0", "0", 0, constraint4_1, constraint4_2); TemplateDefinition templateDef = new TemplateDefinition("TestTemplate"); templateDef.AddPoint(point1); templateDef.AddPoint(point2); templateDef.AddPoint(point3); templateDef.AddPoint(point4); string componentName1 = "Component_name1"; string materialName = "Mesh\\Rail\\TC_Rail 3D"; //Feature TemplateComponent tmpCom1 = new TemplateComponent(componentName1, materialName, TemplateComponentType.Normal, true, "", ""); TemplateVertex vertex1 = new TemplateVertex(point1, 0.0); TemplateVertex vertex2 = new TemplateVertex(point2, 0.0); TemplateVertex vertex3 = new TemplateVertex(point4, 0.0); TemplateVertex vertex4 = new TemplateVertex(point3, 0.0); //Component按照顺序连接每一个Vertex,最终形成组件 tmpCom1.AddVertex(vertex1); tmpCom1.AddVertex(vertex2); tmpCom1.AddVertex(vertex3); tmpCom1.AddVertex(vertex4); templateDef.AddComponent(tmpCom1); templateDef.Compute(false); return templateDef; }
2. 创建带有圆弧的模板
本例所创建含圆弧模板如下图所示:
创建上图中含圆弧模板的代码及注释如下:
/// <summary> /// 创建带圆弧模板两种方式:1.使用切线交点与切线长度。 2.由三点创建一圆弧。 支持圆弧的外凸或内凹 /// </summary> /// <returns></returns> public static Bentley.CifNET.GeometryModel.SDK.Edit.TemplateDefinition Test_Arc_TemplateDefinition() { //test_loadTemplate(); TemplatePointConstraint constraint1_1 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint1_2 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint2_1 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint2_2 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint3_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 0.0, "point_Name2"); TemplatePointConstraint constraint3_2 = new TemplatePointConstraint(ConstraintType.Vertical, -3, "point_Name2"); TemplatePointConstraint constraint4_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 4.0, "point_Name3"); TemplatePointConstraint constraint4_2 = new TemplatePointConstraint(ConstraintType.Slope, 0.02, "point_Name3"); string Point_Name1 = "point_Name1"; string featureName1 = ""; string styleName1 = "Linear\\Rail\\Rail_3D_Line"; double x = 2.0; double y = 2.0; string styleConstraintName = ""; string styleConstraintMode = ""; double styleConstraintRange = 0; TemplatePoint point1 = new TemplatePoint(Point_Name1, featureName1, styleName1, false, x, y, 0, styleConstraintName, styleConstraintMode, styleConstraintRange, constraint1_1, constraint1_2); TemplatePoint point2 = new TemplatePoint("point_Name2", "", "Linear\\Rail\\Rail_3D_Line", false, 4.0, 2.0, 0, "", "", 0, constraint2_1, constraint2_2); TemplatePoint point3 = new TemplatePoint("point_Name3", "", "Linear\\Rail\\Rail_3D_Line", false, 1.5, 0.0, 0, "", "", 0, constraint3_1, constraint3_2); TemplatePoint point4 = new TemplatePoint("point_Name4", "", "Linear\\Rail\\Rail_3D_Line", false, 2.5, 0.0, 0, "0", "0", 0, constraint4_1, constraint4_2); TemplatePoint point5 = new TemplatePoint("point_Name5", "", "Linear\\Rail\\Rail_3D_Line", false, 5.5, -0.5, 0, "0", "0", 0, null, null); TemplateDefinition templateDef = new TemplateDefinition("TestTemplate"); templateDef.AddPoint(point1); templateDef.AddPoint(point2); templateDef.AddPoint(point3); templateDef.AddPoint(point4); templateDef.AddPoint(point5); string componentName1 = "Component_name1"; string materialName = "Mesh\\Rail\\TC_Rail 3D"; //Feature TemplateComponent tmpCom1 = new TemplateComponent(componentName1, materialName, TemplateComponentType.Normal, true, "", ""); TemplateVertex vertex1 = new TemplateVertex(point1, 0.0); double tangentLength = 0.5; TemplateVertex vertex2 = new TemplateVertex(point2, tangentLength); //point2为顶点的两个边与圆弧相切,切点与point2的距离(tangentLength)为0.5。 TemplateVertex vertex3 = new TemplateVertex(point4, 0.0, point5); //两点间(vertex3->vertex4:由AddVertex的顺序决定)插入圆弧,且圆弧过点point5。 TemplateVertex vertex4 = new TemplateVertex(point3, 0.0); //Component按照顺序连接每一个Vertex,最终形成组件 tmpCom1.AddVertex(vertex1); tmpCom1.AddVertex(vertex2); tmpCom1.AddVertex(vertex3); tmpCom1.AddVertex(vertex4); templateDef.AddComponent(tmpCom1); templateDef.Compute(false); return templateDef; }
3. 创建末端条件
本例创建的末端约束如下图所示:
创建上图中末端约束的代码及注释如下:
/// <summary> /// 创建末端约束 /// </summary> /// <returns></returns> public static Bentley.CifNET.GeometryModel.SDK.Edit.TemplateDefinition Test_EndCondition_TemplateDefinition() { //test_loadTemplate(); TemplatePointConstraint constraint1_1 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint1_2 = null; //不设置约束的方式1:设置为null TemplatePointConstraint constraint2_1 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint2_2 = new TemplatePointConstraint(ConstraintType.None, 0, "");//不设置约束的方式2:设置为ConstraintType.None TemplatePointConstraint constraint3_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 1.0, "point_Name2"); TemplatePointConstraint constraint3_2 = new TemplatePointConstraint(ConstraintType.Vertical, 3, "point_Name2"); TemplatePointConstraint constraint4_1 = new TemplatePointConstraint(ConstraintType.Horizontal, 4.0, "point_Name3"); TemplatePointConstraint constraint4_2 = new TemplatePointConstraint(ConstraintType.Slope, 0.6, "point_Name3"); string Point_Name1 = "point_Name1"; string featureName1 = ""; string styleName1 = "Linear\\Rail\\Rail_3D_Line"; double x = 2.0; double y = 2.0; string styleConstraintName = ""; string styleConstraintMode = ""; double styleConstraintRange = 0; TemplatePoint point1 = new TemplatePoint(Point_Name1, featureName1, styleName1, false, x, y, 0, styleConstraintName, styleConstraintMode, styleConstraintRange, constraint1_1, constraint1_2); TemplatePoint point2 = new TemplatePoint("point_Name2", "", "Linear\\Rail\\Rail_3D_Line", false, 4.0, 2.0, 0, "", "", 0, constraint2_1, constraint2_2); TemplatePoint point3 = new TemplatePoint("point_Name3", "", "Linear\\Rail\\Rail_3D_Line", false, 1.5, 0.0, 0, "", "", 0, constraint3_1, constraint3_2); TemplatePoint point4 = new TemplatePoint("point_Name4", "", "Linear\\Rail\\Rail_3D_Line", false, 2.5, 0.0, 0, "0", "0", 0, constraint4_1, constraint4_2); //设置末端条件属性 point1.SeekIntersection = true; point1.PlacePointAtIntersection = true; point2.SeekIntersection = true; point2.PlacePointAtIntersection = true; point3.SeekIntersection = true; point3.PlacePointAtIntersection = true; point4.SeekIntersection = true; point4.PlacePointAtIntersection = true; point4.InfinteWidth = true; TemplateDefinition templateDef = new TemplateDefinition("TestTemplate"); //templateDef.BeginEndConditionComponent("EndCondition1", "Mesh\\Rail\\TC_Rail 3D"); templateDef.AddPoint(point1); templateDef.AddPoint(point2); templateDef.AddPoint(point3); templateDef.AddPoint(point4); string componentName1 = "Component_name1"; string materialName = "Mesh\\Rail\\TC_Rail 3D"; //Feature TemplateComponent tmpCom1 = new TemplateComponent(componentName1, materialName, TemplateComponentType.EndCondition, false, "", ""); TemplateVertex vertex1 = new TemplateVertex(point1, 0.0); TemplateVertex vertex2 = new TemplateVertex(point2, 0.0); TemplateVertex vertex3 = new TemplateVertex(point3, 0.0); TemplateVertex vertex4 = new TemplateVertex(point4, 0.0); tmpCom1.AddVertex(vertex1); tmpCom1.AddVertex(vertex2); tmpCom1.AddVertex(vertex3); tmpCom1.AddVertex(vertex4); templateDef.AddComponent(tmpCom1); //templateDef.FinishAddComponent(); templateDef.Compute(false); return templateDef; }