Ejemplo n.º 1
0
    public RectPattern GetPattern(RectPattern pattern)
    {
        if (!pattern.IsValid() || pattern.IsEmpty())
        {
            return(RectPattern.empty);
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_patternpattern.ContainsKey(pattern))
        {
            return(RectPattern.empty);
        }
        return(_patternpattern[pattern]);

#if UNITY_EDITOR
    }

    else
    {
        int index = _patterns.IndexOf(pattern);
        if (index < 0)
        {
            return(RectPattern.empty);
        }
        return(_patterns[index]);
    }
#endif
    }
Ejemplo n.º 2
0
    public int GetComponentID(RectPattern pattern)
    {
        if (!pattern.IsValid() || pattern.IsEmpty())
        {
            return(0);
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_patternid.ContainsKey(pattern))
        {
            return(0);
        }
        return(_patternid[pattern]);

#if UNITY_EDITOR
    }

    else
    {
        int index = _patterns.IndexOf(pattern);
        if (index < 0)
        {
            return(0);
        }
        return(_pids[index]);
    }
#endif
    }
Ejemplo n.º 3
0
    public override void Enable()
    {
        _update_mesh  = true;
        _render_mesh  = true;
        _repaint_menu = true;
        _addpat       = RectPattern.empty;
        _selectscroll = Vector2.zero;
        _patscroll    = Vector2.zero;

        _facelist = new ReorderableList(_faces, typeof(RectDesign), false, false, false, false);
        _facelist.showDefaultBackground          = false;
        _facelist.headerHeight                   = 0;
        _facelist.footerHeight                   = 0;
        _facelist.elementHeight                  = VxlGUI.MED_BAR;
        _facelist.drawNoneElementCallback       += DrawFaceNoneElement;
        _facelist.drawElementCallback           += DrawFaceElement;
        _facelist.drawElementBackgroundCallback += DrawFaceElementBackground;

        _patternlist = new ReorderableList(_patterns, typeof(RectPattern), false, false, false, false);
        _patternlist.showDefaultBackground          = false;
        _patternlist.headerHeight                   = 0;
        _patternlist.footerHeight                   = 0;
        _patternlist.elementHeightCallback         += PatternHeight;
        _patternlist.drawNoneElementCallback       += DrawPatternNoneElement;
        _patternlist.drawElementCallback           += DrawPatternElement;
        _patternlist.drawElementBackgroundCallback += DrawPatternElementBackground;
    }
Ejemplo n.º 4
0
        public static void CreatePatternBearing()
        {
            oCurrentSketch = oPartBody.Sketches.Add(oPlaneYZ);
            Factory2D oFactory2D = oCurrentSketch.OpenEdition();

            oCurrentCircle1 = oFactory2D.CreateClosedCircle(iCenterX, iCenterY, iBearingDiam / 2);
            oCurrentSketch.CloseEdition();
            ShapeFactory   oShapeFactory   = (ShapeFactory)oPart.ShapeFactory;
            Pad            oPad            = oShapeFactory.AddNewPad(oCurrentSketch, iBearingLength);
            OriginElements originElements1 = oPart.OriginElements;
            Reference      oRefPlaneXY     = oPart.CreateReferenceFromGeometry(oPart.OriginElements.PlaneXY);
            RectPattern    rectPattern1    = oShapeFactory.AddNewRectPattern(oPad, iNumberOfCylinders + 1, 1, iCylinderSpacing, 0, 1, 1, oRefPlaneXY, oRefPlaneXY, true, true, 0);

            iCurrentLevel = iBearingLength;
        }
