Exemplo n.º 1
0
//#define FILEPOS_EOF                     0
//#define FILEPOS_CURRENT                 1
//#define FILEPOS_FIRST_ELE               2
//#define FILEPOS_NEXT_ELE                3
//#define FILEPOS_WORKING_SET             4
//#define FILEPOS_COMPONENT               5
//#define FILEPOS_NEXT_NEW_ELEMENT        6

        private void btnAddToModel_Click(object sender, EventArgs e)
        {
            previewTranContainer.Reset();

            BCOM.Level     activeLevel      = Addin.App.ActiveSettings.Level;
            BCOM.LineStyle activeLineStyle  = Addin.App.ActiveSettings.LineStyle;
            int            activeLineWeight = Addin.App.ActiveSettings.LineWeight;
            int            activeColor      = Addin.App.ActiveSettings.Color;

            var activeModel = Addin.App.ActiveModelReference;

            try
            {
                foreach (var pair in getFramesData())
                {
                    TFCOM.TFFrameList frameList = pair.Key;
                    PenetrTask        task      = pair.Value;

                    {
                        // ! без этого кода не срабатывает перфорация в стенке/плите
                        // судя по всему инициализирует обновление объектов, с которыми
                        // взаимодействует frame

                        Addin.AppTF.ModelReferenceUpdateAutoOpeningsByFrame(
                            activeModel, frameList.AsTFFrame, true, false,
                            TFCOM.TFdFramePerforationPolicy.tfdFramePerforationPolicyNone);
                    }
                    // добавление в модель
                    Addin.AppTF.ModelReferenceAddFrameList(
                        Addin.App.ActiveModelReference, frameList);

                    BCOM.Element newElement = activeModel.GetLastValidGraphicalElement();
                    setDataGroupInstance(newElement, task);

                    { // TODO ОТЛАДКА:
                      //XmlInstanceSchemaManager modelSchema =
                      //        new XmlInstanceSchemaManager((IntPtr)newElement.ModelReference.MdlModelRefP());

                        //    XmlInstanceApi api = XmlInstanceApi.CreateApi(modelSchema);
                        //    IList<string> instances = api.ReadInstances((IntPtr)newElement.MdlElementRef());

                        //    foreach (string inst in instances)
                        //    {
                        //        string instId = XmlInstanceApi.GetInstanceIdFromXmlInstance(inst);
                        //    }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ShowMessage();
            }
            finally
            {
                Addin.App.ActiveSettings.Level      = activeLevel;
                Addin.App.ActiveSettings.LineStyle  = activeLineStyle;
                Addin.App.ActiveSettings.LineWeight = activeLineWeight;
                Addin.App.ActiveSettings.Color      = activeColor;
            }
        }
Exemplo n.º 2
0
 public static void AddToModel(this TFCOM.TFFrameList frameList,
                               BCOM.ModelReference model = null)
 {
     model = model ?? App.ActiveModelReference;
     AppTF.ModelReferenceAddFrameList(App.ActiveModelReference, frameList);
     frameList.ForceRedrawPerforator();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Форсируем обновление для уверенности в пробитии отверстия перфоратора в стене/плите/...
        /// </summary>
        public static void ForceRedrawPerforator(this TFCOM.TFFrameList frameList)
        {
            // ! 1.предварительная трансформация "на месте"
            var    tranIdentity = App.Transform3dIdentity();
            string emptyOption  = string.Empty;

            frameList.Transform(tranIdentity, true, emptyOption);
            // ! 2. обновление перфоратора
            frameList.ApplyPerforatorInModel();
            // ! 3. перезапись
            AppTF.ModelReferenceRewriteFrame(App.ActiveModelReference, frameList.AsTFFrame);
        }
Exemplo n.º 4
0
        Dictionary <TFCOM.TFFrameList, PenetrTask> getFramesData()
        {
            var res = new Dictionary <TFCOM.TFFrameList, PenetrTask>();

            foreach (DataGridViewRow row in dgvFields.Rows)
            {
                PenetrTask        task      = (PenetrTask)row.DataBoundItem;
                TFCOM.TFFrameList frameList = createFrameList(task);

                if (frameList != null) // TODO исключение?
                {
                    res.Add(frameList, task);
                }
            }
            return(res);
        }
Exemplo n.º 5
0
        TFCOM.TFFrameList createFrameList(PenetrTask task)
        {
            BCOM.Level level     = ElementHelper.getOrCreateLevel(PenetrTask.LEVEL_NAME);
            BCOM.Level levelSymb =
                ElementHelper.getOrCreateLevel(PenetrTask.LEVEL_SYMB_NAME);
            BCOM.Level levelRefPoint =
                ElementHelper.getOrCreateLevel(PenetrTask.LEVEL_POINT_NAME);

            long       diamIndex = DiameterType.Parse(task.DiameterTypeStr).number;
            PenetrInfo penInfo   = penData.getPenInfo(task.FlangesType, diamIndex);

            TFCOM.TFFrameList frameList =
                PenetrHelper.createFrameList(task, penInfo, level);

            PenetrHelper.addProjection(ref frameList,
                                       task, penInfo, levelSymb, levelRefPoint);

            // TODO видимость контура перфоратора можно в конфиг. переменную
            PenetrHelper.addPerforator(ref frameList, task, penInfo, levelSymb, false);

            return(frameList);
        }
Exemplo n.º 6
0
        public static void AddProjection(this TFCOM.TFFrameList frameList,
                                         BCOM.Element element, string projectionName, BCOM.Level level)
        {
            TFCOM.TFProjectionList tfProjection = AppTF.CreateTFProjection((string)null);
            tfProjection.Init();
            element.Level = level;

            ElementHelper.setSymbologyByLevel(element);
            tfProjection.AsTFProjection.SetDefinitionName(projectionName);
            tfProjection.AsTFProjection.SetEmbeddedElement(element);
            tfProjection.AsTFProjection.SetIsDoubleSided(true);

            TFCOM.TFProjectionList projectionList = frameList.AsTFFrame.GetProjectionList();
            if (projectionList == null)
            {
                frameList.AsTFFrame.SetProjectionList(tfProjection);
            }
            else
            {
                projectionList.Append(tfProjection);
            }
        }
Exemplo n.º 7
0
        //public static TFCOM.TFFrameListClass createFrameList(
        //    PenetrTaskBase task, PenetrInfo penInfo, BCOM.Level level)
        //{
        //    var taskUOR = new UOR(App.ActiveModelReference);

        //    double pipeInsideDiam = penInfo.pipeDiameterInside / taskUOR.activeSubPerMaster;
        //    double pipeOutsideDiam = penInfo.pipeDiameterOutside / taskUOR.activeSubPerMaster;

        //    double flangeInsideDiam = penInfo.flangeDiameterInside / taskUOR.activeSubPerMaster;
        //    double flangeOutsideDiam = penInfo.flangeDiameterOutside / taskUOR.activeSubPerMaster;
        //    double flangeThick = penInfo.flangeThick / taskUOR.activeSubPerMaster;

        //    double length = task.LengthCm *10 / taskUOR.activeSubPerMaster;

        //    var solids = App.SmartSolid;

        //    /*
        //        ! длина трубы меньше размера проходки на толщину фланца
        //        ! ЕСЛИ ФЛАНЕЦ ЕСТЬ
        //    */

        //    // BCOM.Element template = App.createPointElement();

        //    double delta = task.FlangesCount == 0 ? 0 :
        //        task.FlangesCount * flangeThick / 2;

        //    BCOM.SmartSolidElement cylindrInside =
        //        solids.CreateCylinder(null, pipeInsideDiam / 2, length - delta);

        //    BCOM.SmartSolidElement cylindrOutside =
        //        solids.CreateCylinder(null, pipeOutsideDiam / 2, length - delta);

        //    var cylindr = solids.SolidSubtract(cylindrOutside, cylindrInside);

        //    var elements = new Dictionary<BCOM.Element, double>();
        //    //elements.Add(cylindrInside, 0);

        //    {
        //        double shift  = task.FlangesCount == 1 ? delta : 0;
        //        shift *= 1;
        //        elements.Add(cylindr, (length + shift)/2);
        //    }

        //    // Фланцы:
        //    for (int i = 0; i < task.FlangesCount; ++i)
        //    {
        //        BCOM.SmartSolidElement flangeCylindr = solids.SolidSubtract(
        //            solids.CreateCylinder(null, flangeOutsideDiam / 2, flangeThick),
        //            solids.CreateCylinder(null, pipeOutsideDiam / 2, flangeThick));

        //        double shift = 0;
        //        if (task.FlangesCount == 1)
        //        {
        //            //bool isNearest = App.Vector3dEqualTolerance(task.singleFlangeSide,
        //            //    App.Vector3dFromXYZ(0, 0, -1), 0.1); // 0.001

        //            bool isNearest = true;

        //            // 0.5 - для видимости фланцев на грани стены/плиты
        //            shift = isNearest ?
        //                    0.0    + flangeThick / 2 - task.FlangeWallOffset:
        //                    length - flangeThick / 2 + task.FlangeWallOffset;
        //        }
        //        else
        //        {
        //            shift = i == 0 ? 0.0 : length;
        //            // для самих фланцев:
        //            // 0.5 - для видимости фланцев на грани стены/плиты
        //            shift += Math.Pow(-1, i) * (flangeThick/2 - task.FlangeWallOffset); //0.02);
        //        }
        //        elements.Add(flangeCylindr, shift);
        //    }

        //    BCOM.Transform3d taskTran = App.Transform3dFromMatrix3d(task.Rotation);

        //    //double aboutX, aboutY, aboutZ;
        //    //task.getCorrectiveAngles(out aboutX, out aboutY, out aboutZ);

        //    TFCOM.TFFrameListClass frameList = new TFCOM.TFFrameListClass();

        //    foreach (var pair in elements)
        //    {
        //        BCOM.Element elem = pair.Key;
        //        double shift = pair.Value;

        //        // elem.Color = 0; // TODO
        //        BCOM.Point3d offset = App.Point3dAddScaled(
        //            App.Point3dZero(), App.Point3dFromXYZ(0, 0, 1), shift);
        //        elem.Move(offset);

        //        //elem.Rotate(App.Point3dZero(), aboutX, aboutY, aboutZ);

        //        elem.Transform(taskTran);
        //        elem.Move(task.Location);

        //        //elem.Level = level;
        //        //ElementHelper.setSymbologyByLevel(elem);

        //        // frameList.AsTFFrame.Add3DElement(elem);
        //        frameList.Add3DElement(elem);
        //    }

        //    //frameList.SetName(PenetrVueTask.CELL_NAME); // ранее было 'EmbeddedPart'
        //    return frameList;
        //}


        public static void addProjection(
            TFCOM.TFFrameList frame, IPenetrTask task, PenetrInfo penInfo)
        {
            var taskUOR = new UOR(task.ModelRef);

            double pipeInsideDiam  = penInfo.pipeDiameterInside / taskUOR.activeSubPerMaster;
            double pipeOutsideDiam = penInfo.pipeDiameterOutside / taskUOR.activeSubPerMaster;

            double flangeInsideDiam  = penInfo.flangeDiameterInside / taskUOR.activeSubPerMaster;
            double flangeOutsideDiam = penInfo.flangeDiameterOutside / taskUOR.activeSubPerMaster;
            double flangeThick       = penInfo.flangeThick / taskUOR.activeSubPerMaster;
            double length            = task.LengthCm * 10 / taskUOR.activeSubPerMaster;

            App.Point3dZero();
            frame.AddProjection(ElementHelper.createCrossRound(pipeInsideDiam)
                                .transformByTask(task), "cross", PenetrTaskBase.LevelSymb);
            frame.AddProjection(ElementHelper.createCircle(pipeInsideDiam)
                                .transformByTask(task), "circle", PenetrTaskBase.LevelSymb);
            frame.AddProjection(ElementHelper.createCrossRound(pipeInsideDiam)
                                .transformByTask(task, shiftZ: length), "cross", PenetrTaskBase.LevelSymb);
            frame.AddProjection(ElementHelper.createCircle(pipeInsideDiam)
                                .transformByTask(task, shiftZ: length), "circle", PenetrTaskBase.LevelSymb);
            if (task.FlangesCount > 0)
            {
                frame.AddProjection(ElementHelper.createCircle(flangeOutsideDiam).
                                    transformByTask(task, 0.0, 0.0, -task.FlangeWallOffset),
                                    "flange", PenetrTaskBase.LevelFlangeSymb);

                if (task.FlangesCount == 2)
                {
                    frame.AddProjection(ElementHelper.createCircle(flangeOutsideDiam).
                                        transformByTask(task, 0.0, 0.0, length + task.FlangeWallOffset),
                                        "flange", PenetrTaskBase.LevelFlangeSymb);
                }
            }
            frame.AddProjection(ElementHelper.createPoint().transformByTask(task),
                                "refPoint", PenetrTaskBase.LevelRefPoint);
        }
Exemplo n.º 8
0
 /// <summary>
 /// без этого кода не срабатывает перфорация в стенке/плите
 /// судя по всему инициализирует обновление объектов, с которыми
 /// взаимодействует frame
 /// </summary>
 public static void ApplyPerforatorInModel(this TFCOM.TFFrameList frameList)
 {
     AppTF.ModelReferenceUpdateAutoOpeningsByFrame(
         App.ActiveModelReference, frameList.AsTFFrame, true, false,
         TFCOM.TFdFramePerforationPolicy.tfdFramePerforationPolicyNone);
 }
Exemplo n.º 9
0
        public static void addToModelWithProjAndPerfo(ref TFCOM.TFFrameList frameList,
                                                      PenetrTask task, PenetrInfo penInfo,
                                                      BCOM.Level levelSymb, BCOM.Level levelRefPoint)
        {
            var taskUOR = new UOR(task.modelRef);

            double pipeInsideDiam  = penInfo.pipeDiameterInside / taskUOR.active_subPerMaster;
            double pipeOutsideDiam = penInfo.pipeDiameterOutside / taskUOR.active_subPerMaster;

            double flangeInsideDiam  = penInfo.flangeDiameterInside / taskUOR.active_subPerMaster;
            double flangeOutsideDiam = penInfo.flangeDiameterOutside / taskUOR.active_subPerMaster;
            double flangeThick       = penInfo.flangeThick / taskUOR.active_subPerMaster;

            double length = task.LengthCm * 10 / taskUOR.active_subPerMaster;

            BCOM.ModelReference activeModel = App.ActiveModelReference;
            //AppTF.ModelReferenceAddFrameList(activeModel, ref frameList);

            frameList.Synchronize();
            var frameListClass = frameList as TFCOM.TFFrameListClass;

            BCOM.Element bcomElem;
            frameListClass.GetElement(out bcomElem);

            var tfApi    = new Bentley.Building.Api.TFApplicationList().AsTFApplication;
            var modelRef = Session.Instance.GetActiveDgnModelRef();
            var model    = Session.Instance.GetActiveDgnModel();

            Element ielement = Element.GetFromElementRef((IntPtr)bcomElem.MdlElementRef());

            modelRef.GetFromElementRef((IntPtr)bcomElem.MdlElementRef());

            ITFFrameList iframeList;

            tfApi.CreateTFFrame(0, out iframeList);
            iframeList.InitFromElement(ielement, "");
            iframeList.Synchronize("");

            DPoint3d origin = task.Location.ToDPoint();

            origin.ScaleInPlace(taskUOR.active_perMaster);

            DMatrix3d matrix = DMatrix3d.FromRows(
                task.Rotation.RowX.ToDVector(), task.Rotation.RowY.ToDVector(),
                task.Rotation.RowZ.ToDVector());

            DTransform3d  dTran    = DTransform3d.FromMatrixAndTranslation(matrix, origin);
            TransformInfo tranInfo = new TransformInfo(dTran);

            double pipeInsideRadius = pipeOutsideDiam / 2 * taskUOR.active_perMaster;
            double dgnLength        = length * taskUOR.active_perMaster;

            var ellips = new EllipseElement(model, null,
                                            DEllipse3d.FromCenterRadiusNormal(DPoint3d.Zero, pipeInsideRadius,
                                                                              DVector3d.FromXY(0, 1)));

            ellips.ApplyTransform(tranInfo);



            //{  // ПЕРФОРАТОР:
            //    ITFPerforatorList perfoList;
            //    tfApi.CreateTFPerforator(0, out perfoList);
            //    var dir = DVector3d.FromXY(1, 0);
            //    var tran = DTransform3d.Identity;
            //    //perfoList.InitFromElement(ellips, ref dir, length*toUOR, ref tran, "");
            //    perfoList.InitFromElement2(ellips, length*taskUOR.active_perMaster, "");
            //    perfoList.AsTFPerforator.SetIsVisible(false, 0);
            //    perfoList.SetSweepMode(Bentley.Building.Api.TFdPerforatorSweepMode.tfdPerforatorSweepModeBi, "");
            //    perfoList.SetPolicy(Bentley.Building.Api.TFdPerforatorPolicy.tfdPerforatorPolicyThroughHoleWithinSenseDist, "");

            //    (iframeList as Bentley.Building.Api.TFFrameList).SetPerforatorList(ref perfoList, 0);

            //   // iframeList.AsTFFrame.SetPerforatorList(ref perfoList, 0);
            //    iframeList.AsTFFrame.SetSenseDistance2(length, 0);
            //    iframeList.AsTFFrame.SetPerforatorsAreActive(true, 0);
            //        var frame = iframeList.AsTFFrame;
            //    tfApi.ModelReferenceUpdateAutoOpeningsByFrame(modelRef,
            //ref frame, true, false, Bentley.Building.Api.TFdFramePerforationPolicy.tfdFramePerforationPolicyStrict, 0);

            //}



            // tfApi.ModelReferenceRewriteFrameInstance(modelRef, iframeList.AsTFFrame, 0);
            //iframeList.AsTFFrame.Synchronize(0);

            { // ПРОЕКЦИОННАЯ ГЕОМЕТРИЯ
                ITFProjectionList projList, projList1, projList2, projList3;
                tfApi.CreateTFProjection(0, out projList);
                tfApi.CreateTFProjection(0, out projList1);
                tfApi.CreateTFProjection(0, out projList2);
                tfApi.CreateTFProjection(0, out projList3);

                var        zero  = DPoint3d.Zero;
                DPoint3d[] verts = { zero, zero, zero, zero, zero };
                double     k     = pipeInsideRadius * Math.Cos(Math.PI / 4);
                verts[0].X  = -k;
                verts[0].Z  = -k;
                verts[1].X  = k;
                verts[1].Z  = k;
                verts[3]    = verts[0];
                verts[3].Z *= -1;
                verts[4]    = verts[1];
                verts[4].Z *= -1;

                LineStringElement cross1 = new LineStringElement(model, null, verts);
                for (int i = 0; i < verts.Count(); ++i)
                {
                    verts[i].Y = dgnLength;
                }
                LineStringElement cross2 = new LineStringElement(model, null, verts);

                cross1.ApplyTransform(tranInfo);
                cross2.ApplyTransform(tranInfo);

                projList1.AsTFProjection.SetEmbeddedElement(cross1, 0);
                projList2.AsTFProjection.SetEmbeddedElement(cross2, 0);

                LineElement refPoint =
                    new LineElement(model, null, new DSegment3d(zero, zero));

                refPoint.ApplyTransform(tranInfo);
                ElementPropertiesSetter setter = new ElementPropertiesSetter();
                setter.SetWeight(7);
                setter.Apply(refPoint);

                projList3.AsTFProjection.SetEmbeddedElement(refPoint, 0);

                projList.Append(projList1, "");
                projList.Append(projList2, "");
                projList.Append(projList3, "");
                iframeList.AsTFFrame.SetProjectionList(projList, 0);
                //iframeList.AsTFFrame.Synchronize(0);
                //iframeList.Synchronize(string.Empty);
            }

            tfApi.ModelReferenceRewriteFrameInstance(modelRef, iframeList.AsTFFrame, 0);

            //  int stat = tfApi.ModelReferenceRewriteFrameList(modelRef, iframeList, 0);
            //tfApi.ModelReferenceAddFrameList(modelRef, ref iframeList, 0);


            //    tfApi.ModelReferenceRewriteFrameList(modelRef, iframeList, 0);



            //frameListClass = frameList as TFCOM.TFFrameListClass;
            //frameListClass.GetElement(out bcomElem);

            // setDataGroupInstance(bcomElem, task);
        }
Exemplo n.º 10
0
        public static void addPerforator(TFCOM.TFFrameList frameList,
                                         IPenetrTask task, PenetrInfo penInfo, BCOM.Level levelSymb, bool isVisible)
        {
            var taskUOR = new UOR(task.ModelRef);

            double pipeInsideDiam  = penInfo.pipeDiameterInside / taskUOR.activeSubPerMaster;
            double pipeOutsideDiam = penInfo.pipeDiameterOutside / taskUOR.activeSubPerMaster;

            double flangeInsideDiam  = penInfo.flangeDiameterInside / taskUOR.activeSubPerMaster;
            double flangeOutsideDiam = penInfo.flangeDiameterOutside / taskUOR.activeSubPerMaster;
            double flangeThick       = penInfo.flangeThick / taskUOR.activeSubPerMaster;
            double length            = task.LengthCm * 10 / taskUOR.activeSubPerMaster;

            var angles = task.CorrectiveAngles;

            BCOM.Transform3d taskTran = App.Transform3dFromMatrix3d(task.Rotation);

            // ПЕРФОРАТОР
            BCOM.EllipseElement perfoEl =
                App.CreateEllipseElement2(null, App.Point3dZero(),
                                          pipeInsideDiam / 2, pipeInsideDiam / 2,
                                          App.Matrix3dIdentity(), BCOM.MsdFillMode.Filled);
            {
                BCOM.Point3d offset = App.Point3dAddScaled(
                    App.Point3dZero(),
                    App.Point3dFromXYZ(0, 0, 1), length / 2);
                perfoEl.Move(offset);
                perfoEl.Rotate(App.Point3dZero(), angles.X, angles.Y, angles.Z);
            }
            perfoEl.Level = levelSymb;
            ElementHelper.setSymbologyByLevel(perfoEl);
            perfoEl.Transform(taskTran);
            perfoEl.Move(task.Location);

            BCOM.Point3d perfoVec = perfoEl.Normal;

            TFCOM.TFPerforatorList perfoList = AppTF.CreateTFPerforator();
            var tranIdentity = App.Transform3dIdentity();

            perfoList.InitFromElement(perfoEl, perfoVec, length / 2 * 1.01, tranIdentity);
            perfoList.SetSweepMode(
                TFCOM.TFdPerforatorSweepMode.tfdPerforatorSweepModeBi);
            //perfoList.SetSenseDist(1.01 * length / 2);
            perfoList.SetPolicy(
                TFCOM.TFdPerforatorPolicy.tfdPerforatorPolicyThroughHoleWithinSenseDist);
            perfoList.SetIsVisible(isVisible);

            frameList.AsTFFrame.SetPerforatorList(perfoList);
            frameList.AsTFFrame.SetSenseDistance2(length / 2);
            frameList.AsTFFrame.SetPerforatorsAreActive(true);
            frameList.Synchronize();

            {
                // ! без этого кода не срабатывает перфорация в стенке/плите
                // судя по всему инициализирует обновление объектов, с которыми
                // взаимодействует frame

                AppTF.ModelReferenceUpdateAutoOpeningsByFrame(
                    App.ActiveModelReference, frameList.AsTFFrame, true, false,
                    TFCOM.TFdFramePerforationPolicy.tfdFramePerforationPolicyNone);
            }
        }