Example #1
0
            private void Contraindre(Feature plan, Face2 e)
            {
                AssemblyDoc Ass = MdlBase.eAssemblyDoc();

                e.eSelectEntite(MdlBase);
                plan.eSelect(true);

                int longstatus = 0;

                Ass.AddMate5((int)swMateType_e.swMateCOINCIDENT,
                             (int)swMateAlign_e.swMateAlignCLOSEST, false, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, out longstatus);

                MdlBase.ClearSelection2(true);
            }
Example #2
0
        protected override void Command()
        {
            try
            {
                Face2         face    = null;
                SketchSegment segment = null;

                if (MdlBase.eSelect_RecupererTypeObjet(1) == e_swSelectType.swSelFACES)
                {
                    face    = MdlBase.eSelect_RecupererObjet <Face2>(1);
                    segment = MdlBase.eSelect_RecupererObjet <SketchSegment>(2);
                }
                else
                {
                    face    = MdlBase.eSelect_RecupererObjet <Face2>(2);
                    segment = MdlBase.eSelect_RecupererObjet <SketchSegment>(1);
                }

                if (face == null || segment == null)
                {
                    return;
                }

                MdlBase.eEffacerSelection();

                Boolean r       = false;
                Boolean reverse = false;

                var sk    = segment.GetSketch();
                var xform = (MathTransform)sk.ModelToSketchTransform.Inverse();

                if (segment.GetType() != (int)swSketchSegments_e.swSketchLINE)
                {
                    return;
                }

                var sl = (SketchLine)segment;

                var start = new ePoint(sl.GetStartPoint2());
                var end   = new ePoint(sl.GetEndPoint2());

                start.ApplyMathTransform(xform);
                end.ApplyMathTransform(xform);

                WindowLog.Ecrire(start.IsRef() + " " + start.ToString());
                WindowLog.Ecrire(end.IsRef() + " " + end.ToString());

                var box = (Double[])face.GetBox();

                var pt = new ePoint((box[3] + box[0]) * 0.5, (box[4] + box[1]) * 0.5, (box[5] + box[2]) * 0.5);
                WindowLog.Ecrire(pt.IsRef() + " " + pt.ToString());

                if (start.Distance2(pt) > end.Distance2(pt))
                {
                    reverse = true;
                }

                r = face.eSelectEntite(MdlBase, 4, false);

                r = segment.eSelect(MdlBase, 1, true);

                var cp = (Body2)face.GetBody();
                r = cp.eSelect(MdlBase, 512, true);

                var fm           = MdlBase.FeatureManager;
                var featRepetDef = (CurveDrivenPatternFeatureData)fm.CreateDefinition((int)swFeatureNameID_e.swFmCurvePattern);

                featRepetDef.D1AlignmentMethod  = 0;
                featRepetDef.D1CurveMethod      = 0;
                featRepetDef.D1InstanceCount    = 3;
                featRepetDef.D1IsEqualSpaced    = true;
                featRepetDef.D1ReverseDirection = reverse;
                featRepetDef.D1Spacing          = 0.001;
                featRepetDef.D2InstanceCount    = 1;
                featRepetDef.D2IsEqualSpaced    = false;
                featRepetDef.D2PatternSeedOnly  = false;
                featRepetDef.D2ReverseDirection = false;
                featRepetDef.D2Spacing          = 0.001;
                featRepetDef.GeometryPattern    = true;

                var featRepet = fm.CreateFeature(featRepetDef);

                WindowLog.Ecrire(featRepet != null);
            }
            catch (Exception e)
            {
                this.LogMethode(new Object[] { e });
                WindowLog.Ecrire(new Object[] { e });
            }
        }
        private void Run(Component2 cBase)
        {
            if (cBase == null)
            {
                this.LogMethode(new String[] { _NomConfigActive });
                this.LogMethode(new String[] { "Une reference à un objet a été perdue cBase :", cBase.IsRefToString() });
                return;
            }

            try
            {
                List <Body2> ListeCorps = cBase.eListeCorps();
                List <Face2> ListeFace  = new List <Face2>();

                // Recherche des faces cylindriques
                foreach (Body2 C in ListeCorps)
                {
                    foreach (Face2 F in C.eListeDesFaces())
                    {
                        Surface S = F.GetSurface();
                        if (S.IsCylinder())
                        {
                            if (PercageOuvert || (F.GetLoopCount() > 1))
                            {
                                // Si le diametre == 0 on recupère toutes les faces
                                if ((ListeDiametre.Count == 1) && (ListeDiametre[0] == 0))
                                {
                                    if ((Face == null) || (F.eListeDesFacesContigues().Contains(Face)))
                                    {
                                        ListeFace.Add(F);
                                    }
                                }
                                // Sinon, on verifie qu'elle corresponde bien au diametre demandé
                                else
                                {
                                    Double[] ListeParam = (Double[])S.CylinderParams;
                                    Double   Diam       = Math.Round(ListeParam[6] * 2.0 * 1000, 2);

                                    if (ListeDiametre.Contains(Diam))
                                    {
                                        if ((Face == null) || (F.eListeDesFacesContigues().Contains(Face)))
                                        {
                                            ListeFace.Add(F);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // S'il n'y a pas assez de composant de perçage, on en rajoute
                while (_ListePercage.Count < ListeFace.Count)
                {
                    AjouterPercage();
                }

                _MdlBase.EditRebuild3();

                // Mise à jour des références des perçages
                //ReinitialiserRefListe(ref _ListePercage);

                List <String> ListeComp = new List <String>();
                if (!_DicConfigWithComp.ContainsKey(_NomConfigActive))
                {
                    _DicConfigWithComp.Add(_NomConfigActive, ListeComp);
                }
                else
                {
                    ListeComp = _DicConfigWithComp[_NomConfigActive];
                }


                List <String> ListeNomComp = _ListePercage.Keys.ToList();

                // Contrainte des perçages
                for (int i = 0; i < ListeFace.Count; i++)
                {
                    String     NomComp = ListeNomComp[i];
                    Component2 Comp    = _AssBase.GetComponentByName(NomComp);
                    // On active le composant au cas ou :)

                    _MdlBase.eSelectByIdComp(_ListePercage[NomComp]);
                    _AssBase.eModifierEtatComposant(swComponentSuppressionState_e.swComponentResolved);
                    _MdlBase.eEffacerSelection();

                    Face2 Cylindre = ListeFace[i];

                    ListeComp.Add(NomComp);

                    //DesactiverContrainte(Comp);

                    _MdlBase.ClearSelection2(true);

                    if (Plan.IsRef())
                    {
                        Plan.eSelect();
                    }
                    else if (Face.IsRef())
                    {
                        Face.eSelectEntite();
                    }
                    else
                    {
                        Face2 FaceContrainte = FacePlane(Cylindre);

                        // Si on trouve une face pour la contrainte, on sélectionne
                        // Sinon, on passe au trou suivant
                        if (FaceContrainte.IsRef())
                        {
                            FaceContrainte.eSelectEntite();
                        }
                        else
                        {
                            continue;
                        }
                    }

                    Feature fPlan = PlanContrainte(Comp);

                    if (fPlan == null)
                    {
                        this.LogMethode(new String[] { "Pas de \"Plan de face\"" });
                        continue;
                    }

                    fPlan.eSelect(true);

                    int longstatus = 0;
                    _AssBase.AddMate5((int)swMateType_e.swMateCOINCIDENT,
                                      (int)swMateAlign_e.swMateAlignCLOSEST,
                                      false,
                                      0, 0, 0, 0, 0, 0, 0, 0,
                                      false, false, 0, out longstatus);

                    _MdlBase.eEffacerSelection();

                    Cylindre.eSelectEntite();

                    Face2 fFace = FaceCylindrique(Comp);

                    fFace.eSelectEntite(true);

                    _AssBase.AddMate5((int)swMateType_e.swMateCONCENTRIC,
                                      (int)swMateAlign_e.swMateAlignCLOSEST,
                                      false,
                                      0, 0, 0, 0, 0, 0, 0, 0,
                                      false, true, 0, out longstatus);

                    _MdlBase.eEffacerSelection();
                }
            }
            catch (Exception e)
            {
                this.LogMethode(new Object[] { e });
            }
        }