Ejemplo n.º 5
0
    public void DeletePattern(RectDesign component, RectPattern pattern)
    {
        if (component == null || !pattern.IsValid() || pattern.IsEmpty())
        {
            return;
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_compid.ContainsKey(component) || !_patternid.ContainsKey(pattern))
        {
            return;
        }
        _patternid.Remove(pattern);
        _idpatterns[_compid[component]].Remove(pattern);
        _patternpattern.Remove(pattern);
#if UNITY_EDITOR
    }

    else
    {
        int comp_index = _components.IndexOf(component);
        if (comp_index < 0)
        {
            return;
        }
        int id        = _ids[comp_index];
        int pat_index = _patterns.IndexOf(pattern);
        if (pat_index < 0)
        {
            return;
        }
        if (_pids[pat_index] != id)
        {
            return;
        }
        _pids.RemoveAt(pat_index);
        _patterns.RemoveAt(pat_index);
    }
#endif
    }
Ejemplo n.º 6
0
    public void AddPattern(RectDesign component, RectPattern pattern)
    {
        if (component == null || !pattern.IsValid() || pattern.IsEmpty())
        {
            return;
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_compid.ContainsKey(component) || _patternid.ContainsKey(pattern))
        {
            return;
        }
        int id = _compid[component];
        if (id < 1)
        {
            return;
        }
        _patternid.Add(pattern, id);
        _idpatterns[id].Add(pattern);
        _patternpattern.Add(pattern, pattern);

#if UNITY_EDITOR
    }

    else
    {
        int comp_index = _components.IndexOf(component);
        if (comp_index < 0)
        {
            return;
        }
        if (_patterns.Contains(pattern))
        {
            return;
        }
        _pids.Add(_ids[comp_index]);
        _patterns.Add(pattern);
    }
#endif
    }
Ejemplo n.º 7
0
    public RectDesign GetComponent(RectPattern pattern)
    {
        if (!pattern.IsValid() || pattern.IsEmpty())
        {
            return(null);
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        if (!_patternid.ContainsKey(pattern))
        {
            return(null);
        }
        int id = _patternid[pattern];
        if (!_idcomp.ContainsKey(id))
        {
            return(null);
        }
        return(_idcomp[id]);

#if UNITY_EDITOR
    }

    else
    {
        int pat_index = _patterns.IndexOf(pattern);
        if (pat_index < 0)
        {
            return(null);
        }
        int id         = _pids[pat_index];
        int comp_index = _ids.IndexOf(id);
        if (comp_index < 0)
        {
            return(null);
        }
        return(_components[comp_index]);
    }
#endif
    }
Ejemplo n.º 8
0
    public bool PatternExists(RectPattern pattern)
    {
        if (!pattern.IsValid() || pattern.IsEmpty())
        {
            return(false);
        }
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
#endif
        return(_patternid.ContainsKey(pattern));

#if UNITY_EDITOR
    }

    else
    {
        return(_patterns.Contains(pattern));
    }
#endif
    }
Ejemplo n.º 9
0
    private void DrawAddPatternPanel()
    {
        EditorGUI.BeginChangeCheck();
        VxlGUI.DrawRect(_rect_pattemplateheader, "DarkGradient");
        GUI.Label(_rect_pattemplateheader, "Add Rect Pattern", GUI.skin.GetStyle("LeftLightHeader"));
        VxlGUI.DrawRect(_rect_pattemplate, "DarkWhite");
        Rect rect_content = VxlGUI.GetPaddedRect(_rect_pattemplate, VxlGUI.MED_PAD);

        float two = rect_content.width / 2f;
        //row 0 - a1 a0
        Rect rect_row = VxlGUI.GetAboveElement(rect_content, 0, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0);

        GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Above:", GUI.skin.GetStyle("LeftLightHeader"));
        int a1 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.a1_p);
        int a0 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.a0_p);

        //row 1 - b1 b0
        rect_row = VxlGUI.GetAboveElement(rect_content, 1, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0);
        GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Below:", GUI.skin.GetStyle("LeftLightHeader"));
        int b1 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.b1_p);
        int b0 = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.b0_p);

        //row 2 - vin vout
        rect_row = VxlGUI.GetAboveElement(rect_content, 2, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0);
        GUI.Label(VxlGUI.GetLeftElement(rect_row, 0, two), "Voxels:", GUI.skin.GetStyle("LeftLightHeader"));
        int vin  = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 1, Mathf.Min(two / 2f, 40)), _addpat.vin);
        int vout = EditorGUI.IntField(VxlGUI.GetRightElement(rect_row, 0, Mathf.Min(two / 2f, 40)), _addpat.vout);

        //row 3 - flipx flipy
        rect_row = VxlGUI.GetAboveElement(rect_content, 3, VxlGUI.MED_BAR, VxlGUI.SM_SPACE, 0);
        bool flipx = EditorGUI.Foldout(VxlGUI.GetLeftElement(rect_row, 0, two), _addpat.xflip, "FlipX", true, GUI.skin.GetStyle("LightFoldout"));
        bool flipy = EditorGUI.Foldout(VxlGUI.GetLeftElement(rect_row, 1, two), _addpat.yflip, "FlipY", true, GUI.skin.GetStyle("LightFoldout"));

        //apply change
        if (EditorGUI.EndChangeCheck())
        {
            _addpat       = new RectPattern(flipx, flipy, a0, b0, a1, b1, vin, vout);
            _repaint_menu = false;
        }
    }
