Esempio n. 1
0
        private bool processInput(out PenetrUserTask userTask,
                                  ref BCOM.Point3d Point, BCOM.View View)
        {
            BCOM.Point3d point = Point;
            ensureLocateEnabled(ref point, View);

            userTask = singleModel_.UserTask;

            if (string.IsNullOrEmpty(userTask.Code))
            {
                return(false);
            }

            BCOM.HitPath hitPath = App.CommandState.GetHitPath();
            if (!userTask.IsManualRotateMode && hitPath != null)
            {
                BCOM.Element firstHitElem = hitPath.GetElementAt(1);
                //int type1 = (int)firstHitElem.Type;

                if (firstHitElem.IsPlanarElement())
                {
                    userTask.Rotation = App.Matrix3dFromRotationBetweenVectors(
                        ZAxis, firstHitElem.AsPlanarElement().Normal);
                }
                else
                {
                    // TODO обход по поверхностям

                    var targetFaces = new List <TFCOM.TFBrepFace>();

                    TFCOM.TFBrepList brepList = AppTF.CreateTFBrep();

                    try
                    {
                        // может быть исключение
                        brepList.InitFromElement(firstHitElem, App.ActiveModelReference);
                    }
                    catch (Exception)
                    {
                    }

                    foreach (TFCOM.TFBrepFace faceList in brepList?.GetFacesEx())
                    {
                        TFCOM.TFPlane tfPlane;
                        if (faceList.IsPlanar(out tfPlane))
                        {
                            //BCOM.ShapeElement shapeElement;

                            //BCOM.Point3d[] verts;
                            //faceList.AsTFBrepFace.GetVertexLocations(out verts);
                            //BCOM.ShapeElement shape = App.CreateShapeElement1(null, verts);

                            BCOM.Point3d closest;
                            BCOM.Point3d normal;
                            BCOM.Point2d param;
                            // faceList.GetClosestPoint(out closest, out normal, out param, ref Point);

                            tfPlane.GetNormal(out normal);

                            if (faceList as TFCOM.TFBrepFaceListClass != null)
                            {
                                normal = App.Point3dNegate(normal);
                            }

                            userTask.Rotation = App.Matrix3dFromRotationBetweenVectors(
                                ZAxis, normal);

                            break;

                            //if (closest.EqualsPoint(Point))
                            //{
                            //    targetFaces.Add(faceList);
                            //}
                        }
                    }

                    ;
                }
            }

            if (userTask.IsAutoLength)
            {
                double thickness = 0.0;

                BCOM.Element locEl = app_.CommandState.LocateElement(ref Point, View, true);

                if (locEl != null && locEl.IsCellElement())
                {
                    TFCOM.TFElementList tfList = AppTF.CreateTFElement();
                    tfList.InitFromElement(locEl);

                    int type = tfList.AsTFElement.GetApplicationType();

                    if (tfList.AsTFElement.GetIsFormType())
                    {
                        TFCOM._TFFormRecipeList recipeList;
                        tfList.AsTFElement.GetFormRecipeList(out recipeList);

                        if (type == (int)TFFormTypeEnum.TF_SLAB_FORM_ELM)
                        {
                            var slab = (TFCOM.TFFormRecipeSlabList)recipeList;

                            slab.AsTFFormRecipeSlab.GetThickness(out thickness);
                        }
                        else if (type == (int)TFFormTypeEnum.TF_LINEAR_FORM_ELM)
                        {
                            var wall = (TFCOM.TFFormRecipeLinearList)recipeList;
                            wall.AsTFFormRecipeLinear.GetThickness(out thickness);
                        }
                    }
                }

                if (thickness > 0.0)
                {
                    userTask.LengthCm = (int)Math.Ceiling(thickness) / 10;
                }
                else
                {
                    userTask.LengthCm = 1;
                }
            }

            singleModel_.setLocation(point); // для обновления формы
            return(true);
        }