ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mtu/src/sld_fonction.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months, 1 week ago) by francois
File size: 23029 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

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