Ejemplo n.º 10
0
 public override void Start()
 {
     _compid         = new Dictionary <RectDesign, int>();
     _idcomp         = new Dictionary <int, RectDesign>();
     _idpatterns     = new Dictionary <int, List <RectPattern> >();
     _patternid      = new Dictionary <RectPattern, int>();
     _patternpattern = new Dictionary <RectPattern, RectPattern>();
     for (int k = 0; k < _ids.Count; k++)
     {
         int        id   = _ids[k];
         RectDesign comp = _components[k];
         if (comp == null || id < 1)
         {
             continue;
         }
         _compid.Add(comp, id);
         _idcomp.Add(id, comp);
         _idpatterns.Add(id, new List <RectPattern>());
     }
     for (int k = 0; k < _pids.Count; k++)
     {
         int         id      = _pids[k];
         RectPattern pattern = _patterns[k];
         if (!pattern.IsValid() || pattern.IsEmpty())
         {
             continue;
         }
         if (_patternid.ContainsKey(pattern) || !_idpatterns.ContainsKey(id))
         {
             continue;
         }
         _patternid.Add(pattern, id);
         _patternpattern.Add(pattern, pattern);
         _idpatterns[id].Add(pattern);
     }
 }
Ejemplo n.º 11
0
 public bool RectPatternExists(RectPattern pattern)
 {
     return(_rect.PatternExists(pattern));
 }
