Exemple #1
0
        protected override void Command()
        {
            try
            {
                int NbDvp = 0;

                var dic = MdlBase.ListerComposants(false);

                int MdlPct = 0;
                foreach (var mdl in dic.Keys)
                {
                    WindowLog.SautDeLigne();
                    WindowLog.EcrireF("[{1}/{2}] {0}", mdl.eNomSansExt(), ++MdlPct, dic.Count);

                    mdl.eActiver(swRebuildOnActivation_e.swRebuildActiveDoc);
                    var cfgActive = mdl.eNomConfigActive();

                    var ListeNomConfigs = dic[mdl];

                    if (ToutesLesConfigurations)
                    {
                        mdl.eParcourirConfiguration(
                            (String c) =>
                        {
                            if (c.eEstConfigPliee() && !ListeNomConfigs.ContainsKey(c))
                            {
                                ListeNomConfigs.Add(c, 1);
                            }

                            return(false);
                        }
                            );
                    }

                    if (MasquerEsquisses)
                    {
                        cmdMasquerEsquisses(mdl);
                    }

                    if (SupprimerLesAnciennesConfigs)
                    {
                        cmdSupprimerLesAnciennesConfigs(mdl);
                    }

                    if (!mdl.Extension.LinkedDisplayState)
                    {
                        mdl.Extension.LinkedDisplayState = true;

                        foreach (var c in mdl.eListeConfigs(eTypeConfig.Tous))
                        {
                            c.eRenommerEtatAffichage();
                        }
                    }

                    int CfgPct = 0;
                    foreach (var NomConfigPliee in ListeNomConfigs.Keys)
                    {
                        WindowLog.SautDeLigne();
                        WindowLog.EcrireF("  [{1}/{2}] Config : \"{0}\"", NomConfigPliee, ++CfgPct, ListeNomConfigs.Count);
                        mdl.ShowConfiguration2(NomConfigPliee);
                        mdl.EditRebuild3();

                        if (SupprimerFonctions)
                        {
                            cmdSupprimerFonctions(mdl, NomConfigPliee);
                        }

                        PartDoc Piece = mdl.ePartDoc();

                        var ListeDossier = Piece.eListePIDdesFonctionsDePiecesSoudees(
                            swD =>
                        {
                            BodyFolder dossier = swD.GetSpecificFeature2();
                            if (dossier.eEstExclu() || dossier.IsNull() || (dossier.GetBodyCount() == 0) || dossier.eTypeDeDossier() != eTypeCorps.Tole)
                            {
                                return(false);
                            }

                            return(true);
                        }
                            );

                        for (int noD = 0; noD < ListeDossier.Count; noD++)
                        {
                            var        f       = ListeDossier[noD];
                            BodyFolder dossier = f.GetSpecificFeature2();

                            var RefDossier = dossier.eProp(CONSTANTES.REF_DOSSIER);

                            Body2 Tole = dossier.eCorpsDeTolerie();

                            var pidTole = new SwObjectPID <Body2>(Tole, MdlBase);

                            String NomConfigDepliee = Sw.eNomConfigDepliee(NomConfigPliee, RefDossier);

                            WindowLog.EcrireF("    - [{1}/{2}] Dossier : \"{0}\" -> {3}", f.Name, noD + 1, ListeDossier.Count, NomConfigDepliee);

                            Configuration CfgDepliee = null;

                            if (ReconstuireLesConfigs)
                            {
                                CfgDepliee = MdlBase.GetConfigurationByName(NomConfigDepliee);
                            }

                            if (CfgDepliee.IsNull())
                            {
                                CfgDepliee = mdl.CreerConfigDepliee(NomConfigDepliee, NomConfigPliee);
                            }
                            else if (!ReconstuireLesConfigs)
                            {
                                continue;
                            }

                            if (CfgDepliee.IsNull())
                            {
                                WindowLog.Ecrire("       - Config non crée");
                                continue;
                            }

                            NbDvp++;

                            try
                            {
                                mdl.ShowConfiguration2(NomConfigDepliee);

                                // On ajoute le numero de la config parent aux propriétés de la configuration depliée
                                CfgDepliee.CustomPropertyManager.Add3(CONSTANTES.NO_CONFIG, (int)swCustomInfoType_e.swCustomInfoText, NomConfigPliee, (int)swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd);

                                pidTole.Maj(ref Tole);

                                Tole.DeplierTole(mdl, NomConfigDepliee);
                            }
                            catch (Exception e)
                            {
                                DicErreur.Add(mdl.eNomSansExt() + " -> cfg : " + NomConfigPliee + " - No : " + RefDossier + " = " + NomConfigDepliee);
                                WindowLog.Ecrire("Erreur de depliage");
                                this.LogMethode(new Object[] { e });
                            }

                            try
                            {
                                mdl.ShowConfiguration2(NomConfigPliee);

                                pidTole.Maj(ref Tole);

                                Tole.PlierTole(mdl, NomConfigPliee);
                            }
                            catch (Exception e)
                            {
                                WindowLog.Ecrire("Erreur de repliage");
                                this.LogMethode(new Object[] { e });
                            }
                        }
                    }

                    mdl.ShowConfiguration2(cfgActive);
                    WindowLog.SautDeLigne();

                    mdl.eFermerSiDifferent(MdlBase);
                }

                if (DicErreur.Count > 0)
                {
                    WindowLog.SautDeLigne();

                    WindowLog.Ecrire("Liste des erreurs :");
                    foreach (var item in DicErreur)
                    {
                        WindowLog.Ecrire(" - " + item);
                    }

                    WindowLog.SautDeLigne();
                }
                else
                {
                    WindowLog.Ecrire("Pas d'erreur");
                }

                WindowLog.SautDeLigne();
                WindowLog.Ecrire("Resultat :");
                WindowLog.Ecrire("----------------");
                WindowLog.EcrireF("  {0} dvp crées", NbDvp);

                File.WriteAllText(Path.Combine(MdlBase.eDossier(), "Log_CreerConfigDvp.txt"), WindowLog.Resume);

                MdlBase.eActiver(swRebuildOnActivation_e.swRebuildActiveDoc);
                MdlBase.ShowConfiguration2(nomConfigBase);
                MdlBase.EditRebuild3();
            }
            catch (Exception e)
            {
                this.LogErreur(new Object[] { e });
            }
        }
