Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1994-06-20 |
2 | // Created by: Modeling | |
3 | // Copyright (c) 1994-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
7fd59977 | 17 | #include <BRepTest.hxx> |
18 | #include <TColgp_Array1OfPnt2d.hxx> | |
19 | #include <DBRep.hxx> | |
20 | #include <Draw_Interpretor.hxx> | |
21 | #include <Draw_Appli.hxx> | |
22 | #include <BRepFilletAPI_MakeFillet.hxx> | |
23 | #include <BRepAlgo_BooleanOperation.hxx> | |
24 | #include <BRepAlgo_Fuse.hxx> | |
25 | #include <BRepAlgo_Cut.hxx> | |
26 | #include <BiTgte_Blend.hxx> | |
27 | #include <TopOpeBRepBuild_HBuilder.hxx> | |
28 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
29 | #include <TopAbs_ShapeEnum.hxx> | |
30 | #include <TopoDS_Shape.hxx> | |
31 | #include <TopoDS_Compound.hxx> | |
32 | #include <TopoDS_Edge.hxx> | |
33 | #include <TopoDS_Vertex.hxx> | |
34 | #include <TopoDS.hxx> | |
35 | #include <TopExp.hxx> | |
36 | #include <TopExp_Explorer.hxx> | |
37 | ||
4e57c75e | 38 | //#include <BOPTools_DSFiller.hxx> |
39 | #include <BOPAlgo_PaveFiller.hxx> | |
40 | ||
7fd59977 | 41 | #include <BRepAlgoAPI_BooleanOperation.hxx> |
42 | #include <BRepAlgoAPI_Fuse.hxx> | |
43 | #include <BRepAlgoAPI_Cut.hxx> | |
44 | #include <BRepAlgoAPI_Section.hxx> | |
45 | ||
46 | #include <FilletSurf_Builder.hxx> | |
47 | #include <ChFi3d_FilletShape.hxx> | |
48 | #include <Geom_TrimmedCurve.hxx> | |
49 | #include <TopTools_ListOfShape.hxx> | |
50 | #include <FilletSurf_StatusType.hxx> | |
51 | #include <FilletSurf_ErrorTypeStatus.hxx> | |
52 | #include <TopAbs.hxx> | |
53 | #include <DrawTrSurf.hxx> | |
54 | ||
7fd59977 | 55 | #include <stdio.h> |
7fd59977 | 56 | |
57 | ||
58 | static Standard_Real t3d = 1.e-4; | |
59 | static Standard_Real t2d = 1.e-5; | |
60 | static Standard_Real ta = 1.e-2; | |
61 | static Standard_Real fl = 1.e-3; | |
62 | static Standard_Real tapp_angle = 1.e-2; | |
63 | static GeomAbs_Shape blend_cont = GeomAbs_C1; | |
64 | ||
65 | static BRepFilletAPI_MakeFillet* Rakk = 0; | |
66 | static BRepFilletAPI_MakeFillet* Rake = 0; | |
67 | static char name[100]; | |
68 | ||
69 | ||
70 | static Standard_Integer contblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
71 | { | |
72 | if(narg ==1) { | |
73 | //cout<<"tolerance angular of approximation : "<< tapp_angle <<endl; | |
74 | //cout<<"internal continuity : "; | |
75 | di<<"tolerance angular of approximation : "<< tapp_angle <<"\n"; | |
76 | di<<"internal continuity : "; | |
77 | switch (blend_cont) { | |
78 | case GeomAbs_C0: | |
79 | //cout << ""<<endl; | |
80 | di << "C0"<<"\n"; | |
81 | break; | |
82 | case GeomAbs_C1: | |
83 | //cout << "C1"<<endl; | |
84 | di << "C1"<<"\n"; | |
85 | break; | |
86 | case GeomAbs_C2: | |
87 | //cout << "C2"<<endl; | |
88 | di << "C2"<<"\n"; | |
89 | break; | |
7fd59977 | 90 | default: |
91 | break; | |
7fd59977 | 92 | } |
93 | return 0; | |
94 | } | |
95 | else { | |
96 | if (narg >3) return 1; | |
91322f44 | 97 | if (narg == 3) { tapp_angle = Abs(Draw::Atof(a[2])); } |
7fd59977 | 98 | char c=a[1][1]; |
99 | switch (c) { | |
100 | case '0': | |
101 | blend_cont = GeomAbs_C0; | |
102 | break; | |
103 | case '2': | |
104 | blend_cont = GeomAbs_C2; | |
105 | break; | |
106 | default : | |
107 | blend_cont = GeomAbs_C1; | |
108 | } | |
109 | return 0; | |
110 | } | |
111 | } | |
112 | ||
113 | static void printtolblend(Draw_Interpretor& di) | |
114 | { | |
115 | //cout<<"tolerance ang : "<<ta<<endl; | |
116 | //cout<<"tolerance 3d : "<<t3d<<endl; | |
117 | //cout<<"tolerance 2d : "<<t2d<<endl; | |
118 | //cout<<"fleche : "<<fl<<endl; | |
119 | ||
120 | //cout<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<endl; | |
121 | ||
122 | di<<"tolerance ang : "<<ta<<"\n"; | |
123 | di<<"tolerance 3d : "<<t3d<<"\n"; | |
124 | di<<"tolerance 2d : "<<t2d<<"\n"; | |
125 | di<<"fleche : "<<fl<<"\n"; | |
126 | ||
127 | di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n"; | |
128 | } | |
129 | ||
130 | static Standard_Integer tolblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
131 | { | |
132 | if(narg == 1){ | |
133 | printtolblend(di); | |
134 | return 0; | |
135 | } | |
136 | else if(narg == 5){ | |
91322f44 | 137 | ta = Draw::Atof(a[1]); |
138 | t3d = Draw::Atof(a[2]); | |
139 | t2d = Draw::Atof(a[3]); | |
140 | fl = Draw::Atof(a[4]); | |
7fd59977 | 141 | return 0; |
142 | } | |
143 | return 1; | |
144 | } | |
145 | static Standard_Integer BLEND(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
146 | { | |
147 | if(Rakk != 0) {delete Rakk; Rakk = 0;} | |
148 | printtolblend(di); | |
149 | if (narg<5) return 1; | |
150 | TopoDS_Shape V = DBRep::Get(a[2]); | |
151 | if(V.IsNull()) return 1; | |
152 | ChFi3d_FilletShape FSh = ChFi3d_Rational; | |
153 | if (narg%2 == 0) { | |
154 | if (!strcasecmp(a[narg-1], "Q")) { | |
155 | FSh = ChFi3d_QuasiAngular; | |
156 | } | |
157 | else if (!strcasecmp(a[narg-1], "P")) { | |
158 | FSh = ChFi3d_Polynomial; | |
159 | } | |
160 | } | |
161 | Rakk = new BRepFilletAPI_MakeFillet(V,FSh); | |
162 | Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl); | |
163 | Rakk->SetContinuity(blend_cont, tapp_angle); | |
164 | Standard_Real Rad; | |
165 | TopoDS_Edge E; | |
166 | Standard_Integer nbedge = 0; | |
167 | for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){ | |
91322f44 | 168 | Rad = Draw::Atof(a[2*ii + 1]); |
7fd59977 | 169 | TopoDS_Shape aLocalEdge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE)); |
170 | E = TopoDS::Edge(aLocalEdge); | |
171 | // E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE)); | |
172 | if(!E.IsNull()){ | |
173 | Rakk->Add(Rad,E); | |
174 | nbedge++; | |
175 | } | |
176 | } | |
177 | if(!nbedge) return 1; | |
178 | Rakk->Build(); | |
179 | if(!Rakk->IsDone()) return 1; | |
180 | TopoDS_Shape res = Rakk->Shape(); | |
181 | DBRep::Set(a[1],res); | |
182 | return 0; | |
183 | } | |
184 | ||
185 | static void PrintHist(const TopoDS_Shape& S, | |
186 | TopTools_ListIteratorOfListOfShape& It, | |
187 | Standard_Integer& nbgen) | |
188 | { | |
189 | TopoDS_Compound C; | |
190 | BRep_Builder B; | |
191 | B.MakeCompound(C); | |
192 | B.Add(C,S); | |
193 | char localname[100]; | |
194 | if(nbgen<10){ | |
91322f44 | 195 | Sprintf(localname,"generated_00%d", nbgen++); |
7fd59977 | 196 | } |
197 | else if(nbgen<100){ | |
91322f44 | 198 | Sprintf(localname,"generated_0%d", nbgen++); |
7fd59977 | 199 | } |
200 | else { | |
91322f44 | 201 | Sprintf(localname,"generated_%d", nbgen++); |
7fd59977 | 202 | } |
203 | for(; It.More(); It.Next()){ | |
204 | B.Add(C,It.Value()); | |
205 | } | |
206 | DBRep::Set(localname,C); | |
207 | } | |
208 | ||
209 | static Standard_Integer CheckHist(Draw_Interpretor& di, | |
210 | Standard_Integer , | |
211 | const char** ) | |
212 | { | |
213 | if(Rakk == 0) { | |
0d969553 Y |
214 | //cout<<"No active Builder"<<endl; |
215 | di<<"No active Builder"<<"\n"; | |
7fd59977 | 216 | return 1; |
217 | } | |
218 | if(!Rakk->IsDone()) { | |
0d969553 Y |
219 | //cout<<"Active Builder Not Done"<<endl; |
220 | di<<"Active Builder Not Done"<<"\n"; | |
7fd59977 | 221 | return 1; |
222 | } | |
223 | Standard_Integer nbc = Rakk->NbContours(); | |
224 | Standard_Integer nbgen = 0; | |
225 | TopTools_ListIteratorOfListOfShape It; | |
226 | TopoDS_Shape curshape; | |
227 | for(Standard_Integer i = 1; i <= nbc; i++){ | |
228 | curshape = Rakk->FirstVertex(i); | |
229 | It.Initialize(Rakk->Generated(curshape)); | |
230 | PrintHist(curshape,It,nbgen); | |
231 | Standard_Integer nbe = Rakk->NbEdges(i); | |
232 | for(Standard_Integer j = 1; j <= nbe; j++){ | |
233 | curshape = Rakk->Edge(i,j); | |
234 | It.Initialize(Rakk->Generated(curshape)); | |
235 | PrintHist(curshape,It,nbgen); | |
236 | } | |
237 | curshape = Rakk->LastVertex(i); | |
238 | It.Initialize(Rakk->Generated(curshape)); | |
239 | PrintHist(curshape,It,nbgen); | |
240 | } | |
241 | //cout<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<<endl; | |
242 | di<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<<"\n"; | |
243 | return 0; | |
244 | } | |
245 | ||
246 | static Standard_Integer MKEVOL(Draw_Interpretor& di, | |
247 | Standard_Integer narg, | |
248 | const char** a) | |
249 | { | |
250 | if(Rake != 0) {delete Rake; Rake = 0;} | |
251 | printtolblend(di); | |
252 | if (narg < 3) return 1; | |
253 | TopoDS_Shape V = DBRep::Get(a[2]); | |
254 | Rake = new BRepFilletAPI_MakeFillet(V); | |
255 | Rake->SetParams(ta,t3d,t2d,t3d,t2d,fl); | |
256 | Rake->SetContinuity(blend_cont, tapp_angle); | |
257 | if (narg == 4) { | |
258 | ChFi3d_FilletShape FSh = ChFi3d_Rational; | |
259 | if (!strcasecmp(a[3], "Q")) { | |
260 | FSh = ChFi3d_QuasiAngular; | |
261 | } | |
262 | else if (!strcasecmp(a[3], "P")) { | |
263 | FSh = ChFi3d_Polynomial; | |
264 | } | |
265 | Rake->SetFilletShape(FSh); | |
266 | } | |
267 | strcpy(name, a[1]); | |
268 | return 0; | |
269 | } | |
270 | ||
271 | static Standard_Integer UPDATEVOL(Draw_Interpretor& di, | |
272 | Standard_Integer narg, | |
273 | const char** a) | |
274 | { | |
275 | if(Rake == 0){ | |
0d969553 Y |
276 | //cout << "MakeFillet not initialized"<<endl; |
277 | di << "MakeFillet not initialized"<<"\n"; | |
7fd59977 | 278 | return 1 ; |
279 | } | |
280 | if(narg%2 != 0 || narg < 4) return 1; | |
281 | TColgp_Array1OfPnt2d uandr(1,(narg/2)-1); | |
282 | Standard_Real Rad, Par; | |
283 | TopoDS_Shape aLocalEdge(DBRep::Get(a[1],TopAbs_EDGE)); | |
284 | TopoDS_Edge E = TopoDS::Edge(aLocalEdge); | |
285 | // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE)); | |
286 | for (Standard_Integer ii = 1; ii <= (narg/2)-1; ii++){ | |
91322f44 | 287 | Par = Draw::Atof(a[2*ii]); |
288 | Rad = Draw::Atof(a[2*ii + 1]); | |
7fd59977 | 289 | uandr.ChangeValue(ii).SetCoord(Par,Rad); |
290 | } | |
291 | Rake->Add(uandr,E); | |
292 | return 0; | |
293 | } | |
294 | ||
295 | static Standard_Integer BUILDEVOL(Draw_Interpretor& di, | |
296 | Standard_Integer, | |
297 | const char**) | |
298 | { | |
299 | if(Rake == 0){ | |
0d969553 Y |
300 | //cout << "MakeFillet not initialized"<<endl; |
301 | di << "MakeFillet not initialized"<<"\n"; | |
7fd59977 | 302 | return 1 ; |
303 | } | |
304 | Rake->Build(); | |
305 | if(Rake->IsDone()){ | |
306 | TopoDS_Shape result = Rake->Shape(); | |
307 | DBRep::Set(name,result); | |
308 | if(Rake != 0) {delete Rake; Rake = 0;} | |
309 | return 0; | |
310 | } | |
311 | if(Rake != 0) {delete Rake; Rake = 0;} | |
312 | return 1; | |
313 | } | |
314 | ||
315 | ||
316 | ||
317 | ||
318 | //********************************************** | |
0d969553 | 319 | // command fuse and cut with fillets * |
7fd59977 | 320 | //********************************************** |
321 | ||
322 | Standard_Integer topoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
323 | { | |
324 | printtolblend(di); | |
325 | if(narg != 5) return 1; | |
326 | Standard_Boolean fuse = !strcmp(a[0],"fubl"); | |
327 | TopoDS_Shape S1 = DBRep::Get(a[2]); | |
328 | TopoDS_Shape S2 = DBRep::Get(a[3]); | |
91322f44 | 329 | Standard_Real Rad = Draw::Atof(a[4]); |
7fd59977 | 330 | BRepAlgo_BooleanOperation* BC; |
331 | if(fuse){ | |
332 | BC = new BRepAlgo_Fuse(S1,S2); | |
333 | } | |
334 | else{ | |
335 | BC = new BRepAlgo_Cut(S1,S2); | |
336 | } | |
337 | TopoDS_Shape ShapeCut = BC->Shape(); | |
338 | ||
339 | Handle(TopOpeBRepBuild_HBuilder) build = BC->Builder(); | |
340 | TopTools_ListIteratorOfListOfShape its; | |
341 | ||
342 | TopoDS_Compound result; | |
343 | BRep_Builder B; | |
344 | B.MakeCompound(result); | |
345 | ||
346 | TopExp_Explorer ex; | |
347 | for (ex.Init(ShapeCut,TopAbs_SOLID); ex.More(); ex.Next()) { | |
348 | const TopoDS_Shape& cutsol = ex.Current(); | |
349 | ||
350 | BRepFilletAPI_MakeFillet fill(cutsol); | |
351 | fill.SetParams(ta,t3d,t2d,t3d,t2d,fl); | |
352 | fill.SetContinuity(blend_cont, tapp_angle); | |
353 | its = build->Section(); | |
354 | while (its.More()) { | |
355 | TopoDS_Edge E = TopoDS::Edge(its.Value()); | |
356 | fill.Add(Rad,E); | |
357 | its.Next(); | |
358 | } | |
359 | ||
360 | fill.Build(); | |
361 | if(fill.IsDone()){ | |
362 | B.Add(result,fill.Shape()); | |
363 | } | |
364 | else { | |
365 | B.Add(result,cutsol); | |
366 | } | |
367 | } | |
368 | ||
369 | delete BC; | |
370 | DBRep::Set(a[1],result); | |
371 | return 0; | |
372 | } | |
373 | ||
374 | //********************************************** | |
375 | // bfuse or bcut and then blend the section | |
376 | //********************************************** | |
377 | ||
378 | Standard_Integer boptopoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
379 | { | |
380 | printtolblend(di); | |
b5ef9d91 | 381 | if(narg < 5) |
382 | { | |
383 | cout << "Use <command name> result shape1 shape2 radius [-d]" << endl; | |
384 | return 1; | |
385 | } | |
7fd59977 | 386 | |
387 | Standard_Boolean fuse = !strcmp(a[0],"bfuseblend"); | |
388 | TopoDS_Shape S1 = DBRep::Get(a[2]); | |
389 | TopoDS_Shape S2 = DBRep::Get(a[3]); | |
390 | if (S1.IsNull() || S2.IsNull()) { | |
391 | printf(" Null shapes are not allowed \n"); | |
392 | return 1; | |
393 | } | |
91322f44 | 394 | Standard_Real Rad = Draw::Atof(a[4]); |
b5ef9d91 | 395 | Standard_Boolean isDebug = Standard_False; |
396 | ||
397 | if(narg == 6) | |
398 | { | |
399 | if(!strcmp(a[5], "-d")) | |
400 | { | |
401 | isDebug = Standard_True; | |
402 | } | |
403 | } | |
7fd59977 | 404 | |
4e57c75e | 405 | BOPAlgo_PaveFiller theDSFiller; |
406 | BOPCol_ListOfShape aLS; | |
407 | aLS.Append(S1); | |
408 | aLS.Append(S2); | |
409 | theDSFiller.SetArguments(aLS); | |
410 | // | |
411 | theDSFiller.Perform(); | |
412 | if (theDSFiller.ErrorStatus()) { | |
7fd59977 | 413 | printf("Check types of the arguments, please\n"); |
414 | return 1; | |
415 | } | |
7fd59977 | 416 | |
417 | BRepAlgoAPI_BooleanOperation* pBuilder=NULL; | |
418 | ||
419 | if (fuse) | |
420 | pBuilder = new BRepAlgoAPI_Fuse( S1, S2, theDSFiller ); | |
421 | else | |
422 | pBuilder = new BRepAlgoAPI_Cut ( S1, S2, theDSFiller ); | |
423 | ||
424 | Standard_Boolean anIsDone = pBuilder->IsDone(); | |
425 | if (!anIsDone) | |
b5ef9d91 | 426 | { |
427 | printf("boolean operation not done ErrorStatus()=%d\n", pBuilder->ErrorStatus()); | |
428 | return 1; | |
429 | } | |
7fd59977 | 430 | |
431 | TopoDS_Shape ResultOfBop = pBuilder->Shape(); | |
432 | ||
433 | delete pBuilder; | |
b5ef9d91 | 434 | |
435 | const int aStrLen = 1000; | |
436 | char aBuff[aStrLen]; | |
437 | ||
438 | if(isDebug) | |
439 | { | |
440 | strcpy(aBuff, a[1]); | |
441 | DBRep::Set( strcat(aBuff, "_bop"), ResultOfBop ); | |
442 | ||
443 | di << "Intermediate result of BOP-operation is saved to \"" << aBuff << "\" variable\n"; | |
444 | } | |
445 | ||
7fd59977 | 446 | pBuilder = new BRepAlgoAPI_Section( S1, S2, theDSFiller ); |
447 | TopoDS_Shape theSection = pBuilder->Shape(); | |
448 | ||
b5ef9d91 | 449 | if(isDebug) |
450 | { | |
451 | strcpy(aBuff, a[1]); | |
452 | DBRep::Set( strcat(aBuff, "_sec"), theSection ); | |
453 | di << "Intermediate bopsection result is saved to \"" << aBuff << "\" variable\n"; | |
454 | } | |
455 | ||
7fd59977 | 456 | TopoDS_Compound result; |
457 | BRep_Builder BB; | |
458 | BB.MakeCompound(result); | |
459 | ||
460 | TopExp_Explorer Explo( ResultOfBop, TopAbs_SOLID ); | |
461 | for (; Explo.More(); Explo.Next()) | |
b5ef9d91 | 462 | { |
463 | const TopoDS_Shape& aSolid = Explo.Current(); | |
464 | ||
465 | BRepFilletAPI_MakeFillet Blender(aSolid); | |
466 | Blender.SetParams(ta,t3d,t2d,t3d,t2d,fl); | |
467 | Blender.SetContinuity( blend_cont, tapp_angle ); | |
468 | ||
469 | TopExp_Explorer expsec( theSection, TopAbs_EDGE ); | |
470 | for (; expsec.More(); expsec.Next()) | |
471 | { | |
472 | TopoDS_Edge anEdge = TopoDS::Edge(expsec.Current()); | |
473 | Blender.Add( Rad, anEdge ); | |
474 | } | |
475 | ||
476 | Blender.Build(); | |
477 | if (Blender.IsDone()) | |
478 | BB.Add( result, Blender.Shape() ); | |
479 | else | |
7fd59977 | 480 | { |
b5ef9d91 | 481 | di << "Error: Cannot find the result of BLEND-operation." |
482 | " The result of BOP operation will be returned.\n"; | |
483 | BB.Add( result, aSolid ); | |
7fd59977 | 484 | } |
b5ef9d91 | 485 | } |
7fd59977 | 486 | |
487 | delete pBuilder; | |
488 | DBRep::Set( a[1], result ); | |
489 | return 0; | |
490 | } | |
491 | ||
492 | ||
493 | static Standard_Integer blend1(Draw_Interpretor& di, Standard_Integer narg, const char** a) | |
494 | { | |
495 | if (narg<5) return 1; | |
496 | TopoDS_Shape V = DBRep::Get(a[2]); | |
497 | if(V.IsNull()) return 1; | |
498 | Standard_Integer nb ,i; | |
499 | Standard_Real Rad; | |
500 | Standard_Boolean simul=Standard_False; | |
501 | const char *ns0=(a[1]); | |
91322f44 | 502 | Rad = Draw::Atof(a[3]); |
7fd59977 | 503 | TopTools_ListOfShape E; |
504 | for (i=4; i <=(narg-1) ; i++){ | |
505 | TopoDS_Shape edge= DBRep::Get(a[i],TopAbs_EDGE); | |
506 | if (edge.IsNull()) return 1 ; | |
507 | if(edge.ShapeType()!=TopAbs_EDGE) return 1; | |
508 | E.Append(edge); | |
509 | } | |
75259fc5 | 510 | FilletSurf_Builder aRakk(V,E,Rad); |
511 | if (simul) aRakk.Simulate(); | |
512 | else aRakk.Perform(); | |
7fd59977 | 513 | |
514 | //if (Rakk.IsDone()==FilletSurf_IsNotOk) | |
515 | // { FilletSurf_ErrorTypeStatus err=Rakk.StatusError(); | |
516 | // if (err==FilletSurf_EmptyList) cout<< "StatusError=EmptyList"<<endl; | |
517 | // else if (err==FilletSurf_EdgeNotG1) cout<< "StatusError=NotG1"<<endl; | |
518 | // else if (err==FilletSurf_FacesNotG1) cout<< "StatusError=facesNotG1"<<endl; | |
519 | // else if (err==FilletSurf_EdgeNotOnShape) | |
520 | // cout<< "StatusError=edgenotonshape"<<endl; | |
521 | // else if (err==FilletSurf_NotSharpEdge ) cout<< "StatusError=notsharpedge"<<endl; | |
522 | // else if (err==FilletSurf_PbFilletCompute) cout <<"StatusError=PBFillet"<<endl; | |
523 | // } | |
524 | // else { | |
525 | // if (Rakk.IsDone()==FilletSurf_IsPartial) cout <<"resultat partiel"<<endl; | |
75259fc5 | 526 | if (aRakk.IsDone()==FilletSurf_IsNotOk) |
527 | { FilletSurf_ErrorTypeStatus err=aRakk.StatusError(); | |
7fd59977 | 528 | if (err==FilletSurf_EmptyList) di<< "StatusError=EmptyList"<<"\n"; |
529 | else if (err==FilletSurf_EdgeNotG1) di<< "StatusError=NotG1"<<"\n"; | |
75259fc5 | 530 | else if (err==FilletSurf_FacesNotG1) di<< "StatusError=facesNotG1"<<"\n"; |
531 | else if (err==FilletSurf_EdgeNotOnShape) | |
7fd59977 | 532 | di<< "StatusError=edgenotonshape"<<"\n"; |
533 | else if (err==FilletSurf_NotSharpEdge ) di<< "StatusError=notsharpedge"<<"\n"; | |
534 | else if (err==FilletSurf_PbFilletCompute) di <<"StatusError=PBFillet"<<"\n"; | |
535 | } | |
536 | else { | |
75259fc5 | 537 | if (aRakk.IsDone()==FilletSurf_IsPartial) di <<"partial result"<<"\n"; |
7fd59977 | 538 | |
75259fc5 | 539 | nb=aRakk.NbSurface(); |
7fd59977 | 540 | char localname [100]; |
541 | char *temp; | |
542 | ||
543 | // affichage du type d'arret | |
544 | ||
545 | if (!simul) | |
546 | { | |
75259fc5 | 547 | //if (Rakk.StartSectionStatus()==FilletSurf_NoExtremityOnEdge) |
7fd59977 | 548 | // {cout<<" type deb conges = WLBLOUT"<<endl;} |
75259fc5 | 549 | //else if (Rakk.StartSectionStatus()==FilletSurf_OneExtremityOnEdge ) |
7fd59977 | 550 | // { cout<<" type deb conges = WLBLSTOP"<<endl;} |
551 | //else if (Rakk.StartSectionStatus()==FilletSurf_TwoExtremityOnEdge) | |
552 | // {cout<<" type deb conges = WLBLEND"<<endl;} | |
75259fc5 | 553 | if (aRakk.StartSectionStatus()==FilletSurf_NoExtremityOnEdge) |
0d969553 | 554 | {di<<" type start fillets = WLBLOUT"<<"\n";} |
75259fc5 | 555 | else if (aRakk.StartSectionStatus()==FilletSurf_OneExtremityOnEdge) |
0d969553 | 556 | { di<<" type start fillets = WLBLSTOP"<<"\n";} |
75259fc5 | 557 | else if (aRakk.StartSectionStatus()==FilletSurf_TwoExtremityOnEdge) |
0d969553 | 558 | {di<<" type start fillets = WLBLEND"<<"\n";} |
7fd59977 | 559 | |
560 | //if (Rakk.EndSectionStatus()==FilletSurf_NoExtremityOnEdge) | |
561 | // {cout<<" type fin conges = WLBLOUT"<<endl;} | |
562 | //else if (Rakk.EndSectionStatus()==FilletSurf_OneExtremityOnEdge) | |
563 | // {cout<<" type fin conges = WLBLSTOP"<<endl;} | |
564 | //else if (Rakk.EndSectionStatus()==FilletSurf_TwoExtremityOnEdge) | |
565 | // { cout<<" type fin conges = WLBLEND"<<endl;} | |
75259fc5 | 566 | if (aRakk.EndSectionStatus()==FilletSurf_NoExtremityOnEdge) |
0d969553 | 567 | {di<<" type end fillets = WLBLOUT"<<"\n";} |
75259fc5 | 568 | else if (aRakk.EndSectionStatus()==FilletSurf_OneExtremityOnEdge) |
0d969553 | 569 | {di<<" type end fillets = WLBLSTOP"<<"\n";} |
75259fc5 | 570 | else if (aRakk.EndSectionStatus()==FilletSurf_TwoExtremityOnEdge) |
0d969553 | 571 | { di<<" type end fillets = WLBLEND"<<"\n";} |
7fd59977 | 572 | Standard_Real f,l; |
75259fc5 | 573 | f = aRakk.FirstParameter(); |
574 | l = aRakk.LastParameter(); | |
0d969553 Y |
575 | //cout<<"parameter on edge start : "<<f<<endl; |
576 | //cout<<"parameter on edge end : "<<l<<endl; | |
577 | di<<"parametre on edge start : "<<f<<"\n"; | |
578 | di<<"parametre on edge end : "<<l<<"\n"; | |
7fd59977 | 579 | for (i=1;i<=nb;i++){ |
580 | //precision | |
581 | //cout<<"precision "<< i << "= "<<Rakk.TolApp3d(i)<<endl; | |
75259fc5 | 582 | di<<"precision "<< i << "= "<<aRakk.TolApp3d(i)<<"\n"; |
7fd59977 | 583 | |
0d969553 | 584 | // display resulting surfaces |
91322f44 | 585 | Sprintf(localname, "%s%d" ,ns0,i); |
7fd59977 | 586 | temp = localname; |
75259fc5 | 587 | DrawTrSurf::Set(temp,aRakk.SurfaceFillet(i)); |
7fd59977 | 588 | di << localname<< " "; |
589 | ||
0d969553 | 590 | // display curves 3d |
91322f44 | 591 | Sprintf(localname, "%s%d" ,"courb1",i); |
7fd59977 | 592 | temp =localname; |
75259fc5 | 593 | DrawTrSurf::Set(temp,aRakk.CurveOnFace1(i)); |
7fd59977 | 594 | di << localname<< " "; |
91322f44 | 595 | Sprintf(localname, "%s%d" ,"courb2",i); |
7fd59977 | 596 | temp =localname; |
75259fc5 | 597 | DrawTrSurf::Set(temp,aRakk.CurveOnFace2(i)); |
7fd59977 | 598 | di << localname<< " "; |
599 | ||
0d969553 | 600 | // display supports |
91322f44 | 601 | Sprintf(localname, "%s%d" ,"face1",i); |
7fd59977 | 602 | temp =localname ; |
75259fc5 | 603 | DBRep::Set(temp,aRakk.SupportFace1(i)); |
7fd59977 | 604 | di << localname<< " "; |
91322f44 | 605 | Sprintf(localname, "%s%d" ,"face2",i); |
7fd59977 | 606 | temp =localname; |
75259fc5 | 607 | DBRep::Set(temp,aRakk.SupportFace2(i)); |
7fd59977 | 608 | di << localname<< " "; |
609 | ||
0d969553 | 610 | // display Pcurves on faces |
91322f44 | 611 | Sprintf(localname, "%s%d" ,"pcurveonface1",i); |
7fd59977 | 612 | temp =localname ; |
75259fc5 | 613 | DrawTrSurf::Set(temp,aRakk.PCurveOnFace1(i)); |
7fd59977 | 614 | di << localname<< " "; |
91322f44 | 615 | Sprintf(localname, "%s%d" ,"pcurveonface2",i); |
7fd59977 | 616 | temp =localname; |
75259fc5 | 617 | DrawTrSurf::Set(temp,aRakk.PCurveOnFace2(i)); |
7fd59977 | 618 | di << localname<< " "; |
619 | ||
0d969553 | 620 | // display Pcurves on the fillet |
91322f44 | 621 | Sprintf(localname, "%s%d" ,"pcurveonconge1",i); |
7fd59977 | 622 | temp =localname; |
75259fc5 | 623 | DrawTrSurf::Set(temp,aRakk.PCurve1OnFillet(i)); |
7fd59977 | 624 | di << localname<< " "; |
91322f44 | 625 | Sprintf(localname, "%s%d" ,"pcurveonconge2",i); |
7fd59977 | 626 | temp =localname; |
75259fc5 | 627 | DrawTrSurf::Set(temp,aRakk.PCurve2OnFillet(i)); |
7fd59977 | 628 | di << localname<< " "; |
629 | ||
630 | } } | |
631 | else{ | |
632 | Standard_Integer j; | |
633 | ||
634 | for (i=1;i<=nb;i++) | |
75259fc5 | 635 | {Standard_Integer s=aRakk.NbSection(i); |
7fd59977 | 636 | for (j=1;j<=s;j++) |
c04c30b3 | 637 | {Handle(Geom_TrimmedCurve) Sec; |
75259fc5 | 638 | aRakk.Section(i,j,Sec); |
91322f44 | 639 | Sprintf(localname, "%s%d%d" ,"sec",i,j); |
7fd59977 | 640 | temp =localname; |
641 | DrawTrSurf::Set (temp,Sec); | |
642 | di << localname<< " ";} | |
643 | }} | |
644 | } | |
645 | return 0; | |
646 | } | |
647 | ||
648 | //======================================================================= | |
649 | //function : rollingball | |
650 | //purpose : | |
651 | //======================================================================= | |
652 | ||
653 | Standard_Integer rollingball(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
654 | { | |
655 | if ( n < 2) return 1; | |
656 | ||
657 | TopoDS_Shape S = DBRep::Get(a[2]); | |
658 | if ( S.IsNull()) return 1; | |
91322f44 | 659 | Standard_Real Rad = Draw::Atof(a[3]); |
7fd59977 | 660 | |
0d969553 | 661 | Standard_Real Tol = t3d; //the same as blend ! 1.e-7; |
7fd59977 | 662 | |
663 | BiTgte_Blend Roll; | |
664 | Roll.Init(S,Rad,Tol,Standard_False); | |
665 | ||
666 | Standard_Integer Nb = 0; | |
667 | for ( Standard_Integer i = 4; i <= n-1; i++) { | |
668 | if ( !strcmp(a[i],"@")) { | |
669 | Nb++; | |
670 | continue; | |
671 | } | |
672 | ||
0d969553 | 673 | if ( Nb == 0) { // return stop faces. |
7fd59977 | 674 | TopoDS_Shape aLocalFace(DBRep::Get(a[i],TopAbs_FACE)); |
675 | TopoDS_Face F1 = TopoDS::Face(aLocalFace); | |
676 | // TopoDS_Face F1 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)); | |
677 | if ( F1.IsNull()) { | |
0d969553 Y |
678 | //cout << " Stop face not referenced." << endl; |
679 | di << " Stop face not referenced." << "\n"; | |
7fd59977 | 680 | return 1; |
681 | } | |
682 | Roll.SetStoppingFace(F1); | |
683 | } | |
0d969553 | 684 | else if (Nb == 1) { // return faces on which the ball rotates |
7fd59977 | 685 | TopoDS_Shape aLocalFace(DBRep::Get(a[i],TopAbs_FACE)); |
686 | TopoDS_Face F1 = TopoDS::Face(aLocalFace); | |
687 | // TopoDS_Face F1 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)); | |
688 | i++; | |
689 | if ( !strcmp(a[i],"@")) { | |
0d969553 Y |
690 | //cout << " Even number of ball support faces is required " << endl; |
691 | di << " Even number of ball support faces is required " << "\n"; | |
7fd59977 | 692 | return 1; |
693 | } | |
694 | aLocalFace = DBRep::Get(a[i],TopAbs_FACE); | |
695 | TopoDS_Face F2 = TopoDS::Face(aLocalFace); | |
696 | // TopoDS_Face F2 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)); | |
697 | if ( F1.IsNull() || F2.IsNull()) { | |
0d969553 Y |
698 | //cout << " Support face not referenced." << endl; |
699 | di << " Support face not referenced." << "\n"; | |
7fd59977 | 700 | return 1; |
701 | } | |
702 | Roll.SetFaces(F1,F2); | |
703 | } | |
0d969553 | 704 | else if (Nb == 2) { // return the edge on which the ball rotates |
7fd59977 | 705 | TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE)); |
706 | TopoDS_Edge E = TopoDS::Edge(aLocalShape); | |
707 | // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE)); | |
708 | if ( E.IsNull()) { | |
0d969553 Y |
709 | //cout << " Edge not referenced." << endl; |
710 | di << " Edge not referenced." << "\n"; | |
7fd59977 | 711 | return 1; |
712 | } | |
713 | Roll.SetEdge(E); | |
714 | } | |
715 | ||
716 | } | |
717 | Standard_Boolean BuildShape = (!strcmp(a[0],"brollingball")); | |
718 | ||
719 | Roll.Perform(BuildShape); | |
720 | ||
721 | Standard_Boolean ComputeBranches = (!strcmp(a[0],"trollingball")); | |
722 | char localname[100]; | |
723 | if (ComputeBranches) { | |
724 | Standard_Integer NbBranches = Roll.NbBranches(); | |
725 | for (Standard_Integer i = 1; i <= NbBranches; i++) { | |
726 | Standard_Integer From,To; | |
727 | Roll.IndicesOfBranche(i,From,To); | |
0d969553 | 728 | //cout << " Indexes of the " << i << "th Branch : "; |
7fd59977 | 729 | //cout << " " << From << " " << To << endl; |
0d969553 | 730 | di << " Indexes of the " << i << "th Branch : "; |
7fd59977 | 731 | di << " " << From << " " << To << "\n"; |
732 | for (Standard_Integer j = From; j <= To; j++) { | |
733 | const TopoDS_Shape& CurF = Roll.Face(j); | |
91322f44 | 734 | Sprintf(localname,"%s_%d_%d",a[1],i,j); |
7fd59977 | 735 | DBRep::Set(localname,CurF); |
736 | } | |
737 | } | |
738 | ||
739 | } | |
740 | else | |
741 | DBRep::Set(a[1],Roll.Shape()); | |
742 | ||
743 | return 0; | |
744 | } | |
745 | ||
746 | //======================================================================= | |
747 | //function : FilletCommands | |
748 | //purpose : | |
749 | //======================================================================= | |
750 | ||
751 | void BRepTest::FilletCommands(Draw_Interpretor& theCommands) | |
752 | { | |
753 | static Standard_Boolean done = Standard_False; | |
754 | if (done) return; | |
755 | done = Standard_True; | |
756 | ||
757 | DBRep::BasicCommands(theCommands); | |
758 | ||
759 | const char* g = "TOPOLOGY Fillet construction commands"; | |
760 | ||
761 | theCommands.Add("continuityblend", | |
762 | "continuityblend C0/C1/C2 [tangle]",__FILE__, | |
763 | contblend,g); | |
764 | ||
765 | theCommands.Add("tolblend", | |
766 | "tolblend [ta t3d t2d fl]",__FILE__, | |
767 | tolblend,g); | |
768 | ||
769 | theCommands.Add("blend", | |
770 | "blend result object rad1 ed1 rad2 ed2 ... [R/Q/P]",__FILE__, | |
771 | BLEND,g); | |
772 | ||
773 | theCommands.Add("checkhist", | |
774 | "checkhist",__FILE__, | |
775 | CheckHist,g); | |
776 | ||
777 | theCommands.Add("mkevol", | |
778 | "mkevol result object (then use updatevol) [R/Q/P]",__FILE__, | |
779 | MKEVOL,g); | |
780 | ||
781 | theCommands.Add("updatevol", | |
782 | "updatevol edge u1 rad1 u2 rad2 ...",__FILE__, | |
783 | UPDATEVOL,g); | |
784 | ||
785 | theCommands.Add("buildevol", | |
786 | "buildevol end of the evol fillet computation",__FILE__, | |
787 | BUILDEVOL,g); | |
788 | ||
789 | theCommands.Add("fubl", | |
790 | "fubl result shape1 shape2 radius",__FILE__, | |
791 | topoblend,g); | |
792 | ||
793 | theCommands.Add("cubl", | |
794 | "cubl result shape tool radius",__FILE__, | |
795 | topoblend,g); | |
796 | ||
797 | theCommands.Add("bfuseblend", | |
b5ef9d91 | 798 | "bfuseblend result shape1 shape2 radius [-d]",__FILE__, |
7fd59977 | 799 | boptopoblend,g); |
800 | ||
801 | theCommands.Add("bcutblend", | |
b5ef9d91 | 802 | "bcutblend result shape1 tool radius [-d]",__FILE__, |
7fd59977 | 803 | boptopoblend,g); |
804 | ||
805 | theCommands.Add("blend1", | |
806 | "blend1 result object rad ed1 ed2 ...",__FILE__, | |
807 | blend1,g); | |
808 | ||
809 | theCommands.Add("rollingball", | |
810 | "rollingball r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]", | |
811 | __FILE__, | |
812 | rollingball); | |
813 | ||
814 | theCommands.Add("brollingball", | |
815 | "brollingball r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]", | |
816 | __FILE__, | |
817 | rollingball); | |
818 | ||
819 | theCommands.Add("trollingball", | |
820 | "trollingball r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]", | |
821 | __FILE__, | |
822 | rollingball); | |
823 | } |