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 |
|
|
|
39 |
|
|
using namespace std;
|
40 |
|
|
|
41 |
|
|
SLD_FONCTION::SLD_FONCTION():ouvert(0)
|
42 |
|
|
{
|
43 |
bournival |
22 |
tolerance = 0;
|
44 |
|
5 |
}
|
45 |
|
|
|
46 |
|
|
SLD_FONCTION::~SLD_FONCTION()
|
47 |
|
|
{
|
48 |
foucault |
27 |
if (swApp.p!=NULL) swApp.p = NULL;
|
49 |
|
|
if (swModel.p != NULL) swModel.p = NULL;
|
50 |
|
5 |
}
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
void SLD_FONCTION::OuvrirFichier(char* file)
|
54 |
|
|
{
|
55 |
|
|
WideString acstostr(file);
|
56 |
|
|
BSTR filename=BSTR(acstostr);
|
57 |
|
|
WideString acstostr2("");
|
58 |
|
|
BSTR configuration=BSTR(acstostr2);
|
59 |
|
|
|
60 |
|
|
long type ;
|
61 |
|
|
type=1 ;
|
62 |
|
|
long options ;
|
63 |
|
|
options= 1;
|
64 |
|
|
|
65 |
|
|
long Errors;
|
66 |
|
|
long Warnings;
|
67 |
|
|
swApp->OpenDoc6(filename, type, options, configuration, &Errors, &Warnings, &swModel);
|
68 |
foucault |
27 |
|
69 |
|
|
double tolerance=1E-5;
|
70 |
|
|
Modeler_SetToleranceValue(1,tolerance);
|
71 |
|
|
Modeler_SetToleranceValue(2,tolerance);
|
72 |
|
|
|
73 |
|
5 |
return ;
|
74 |
|
|
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
void SLD_FONCTION::get_face_tessellation(CComPtr<IFace2> __swFace, long *__triangleCount, double ** __tessPts)
|
80 |
|
|
{
|
81 |
|
|
HRESULT hr;
|
82 |
|
|
hr = __swFace->GetTessTriangleCount(__triangleCount);
|
83 |
foucault |
27 |
if (hr != S_OK)return;
|
84 |
|
5 |
|
85 |
|
|
CComVariant vTessTriang;
|
86 |
foucault |
27 |
hr = __swFace->GetTessTriangles(VARIANT_TRUE, &vTessTriang);
|
87 |
|
|
if (hr != S_OK)return;
|
88 |
|
5 |
SafeFloatArray saTessPts (vTessTriang);
|
89 |
|
|
|
90 |
|
|
unsigned long nbCoords = *__triangleCount*9;
|
91 |
|
|
*__tessPts = new double [nbCoords];
|
92 |
|
|
|
93 |
foucault |
27 |
for (unsigned i=0; i < nbCoords; i++)
|
94 |
|
5 |
{
|
95 |
|
|
(*__tessPts)[i] = saTessPts[i];
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
foucault |
27 |
/*
|
100 |
|
|
iTol=1 : swBSCurveOutputTol -3 D bspline curve output tolerance (meters)
|
101 |
|
|
iTol=2 : swBSCurveNonRationalOutputTol - 3D nonrational b-spline curve output tolerance (meters)
|
102 |
|
|
iTol=3 : swUVCurveOutputTol - 2D trim curve output tolerance (fraction of characteristic minimum face dimension)
|
103 |
|
|
iTol=4 : swSurfChordTessellationTol - Chord tolerance or deviation for tessellation for surfaces
|
104 |
|
|
iTol=5 : swSurfAngularTessellationTol - Angular tolerance or deviation for tessellation for surfaces
|
105 |
|
|
iTol=6 : swCurveChordTessellationTol - Chord tolerance or deviation for tessellation for curves
|
106 |
|
|
*/
|
107 |
|
|
void SLD_FONCTION::Modeler_SetToleranceValue(long iTol, double __tolerance)
|
108 |
|
|
{
|
109 |
|
|
long iswToleranceID;
|
110 |
|
|
switch (iTol)
|
111 |
|
|
{
|
112 |
|
|
case 1: iswToleranceID = swBSCurveOutputTol;
|
113 |
|
|
break;
|
114 |
|
|
case 2: iswToleranceID = swBSCurveNonRationalOutputTol;
|
115 |
|
|
break;
|
116 |
|
|
case 3: iswToleranceID = swUVCurveOutputTol;
|
117 |
|
|
break;
|
118 |
|
|
case 4: iswToleranceID = swSurfChordTessellationTol;
|
119 |
|
|
break;
|
120 |
|
|
case 5: iswToleranceID = swSurfAngularTessellationTol;
|
121 |
|
|
break;
|
122 |
|
|
case 6: iswToleranceID = swCurveChordTessellationTol;
|
123 |
|
|
break;
|
124 |
|
|
default:
|
125 |
|
|
return;
|
126 |
|
|
}
|
127 |
|
|
CComPtr<IModeler> swModeler;
|
128 |
|
|
swApp->IGetModeler(&swModeler);
|
129 |
|
|
/*double oldTol=*/swModeler->SetToleranceValue(iswToleranceID,__tolerance);
|
130 |
|
|
}
|
131 |
|
5 |
|
132 |
foucault |
27 |
|
133 |
|
5 |
void SLD_FONCTION::Sauvegarder(char* file)
|
134 |
|
|
{
|
135 |
|
|
short retval =-1;
|
136 |
|
|
long Errors = -1;
|
137 |
|
|
long Warnings=-1;
|
138 |
|
|
|
139 |
|
|
WideString acstostr(file);
|
140 |
|
|
BSTR nom=BSTR(acstostr);
|
141 |
|
|
swModel->SaveAs4 ( nom, swSaveAsCurrentVersion, swSaveAsOptions_SaveReferenced , &Errors, &Warnings ,&retval);
|
142 |
|
|
//if (retval==0 || hres !=S_OK)
|
143 |
|
|
//cout<<"Sauvegarde échouée!"<<endl;
|
144 |
|
|
return;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
void SLD_FONCTION::Connection(void)
|
154 |
|
|
{
|
155 |
|
|
//HRESULT hres;
|
156 |
|
|
CoInitialize(NULL); //Initialize COM
|
157 |
|
|
swApp.CoCreateInstance(CLSID_SldWorks_, NULL, CLSCTX_LOCAL_SERVER); //Create an instance of SolidWorks
|
158 |
|
|
//HRESULT status =swApp->put_Visible( true );
|
159 |
|
|
ouvert=1;
|
160 |
|
|
return;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
void SLD_FONCTION::Fermer(void)
|
170 |
|
|
{
|
171 |
|
|
if (!ouvert) return;
|
172 |
|
|
swApp->ExitApp();
|
173 |
|
|
swApp = NULL;
|
174 |
|
|
CoUninitialize();
|
175 |
|
|
return;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
// ********************************************************************
|
185 |
|
|
// ******** Procédure qui met un nom sur les entités de solidworks ****
|
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 |
|
|
//******************************************************************
|
283 |
|
|
void SLD_FONCTION::VideNom(void)
|
284 |
|
|
{
|
285 |
|
|
CComQIPtr <IPartDoc> swPart;
|
286 |
|
|
swPart = swModel;
|
287 |
|
|
long count;
|
288 |
|
|
CComPtr <IEntity> entite;
|
289 |
|
|
|
290 |
|
|
swPart->GetNamedEntitiesCount ( &count );
|
291 |
|
|
if (count==0)
|
292 |
|
|
return;
|
293 |
|
|
|
294 |
|
|
CComVariant vBodyArr; // si plus d'un corps dans le fichier part
|
295 |
|
|
swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
|
296 |
|
|
SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
|
297 |
|
|
LPDISPATCH* pBodyDispArray = NULL;
|
298 |
|
|
long nBodyHighIndex = -1;
|
299 |
|
|
long nBodyCount = -1;
|
300 |
|
|
SafeArrayAccessData(psaBody, (void **) &pBodyDispArray);
|
301 |
|
|
SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
|
302 |
|
|
nBodyCount = nBodyHighIndex + 1;
|
303 |
|
|
|
304 |
|
|
for (int i = 0; i < nBodyCount; i++)
|
305 |
|
|
{
|
306 |
|
|
CComQIPtr <IBody2> pBody;
|
307 |
|
|
pBody = pBodyDispArray[i];
|
308 |
|
|
CComPtr <IFace2> face;
|
309 |
|
|
CComPtr <IFace2> suivantface;
|
310 |
|
|
CComPtr <ISurface> surf;
|
311 |
|
|
long nbFaces;
|
312 |
|
|
pBody->GetFaceCount(&nbFaces);
|
313 |
|
|
pBody->IGetFirstFace(&face);
|
314 |
|
|
|
315 |
|
|
for(int f=0;f<nbFaces;f++)// boucle sur les faces
|
316 |
|
|
{
|
317 |
|
|
EffaceID(face);
|
318 |
|
|
|
319 |
|
|
CComPtr <ILoop2> loope;
|
320 |
|
|
CComPtr <ILoop2> nextloope;
|
321 |
|
|
face->IGetFirstLoop(&loope);
|
322 |
|
|
long nbloop = -1;
|
323 |
|
|
face->GetLoopCount(&nbloop);
|
324 |
|
|
for (int l = 0;l<nbloop;l++)
|
325 |
|
|
{
|
326 |
|
|
// maintenant les aretes
|
327 |
|
|
CComPtr <ICoEdge> Coarete;
|
328 |
|
|
CComPtr <ICoEdge> nextCoarete;
|
329 |
|
|
loope->IGetFirstCoEdge(&Coarete);
|
330 |
|
|
long nbCoarete = -1;
|
331 |
|
|
loope->GetEdgeCount(&nbCoarete);
|
332 |
|
|
for (int coa=0;coa<nbCoarete;coa++)
|
333 |
|
|
{
|
334 |
|
|
|
335 |
|
|
CComPtr <IEdge> arete;
|
336 |
|
|
Coarete->IGetEdge(&arete);
|
337 |
|
|
|
338 |
|
|
EffaceID(arete.p);
|
339 |
|
|
|
340 |
|
|
CComPtr <IVertex> Sommet1;
|
341 |
|
|
arete->IGetStartVertex(&Sommet1);
|
342 |
|
|
|
343 |
|
|
if (Sommet1!=NULL)
|
344 |
|
|
{
|
345 |
|
|
EffaceID(Sommet1.p);
|
346 |
|
|
CComPtr <IVertex> Sommet2;
|
347 |
|
|
arete->IGetEndVertex(&Sommet2);
|
348 |
|
|
EffaceID(Sommet2.p);
|
349 |
|
|
Sommet2.Release();
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
arete.Release();
|
353 |
|
|
Sommet1.Release();
|
354 |
|
|
|
355 |
|
|
Coarete->IGetNext(&nextCoarete);
|
356 |
|
|
Coarete = nextCoarete;
|
357 |
|
|
nextCoarete.Release();
|
358 |
|
|
|
359 |
|
|
} // next CoEdge
|
360 |
|
|
Coarete.Release();
|
361 |
|
|
|
362 |
|
|
loope->IGetNext(&nextloope);
|
363 |
|
|
loope = nextloope;
|
364 |
|
|
nextloope.Release();
|
365 |
|
|
} // next loop
|
366 |
|
|
|
367 |
|
|
loope.Release();
|
368 |
|
|
face->IGetNextFace(&suivantface);
|
369 |
|
|
face = suivantface;
|
370 |
|
|
suivantface.Release();
|
371 |
|
|
} // next face
|
372 |
|
|
face.Release();
|
373 |
|
|
pBody.Release();
|
374 |
|
|
} // next body
|
375 |
|
|
|
376 |
|
|
return;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
|
|
//*****************************************
|
383 |
|
|
BOOL SLD_FONCTION::GetParID(char* ID, CComPtr<IFace2> &face )
|
384 |
|
|
{
|
385 |
|
|
CComPtr <IEntity> ent;
|
386 |
|
|
WideString acstostr(ID);
|
387 |
|
|
BSTR nom=BSTR(acstostr);
|
388 |
|
|
CComQIPtr <IPartDoc> swPart;
|
389 |
|
|
swPart = swModel;
|
390 |
foucault |
27 |
swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
|
391 |
|
|
if (ent == 0)
|
392 |
|
|
{
|
393 |
|
|
face = 0;
|
394 |
|
|
return false;
|
395 |
|
|
}
|
396 |
|
5 |
ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
|
397 |
|
|
|
398 |
|
|
return true;
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
BOOL SLD_FONCTION::GetParID(BSTR nom, CComPtr<IFace2> &face )
|
402 |
|
|
{
|
403 |
|
|
CComPtr <IEntity> ent;
|
404 |
|
|
CComQIPtr <IPartDoc> swPart;
|
405 |
|
|
swPart = swModel;
|
406 |
|
|
swPart->IGetEntityByName ( nom, swSelFACES , &ent ) ;
|
407 |
foucault |
27 |
if (ent == 0)
|
408 |
|
|
{
|
409 |
|
|
face = 0;
|
410 |
|
|
return false;
|
411 |
|
|
}
|
412 |
|
5 |
ent->QueryInterface( IID_IFace2, (LPVOID*)&face);
|
413 |
|
|
|
414 |
|
|
return true;
|
415 |
|
|
}
|
416 |
|
|
|
417 |
|
|
//*****************************************
|
418 |
|
|
BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<IEdge> &arete)
|
419 |
|
|
{
|
420 |
|
|
CComPtr <IEntity> ent;
|
421 |
|
|
WideString acstostr(ID);
|
422 |
|
|
BSTR nom=BSTR(acstostr);
|
423 |
|
|
CComQIPtr <IPartDoc> swPart;
|
424 |
|
|
swPart = swModel;
|
425 |
foucault |
27 |
swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
|
426 |
|
|
if (ent == 0)
|
427 |
|
|
{
|
428 |
|
|
printf("Failed to get %s\n", ID);
|
429 |
|
|
arete = 0;
|
430 |
|
|
return false;
|
431 |
|
|
}
|
432 |
|
5 |
ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
|
433 |
|
|
return true;
|
434 |
|
|
}
|
435 |
|
|
|
436 |
|
|
BOOL SLD_FONCTION::GetParID(BSTR nom,CComPtr<IEdge> &arete)
|
437 |
|
|
{
|
438 |
|
|
CComPtr <IEntity> ent;
|
439 |
|
|
CComQIPtr <IPartDoc> swPart;
|
440 |
|
|
swPart = swModel;
|
441 |
foucault |
27 |
swPart->IGetEntityByName ( nom, swSelEDGES , &ent ) ;
|
442 |
|
|
if (ent == 0)
|
443 |
|
|
{
|
444 |
|
|
arete = 0;
|
445 |
|
|
return false;
|
446 |
|
|
}
|
447 |
|
5 |
ent->QueryInterface( IID_IEdge, (LPVOID*)&arete);
|
448 |
|
|
return true;
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
//*****************************************
|
452 |
|
|
BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<IVertex> &sommet)
|
453 |
|
|
{
|
454 |
|
|
CComPtr <IEntity> ent;
|
455 |
|
|
WideString acstostr(ID);
|
456 |
|
|
BSTR nom=BSTR(acstostr);
|
457 |
|
|
CComQIPtr <IPartDoc> swPart;
|
458 |
|
|
swPart = swModel;
|
459 |
|
|
swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
|
460 |
foucault |
27 |
if (ent == 0)
|
461 |
|
|
{
|
462 |
|
|
printf("Failed to get %s\n", ID);
|
463 |
|
|
sommet = 0;
|
464 |
|
|
return false;
|
465 |
|
|
}
|
466 |
|
5 |
ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
|
467 |
|
|
return true;
|
468 |
|
|
}
|
469 |
|
|
|
470 |
|
|
BOOL SLD_FONCTION::GetParID(BSTR nom,CComPtr<IVertex> &sommet)
|
471 |
|
|
{
|
472 |
|
|
CComPtr <IEntity> ent;
|
473 |
|
|
CComQIPtr <IPartDoc> swPart;
|
474 |
|
|
swPart = swModel;
|
475 |
foucault |
27 |
swPart->IGetEntityByName ( nom, swSelVERTICES , &ent ) ;
|
476 |
|
|
if (ent == 0)
|
477 |
|
|
{
|
478 |
|
|
sommet = 0;
|
479 |
|
|
return false;
|
480 |
|
|
}
|
481 |
|
5 |
ent->QueryInterface( IID_IVertex, (LPVOID*)&sommet);
|
482 |
|
|
return true;
|
483 |
|
|
}
|
484 |
|
|
|
485 |
|
|
//********************************************************
|
486 |
|
|
BOOL SLD_FONCTION::GetParID(char* ID, CComPtr<ISurface> &surface)
|
487 |
|
|
{
|
488 |
|
|
CComPtr<IFace2> face;
|
489 |
|
|
GetParID( ID,face); // on va chercher le pointeur pour la face
|
490 |
|
|
face->IGetSurface(&surface);
|
491 |
|
|
return true;
|
492 |
|
|
}
|
493 |
|
|
|
494 |
|
|
//********************************************************
|
495 |
|
|
BOOL SLD_FONCTION::GetParID(char* ID,CComPtr<ICurve> &courbe)
|
496 |
|
|
{
|
497 |
|
|
CComPtr<IEdge> arete;
|
498 |
|
|
GetParID(ID,arete );
|
499 |
|
|
arete->IGetCurve(&courbe);
|
500 |
|
|
return true;
|
501 |
|
|
}
|
502 |
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
|
|
|
506 |
|
|
//********************************************************
|
507 |
|
|
// **** place l'ID de la Face dans solidworks ****
|
508 |
|
|
// *******************************************************
|
509 |
|
|
void SLD_FONCTION::SetID(IFace2 *face, long type )
|
510 |
|
|
{
|
511 |
|
|
|
512 |
|
|
static long compteur=1;
|
513 |
|
|
CComPtr <IEntity> ent;
|
514 |
|
|
short retval; //et la doc qui dit que ce doit être un booléen ?!?
|
515 |
|
|
|
516 |
|
|
char nom2[20];
|
517 |
|
|
|
518 |
|
|
if( type==0 )// face normale apartient à un volume
|
519 |
|
|
strcpy(nom2,"Face");
|
520 |
|
|
else // face appartenant à une coque
|
521 |
|
|
strcpy(nom2,"Face_Libre");
|
522 |
|
|
|
523 |
|
|
char nom3[10];
|
524 |
|
|
_ltoa(compteur,nom3,10);
|
525 |
|
|
strcat(nom2,nom3);
|
526 |
|
|
|
527 |
|
|
WideString acstostr(nom2);
|
528 |
|
|
BSTR nom=BSTR(acstostr);
|
529 |
|
|
|
530 |
|
|
face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
531 |
|
|
CComQIPtr <IPartDoc> swPart;
|
532 |
|
|
swPart = swModel;
|
533 |
|
|
swPart->ISetEntityName( ent, nom , &retval );
|
534 |
|
|
if (retval!=0) compteur++;
|
535 |
|
|
|
536 |
|
|
}
|
537 |
|
|
|
538 |
|
|
|
539 |
|
|
void SLD_FONCTION::EffaceID(IFace2 *face)
|
540 |
|
|
{
|
541 |
|
|
CComPtr <IEntity> ent;
|
542 |
|
|
short retval;
|
543 |
|
|
face->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
544 |
|
|
CComQIPtr <IPartDoc> swPart;
|
545 |
|
|
swPart = swModel;
|
546 |
|
|
swPart->DeleteEntityName ( ent, &retval );
|
547 |
|
|
|
548 |
|
|
}
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
//********************************************************
|
552 |
|
|
void SLD_FONCTION::SetID(IEdge *arete,long type )
|
553 |
|
|
{
|
554 |
|
|
|
555 |
|
|
static long compteur=1;
|
556 |
|
|
CComPtr <IEntity> ent;
|
557 |
|
|
short retval; //et la doc qui dit que ce doit être un booléen ?!?
|
558 |
|
|
|
559 |
|
|
char nom2[20];
|
560 |
|
|
|
561 |
|
|
if( type==0 ) // arete apartient à un volume
|
562 |
|
|
strcpy(nom2,"Arete");
|
563 |
|
|
else if (type==1) // arete appartenant à une coque
|
564 |
|
|
strcpy(nom2,"Arete_Coque");
|
565 |
|
|
else // arete seule (poutre)
|
566 |
|
|
strcpy(nom2,"Arete_Poutre");
|
567 |
|
|
|
568 |
|
|
char nom3[10];
|
569 |
|
|
_ltoa(compteur,nom3,10);
|
570 |
|
|
strcat(nom2,nom3);
|
571 |
|
|
|
572 |
|
|
WideString acstostr(nom2);
|
573 |
|
|
BSTR nom=BSTR(acstostr);
|
574 |
|
|
|
575 |
|
|
arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
576 |
|
|
CComQIPtr <IPartDoc> swPart;
|
577 |
|
|
swPart = swModel;
|
578 |
|
|
swPart->ISetEntityName( ent, nom , &retval );
|
579 |
|
|
|
580 |
|
|
if (retval!=0) compteur++;
|
581 |
|
|
|
582 |
|
|
}
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
|
|
void SLD_FONCTION::EffaceID(IEdge* arete)
|
587 |
|
|
{
|
588 |
|
|
CComPtr <IEntity> ent;
|
589 |
|
|
short retval;
|
590 |
|
|
arete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
591 |
|
|
CComQIPtr <IPartDoc> swPart;
|
592 |
|
|
swPart = swModel;
|
593 |
|
|
swPart->DeleteEntityName ( ent, &retval );
|
594 |
|
|
|
595 |
|
|
}
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
//********************************************************
|
599 |
|
|
void SLD_FONCTION::SetID(IVertex* sommet,long type )
|
600 |
|
|
{
|
601 |
|
|
|
602 |
|
|
static long compteur=1;
|
603 |
|
|
CComPtr <IEntity> ent;
|
604 |
|
|
short retval; //et la doc qui dit que ce doit être un booléen ?!?
|
605 |
|
|
|
606 |
|
|
char nom2[20];
|
607 |
|
|
|
608 |
|
|
if( type==0 ) // sommet d'un volume
|
609 |
|
|
strcpy(nom2,"Sommet");
|
610 |
|
|
else if (type==1) // sommet d'une coque
|
611 |
|
|
strcpy(nom2,"Sommet_Coque");
|
612 |
|
|
else // sommet d'une poutre
|
613 |
|
|
strcpy(nom2,"Sommet_Poutre");
|
614 |
|
|
|
615 |
|
|
char nom3[10];
|
616 |
|
|
_ltoa(compteur,nom3,10);
|
617 |
|
|
strcat(nom2,nom3);
|
618 |
|
|
|
619 |
|
|
WideString acstostr(nom2);
|
620 |
|
|
BSTR nom=BSTR(acstostr);
|
621 |
|
|
|
622 |
|
|
sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
623 |
|
|
CComQIPtr <IPartDoc> swPart;
|
624 |
|
|
swPart = swModel;
|
625 |
|
|
swPart->ISetEntityName( ent, nom , &retval );
|
626 |
|
|
|
627 |
|
|
if (retval!=0) compteur++;
|
628 |
|
|
|
629 |
|
|
}
|
630 |
|
|
|
631 |
|
|
void SLD_FONCTION::EffaceID(IVertex* sommet)
|
632 |
|
|
{
|
633 |
|
|
CComPtr <IEntity> ent;
|
634 |
|
|
short retval;
|
635 |
|
|
sommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
636 |
|
|
CComQIPtr <IPartDoc> swPart;
|
637 |
|
|
swPart = swModel;
|
638 |
|
|
swPart->DeleteEntityName ( ent, &retval );
|
639 |
|
|
|
640 |
|
|
}
|
641 |
|
|
|
642 |
|
|
|
643 |
|
|
//*********************************************************
|
644 |
|
|
// **** Procédure qui renvoie le ID d'une arete **********
|
645 |
|
|
//*********************************************************
|
646 |
|
|
AnsiString SLD_FONCTION::GetID(IEdge* arete)
|
647 |
|
|
{
|
648 |
|
|
|
649 |
|
|
CComPtr <IEntity> ent;
|
650 |
|
|
CComPtr <IEdge> swarete(arete);
|
651 |
|
|
swarete->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
652 |
|
|
|
653 |
|
|
BSTR retval;
|
654 |
|
|
swModel->IGetEntityName ( ent, &retval );
|
655 |
|
|
|
656 |
bournival |
22 |
|
657 |
|
|
// on vérifie, si c'est un esclave on retourne le nom du maitre.
|
658 |
|
|
CComPtr <IAttribute> Attribut;
|
659 |
|
|
ent->IFindAttribute ( DefAttrDoublon, 0, &Attribut ) ;
|
660 |
|
|
if(Attribut!=NULL)
|
661 |
|
|
{
|
662 |
|
|
IParameter* parammaitre;
|
663 |
|
|
CComBSTR nomParam("Maitre.") ;
|
664 |
|
|
Attribut->IGetParameter ( nomParam, ¶mmaitre );
|
665 |
|
|
parammaitre->GetStringValue(&retval) ;
|
666 |
|
|
}
|
667 |
|
|
else
|
668 |
|
|
{
|
669 |
|
|
swModel->IGetEntityName ( ent, &retval );
|
670 |
|
|
}
|
671 |
|
|
|
672 |
|
5 |
AnsiString rep(retval);
|
673 |
|
|
return (rep);
|
674 |
|
|
|
675 |
|
|
}
|
676 |
|
|
|
677 |
|
|
//******************************************************
|
678 |
|
|
AnsiString SLD_FONCTION::GetID(IFace2* face)
|
679 |
|
|
{
|
680 |
|
|
|
681 |
|
|
CComPtr <IEntity> ent;
|
682 |
|
|
CComPtr <IFace2> swface(face);
|
683 |
|
|
|
684 |
|
|
swface->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
685 |
|
|
|
686 |
|
|
BSTR retval;
|
687 |
|
|
swModel->IGetEntityName ( ent, &retval );
|
688 |
|
|
|
689 |
|
|
AnsiString rep(retval);
|
690 |
|
|
return (rep);
|
691 |
|
|
|
692 |
|
|
}
|
693 |
|
|
|
694 |
|
|
|
695 |
|
|
//****************************
|
696 |
|
|
AnsiString SLD_FONCTION::GetID(IVertex* sommet )
|
697 |
|
|
{
|
698 |
|
|
CComPtr <IEntity> ent;
|
699 |
|
|
CComPtr<IVertex> swSommet(sommet);
|
700 |
|
|
swSommet->QueryInterface( IID_IEntity, (LPVOID*)&ent);
|
701 |
|
|
BSTR retval;
|
702 |
|
|
|
703 |
|
|
|
704 |
|
|
// on vérifie, si c'est un esclave on retourne le nom du maitre.
|
705 |
|
|
|
706 |
|
|
CComPtr <IAttribute> Attribut;
|
707 |
|
|
ent->IFindAttribute ( DefAttrDoublon, 0, &Attribut ) ;
|
708 |
|
|
if(Attribut!=NULL)
|
709 |
|
|
{
|
710 |
|
|
IParameter* parammaitre;
|
711 |
|
|
CComBSTR nomParam("Maitre.") ;
|
712 |
|
|
Attribut->IGetParameter ( nomParam, ¶mmaitre );
|
713 |
|
|
parammaitre->GetStringValue(&retval) ;
|
714 |
|
|
}
|
715 |
|
|
else
|
716 |
|
|
{
|
717 |
|
|
swModel->IGetEntityName ( ent, &retval );
|
718 |
|
|
}
|
719 |
|
|
|
720 |
|
|
AnsiString rep(retval);
|
721 |
|
|
return (rep);
|
722 |
|
|
|
723 |
|
|
}
|
724 |
|
|
|
725 |
|
|
|
726 |
bournival |
22 |
double SLD_FONCTION::GetValeurTolerance()
|
727 |
|
|
{
|
728 |
|
|
if(tolerance!=0) return tolerance; // pour ne pas refaire le calcul plusieurs fois pour avoir la même valeur.
|
729 |
|
|
double petit = 999999999;
|
730 |
|
|
double actuelle = 0;
|
731 |
|
5 |
|
732 |
bournival |
22 |
// on demande le body au model
|
733 |
|
|
CComVariant vBodyArr; // si plus d'un corps dans le fichier part
|
734 |
|
|
CComQIPtr<IPartDoc> swPart;
|
735 |
|
|
swPart = swModel;
|
736 |
|
|
swPart->GetBodies2(swSolidBody, VARIANT_TRUE, &vBodyArr);
|
737 |
|
|
SAFEARRAY* psaBody = V_ARRAY(&vBodyArr);
|
738 |
|
|
LPDISPATCH* pBodyDispArray = NULL;
|
739 |
|
|
long nBodyHighIndex = -1;
|
740 |
|
|
SafeArrayAccessData(psaBody, (void **) &pBodyDispArray);
|
741 |
|
|
SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex);
|
742 |
|
|
long nb_sld_corps = nBodyHighIndex + 1;
|
743 |
|
5 |
|
744 |
bournival |
22 |
for (long i=0;i<nb_sld_corps;i++) // boucle sur les corps
|
745 |
|
|
{
|
746 |
|
|
CComQIPtr <IBody2> swBody;
|
747 |
|
|
swBody = pBodyDispArray[i];
|
748 |
|
|
double coins[6];
|
749 |
|
|
CComVariant vRetval;
|
750 |
|
|
vRetval=swBody->GetBodyBox();
|
751 |
|
|
SafeDoubleArray sda(vRetval);
|
752 |
|
|
//HRESULT status = swBody->IGetBodyBox ( coins );
|
753 |
|
|
coins[0]=sda[0];
|
754 |
|
|
coins[1]=sda[1];
|
755 |
|
|
coins[2]=sda[2];
|
756 |
|
|
coins[3]=sda[3];
|
757 |
|
|
coins[4]=sda[4];
|
758 |
|
|
coins[5]=sda[5];
|
759 |
|
|
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 ;
|
760 |
foucault |
27 |
//Gilles : avec une tolerance de 1E-8, SolidWorks plante lors de la fonction GetBCurbveParams
|
761 |
|
|
actuelle = std::max(actuelle, 1E-6);
|
762 |
bournival |
22 |
if (actuelle <petit ) petit = actuelle;
|
763 |
|
|
}
|
764 |
|
|
tolerance = petit;
|
765 |
|
5 |
|
766 |
bournival |
22 |
return tolerance;
|
767 |
|
|
}
|
768 |
|
|
|
769 |
|
|
|
770 |
|
5 |
#endif
|
771 |
|
|
|
772 |
|
|
|