Exemple #2
0
        protected override void Command()
        {
            try
            {
                if (ConvertirEsquisse)
                {
                    WindowLog.Ecrire("Attention !!!");
                    WindowLog.Ecrire("Les dvp seront convertis en esquisse");
                    WindowLog.SautDeLigne();
                }

                CreerDossierDVP();

                eTypeCorps       Filtre        = eTypeCorps.Tole;
                HashSet <String> HashMateriaux = new HashSet <string>(ListeMateriaux);
                HashSet <String> HashEp        = new HashSet <string>(ListeEp);

                var dic = MdlBase.DenombrerDossiers(ComposantsExterne,
                                                    fDossier =>
                {
                    BodyFolder swDossier = fDossier.GetSpecificFeature2();

                    if (Filtre.HasFlag(swDossier.eTypeDeDossier()) && HashMateriaux.Contains(swDossier.eGetMateriau()))
                    {
                        String Ep = swDossier.ePremierCorps().eEpaisseurCorps().ToString();

                        if (HashEp.Contains(Ep))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }
                                                    );

                int MdlPct = 0;
                foreach (var mdl in dic.Keys)
                {
                    mdl.eActiver(swRebuildOnActivation_e.swRebuildActiveDoc);

                    WindowLog.SautDeLigne();
                    WindowLog.EcrireF("[{1}/{2}] {0}", mdl.eNomSansExt(), ++MdlPct, dic.Count);


                    int CfgPct = 0;
                    foreach (var NomConfigPliee in dic[mdl].Keys)
                    {
                        WindowLog.SautDeLigne();
                        WindowLog.EcrireF("  [{1}/{2}] Config : \"{0}\"", NomConfigPliee, ++CfgPct, dic[mdl].Count);
                        mdl.ShowConfiguration2(NomConfigPliee);
                        mdl.EditRebuild3();
                        PartDoc Piece = mdl.ePartDoc();

                        var ListeDossier = dic[mdl][NomConfigPliee];
                        int DrPct        = 0;
                        foreach (var t in ListeDossier)
                        {
                            var IdDossier    = t.Key;
                            var QuantiteTole = t.Value * Quantite;

                            Feature    fDossier = Piece.FeatureById(IdDossier);
                            BodyFolder dossier  = fDossier.GetSpecificFeature2();

                            var RefDossier = dossier.eProp(CONSTANTES.REF_DOSSIER);

                            Body2 Tole = dossier.eCorpsDeTolerie();

                            WindowLog.SautDeLigne();
                            WindowLog.EcrireF("    - [{1}/{2}] Dossier : \"{0}\" x{3}", RefDossier, ++DrPct, ListeDossier.Count, QuantiteTole);

                            String Materiau = Tole.eGetMateriauCorpsOuPiece(Piece, NomConfigPliee);

                            Materiau = ForcerMateriau.IsRefAndNotEmpty(Materiau);

                            Double Epaisseur        = Tole.eEpaisseurCorps();
                            String NomConfigDepliee = Sw.eNomConfigDepliee(NomConfigPliee, RefDossier);

                            WindowLog.EcrireF("      Ep {0} / Materiau {1}", Epaisseur, Materiau);
                            WindowLog.EcrireF("          Config {0}", NomConfigDepliee);

                            if (ConvertirEsquisse)
                            {
                                if (!mdl.eListeNomConfiguration().Contains(NomConfigDepliee))
                                {
                                    mdl.CreerConfigDepliee(NomConfigDepliee, NomConfigPliee);
                                }

                                WindowLog.EcrireF("          Configuration crée : {0}", NomConfigDepliee);
                                mdl.ShowConfiguration2(NomConfigDepliee);
                                Tole.DeplierTole(mdl, NomConfigDepliee);
                            }
                            else if (!mdl.ShowConfiguration2(NomConfigDepliee))
                            {
                                DicErreur.Add(mdl.eNomSansExt() + " -> cfg : " + NomConfigPliee + " - No : " + RefDossier + " = " + NomConfigDepliee);
                                WindowLog.EcrireF("La configuration n'éxiste pas");
                                continue;
                            }

                            mdl.EditRebuild3();

                            DrawingDoc dessin = CreerPlan(Materiau, Epaisseur);
                            dessin.eModelDoc2().eActiver();
                            Sheet Feuille = dessin.eFeuilleActive();

                            View v = CreerVueToleDvp(dessin, Feuille, Piece, NomConfigDepliee, RefDossier, Materiau, QuantiteTole, Epaisseur);

                            if (ConvertirEsquisse)
                            {
                                mdl.ShowConfiguration2(NomConfigPliee);
                                mdl.EditRebuild3();
                                mdl.DeleteConfiguration2(NomConfigDepliee);
                            }
                        }

                        NouvelleLigne = true;
                    }

                    mdl.eFermerSiDifferent(MdlBase);
                }

                foreach (DrawingDoc dessin in DicDessins.Values)
                {
                    int Errors = 0, Warnings = 0;
                    dessin.eModelDoc2().eActiver();
                    dessin.eFeuilleActive().eAjusterAutourDesVues();
                    dessin.eModelDoc2().ViewZoomtofit2();
                    dessin.eModelDoc2().Save3((int)swSaveAsOptions_e.swSaveAsOptions_SaveReferenced + (int)swSaveAsOptions_e.swSaveAsOptions_Silent, ref Errors, ref Warnings);
                }

                if (FermerPlan)
                {
                    foreach (ModelDoc2 dessin in DicDessins.Values)
                    {
                        dessin.eFermer();
                    }
                }

                if (DicErreur.Count > 0)
                {
                    WindowLog.SautDeLigne();

                    WindowLog.Ecrire("Liste des erreurs :");
                    foreach (var item in DicErreur)
                    {
                        WindowLog.Ecrire(" - " + item);
                    }

                    WindowLog.SautDeLigne();
                }
                else
                {
                    WindowLog.Ecrire("Pas d'erreur");
                }

                File.WriteAllText(Path.Combine(DossierDVP, "Log_CreerDvp.txt"), WindowLog.Resume);
            }
            catch (Exception e)
            {
                this.LogErreur(new Object[] { e });
            }
        }