ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_fonction.cpp
Revision: 131
Committed: Wed Jul 30 21:32:52 2008 UTC (16 years, 9 months ago) by bournival
Original Path: magic/lib/geometrie/geometrie/src/sld_fonction.cpp
File size: 22548 byte(s)
Log Message:
Des modifications au sld_import et fem_maillage pour les études multidimensionnelles.  Le code ne devrait pas affecter les autres études.

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