Ejemplo n.º 12
0
        enum RxHoleType { PinHole, NSmoothHole, ISmoothHole, ThreadHole }//PinHole销孔  NormarlSmoothHole 光孔 Inner SmoothHole 沉头孔  ThreadHole 螺纹孔

        /// <summary>
        /// 新增孔
        /// </summary>
        /// <param name="UserSelected">用户选择的3个参考</param>
        /// <param name="tform">父级窗体</param>
        /// <param name="AbortHole">是否对装配零件直接打孔</param>
        public void CreateNwThroughtHole(Reference[] UserSelected, Form tform, bool AbortHole, object[] UserSelectedValue)
        {
            object[] HolePoint = new object[3];
            Edge     ed1       = (Edge)UserSelected[0];
            Edge     ed2       = (Edge)UserSelected[1];

            if (CatActiveDoc == null)
            {
                InitCatEnv(tform);
            }
            SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatActiveDoc.GetWorkbench("SPAWorkbench");
            Measurable   LengthA         = TheSPAWorkbench.GetMeasurable(ed1);
            Measurable   LengthB         = TheSPAWorkbench.GetMeasurable(ed2);
            Edge         LengthEdge      = LengthA.Length >= LengthB.Length ? ed1 : ed2; //获取长边
            Edge         WeightEdge      = LengthA.Length <= LengthB.Length ? ed1 : ed2; //获取短边
            double       Weight          = LengthA.Length <= LengthB.Length ? LengthA.Length : LengthB.Length;
            double       Length          = LengthA.Length >= LengthB.Length ? LengthA.Length : LengthB.Length;
            double       JianDis         = 0;

            if (Length <= 45)
            {
                JianDis = 12.5;
            }
            else if (Length <= 60 && Length > 45)
            {
                JianDis = 15;
            }
            else if (Length > 60)
            {
                JianDis = 15;
            }
            GetProductByFace GPB          = new GetProductByFace();
            Part             Spart        = GPB.GetPart((Face)UserSelected[2]);
            ShapeFactory     shapeFactory = (ShapeFactory)Spart.ShapeFactory;
            Hole             Nwhole       = shapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(HolePoint[0]), Convert.ToDouble(HolePoint[1]), Convert.ToDouble(HolePoint[2]), UserSelected[0], UserSelected[1], UserSelected[2], 50);//创建过孔

            RxSetHoleType(Nwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole);
            Spart.Update();
            Hole NwPinHole = shapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(HolePoint[0]) + 5, Convert.ToDouble(HolePoint[1]) + 5, Convert.ToDouble(HolePoint[2]), UserSelected[0], UserSelected[1], UserSelected[2], 50);//创建销孔

            RxSetHoleType(NwPinHole, 10, Weight / 2 + JianDis, 8, RxHoleType.PinHole);
            Spart.Update();
            if (Length <= 60)
            {
                RectPattern RPhole = shapeFactory.AddNewRectPattern(Nwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                Spart.Update();
            }
            else
            {
                RectPattern RPhole = shapeFactory.AddNewRectPattern(Nwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;

                RectPattern RPinhole = shapeFactory.AddNewRectPattern(NwPinHole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                RPinhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                RPinhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                Spart.Update();
            }
            if (AbortHole)
            {
                CreateThreadHole(Spart, UserSelected, UserSelectedValue, WeightEdge, LengthEdge, Weight, Length, JianDis);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 创建螺纹孔安装面
        /// </summary>
        /// <param name="Spart">对象零件</param>
        /// <param name="UserSelected">用户选择参考对象2边1面</param>
        /// <param name="WeightEdge">宽边</param>
        /// <param name="LengthEdge">长边</param>
        /// <param name="Weight">宽边宽度</param>
        /// <param name="Length">长边长度</param>
        /// <param name="JianDis">孔间距</param>
        public void CreateThreadHole(Part Spart, Reference[] UserSelected, object[] UserSelectedValue, Edge WeightEdge, Edge LengthEdge, double Weight, double Length, double JianDis)
        {
            //对与孔装配的零件执行打孔
            object[]  SHolePoint = new object[3];
            Selection SelectArc  = CatActiveDoc.Selection;

            SelectArc.Clear();
            var Result = SelectArc.SelectElement2(InputObjectType(2), "请选择子零件孔支持面!", true);

            if (Result == "Cancel" || SelectArc == null || SelectArc.Count2 == 0)
            {
                return;
            }
            Reference        SonReface = SelectArc.Item(1).Reference;
            GetProductByFace SGPB      = new GetProductByFace();
            Part             SonPart   = SGPB.GetPart((Face)SelectArc.Item(1).Value);

            SelectArc.Item(1).GetCoordinates(SHolePoint);
            SelectArc.Clear();
            ShapeFactory       NextshapeFactory   = (ShapeFactory)SonPart.ShapeFactory;
            HybridShapeFactory NextHyShapeFactory = (HybridShapeFactory)SonPart.HybridShapeFactory;
            InstanceFactory    NextInf            = (InstanceFactory)SonPart.GetCustomerFactory("InstanceFactory");

            NextInf.AddInstance(WeightEdge);
            try
            {
                Reference Wref = null;
                Reference Lref = null;
                try
                {
                    object[]     LinePoint       = new object[12];
                    object[]     LineDirection   = new object[12];
                    SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatActiveDoc.GetWorkbench("SPAWorkbench");
                    Measurable   LengthA         = TheSPAWorkbench.GetMeasurable(WeightEdge);
                    Measurable   LengthB         = TheSPAWorkbench.GetMeasurable(LengthEdge);
                    //LengthA.GetMinimumDistancePoints(, LinePoint);
                    //LengthA.GetDirection(LineDirection);
                    //NextHyShapeFactory.AddNewLineNormal(SonReface, 10, 10, true);
                    Edge   WeightEdgeT     = (Edge)UserSelectedValue[0];
                    Edge   LengthEdgeT     = (Edge)UserSelectedValue[1];
                    string WeightEdgeName  = WeightEdgeT.get_Name();
                    string LengthEdgeTName = LengthEdgeT.get_Name();
                    Wref            = SonPart.CreateReferenceFromName(null);
                    Lref            = SonPart.CreateReferenceFromName(null);
                    WeightEdgeName  = Wref.get_Name();
                    LengthEdgeTName = Lref.get_Name();
                    SelectArc.Add(WeightEdgeT);
                    SelectArc.Add(LengthEdgeT);
                    SelectArc.Copy();
                }
                catch (Exception e)
                {
                    throw e;
                }
                Hole SonNwhole = NextshapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(SHolePoint[0]), Convert.ToDouble(SHolePoint[1]), Convert.ToDouble(SHolePoint[2]), Wref, Lref, SonReface, 50);//创建过孔
                try
                {
                    RxSetHoleType(SonNwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole);
                }
                catch (Exception)
                {
                    RxSetHoleType(SonPart, SonNwhole, 10, Weight / 2, 9, RxHoleType.NSmoothHole, WeightEdge, LengthEdge);
                }
                SonPart.Update();
                Hole SonNwPinHole = NextshapeFactory.AddNewHoleWith2Constraints(Convert.ToDouble(SHolePoint[0]) + 5, Convert.ToDouble(SHolePoint[1]) + 5, Convert.ToDouble(SHolePoint[2]), UserSelected[0], UserSelected[1], SonReface, 50);//创建销孔
                RxSetHoleType(SonNwPinHole, 10, Weight / 2 + JianDis, 8, RxHoleType.PinHole);
                SonPart.Update();
                if (Length <= 60)
                {
                    RectPattern RPhole = NextshapeFactory.AddNewRectPattern(SonNwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                    RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                    RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                    Spart.Update();
                }
                else
                {
                    RectPattern RPhole = NextshapeFactory.AddNewRectPattern(SonNwhole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                    RPhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                    RPhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;

                    RectPattern RPinhole = NextshapeFactory.AddNewRectPattern(SonNwPinHole, 2, 1, JianDis * 2, 20, 1, 1, LengthEdge, WeightEdge, true, true, 0); //阵列过孔
                    RPinhole.FirstRectangularPatternParameters  = CatRectangularPatternParameters.catInstancesandSpacing;
                    RPinhole.SecondRectangularPatternParameters = CatRectangularPatternParameters.catInstancesandSpacing;
                    Spart.Update();
                }
            }
            catch (Exception)
            {
                throw;
                MessageBox.Show("打孔失败!请确定选择是否有误!");
            }
        }
Ejemplo n.º 14
0
 public RectPattern GetRectPattern(RectPattern pattern)
 {
     return(_rect.GetPattern(pattern));
 }
Ejemplo n.º 15
0
 public RectDesign GetRect(RectPattern pattern)
 {
     return(_rect.GetComponent(pattern));
 }
Ejemplo n.º 16
0
 public int GetRectID(RectPattern pattern)
 {
     return(_rect.GetComponentID(pattern));
 }
Ejemplo n.º 17
0
 public void DeleteRectPattern(RectDesign rect, RectPattern pattern)
 {
     _rect.DeletePattern(rect, pattern);
 }
Ejemplo n.º 18
0
 public void AddRectPattern(RectDesign rect, RectPattern pattern)
 {
     _rect.AddPattern(rect, pattern);
 }