Example #1
0
        private void OnSelectElement(SelectionChangeArgs args)
        {
            if (!args.IsHighlightMode())
            {
                SelectedShapeQuery query = new SelectedShapeQuery();
                renderView.QuerySelection(query);
                var ids = query.GetIds();
                if (ids.Length > 0)
                {
                    var shape = query.GetGeometry();

                    if (shape != null)
                    {
                        GeomCurve curve = new GeomCurve();
                        if (curve.Initialize(shape))
                        {
                            TopoShapeProperty property = new TopoShapeProperty();
                            property.SetShape(shape);
                            var str = String.Format("Length:{0}", property.EdgeLength());
                            toolStripStatusLabel2.Text = str;

                            return;
                        }
                    }
                }
                else
                {
                    toolStripStatusLabel2.Text = "";
                }
            }
        }
Example #2
0
        private void TransOnMaxBtn_Click(object sender, EventArgs e)
        {
            SelectedShapeQuery context = new SelectedShapeQuery();

            renderView.QuerySelection(context);
            var shape = context.GetGeometry();

            TransOnMax(shape);
        }
Example #3
0
 private void OnSelectElement(SelectionChangeArgs args)
 {
     if (!args.IsHighlightMode())
     {
         SelectedShapeQuery query = new SelectedShapeQuery();
         renderView.QuerySelection(query);
         var shape = query.GetGeometry();
         if (shape != null)
         {
             GeomCurve curve = new GeomCurve();
             if (curve.Initialize(shape))
             {
                 TopoShapeProperty property = new TopoShapeProperty();
                 property.SetShape(shape);
                 Console.WriteLine("Edge Length {0}", property.EdgeLength());
             }
         }
     }
 }
Example #4
0
        private void BtnDown_Click(object sender, EventArgs e)
        {
            //Get selected shape
            SelectedShapeQuery context = new SelectedShapeQuery();

            renderViewDraw.QuerySelection(context);
            var face = context.GetGeometry();
            var line = context.GetSubGeometry();

            if (face == null || line == null)
            {
                return;
            }
            if (face.GetShapeType() != EnumTopoShapeType.Topo_FACE || line.GetShapeType() != EnumTopoShapeType.Topo_EDGE)
            {
                return;
            }

            //记录输入参数
            Bending bending = new Bending()
            {
                Direction = EnumDir.Edge_DOWN,
                Angle     = Convert.ToDouble(txtAngle.Text),
                Radius    = Convert.ToDouble(txtRadius.Text),
                Length    = Convert.ToDouble(txtLength.Text)
            };
            GeomCurve curve = new GeomCurve();

            curve.Initialize(line);
            Vector3 dirL = curve.DN(curve.FirstParameter(), 1);

            if (dirL.Y >= 0)
            {
                bending.Orientation = Math.Round(dirL.AngleBetween(Vector3.UNIT_X), 3);
            }
            else
            {
                bending.Orientation = Math.Round(360 - dirL.AngleBetween(Vector3.UNIT_X), 3);
            }
            //if (dirL.X == 1)
            //{
            //    bending.Orientation = EnumEdge.Edge_1;
            //}
            //else if (dirL.Y == 1)
            //{
            //    bending.Orientation = EnumEdge.Edge_2;
            //}
            //else if (dirL.X == -1)
            //{
            //    bending.Orientation = EnumEdge.Edge_3;
            //}
            //else
            //{
            //    bending.Orientation = EnumEdge.Edge_4;
            //}

            TopoShape sweep = BendDown(face, line, bending).Sweep;

            bendings.Add(bending);

            #region 渲染
            ElementId    faceId   = new ElementId(bending.Index + shapeId);
            ElementId    edgeId   = new ElementId(bending.Index);
            SceneManager sceneMgr = renderViewDraw.SceneManager;
            SceneNode    rootNode = GlobalInstance.TopoShapeConvert.ToSceneNode(sweep, 0.1f);
            SceneNode    faceNode = GlobalInstance.TopoShapeConvert.ToSceneNode(face, 0.1f);
            SceneNode    edgeNode = GlobalInstance.TopoShapeConvert.ToSceneNode(line, 0.1f);
            faceNode.SetId(faceId);
            faceNode.SetVisible(false);
            edgeNode.SetId(edgeId);
            edgeNode.SetVisible(false);
            if (rootNode != null)
            {
                sceneMgr.AddNode(rootNode);
                sceneMgr.AddNode(faceNode);
                sceneMgr.AddNode(edgeNode);
            }
            renderViewDraw.FitAll();
            renderViewDraw.RequestDraw(EnumRenderHint.RH_LoadScene);

            #endregion
        }
Example #5
0
        private void TransOnSelectBtn_Click(object sender, EventArgs e)
        {
            //Get selected shape
            SelectedShapeQuery context = new SelectedShapeQuery();

            renderView.QuerySelection(context);
            var shape = context.GetGeometry();
            var face  = context.GetSubGeometry();

            if (shape == null)
            {
                return;
            }
            var center = shape.GetBBox().GetCenter();

            #region 计算法向量
            GeomSurface surface = new GeomSurface();
            surface.Initialize(face);
            //参数域UV范围
            double uFirst = surface.FirstUParameter();
            double uLast  = surface.LastUParameter();
            double vFirst = surface.FirstVParameter();
            double vLast  = surface.LastVParameter();
            //取中点
            double umid = uFirst + (uLast - uFirst) * 0.5f;
            double vmid = vFirst + (vLast - vFirst) * 0.5f;
            //计算法向量
            var     data = surface.D1(umid, vmid);
            Vector3 dirU = data[1];
            Vector3 dirV = data[2];
            Vector3 dir  = dirV.CrossProduct(dirU);
            dir.Normalize();
            Console.WriteLine("\tDir {0}", dir);
            #endregion

            #region 坐标变换
            Vector3 dirN = new Vector3();
            if (face.GetOrientation() == EnumShapeOrientation.ShapeOrientation_REVERSED)
            {
                dirN = dir * -1;
            }
            else
            {
                dirN = dir;
            }

            //Translation
            shape = GlobalInstance.BrepTools.Translate(shape, -center);
            //Rotation
            Vector3 dirZ = new Vector3(0, 0, -1);
            shape = GlobalInstance.BrepTools.Rotation(shape, dirN.CrossProduct(dirZ), dirN.AngleBetween(dirZ));
            #endregion

            #region Render
            if (shape != null)
            {
                topoShape = shape;
                renderView.ClearScene();
                renderView.ShowGeometry(shape, shapeId);
            }
            renderView.FitAll();
            renderView.RequestDraw(EnumRenderHint.RH_LoadScene);

            #endregion
        }