ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_fonction.cpp
Revision: 34
Committed: Wed Aug 15 18:04:10 2007 UTC (17 years, 9 months ago) by bournival
Original Path: magic/lib/geometrie/geometrie/src/sld_fonction.cpp
File size: 22628 byte(s)
Log Message:
Sylvain,
Je coupe les coques maintenant, alors je dois les importer d'un efaçon un peu différente.
Quelques autres trucs ailleur, surtout pour les coques et poutres

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuillière et Vincent FRANCOIS
5     // Département de Génie Mécanique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du département
8     // de génie mécanique de l'Université du Québec à
9     // Trois Rivières
10     // Les librairies ne peuvent être utilisées sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // sld_fonction.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 à 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #ifdef BREP_SLD
27     //#include <atl\atlmod.h>
28     #include "smartvars.h"
29     //#include <clx.h>
30     //#include "sldworks_tlb.h"
31     //#include "swconst_tlb.h"
32    
33     #include <iostream>
34    
35     #include <system.hpp>
36     #include "sld_fonction.h"
37     #include <math.h>
38 bournival 34 #include <string.h>
39     #include <iostream>
40     #include <stdlib.h>
41 5
42 bournival 34
43 5 using namespace std;
44    
45     SLD_FONCTION::SLD_FONCTION():ouvert(0)
46     {
47 bournival 22 tolerance = 0;
48 5 }
49    
50     SLD_FONCTION::~SLD_FONCTION()
51     {
52 foucault 27 if (swApp.p!=NULL) swApp.p = NULL;
53     if (swModel.p != NULL) swModel.p = NULL;
54 5 }
55    
56    
57     void SLD_FONCTION::OuvrirFichier(char* file)
58     {
59     WideString acstostr(file);
60     BSTR filename=BSTR(acstostr);
61     WideString acstostr2("");
62     BSTR configuration=BSTR(acstostr2);
63    
64     long type ;
65     type=1 ;
66     long options ;
67     options= 1;
68    
69     long Errors;
70     long Warnings;
71     swApp->OpenDoc6(filename, type, options, configuration, &Errors, &Warnings, &swModel);
72 bournival 34 //swApp->Visible;
73 foucault 27 double tolerance=1E-5;
74     Modeler_SetToleranceValue(1,tolerance);
75     Modeler_SetToleranceValue(2,tolerance);
76 bournival 34
77     return ;
78 foucault 27
79 5 }
80    
81    
82    
83     void SLD_FONCTION::get_face_tessellation(CComPtr<IFace2> __swFace, long *__triangleCount, double ** __tessPts)
84     {
85     HRESULT hr;
86     hr = __swFace->GetTessTriangleCount(__triangleCount);
87 foucault 27 if (hr != S_OK)return;
88 5
89     CComVariant vTessTriang;
90 foucault 27 hr = __swFace->GetTessTriangles(VARIANT_TRUE, &vTessTriang);
91     if (hr != S_OK)return;
92 5 SafeFloatArray saTessPts (vTessTriang);
93    
94     unsigned long nbCoords = *__triangleCount*9;
95     *__tessPts = new double [nbCoords];
96    
97 foucault 27 for (unsigned i=0; i < nbCoords; i++)
98 5 {
99     (*__tessPts)[i] = saTessPts[i];
100     }
101     }
102    
103 foucault 27 /*
104     iTol=1 : swBSCurveOutputTol -3 D bspline curve output tolerance (meters)
105     iTol=2 : swBSCurveNonRationalOutputTol - 3D nonrational b-spline curve output tolerance (meters)
106     iTol=3 : swUVCurveOutputTol - 2D trim curve output tolerance (fraction of characteristic minimum face dimension)
107     iTol=4 : swSurfChordTessellationTol - Chord tolerance or deviation for tessellation for surfaces
108     iTol=5 : swSurfAngularTessellationTol - Angular tolerance or deviation for tessellation for surfaces
109     iTol=6 : swCurveChordTessellationTol - Chord tolerance or deviation for tessellation for curves
110     */
111     void SLD_FONCTION::Modeler_SetToleranceValue(long iTol, double __tolerance)
112     {
113     long iswToleranceID;
114     switch (iTol)
115     {
116     case 1: iswToleranceID = swBSCurveOutputTol;
117     break;
118     case 2: iswToleranceID = swBSCurveNonRationalOutputTol;
119     break;
120     case 3: iswToleranceID = swUVCurveOutputTol;
121     break;
122     case 4: iswToleranceID = swSurfChordTessellationTol;
123     break;
124     case 5: iswToleranceID = swSurfAngularTessellationTol;
125     break;
126     case 6: iswToleranceID = swCurveChordTessellationTol;
127     break;
128     default:
129     return;
130     }
131     CComPtr<IModeler> swModeler;
132     swApp->IGetModeler(&swModeler);
133     /*double oldTol=*/swModeler->SetToleranceValue(iswToleranceID,__tolerance);
134     }
135 5
136 foucault 27
137 5 void SLD_FONCTION::Sauvegarder(char* file)
138     {
139     short retval =-1;
140     long Errors = -1;
141     long Warnings=-1;
142    
143     WideString acstostr(file);
144     BSTR nom=BSTR(acstostr);
145     swModel->SaveAs4 ( nom, swSaveAsCurrentVersion, swSaveAsOptions_SaveReferenced , &Errors, &Warnings ,&retval);
146     //if (retval==0 || hres !=S_OK)
147     //cout<<"Sauvegarde échouée!"<<endl;
148     return;
149     }
150    
151    
152    
153    
154    
155    
156    
157     void SLD_FONCTION::Connection(void)
158     {
159     //HRESULT hres;
160     CoInitialize(NULL); //Initialize COM
161     swApp.CoCreateInstance(CLSID_SldWorks_, NULL, CLSCTX_LOCAL_SERVER); //Create an instance of SolidWorks
162     //HRESULT status =swApp->put_Visible( true );
163     ouvert=1;
164     return;
165     }
166    
167    
168    
169    
170    
171    
172    
173     void SLD_FONCTION::Fermer(void)
174     {
175 bournival 34 return; // 26 juillet, Sylvain utilisé pour débugger sans fermer solidworks.
176 5 if (!ouvert) return;
177     swApp->ExitApp();
178     swApp = NULL;
179     CoUninitialize();
180     return;
181     }
182    
183    
184    
185    
186    
187    
188    
189     // ********************************************************************
190     // ******** Procédure qui met un nom sur les entités de solidworks ****
191     // ********************************************************************
192    
193     void SLD_FONCTION::identificateur(void)
194     {
195 bournival 34 VideNom(); // procédure qui s'assure que toutes les entités sont vides (n'ont pas de nom)
196     CComQIPtr <IPartDoc> swPart;
197     swPart = swModel;
198 5 CComVariant vBodyArr; // si plus d'un corps dans le fichier part
199     swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
200     SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
201     LPDISPATCH* pBodyDispArray = NULL;
202     long nBodyHighIndex = -1;
203     long nBodyCount = -1;
204     SafeArrayAccessData(psaBody, (void **) &pBodyDispArray);
205     SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
206     nBodyCount = nBodyHighIndex + 1;
207     for (int i = 0; i < nBodyCount; i++)
208     {
209     CComQIPtr <IBody2> pBody;
210     pBody = pBodyDispArray[i];
211     CComPtr <IFace2> face;
212     CComPtr <IFace2> suivantface;
213     CComPtr <ISurface> surf;
214     long nbFaces;
215     pBody->GetFaceCount(&nbFaces);
216     pBody->IGetFirstFace(&face);
217    
218     for(int f=0;f<nbFaces;f++)// boucle sur les faces
219     {
220     SetID(face.p,0);
221     CComPtr <ILoop2> loope;
222     CComPtr <ILoop2> nextloope;
223     face->IGetFirstLoop(&loope);
224     long nbloop = -1;
225     face->GetLoopCount(&nbloop);
226     for (int l = 0;l<nbloop;l++)
227     {
228     // maintenant les aretes
229     CComPtr <ICoEdge> Coarete;
230     CComPtr <ICoEdge> nextCoarete;
231     loope->IGetFirstCoEdge(&Coarete);
232     long nbCoarete = -1;
233     loope->GetEdgeCount(&nbCoarete);
234     for (int coa=0;coa<nbCoarete;coa++)
235     {
236     CComPtr <IEdge> arete;
237     Coarete->IGetEdge(&arete);
238     SetID(arete.p,0); // numérotation de l'arrète.
239     CComPtr <IVertex> Sommet1;
240     arete->IGetStartVertex(&Sommet1);
241    
242     if (Sommet1!=NULL)
243     {
244     SetID(Sommet1.p,0);
245     CComPtr <IVertex> Sommet2;
246     arete->IGetEndVertex(&Sommet2);
247     SetID(Sommet2.p,0);
248     Sommet2.Release();
249     }
250     arete.Release();
251     Sommet1.Release();
252     Coarete->IGetNext(&nextCoarete);
253     Coarete = nextCoarete;
254     nextCoarete.Release();
255     } // next CoEdge
256     Coarete.Release();
257     loope->IGetNext(&nextloope);
258     loope = nextloope;
259     nextloope.Release();
260    
261     } // next loop
262     loope.Release();
263     face->IGetNextFace(&suivantface);
264     face = suivantface;
265     suivantface.Release();
266     } // next face
267     face.Release();
268     pBody.Release();
269     } // next body
270     return;
271     }
272    
273    
274    
275    
276    
277    
278    
279    
280    
281    
282    
283    
284    
285    
286    
287     //******************************************************************
288     void SLD_FONCTION::VideNom(void)
289     {
290     CComQIPtr <IPartDoc> swPart;
291     swPart = swModel;
292     long count;
293     CComPtr <IEntity> entite;
294    
295     swPart->GetNamedEntitiesCount ( &count );
296     if (count==0)
297     return;
298    
299     CComVariant vBodyArr; // si plus d'un corps dans le fichier part
300     swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
301     SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
302     LPDISPATCH* pBodyDispArray = NULL;
303     long nBodyHighIndex = -1;
304     long nBodyCount = -1;
305     SafeArrayAccessData(psaBody, (void **) &pBodyDispArray);
306     SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
307     nBodyCount = nBodyHighIndex + 1;
308    
309     for (int i = 0; i < nBodyCount; i++)
310     {
311     CComQIPtr <IBody2> pBody;
312     pBody = pBodyDispArray[i];
313     CComPtr <IFace2> face;
314     CComPtr <IFace2> suivantface;
315     CComPtr <ISurface> surf;
316     long nbFaces;
317     pBody->GetFaceCount(&nbFaces);
318     pBody->IGetFirstFace(&face);
319    
320     for(int f=0;f<nbFaces;f++)// boucle sur les faces
321     {
322     EffaceID(face);
323    
324     CComPtr <ILoop2> loope;
325     CComPtr <ILoop2> nextloope;
326     face->IGetFirstLoop(&loope);
327     long nbloop = -1;
328     face->GetLoopCount(&nbloop);
329     for (int l = 0;l<nbloop;l++)
330     {
331     // maintenant les aretes
332     CComPtr <ICoEdge> Coarete;
333     CComPtr <ICoEdge> nextCoarete;
334     loope->IGetFirstCoEdge(&Coarete);
335     long nbCoarete = -1;
336     loope->GetEdgeCount(&nbCoarete);
337     for (int coa=0;coa<nbCoarete;coa++)
338     {
339    
340     CComPtr <IEdge> arete;
341     Coarete->IGetEdge(&arete);
342    
343     EffaceID(arete.p);
344    
345     CComPtr <IVertex> Sommet1;
346     arete->IGetStartVertex(&Sommet1);
347    
348     if (Sommet1!=NULL)
349     {
350     EffaceID(Sommet1.p);
351     CComPtr <IVertex> Sommet2;
352     arete->IGetEndVertex(&Sommet2);
353     EffaceID(Sommet2.p);
354     Sommet2.Release();
355     }
356    
357     arete.Release();
358     Sommet1.Release();
359    
360     Coarete->IGetNext(&nextCoarete);
361     Coarete = nextCoarete;
362     nextCoarete.Release();
363    
364     } // next CoEdge
365     Coarete.Release();
366    
367     loope->IGetNext(&nextloope);
368     loope = nextloope;
369     nextloope.Release();
370     } // next loop
371    
372     loope.Release();
373     face->IGetNextFace(&suivantface);
374     face = suivantface;
375     suivantface.Release();
376     } // next face
377     face.Release();
378     pBody.Release();
379     } // next body
380    
381     return;
382     }
383    
384    
385    
386    
387     //*****************************************
388     BOOL SLD_FONCTION::GetParID(char* ID, CComPtr<IFace2> &face )
389     {
390     CComPtr <IEntity> ent;
391     WideString acstostr(ID);
392     BSTR nom=BSTR(acstostr);
393     CComQIPtr <IPartDoc> swPart;
394     swPart = swModel;
395 foucault 27 swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
396     if (ent == 0)
397     {
398     face = 0;
399     return false;
400     }
401 5 ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
402    
403     return true;
404     }
405    
406     BOOL SLD_FONCTION::GetParID(BSTR nom, CComPtr<IFace2> &face )
407     {
408     CComPtr <IEntity> ent;
409     CComQIPtr <IPartDoc> swPart;
410     swPart = swModel;
411     swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
412 foucault 27 if (ent == 0)
413     {
414     face = 0;
415     return false;
416     }
417 5 ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
418    
419     return true;
420     }
421    
422     //*****************************************
423     BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<IEdge> &arete)
424     {
425     CComPtr <IEntity> ent;
426     WideString acstostr(ID);
427     BSTR nom=BSTR(acstostr);
428     CComQIPtr <IPartDoc> swPart;
429     swPart = swModel;
430 bournival 34 swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
431 foucault 27 if (ent == 0)
432     {
433 bournival 34 // on a peut-être un refEdge, c'est fucké, mais la solution suivante semble fonctioner..
434     //*************************
435    
436     /* HRESULT hr = S_OK;
437     long nEntCount = -1;
438     CComPtr <IEntity> pEntity;
439     CComBSTR sEntName;
440    
441     hr = swPart->GetNamedEntitiesCount (&nEntCount);
442    
443     IEntity **ppEntity;
444     ppEntity = new IEntity* [nEntCount];
445    
446     hr = swPart->IGetNamedEntities(nEntCount, ppEntity);
447    
448     for (long i = 0; i < nEntCount; i++)
449     {
450     pEntity= ppEntity[5];
451     hr = swPart->IGetEntityName(pEntity, &sEntName);
452     if (nom == sEntName )
453     {
454     pEntity->QueryInterface( IID_IEdge, (LPVOID*)&arete);
455     return true;
456     }
457    
458     //pEntity = NULL;
459     pEntity.Release();
460    
461     }
462     delete sEntName;
463     delete pEntity;
464    
465     delete [] ppEntity;
466     */
467     //***************************
468     // Ça marche pas, donc la prochaine solution est de parcourir les features, et de noter le nom de chaque edge puis voir si on a le bon...
469    
470     CComPtr <IFeature> swFeat;
471     CComPtr <IFeature> swNextFeat;
472     VARIANT_BOOL bSupprime;
473     CComVariant vArete;
474     CComVariant vEdge;
475     CComPtr <IEntity> ent;
476    
477     swPart->IFirstFeature(&swFeat);
478     while (swFeat)
479     {
480     swFeat->IsSuppressed(&bSupprime);
481     if(!bSupprime)
482     {
483     CComBSTR NomFeat;
484     swFeat->GetTypeName(&NomFeat);
485    
486     CComBSTR Compo1 ("CompositeCurve."); // le dernier point est mangé par le BSTR
487     CComBSTR Compo2 ("3DSplineCurve.");
488    
489     if ((Compo1==NomFeat) || (Compo2==NomFeat)) // code de traitement des poutres
490     {
491     CComPtr <IReferenceCurve> refCourbe;
492     CComPtr <IUnknown> Unk;
493    
494     swFeat->IGetSpecificFeature(&Unk);
495     Unk->QueryInterface( IID_IReferenceCurve, (LPVOID*)&refCourbe);
496    
497     CComPtr<IEdge> swArete;
498     refCourbe->IGetFirstSegment(&swArete);
499    
500     while(swArete)
501     {
502     char id3[1000]; // était dans la boucle while avant
503     sprintf(id3,"%s",GetID(swArete.p).c_str());
504     if (strcmp(ID, id3)==0 )
505     {
506     arete = swArete;
507     return true;
508     }
509     swArete.Release();
510     refCourbe->IGetNextSegment(&swArete);
511     } // end while (swarete)
512     } // end if feature est une poutre
513     } // end if supprimé
514    
515     swFeat->IGetNextFeature(&swNextFeat);
516     swFeat = swNextFeat;
517     swNextFeat.Release();
518     } // end while des features
519    
520     if (ent ==0)
521     {
522     arete = 0;
523     return false;
524     }
525     return true;
526 foucault 27 }
527 5 ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
528     return true;
529     }
530    
531 bournival 34
532    
533    
534    
535    
536    
537 5 BOOL SLD_FONCTION::GetParID(BSTR nom,CComPtr<IEdge> &arete)
538     {
539     CComPtr <IEntity> ent;
540     CComQIPtr <IPartDoc> swPart;
541     swPart = swModel;
542 bournival 34 swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
543 foucault 27 if (ent == 0)
544     {
545     arete = 0;
546     return false;
547     }
548 5 ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
549     return true;
550     }
551    
552     //*****************************************
553     BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<IVertex> &sommet)
554     {
555     CComPtr <IEntity> ent;
556     WideString acstostr(ID);
557     BSTR nom=BSTR(acstostr);
558     CComQIPtr <IPartDoc> swPart;
559     swPart = swModel;
560     swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
561 foucault 27 if (ent == 0)
562     {
563     printf("Failed to get %s\n", ID);
564     sommet = 0;
565     return false;
566     }
567 5 ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
568     return true;
569     }
570    
571     BOOL SLD_FONCTION::GetParID(BSTR nom,CComPtr<IVertex> &sommet)
572     {
573     CComPtr <IEntity> ent;
574     CComQIPtr <IPartDoc> swPart;
575     swPart = swModel;
576 foucault 27 swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
577     if (ent == 0)
578     {
579     sommet = 0;
580     return false;
581     }
582 5 ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
583     return true;
584     }
585    
586     //********************************************************
587     BOOL SLD_FONCTION::GetParID(char* ID, CComPtr<ISurface> &surface)
588     {
589     CComPtr<IFace2> face;
590     GetParID( ID,face); // on va chercher le pointeur pour la face
591     face->IGetSurface(&surface);
592     return true;
593     }
594    
595     //********************************************************
596     BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<ICurve> &courbe)
597     {
598     CComPtr<IEdge> arete;
599     GetParID(ID,arete );
600     arete->IGetCurve(&courbe);
601     return true;
602     }
603    
604    
605    
606    
607     //********************************************************
608     // **** place l'ID de la Face dans solidworks ****
609     // *******************************************************
610     void SLD_FONCTION::SetID(IFace2 *face, long type )
611     {
612    
613     static long compteur=1;
614     CComPtr <IEntity> ent;
615     short retval; //et la doc qui dit que ce doit être un booléen ?!?
616    
617     char nom2[20];
618    
619     if( type==0 )// face normale apartient à un volume
620     strcpy(nom2,"Face");
621     else // face appartenant à une coque
622     strcpy(nom2,"Face_Libre");
623    
624     char nom3[10];
625     _ltoa(compteur,nom3,10);
626     strcat(nom2,nom3);
627    
628     WideString acstostr(nom2);
629     BSTR nom=BSTR(acstostr);
630    
631     face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
632     CComQIPtr <IPartDoc> swPart;
633     swPart = swModel;
634     swPart->ISetEntityName( ent, nom , &retval );
635     if (retval!=0) compteur++;
636    
637     }
638    
639    
640     void SLD_FONCTION::EffaceID(IFace2 *face)
641     {
642     CComPtr <IEntity> ent;
643     short retval;
644     face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
645     CComQIPtr <IPartDoc> swPart;
646     swPart = swModel;
647     swPart->DeleteEntityName ( ent, &retval );
648    
649     }
650    
651    
652     //********************************************************
653     void SLD_FONCTION::SetID(IEdge *arete,long type )
654     {
655    
656     static long compteur=1;
657     CComPtr <IEntity> ent;
658     short retval; //et la doc qui dit que ce doit être un booléen ?!?
659    
660     char nom2[20];
661    
662     if( type==0 ) // arete apartient à un volume
663     strcpy(nom2,"Arete");
664     else if (type==1) // arete appartenant à une coque
665     strcpy(nom2,"Arete_Coque");
666     else // arete seule (poutre)
667     strcpy(nom2,"Arete_Poutre");
668    
669     char nom3[10];
670     _ltoa(compteur,nom3,10);
671     strcat(nom2,nom3);
672    
673     WideString acstostr(nom2);
674     BSTR nom=BSTR(acstostr);
675    
676     arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
677     CComQIPtr <IPartDoc> swPart;
678     swPart = swModel;
679     swPart->ISetEntityName( ent, nom , &retval );
680    
681     if (retval!=0) compteur++;
682    
683     }
684    
685    
686    
687     void SLD_FONCTION::EffaceID(IEdge* arete)
688     {
689     CComPtr <IEntity> ent;
690     short retval;
691     arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
692     CComQIPtr <IPartDoc> swPart;
693     swPart = swModel;
694     swPart->DeleteEntityName ( ent, &retval );
695    
696     }
697    
698    
699     //********************************************************
700     void SLD_FONCTION::SetID(IVertex* sommet,long type )
701     {
702    
703     static long compteur=1;
704     CComPtr <IEntity> ent;
705     short retval; //et la doc qui dit que ce doit être un booléen ?!?
706    
707     char nom2[20];
708    
709     if( type==0 ) // sommet d'un volume
710     strcpy(nom2,"Sommet");
711     else if (type==1) // sommet d'une coque
712     strcpy(nom2,"Sommet_Coque");
713     else // sommet d'une poutre
714     strcpy(nom2,"Sommet_Poutre");
715    
716     char nom3[10];
717     _ltoa(compteur,nom3,10);
718     strcat(nom2,nom3);
719    
720     WideString acstostr(nom2);
721     BSTR nom=BSTR(acstostr);
722    
723     sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
724     CComQIPtr <IPartDoc> swPart;
725     swPart = swModel;
726     swPart->ISetEntityName( ent, nom , &retval );
727    
728     if (retval!=0) compteur++;
729    
730     }
731    
732     void SLD_FONCTION::EffaceID(IVertex* sommet)
733     {
734     CComPtr <IEntity> ent;
735     short retval;
736     sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
737     CComQIPtr <IPartDoc> swPart;
738     swPart = swModel;
739     swPart->DeleteEntityName ( ent, &retval );
740    
741     }
742    
743    
744     //*********************************************************
745     // **** Procédure qui renvoie le ID d'une arete **********
746     //*********************************************************
747     AnsiString SLD_FONCTION::GetID(IEdge* arete)
748     {
749    
750     CComPtr <IEntity> ent;
751     CComPtr <IEdge> swarete(arete);
752     swarete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
753    
754     BSTR retval;
755     swModel->IGetEntityName ( ent, &retval );
756 bournival 34 sensMaitre = 1; // par défaut le sens est le même
757 5
758 bournival 22 // on vérifie, si c'est un esclave on retourne le nom du maitre.
759     CComPtr <IAttribute> Attribut;
760     ent->IFindAttribute ( DefAttrDoublon, 0, &Attribut ) ;
761     if(Attribut!=NULL)
762     {
763     IParameter* parammaitre;
764     CComBSTR nomParam("Maitre.") ;
765     Attribut->IGetParameter ( nomParam, &parammaitre );
766     parammaitre->GetStringValue(&retval) ;
767 bournival 34
768     double sens2;
769     IParameter* paramsens;
770     CComBSTR nomParam2("Sens.") ;
771     Attribut->IGetParameter ( nomParam2, &paramsens );
772     paramsens->GetDoubleValue(&sens2) ;
773     sensMaitre = sens2;
774 bournival 22 }
775     else
776     {
777     swModel->IGetEntityName ( ent, &retval );
778     }
779    
780 5 AnsiString rep(retval);
781     return (rep);
782    
783     }
784    
785     //******************************************************
786     AnsiString SLD_FONCTION::GetID(IFace2* face)
787     {
788    
789     CComPtr <IEntity> ent;
790     CComPtr <IFace2> swface(face);
791    
792     swface->QueryInterface( IID_IEntity, (LPVOID*)&ent);
793    
794     BSTR retval;
795     swModel->IGetEntityName ( ent, &retval );
796    
797     AnsiString rep(retval);
798     return (rep);
799    
800     }
801    
802    
803     //****************************
804     AnsiString SLD_FONCTION::GetID(IVertex* sommet )
805     {
806     CComPtr <IEntity> ent;
807     CComPtr<IVertex> swSommet(sommet);
808     swSommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
809     BSTR retval;
810    
811    
812 bournival 34 swModel->IGetEntityName ( ent, &retval );
813 5 // on vérifie, si c'est un esclave on retourne le nom du maitre.
814    
815     CComPtr <IAttribute> Attribut;
816     ent->IFindAttribute ( DefAttrDoublon, 0, &Attribut ) ;
817     if(Attribut!=NULL)
818     {
819     IParameter* parammaitre;
820     CComBSTR nomParam("Maitre.") ;
821     Attribut->IGetParameter ( nomParam, &parammaitre );
822     parammaitre->GetStringValue(&retval) ;
823     }
824     else
825     {
826     swModel->IGetEntityName ( ent, &retval );
827     }
828    
829     AnsiString rep(retval);
830     return (rep);
831    
832     }
833    
834    
835 bournival 22 double SLD_FONCTION::GetValeurTolerance()
836     {
837     if(tolerance!=0) return tolerance; // pour ne pas refaire le calcul plusieurs fois pour avoir la même valeur.
838     double petit = 999999999;
839     double actuelle = 0;
840 5
841 bournival 22 // on demande le body au model
842     CComVariant vBodyArr; // si plus d'un corps dans le fichier part
843     CComQIPtr<IPartDoc> swPart;
844     swPart = swModel;
845     swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
846     SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
847     LPDISPATCH* pBodyDispArray = NULL;
848     long nBodyHighIndex = -1;
849     SafeArrayAccessData(psaBody, (void **) &pBodyDispArray);
850     SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
851     long nb_sld_corps = nBodyHighIndex + 1;
852 5
853 bournival 22 for (long i=0;i<nb_sld_corps;i++) // boucle sur les corps
854     {
855     CComQIPtr <IBody2> swBody;
856     swBody = pBodyDispArray[i];
857     double coins[6];
858     CComVariant vRetval;
859     vRetval=swBody->GetBodyBox();
860     SafeDoubleArray sda(vRetval);
861     //HRESULT status = swBody->IGetBodyBox ( coins );
862     coins[0]=sda[0];
863     coins[1]=sda[1];
864     coins[2]=sda[2];
865     coins[3]=sda[3];
866     coins[4]=sda[4];
867     coins[5]=sda[5];
868     actuelle = sqrt( (coins[0] - coins[3])*(coins[0] - coins[3]) + (coins[1] - coins[4])*(coins[1] - coins[4]) + (coins[2] - coins[5])*(coins[2] - coins[5])) /10000000 ;
869 foucault 27 //Gilles : avec une tolerance de 1E-8, SolidWorks plante lors de la fonction GetBCurbveParams
870     actuelle = std::max(actuelle, 1E-6);
871 bournival 22 if (actuelle <petit ) petit = actuelle;
872     }
873     tolerance = petit;
874 5
875 bournival 22 return tolerance;
876     }
877    
878    
879 5 #endif
880    
881    
882 bournival 34