ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_fonction.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 24426 byte(s)
Log Message:
structure de l'écriture

File Contents

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