0026555: Modeling Algorithms - Exception-safe status reporting in BRepOffset_MakeOffset
[occt.git] / src / BRepTest / BRepTest_FeatureCommands.cxx
CommitLineData
b311480e 1// Created on: 1995-06-16
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1995-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 <Draw_Interpretor.hxx>
18#include <Draw_Appli.hxx>
19#include <DrawTrSurf.hxx>
20
21#include <TopTools_ListOfShape.hxx>
22#include <TopTools_ListIteratorOfListOfShape.hxx>
23#include <TopTools_MapOfShape.hxx>
24#include <TopTools_MapIteratorOfMapOfShape.hxx>
25#include <TopExp_Explorer.hxx>
26#include <TopoDS_Face.hxx>
27#include <TopoDS_Wire.hxx>
28#include <TopoDS_Shell.hxx>
29#include <TopoDS_Compound.hxx>
30#include <TopoDS_Edge.hxx>
31#include <TopoDS.hxx>
32
33#include <Geom_RectangularTrimmedSurface.hxx>
34#include <Geom_Plane.hxx>
35#include <Geom_CylindricalSurface.hxx>
36#include <gp_Lin.hxx>
37#include <gp_Pln.hxx>
38#include <gp_Cylinder.hxx>
39
4e57c75e 40//#include <BRepFeat_LocalOperation.hxx>
41#include <BRepFeat_Builder.hxx>
7fd59977 42#include <BRepFeat_MakeCylindricalHole.hxx>
43#include <BRepFeat_SplitShape.hxx>
44#include <BRepFeat_Gluer.hxx>
45
46#include <BRepFeat.hxx>
47#include <BRepFeat_MakePrism.hxx>
48#include <BRepFeat_MakeRevol.hxx>
49#include <BRepFeat_MakePipe.hxx>
50#include <BRepFeat_MakeDPrism.hxx>
51#include <BRepFeat_MakeLinearForm.hxx>
52#include <BRepFeat_MakeRevolutionForm.hxx>
53
54#include <LocOpe_FindEdges.hxx>
55#include <LocOpe_FindEdgesInFace.hxx>
56
8013367c 57#include <BRepOffset_MakeOffset.hxx>
58#include <BRepOffset_MakeSimpleOffset.hxx>
7fd59977 59#include <BRep_Tool.hxx>
60#include <BRep_Builder.hxx>
61#include <DBRep.hxx>
62#include <DBRep_DrawableShape.hxx>
63#include <BRepTest.hxx>
4f7d41ea 64#include <BRepTest_Objects.hxx>
7fd59977 65
66#include <BRepFilletAPI_MakeFillet.hxx>
67#include <ChFi3d_FilletShape.hxx>
68
69#include <Precision.hxx>
70
03155c18 71#ifdef _WIN32
7fd59977 72//#define strcasecmp _stricmp Already defined
73Standard_IMPORT Draw_Viewer dout;
74#endif
7fd59977 75
76static BRepFeat_MakeCylindricalHole theHole;
77static Standard_Boolean WithControl = Standard_True;
78
79Standard_Boolean DownCastingEnforcing = Standard_False;
80
81static BRepFeat_MakePrism thePrism;
82static BRepFeat_MakeDPrism theDPrism;
83static BRepFeat_MakeRevol theRevol;
84static BRepFeat_MakePipe thePipe;
85static BRepFeat_MakeLinearForm theLF;
86static BRepFeat_MakeRevolutionForm theRF;
87
f0ada3e8 88//Input shapes for Prism, DPrism, Revol, Pipe
89static TopoDS_Shape theSbase, thePbase;
90static TopoDS_Face theSkface;
91
7fd59977 92static Standard_Boolean dprdef = Standard_False;
93static Standard_Boolean prdef = Standard_False;
94static Standard_Boolean rvdef = Standard_False;
95static Standard_Boolean pidef = Standard_False;
96static Standard_Boolean lfdef = Standard_False;
97static Standard_Boolean rfdef = Standard_False;
98
99static Standard_Real t3d = 1.e-4;
100static Standard_Real t2d = 1.e-5;
f0ada3e8 101static Standard_Real ta = 1.e-2;
102static Standard_Real fl = 1.e-3;
7fd59977 103static Standard_Real tapp_angle = 1.e-2;
104static GeomAbs_Shape blend_cont = GeomAbs_C1;
105static BRepFilletAPI_MakeFillet* Rakk = 0;
106
107
108
109static void Print(Draw_Interpretor& di,
f0ada3e8 110 const BRepFeat_Status St)
7fd59977 111{
112 di << " Error Status : ";
113 switch (St) {
114 case BRepFeat_NoError:
115 di << "No error";
116 break;
117
118 case BRepFeat_InvalidPlacement:
119 di << "Invalid placement";
120 break;
121
122 case BRepFeat_HoleTooLong:
123 di << "Hole too long";
124 break;
125 }
126}
127
128static Standard_Integer Loc(Draw_Interpretor& theCommands,
f0ada3e8 129 Standard_Integer narg, const char** a)
7fd59977 130{
f0ada3e8 131 if (narg < 6) return 1;
7fd59977 132 TopoDS_Shape S = DBRep::Get(a[2]);
133 TopoDS_Shape T = DBRep::Get(a[3]);
134
135 Standard_Boolean Fuse;
f0ada3e8 136 if (!strcasecmp("F", a[4])) {
7fd59977 137 Fuse = Standard_True;
138 }
f0ada3e8 139 else if (!strcasecmp("C", a[4])) {
7fd59977 140 Fuse = Standard_False;
141 }
142 else {
143 return 1;
144 }
145
146 TopTools_ListOfShape LF;
f0ada3e8 147 for (Standard_Integer i = 0; i <= narg - 6; i++) {
148 TopoDS_Shape aLocalShape(DBRep::Get(a[i + 5], TopAbs_FACE));
7fd59977 149 LF.Append(aLocalShape);
f0ada3e8 150 // LF.Append(TopoDS::Face(DBRep::Get(a[i+5],TopAbs_FACE)));
7fd59977 151 }
152
4e57c75e 153 //BRepFeat_LocalOperation BLoc(S);
154 //BLoc.Perform(T,LF,Fuse);
155 //BLoc.BuildPartsOfTool();
156 TopTools_ListOfShape parts;
157 BRepFeat_Builder BLoc;
f0ada3e8 158 BLoc.Init(S, T);
4e57c75e 159 BLoc.SetOperation(Fuse);
160 //BRepFeat_LocalOperation BLoc;
161 //BLoc.Init(S,T,Fuse);
162 BLoc.Perform();
163 BLoc.PartsOfTool(parts);
7fd59977 164
165#if 0
166 char newname[1024];
f0ada3e8 167 strcpy(newname, a[1]);
7fd59977 168 char* p = newname;
169 while (*p != '\0') p++;
170 *p = '_';
171 p++;
4e57c75e 172 TopTools_ListIteratorOfListOfShape its(parts);
7fd59977 173 dout.Clear();
174 i = 0;
175 for (; its.More(); its.Next()) {
176 i++;
f0ada3e8 177 Sprintf(p, "%d", i);
178 DBRep::Set(newname, its.Value());
7fd59977 179 }
180 if (i >= 2) {
181 dout.Flush();
f0ada3e8 182 Standard_Integer qq, ww, ee, button;
7fd59977 183 TopoDS_Shell S;
184 do {
f0ada3e8 185 TopoDS_Shape aLocalShape(DBRep::Get(".", TopAbs_SHELL));
7fd59977 186 S = TopoDS::Shell(aLocalShape);
f0ada3e8 187 // S = TopoDS::Shell(DBRep::Get(".",TopAbs_SHELL));
188 Draw::LastPick(qq, ww, ee, button);
7fd59977 189 if (!S.IsNull()) {
f0ada3e8 190
4e57c75e 191 switch (button) {
192 case 1:
193 //BLoc.RemovePart(S);
194 break;
195 case 2:
196 BLoc.KeepPart(S);
197 break;
198 default:
f0ada3e8 199 {}
4e57c75e 200 }
7fd59977 201 }
202 else {
4e57c75e 203 button = 3;
7fd59977 204 }
205
206 } while (button != 3);
207 }
208#endif
4e57c75e 209 BLoc.PerformResult();
33ba8565 210 if (!BLoc.HasErrors()) {
f0ada3e8 211 // dout.Clear();
212 DBRep::Set(a[1], BLoc.Shape());
7fd59977 213 dout.Flush();
214 return 0;
215 }
f0ada3e8 216 theCommands << "Local operation not done";
7fd59977 217 return 1;
218}
219
220
221
222static Standard_Integer HOLE1(Draw_Interpretor& theCommands,
f0ada3e8 223 Standard_Integer narg, const char** a)
7fd59977 224{
f0ada3e8 225 if (narg < 10 || narg == 11) return 1;
7fd59977 226 TopoDS_Shape S = DBRep::Get(a[2]);
227
f0ada3e8 228 gp_Pnt Or(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]));
229 gp_Dir Di(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
7fd59977 230
91322f44 231 Standard_Real Radius = Draw::Atof(a[9]);
7fd59977 232
f0ada3e8 233 theHole.Init(S, gp_Ax1(Or, Di));
7fd59977 234
235 if (narg <= 10) {
236 theHole.Perform(Radius);
237 }
238 else {
91322f44 239 Standard_Real pfrom = Draw::Atof(a[10]);
f0ada3e8 240 Standard_Real pto = Draw::Atof(a[11]);
241 theHole.Perform(Radius, pfrom, pto, WithControl);
7fd59977 242 }
243
244 theHole.Build();
33ba8565 245 if (!theHole.HasErrors()) {
f0ada3e8 246 // dout.Clear();
247 DBRep::Set(a[1], theHole.Shape());
7fd59977 248 dout.Flush();
249 return 0;
250 }
251 theCommands << "Echec de MakeCylindricalHole";
f0ada3e8 252 Print(theCommands, theHole.Status());
7fd59977 253 return 1;
254}
255
256static Standard_Integer HOLE2(Draw_Interpretor& theCommands,
f0ada3e8 257 Standard_Integer narg, const char** a)
7fd59977 258{
f0ada3e8 259 if (narg < 10) return 1;
7fd59977 260 TopoDS_Shape S = DBRep::Get(a[2]);
261
f0ada3e8 262 gp_Pnt Or(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]));
263 gp_Dir Di(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
7fd59977 264
91322f44 265 Standard_Real Radius = Draw::Atof(a[9]);
7fd59977 266
f0ada3e8 267 theHole.Init(S, gp_Ax1(Or, Di));
268 theHole.PerformThruNext(Radius, WithControl);
7fd59977 269
270 theHole.Build();
33ba8565 271 if (!theHole.HasErrors()) {
f0ada3e8 272 // dout.Clear();
273 DBRep::Set(a[1], theHole.Shape());
7fd59977 274 dout.Flush();
275 return 0;
276 }
277 theCommands << "Echec de MakeCylindricalHole";
f0ada3e8 278 Print(theCommands, theHole.Status());
7fd59977 279 return 1;
280}
281
282static Standard_Integer HOLE3(Draw_Interpretor& theCommands,
f0ada3e8 283 Standard_Integer narg, const char** a)
7fd59977 284{
f0ada3e8 285 if (narg < 10) return 1;
7fd59977 286 TopoDS_Shape S = DBRep::Get(a[2]);
287
f0ada3e8 288 gp_Pnt Or(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]));
289 gp_Dir Di(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
7fd59977 290
91322f44 291 Standard_Real Radius = Draw::Atof(a[9]);
7fd59977 292
f0ada3e8 293 theHole.Init(S, gp_Ax1(Or, Di));
294 theHole.PerformUntilEnd(Radius, WithControl);
7fd59977 295 theHole.Build();
33ba8565 296 if (!theHole.HasErrors()) {
f0ada3e8 297 // dout.Clear();
298 DBRep::Set(a[1], theHole.Shape());
7fd59977 299 dout.Flush();
300 return 0;
301 }
302 theCommands << "Echec de MakeCylindricalHole";
f0ada3e8 303 Print(theCommands, theHole.Status());
7fd59977 304 return 1;
305}
306
307
308static Standard_Integer HOLE4(Draw_Interpretor& theCommands,
f0ada3e8 309 Standard_Integer narg, const char** a)
7fd59977 310{
f0ada3e8 311 if (narg < 11) return 1;
7fd59977 312 TopoDS_Shape S = DBRep::Get(a[2]);
313
f0ada3e8 314 gp_Pnt Or(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]));
315 gp_Dir Di(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
7fd59977 316
91322f44 317 Standard_Real Radius = Draw::Atof(a[9]);
318 Standard_Real Length = Draw::Atof(a[10]);
7fd59977 319
f0ada3e8 320 theHole.Init(S, gp_Ax1(Or, Di));
321 theHole.PerformBlind(Radius, Length, WithControl);
7fd59977 322 theHole.Build();
33ba8565 323 if (!theHole.HasErrors()) {
f0ada3e8 324 // dout.Clear();
325 DBRep::Set(a[1], theHole.Shape());
7fd59977 326 dout.Flush();
327 return 0;
328 }
329 theCommands << "Echec de MakeCylindricalHole";
f0ada3e8 330 Print(theCommands, theHole.Status());
7fd59977 331 return 1;
332}
333
334static Standard_Integer CONTROL(Draw_Interpretor& theCommands,
f0ada3e8 335 Standard_Integer narg, const char** a)
7fd59977 336{
337 if (narg >= 2) {
dde68833 338 WithControl = strcmp("0", a[1]) != 0;
7fd59977 339 }
340 if (WithControl) {
341 theCommands << "Mode avec controle";
342 }
343 else {
344 theCommands << "Mode sans controle";
345 }
346 return 0;
347}
e1ed38e0 348
349//=======================================================================
350//function : reportOffsetState
351//purpose : Print state of offset operation by error code.
352//=======================================================================
353static void reportOffsetState(Draw_Interpretor& theCommands,
f0ada3e8 354 const BRepOffset_Error theErrorCode)
e1ed38e0 355{
f0ada3e8 356 switch (theErrorCode)
e1ed38e0 357 {
358 case BRepOffset_NoError:
f0ada3e8 359 {
360 theCommands << "OK. Offset performed succesfully.";
361 break;
362 }
e1ed38e0 363 case BRepOffset_BadNormalsOnGeometry:
f0ada3e8 364 {
365 theCommands << "ERROR. Degenerated normal on input data.";
366 break;
367 }
e1ed38e0 368 case BRepOffset_C0Geometry:
f0ada3e8 369 {
370 theCommands << "ERROR. C0 continuity of input data.";
371 break;
372 }
e1ed38e0 373 case BRepOffset_NullOffset:
f0ada3e8 374 {
375 theCommands << "ERROR. Null offset of all faces.";
376 break;
377 }
e1ed38e0 378 case BRepOffset_NotConnectedShell:
f0ada3e8 379 {
380 theCommands << "ERROR. Incorrect set of faces to remove, the remaining shell is not connected.";
381 break;
382 }
3e85dfc5 383 case BRepOffset_CannotTrimEdges:
384 {
385 theCommands << "ERROR. Can not trim edges.";
386 break;
387 }
388 case BRepOffset_CannotFuseVertices:
389 {
390 theCommands << "ERROR. Can not fuse vertices.";
391 break;
392 }
393 case BRepOffset_CannotExtentEdge:
394 {
395 theCommands << "ERROR. Can not extent edge.";
396 break;
397 }
e1ed38e0 398 default:
f0ada3e8 399 {
400 theCommands << "ERROR. offsetperform operation not done.";
401 break;
402 }
e1ed38e0 403 }
404}
7fd59977 405
406//=======================================================================
407//function : PRW
408//purpose :
409//=======================================================================
410
411static Standard_Integer PRW(Draw_Interpretor& theCommands,
f0ada3e8 412 Standard_Integer narg, const char** a)
7fd59977 413{
f0ada3e8 414 if (narg < 9) return 1;
7fd59977 415 TopoDS_Shape S = DBRep::Get(a[3]);
416 BRepFeat_MakePrism thePFace;
417 gp_Vec V;
f0ada3e8 418 TopoDS_Shape FFrom, FUntil;
7fd59977 419 Standard_Integer borne;
420 Standard_Boolean fuse;
421 if (a[1][0] == 'f' || a[1][0] == 'F') {
422 fuse = Standard_True;
423 }
424 else if (a[1][0] == 'c' || a[1][0] == 'C') {
425 fuse = Standard_False;
426 }
427 else {
428 return 1;
429 }
430
431 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
432 if (narg < 10) {
433 return 1;
434 }
435 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
436 if (narg < 11) {
f0ada3e8 437 return 1;
7fd59977 438 }
f0ada3e8 439 V.SetCoord(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
440 FFrom = DBRep::Get(a[4], TopAbs_SHAPE);
441 FUntil = DBRep::Get(a[5], TopAbs_SHAPE);
7fd59977 442 borne = 9;
443 }
444 else {
f0ada3e8 445 V.SetCoord(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
446 FUntil = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 447 borne = 8;
448 }
449 }
450 else {
f0ada3e8 451 V.SetCoord(Draw::Atof(a[4]), Draw::Atof(a[5]), Draw::Atof(a[6]));
7fd59977 452 borne = 7;
453 }
454 Standard_Real Length = V.Magnitude();
455 if (Length < Precision::Confusion()) {
456 return 1;
457 }
458
f0ada3e8 459 TopoDS_Shape aLocalShape(DBRep::Get(a[borne], TopAbs_FACE));
460 TopoDS_Face F = TopoDS::Face(aLocalShape);
461 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
7fd59977 462 BRepFeat_SplitShape Spls(F);
f0ada3e8 463 for (Standard_Integer i = borne + 1; i < narg; i++) {
7fd59977 464 TopoDS_Wire wir;
f0ada3e8 465 if (a[i][0] != '-') {
466 aLocalShape = DBRep::Get(a[i], TopAbs_WIRE);
7fd59977 467 wir = TopoDS::Wire(aLocalShape);
f0ada3e8 468 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
7fd59977 469 }
470 else {
471 if (a[i][1] == '\0')
f0ada3e8 472 return 1;
473 const char* Temp = a[i] + 1;
474 aLocalShape = DBRep::Get(Temp, TopAbs_WIRE);
7fd59977 475 wir = TopoDS::Wire(aLocalShape);
f0ada3e8 476 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
7fd59977 477 wir.Reverse();
478 }
f0ada3e8 479 Spls.Add(wir, F);
7fd59977 480 }
481 Spls.Build();
482
483 TopoDS_Shape ToPrism;
484 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
485 if (lleft.Extent() == 1) {
f0ada3e8 486 thePFace.Init(S, lleft.First(), F, V, fuse, Standard_True);
7fd59977 487 ToPrism = lleft.First();
488 }
489 else {
490 BRep_Builder B;
491 TopoDS_Shell Sh;
492 B.MakeShell(Sh);
493 TopTools_ListIteratorOfListOfShape it;
f0ada3e8 494 for (it.Initialize(lleft); it.More(); it.Next()) {
495 B.Add(Sh, TopoDS::Face(it.Value()));
7fd59977 496 }
f0ada3e8 497 Sh.Closed(BRep_Tool::IsClosed(Sh));
498 thePFace.Init(S, Sh, F, V, fuse, Standard_True);
7fd59977 499 ToPrism = Sh;
500 }
501
502 // Recherche des faces de glissement, si on n`a pas sketche sur une face
503 // du shape de depart
504
505// for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
f0ada3e8 506 TopExp_Explorer exp(S, TopAbs_FACE);
507 for (; exp.More(); exp.Next()) {
7fd59977 508 if (exp.Current().IsSame(F)) {
509 break;
510 }
511 }
512
513 if (!exp.More()) {
514 LocOpe_FindEdgesInFace FEIF;
f0ada3e8 515 for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next()) {
7fd59977 516 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
517 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
518 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
f0ada3e8 519 Su = Handle(Geom_RectangularTrimmedSurface)::
520 DownCast(Su)->BasisSurface();
7fd59977 521 }
522 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
f0ada3e8 523 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
524 if (pl.Contains(gp_Lin(pl.Location(), V),
525 Precision::Confusion(),
526 Precision::Angular())) {
527 FEIF.Set(ToPrism, fac);
528 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
529 thePFace.Add(FEIF.Edge(), fac);
530 }
531 }
7fd59977 532 }
533 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
f0ada3e8 534 gp_Cylinder cy =
535 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
536 if (V.IsParallel(cy.Axis().Direction(), Precision::Angular())) {
537 FEIF.Set(ToPrism, fac);
538 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
539 thePFace.Add(FEIF.Edge(), fac);
540 }
541 }
7fd59977 542 }
543 }
544 }
545
546 if (borne == 7) {
547 thePFace.Perform(Length);
548 }
549 else if (borne == 8) {
550 thePFace.Perform(FUntil);
551 }
552 else if (borne == 9) {
553 if (!(FFrom.IsNull() || FUntil.IsNull())) {
f0ada3e8 554 thePFace.Perform(FFrom, FUntil);
7fd59977 555 }
556 else if (FFrom.IsNull()) {
557 if (!FUntil.IsNull()) {
f0ada3e8 558 thePFace.PerformFromEnd(FUntil);
7fd59977 559 }
560 else {
f0ada3e8 561 thePFace.PerformThruAll();
7fd59977 562 }
563 }
564 else {
565 // il faudrait inverser V et appeler PerfomFromEnd...
04232180 566 //std::cout << "Not Implemented" << std::endl;
586db386 567 theCommands << "Not Implemented\n";
7fd59977 568 }
569 }
570 if (!thePFace.IsDone()) {
571 theCommands << "Local operation not done";
572 return 1;
573 }
574
f0ada3e8 575 DBRep::Set(a[2], thePFace);
7fd59977 576 dout.Flush();
577 return 0;
578}
579
580
581//=======================================================================
582//function : PRF
583//purpose :
584//=======================================================================
585
586static Standard_Integer PRF(Draw_Interpretor& theCommands,
f0ada3e8 587 Standard_Integer narg, const char** a)
7fd59977 588{
f0ada3e8 589 if (narg < 8) return 1;
7fd59977 590 TopoDS_Shape S = DBRep::Get(a[3]);
591 BRepFeat_MakePrism thePFace;
592 Standard_Integer borne;
593 gp_Vec V;
f0ada3e8 594 TopoDS_Shape FFrom, FUntil;
7fd59977 595 Standard_Boolean fuse;
596 if (a[1][0] == 'f' || a[1][0] == 'F') {
597 fuse = Standard_True;
598 }
599 else if (a[1][0] == 'c' || a[1][0] == 'C') {
600 fuse = Standard_False;
601 }
602 else {
603 return 1;
604 }
605
606
607 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
608 if (narg < 9) {
609 return 1;
610 }
611 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
612 if (narg < 10) {
f0ada3e8 613 return 1;
7fd59977 614 }
615 borne = 9;
f0ada3e8 616 V.SetCoord(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8]));
617 FFrom = DBRep::Get(a[4], TopAbs_SHAPE);
618 FUntil = DBRep::Get(a[5], TopAbs_SHAPE);
7fd59977 619 }
620 else {
621 borne = 8;
f0ada3e8 622 V.SetCoord(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
623 FUntil = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 624 }
625 }
626 else {
627 borne = 7;
f0ada3e8 628 V.SetCoord(Draw::Atof(a[4]), Draw::Atof(a[5]), Draw::Atof(a[6]));
7fd59977 629 }
630 Standard_Real Length = V.Magnitude();
631 if (Length < Precision::Confusion()) {
632 return 1;
633 }
634
635 TopoDS_Shape ToPrism;
f0ada3e8 636 if (narg == borne + 1) {
637 TopoDS_Shape aLocalShape(DBRep::Get(a[borne], TopAbs_FACE));
638 TopoDS_Face F = TopoDS::Face(aLocalShape);
639 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
640 thePFace.Init(S, F, F, V, fuse, Standard_True);
7fd59977 641 ToPrism = F;
642 }
643 else {
644 TopoDS_Shell She;
645 BRep_Builder B;
646 B.MakeShell(She);
f0ada3e8 647 for (Standard_Integer i = borne; i < narg; i++) {
648 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_FACE));
649 TopoDS_Face F = TopoDS::Face(aLocalShape);
650 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
7fd59977 651 if (!F.IsNull()) {
f0ada3e8 652 B.Add(She, F);
7fd59977 653 }
654 }
f0ada3e8 655 She.Closed(BRep_Tool::IsClosed(She));
656 thePFace.Init(S, She, TopoDS_Face(), V, fuse, Standard_False);
7fd59977 657 ToPrism = She;
658 }
f0ada3e8 659
7fd59977 660 // Recherche des faces de glissement, on ne prisme pas une face
661 // du shape de depart
662
663// for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
f0ada3e8 664 TopExp_Explorer exp(ToPrism, TopAbs_FACE);
665 for (; exp.More(); exp.Next()) {
666 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
667 TopExp_Explorer exp2(S, TopAbs_FACE);
668 for (; exp2.More(); exp2.Next()) {
7fd59977 669 if (exp2.Current().IsSame(exp.Current())) {
f0ada3e8 670 break;
7fd59977 671 }
672 }
673 if (exp2.More()) {
674 break;
675 }
676 }
677
678 if (!exp.More()) {
679 LocOpe_FindEdgesInFace FEIF;
f0ada3e8 680 for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next()) {
7fd59977 681 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
682 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
683 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
f0ada3e8 684 Su = Handle(Geom_RectangularTrimmedSurface)::
685 DownCast(Su)->BasisSurface();
7fd59977 686 }
687 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
f0ada3e8 688 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
689 if (pl.Contains(gp_Lin(pl.Location(), V),
690 Precision::Confusion(),
691 Precision::Angular())) {
692 FEIF.Set(ToPrism, fac);
693 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
694 thePFace.Add(FEIF.Edge(), fac);
695 }
696 }
7fd59977 697 }
698 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
f0ada3e8 699 gp_Cylinder cy =
700 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
701 if (V.IsParallel(cy.Axis().Direction(), Precision::Angular())) {
702 FEIF.Set(ToPrism, fac);
703 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
704 thePFace.Add(FEIF.Edge(), fac);
705 }
706 }
7fd59977 707 }
708 }
709 }
710
711 if (borne == 7) {
712 thePFace.Perform(Length);
713 }
714 else if (borne == 8) {
715 thePFace.Perform(FUntil);
716 }
717 else if (borne == 9) {
718 if (!(FFrom.IsNull() || FUntil.IsNull())) {
f0ada3e8 719 thePFace.Perform(FFrom, FUntil);
7fd59977 720 }
721 else if (FFrom.IsNull()) {
722 if (!FUntil.IsNull()) {
f0ada3e8 723 thePFace.PerformFromEnd(FUntil);
7fd59977 724 }
725 else {
f0ada3e8 726 thePFace.PerformThruAll();
7fd59977 727 }
728 }
729 else { //FUntil.IsNull()
730 // il faudrait inverser V et appeler PerfomFromEnd...
04232180 731 //std::cout << "Not Implemented" << std::endl;
586db386 732 theCommands << "Not Implemented\n";
7fd59977 733 }
734 }
735 if (!thePFace.IsDone()) {
736 theCommands << "Local operation not done";
737 return 1;
738 }
739
f0ada3e8 740 DBRep::Set(a[2], thePFace);
7fd59977 741 dout.Flush();
742 return 0;
743}
744
745
746
747//=======================================================================
748//function : SPLS
749//purpose :
750//=======================================================================
751
f0ada3e8 752static Standard_Integer SPLS(Draw_Interpretor&,
753 Standard_Integer narg, const char** a)
7fd59977 754{
b94d4858 755 Standard_Integer newnarg;
7fd59977 756
b94d4858 757 if (narg < 3)
758 {
04232180 759 std::cout << "Invalid number of arguments. Should be : splitshape result shape [splitedges] \
b94d4858 760 [face wire/edge/compound [wire/edge/compound ...] \
761 [face wire/edge/compound [wire/edge/compound...] ...] \
04232180 762 [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]" << std::endl;
b94d4858 763 return 1;
764 }
7fd59977 765 TopoDS_Shape S = DBRep::Get(a[2]);
b94d4858 766 if (S.IsNull())
767 {
f0ada3e8 768 std::cout << "Invalid input shape " << a[2] << std::endl;
b94d4858 769 return 1;
770 }
7fd59977 771 BRepFeat_SplitShape Spls(S);
772 Standard_Boolean pick = Standard_False;
773 TopoDS_Shape EF;
f0ada3e8 774 Standard_Real u, v;
7fd59977 775 Standard_Integer i = 3;
776
f0ada3e8 777 for (newnarg = 3; newnarg < narg; newnarg++) {
7fd59977 778 if (a[newnarg][0] == '@') {
779 break;
780 }
781 }
782
f0ada3e8 783 if (newnarg == 3 ||
784 (newnarg != narg && ((narg - newnarg) <= 2 || (narg - newnarg) % 2 != 1))) {
7fd59977 785 return 1;
786 }
b94d4858 787 Standard_Boolean isSplittingEdges = Standard_False;
788 TopTools_SequenceOfShape aSplitEdges;
789 if (i < newnarg) {
7fd59977 790 pick = (a[i][0] == '.');
f0ada3e8 791
b94d4858 792 TopoDS_Shape aSh = DBRep::Get(a[i]);
793 if (aSh.IsNull())
794 {
f0ada3e8 795 std::cout << "Invalid input shape " << a[i] << std::endl;
b94d4858 796 return 1;
797 }
798
799
800 if (aSh.ShapeType() == TopAbs_FACE)
801 EF = TopoDS::Face(aSh);
802 else
803 {
804 if (aSh.ShapeType() == TopAbs_COMPOUND || aSh.ShapeType() == TopAbs_WIRE || aSh.ShapeType() == TopAbs_EDGE)
805 {
806 TopExp_Explorer aExpE(aSh, TopAbs_EDGE, TopAbs_FACE);
807 for (; aExpE.More(); aExpE.Next())
808 aSplitEdges.Append(aExpE.Current());
809
dde68833 810 isSplittingEdges = !aSplitEdges.IsEmpty();
b94d4858 811 }
812 }
813
7fd59977 814 }
b94d4858 815 i++;
7fd59977 816 while (i < newnarg) {
817 if (pick) {
f0ada3e8 818 DBRep_DrawableShape::LastPick(EF, u, v);
7fd59977 819 }
f0ada3e8 820 if (!isSplittingEdges && !EF.IsNull() && EF.ShapeType() == TopAbs_FACE) {
7fd59977 821 // face wire/edge ...
f0ada3e8 822
7fd59977 823 while (i < newnarg) {
f0ada3e8 824 TopoDS_Shape W;
825 Standard_Boolean rever = Standard_False;
826 if (a[i][0] == '-') {
827 if (a[i][1] == '\0')
828 return 1;
829 pick = (a[i][1] == '.');
830 const char* Temp = a[i] + 1;
831 W = DBRep::Get(Temp, TopAbs_SHAPE, Standard_False);
832 rever = Standard_True;
833 }
834 else {
835 pick = (a[i][0] == '.');
836 W = DBRep::Get(a[i], TopAbs_SHAPE, Standard_False);
837 }
838 if (W.IsNull()) {
839 return 1; // on n`a rien recupere
840 }
841 TopAbs_ShapeEnum wtyp = W.ShapeType();
842 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND && pick) {
843 DBRep_DrawableShape::LastPick(W, u, v);
844 wtyp = W.ShapeType();
845 }
846 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND) {
847 EF = DBRep::Get(a[i]);
848 break;
849 }
850 else {
851 if (rever) {
852 W.Reverse();
853 }
854 if (wtyp == TopAbs_WIRE) {
855 Spls.Add(TopoDS::Wire(W), TopoDS::Face(EF));
856 }
857 else if (wtyp == TopAbs_EDGE) {
858 Spls.Add(TopoDS::Edge(W), TopoDS::Face(EF));
859 }
ed60a55e 860 else {
f0ada3e8 861 Spls.Add(TopoDS::Compound(W), TopoDS::Face(EF));
ed60a55e 862 }
f0ada3e8 863 }
864 i++;
7fd59977 865 }
866 }
867 else
b94d4858 868 {
869 if (isSplittingEdges)
870 {
871 TopoDS_Shape aSh = DBRep::Get(a[i]);
872 if (aSh.IsNull())
873 {
f0ada3e8 874 std::cout << "Invalid input shape " << a[i] << std::endl;
b94d4858 875 return 1;
876 }
877 TopExp_Explorer aExpE(aSh, TopAbs_EDGE, TopAbs_FACE);
878 for (; aExpE.More(); aExpE.Next())
879 aSplitEdges.Append(aExpE.Current());
880 }
881 else
882 {
f0ada3e8 883 std::cout << "Invalid input arguments. Should be : splitshape result shape [splitedges] \
b94d4858 884 [face wire/edge/compound [wire/edge/compound ...] \
885 [face wire/edge/compound [wire/edge/compound...] ...] \
f0ada3e8 886 [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]" << std::endl;
b94d4858 887 return 1;
888 }
889 }
890 i++;
7fd59977 891 }
f0ada3e8 892
b94d4858 893 if (isSplittingEdges)
894 Spls.Add(aSplitEdges);
895
7fd59977 896 // ici, i vaut newnarg
b94d4858 897 for (; i < narg; i += 2) {
f0ada3e8 898 TopoDS_Shape Ew, Es;
899 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_EDGE));
7fd59977 900 Es = TopoDS::Edge(aLocalShape);
f0ada3e8 901 // Es = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
7fd59977 902 if (Es.IsNull()) {
903 return 1;
904 }
f0ada3e8 905 aLocalShape = DBRep::Get(a[i + 1], TopAbs_EDGE);
7fd59977 906 Ew = TopoDS::Edge(aLocalShape);
f0ada3e8 907 // Ew = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
7fd59977 908 if (Ew.IsNull()) {
f0ada3e8 909 std::cout << "Invalid input shape " << a[i + 1] << std::endl;
7fd59977 910 return 1;
911 }
f0ada3e8 912 Spls.Add(TopoDS::Edge(Ew), TopoDS::Edge(Es));
7fd59977 913 }
914
915
f0ada3e8 916 DBRep::Set(a[1], Spls);
7fd59977 917 return 0;
918}
919
920//=======================================================================
921//function : thickshell
922//purpose :
923//=======================================================================
e1ed38e0 924Standard_Integer thickshell(Draw_Interpretor& theCommands,
925 Standard_Integer n, const char** a)
7fd59977 926{
f0ada3e8 927 if (n < 4) return 1;
928 TopoDS_Shape S = DBRep::Get(a[2]);
7fd59977 929 if (S.IsNull()) return 1;
930
f0ada3e8 931 Standard_Real Of = Draw::Atof(a[3]);
7fd59977 932
f0ada3e8 933 GeomAbs_JoinType JT = GeomAbs_Arc;
7fd59977 934 if (n > 4)
e1ed38e0 935 {
f0ada3e8 936 if (!strcmp(a[4], "i"))
e1ed38e0 937 JT = GeomAbs_Intersection;
f0ada3e8 938 if (!strcmp(a[4], "t"))
e1ed38e0 939 JT = GeomAbs_Tangent;
940 }
941
7fd59977 942 Standard_Boolean Inter = Standard_False; //Standard_True;
943 Standard_Real Tol = Precision::Confusion();
944 if (n > 5)
91322f44 945 Tol = Draw::Atof(a[5]);
7fd59977 946
947 BRepOffset_MakeOffset B;
f0ada3e8 948 B.Initialize(S, Of, Tol, BRepOffset_Skin, Inter, 0, JT, Standard_True);
7fd59977 949
7fd59977 950 B.MakeOffsetShape();
7fd59977 951
e1ed38e0 952 const BRepOffset_Error aRetCode = B.Error();
953 reportOffsetState(theCommands, aRetCode);
7fd59977 954
f0ada3e8 955 DBRep::Set(a[1], B.Shape());
7fd59977 956 return 0;
957}
958
959//=======================================================================
960//function : offsetshape
961//purpose :
962//=======================================================================
963
e1ed38e0 964Standard_Integer offsetshape(Draw_Interpretor& theCommands,
f0ada3e8 965 Standard_Integer n, const char** a)
7fd59977 966{
f0ada3e8 967 if (n < 4) return 1;
968 TopoDS_Shape S = DBRep::Get(a[2]);
7fd59977 969 if (S.IsNull()) return 1;
970
f0ada3e8 971 Standard_Real Of = Draw::Atof(a[3]);
972 Standard_Boolean Inter = (!strcmp(a[0], "offsetcompshape"));
973 GeomAbs_JoinType JT = GeomAbs_Arc;
974 if (!strcmp(a[0], "offsetinter"))
e1ed38e0 975 {
f0ada3e8 976 JT = GeomAbs_Intersection;
7fd59977 977 Inter = Standard_True;
978 }
f0ada3e8 979
7fd59977 980 BRepOffset_MakeOffset B;
f0ada3e8 981 Standard_Integer IB = 4;
7fd59977 982 Standard_Real Tol = Precision::Confusion();
e1ed38e0 983 if (n > 4)
984 {
f0ada3e8 985 TopoDS_Shape SF = DBRep::Get(a[4], TopAbs_FACE);
e1ed38e0 986 if (SF.IsNull())
987 {
f0ada3e8 988 IB = 5;
91322f44 989 Tol = Draw::Atof(a[4]);
7fd59977 990 }
991 }
f0ada3e8 992 B.Initialize(S, Of, Tol, BRepOffset_Skin, Inter, 0, JT);
7fd59977 993 //------------------------------------------
994 // recuperation et chargement des bouchons.
995 //----------------------------------------
996 Standard_Boolean YaBouchon = Standard_False;
997
f0ada3e8 998 for (Standard_Integer i = IB; i < n; i++)
e1ed38e0 999 {
f0ada3e8 1000 TopoDS_Shape SF = DBRep::Get(a[i], TopAbs_FACE);
e1ed38e0 1001 if (!SF.IsNull())
1002 {
7fd59977 1003 YaBouchon = Standard_True;
1004 B.AddFace(TopoDS::Face(SF));
1005 }
1006 }
1007
7fd59977 1008 if (!YaBouchon) B.MakeOffsetShape();
f0ada3e8 1009 else B.MakeThickSolid();
e1ed38e0 1010
1011 const BRepOffset_Error aRetCode = B.Error();
1012 reportOffsetState(theCommands, aRetCode);
7fd59977 1013
f0ada3e8 1014 DBRep::Set(a[1], B.Shape());
7fd59977 1015
1016 return 0;
1017}
1018
1019static BRepOffset_MakeOffset TheOffset;
1020static Standard_Real TheRadius;
1021static Standard_Boolean theYaBouchon;
1022static Standard_Real TheTolerance = Precision::Confusion();
f0ada3e8 1023static Standard_Boolean TheInter = Standard_False;
1024static GeomAbs_JoinType TheJoin = GeomAbs_Arc;
9b7f3f83 1025static Standard_Boolean RemoveIntEdges = Standard_False;
7fd59977 1026
1027Standard_Integer offsetparameter(Draw_Interpretor& di,
f0ada3e8 1028 Standard_Integer n, const char** a)
7fd59977 1029{
f0ada3e8 1030 if (n == 1) {
ecf4f17c 1031 di << " offsetparameter Tol Inter(c/p) JoinType(a/i/t) [RemoveInternalEdges(r/k)]\n";
586db386 1032 di << " Current Values\n";
9b7f3f83 1033 di << " --> Tolerance : " << TheTolerance << "\n";
1034 di << " --> TheInter : ";
f0ada3e8 1035 if (TheInter) {
1036 di << "Complet";
1037 }
1038 else {
7fd59977 1039 di << "Partial";
1040 }
586db386 1041 di << "\n --> TheJoin : ";
f0ada3e8 1042
7fd59977 1043 switch (TheJoin) {
9b7f3f83 1044 case GeomAbs_Arc: di << "Arc"; break;
1045 case GeomAbs_Intersection: di << "Intersection"; break;
7fd59977 1046 default:
f0ada3e8 1047 break;
7fd59977 1048 }
9b7f3f83 1049 //
586db386 1050 di << "\n --> Internal Edges : ";
9b7f3f83 1051 if (RemoveIntEdges) {
1052 di << "Remove";
1053 }
1054 else {
1055 di << "Keep";
1056 }
7fd59977 1057 di << "\n";
9b7f3f83 1058 //
7fd59977 1059 return 0;
1060 }
1061
f0ada3e8 1062 if (n < 4) return 1;
9b7f3f83 1063 //
91322f44 1064 TheTolerance = Draw::Atof(a[1]);
f0ada3e8 1065 TheInter = strcmp(a[2], "p") != 0;
9b7f3f83 1066 //
f0ada3e8 1067 if (!strcmp(a[3], "a")) TheJoin = GeomAbs_Arc;
1068 else if (!strcmp(a[3], "i")) TheJoin = GeomAbs_Intersection;
1069 else if (!strcmp(a[3], "t")) TheJoin = GeomAbs_Tangent;
9b7f3f83 1070 //
1071 RemoveIntEdges = (n >= 5) ? !strcmp(a[4], "r") : Standard_False;
9b7f3f83 1072 //
1073 return 0;
7fd59977 1074}
1075
7fd59977 1076//=======================================================================
1077//function : offsetinit
1078//purpose :
1079//=======================================================================
1080
f0ada3e8 1081Standard_Integer offsetload(Draw_Interpretor&,
9b7f3f83 1082 Standard_Integer n, const char** a)
7fd59977 1083{
f0ada3e8 1084 if (n < 2) return 1;
1085 TopoDS_Shape S = DBRep::Get(a[1]);
7fd59977 1086 if (S.IsNull()) return 1;
1087
f0ada3e8 1088 Standard_Real Of = Draw::Atof(a[2]);
7fd59977 1089 TheRadius = Of;
f0ada3e8 1090 // Standard_Boolean Inter = Standard_True;
1091
1092 TheOffset.Initialize(S, Of, TheTolerance, BRepOffset_Skin, TheInter, 0, TheJoin,
1093 Standard_False, RemoveIntEdges);
7fd59977 1094 //------------------------------------------
1095 // recuperation et chargement des bouchons.
1096 //----------------------------------------
f0ada3e8 1097 for (Standard_Integer i = 3; i < n; i++) {
1098 TopoDS_Shape SF = DBRep::Get(a[i], TopAbs_FACE);
7fd59977 1099 if (!SF.IsNull()) {
1100 TheOffset.AddFace(TopoDS::Face(SF));
1101 }
1102 }
1103 if (n < 4) theYaBouchon = Standard_False; //B.MakeOffsetShape();
1104 else theYaBouchon = Standard_True; //B.MakeThickSolid ();
1105
1106 return 0;
1107}
1108
1109
1110//=======================================================================
1111//function : offsetonface
1112//purpose :
1113//=======================================================================
1114
1115Standard_Integer offsetonface(Draw_Interpretor&, Standard_Integer n, const char** a)
1116{
f0ada3e8 1117 if (n < 3) return 1;
7fd59977 1118
f0ada3e8 1119 for (Standard_Integer i = 1; i < n; i += 2) {
1120 TopoDS_Shape SF = DBRep::Get(a[i], TopAbs_FACE);
7fd59977 1121 if (!SF.IsNull()) {
f0ada3e8 1122 Standard_Real Of = Draw::Atof(a[i + 1]);
1123 TheOffset.SetOffsetOnFace(TopoDS::Face(SF), Of);
7fd59977 1124 }
1125 }
f0ada3e8 1126
7fd59977 1127 return 0;
1128}
1129
1130//=======================================================================
1131//function : offsetperform
1132//purpose :
1133//=======================================================================
1134
ab87e6fc 1135Standard_Integer offsetperform(Draw_Interpretor& theCommands,
f0ada3e8 1136 Standard_Integer theNArg, const char** a)
1137{
1138 if (theNArg < 2) return 1;
7fd59977 1139
ab87e6fc 1140 if (theYaBouchon)
f0ada3e8 1141 TheOffset.MakeThickSolid();
ab87e6fc 1142 else
1143 TheOffset.MakeOffsetShape();
1144
f0ada3e8 1145 if (TheOffset.IsDone())
1146 {
1147 DBRep::Set(a[1], TheOffset.Shape());
1148 }
ab87e6fc 1149 else
f0ada3e8 1150 {
1151 const BRepOffset_Error aRetCode = TheOffset.Error();
1152 reportOffsetState(theCommands, aRetCode);
1153 }
7fd59977 1154
420b38fd 1155 // Store the history of Boolean operation into the session
1156 if (BRepTest_Objects::IsHistoryNeeded())
1157 {
1158 TopTools_ListOfShape aLA;
f0ada3e8 1159 aLA.Append(TheOffset.InitShape());
420b38fd 1160 BRepTest_Objects::SetHistory<BRepOffset_MakeOffset>(aLA, TheOffset);
1161 }
1162
7fd59977 1163 return 0;
f0ada3e8 1164}
7fd59977 1165
1166
1167//=======================================================================
7fd59977 1168//function : ROW
1169//purpose :
1170//=======================================================================
1171
1172static Standard_Integer ROW(Draw_Interpretor& theCommands,
f0ada3e8 1173 Standard_Integer narg, const char** a)
7fd59977 1174{
f0ada3e8 1175 if (narg < 13) return 1;
7fd59977 1176 TopoDS_Shape S = DBRep::Get(a[3]);
1177 BRepFeat_MakeRevol theRFace;
1178 gp_Dir D;
1179 gp_Pnt Or;
f0ada3e8 1180 Standard_Real Angle = 0;
1181 TopoDS_Shape FFrom, FUntil;
1182 Standard_Integer i, borne;
7fd59977 1183 Standard_Boolean fuse;
1184
1185 if (a[1][0] == 'f' || a[1][0] == 'F') {
1186 fuse = Standard_True;
1187 }
1188 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1189 fuse = Standard_False;
1190 }
1191 else {
1192 return 1;
1193 }
1194
f0ada3e8 1195 FFrom = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 1196 if (FFrom.IsNull()) {
91322f44 1197 Angle = Draw::Atof(a[4]);
f0ada3e8 1198 Angle *= M_PI / 180.;
7fd59977 1199 i = 5;
1200 }
1201 else {
f0ada3e8 1202 FUntil = DBRep::Get(a[5], TopAbs_SHAPE);
7fd59977 1203 if (FUntil.IsNull()) {
1204 i = 5;
1205 FUntil = FFrom;
1206 FFrom.Nullify();
f0ada3e8 1207
7fd59977 1208 }
1209 else {
1210 if (narg < 14) {
f0ada3e8 1211 return 1;
7fd59977 1212 }
1213 i = 6;
1214 }
1215 }
f0ada3e8 1216 borne = i + 6;
7fd59977 1217
f0ada3e8 1218 Or.SetCoord(Draw::Atof(a[i]), Draw::Atof(a[i + 1]), Draw::Atof(a[i + 2]));
1219 D.SetCoord(Draw::Atof(a[i + 3]), Draw::Atof(a[i + 4]), Draw::Atof(a[i + 5]));
1220 gp_Ax1 theAxis(Or, D);
7fd59977 1221
f0ada3e8 1222 TopoDS_Shape aLocalShape(DBRep::Get(a[borne], TopAbs_FACE));
1223 TopoDS_Face F = TopoDS::Face(aLocalShape);
1224 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
7fd59977 1225 BRepFeat_SplitShape Spls(F);
f0ada3e8 1226 for (i = borne + 1; i < narg; i++) {
7fd59977 1227 TopoDS_Wire wir;
f0ada3e8 1228 if (a[i][0] != '-') {
1229 aLocalShape = DBRep::Get(a[i], TopAbs_WIRE);
7fd59977 1230 wir = TopoDS::Wire(aLocalShape);
f0ada3e8 1231 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
7fd59977 1232 }
1233 else {
1234 if (a[i][1] == '\0')
f0ada3e8 1235 return 1;
1236 const char* Temp = a[i] + 1;
1237 aLocalShape = DBRep::Get(Temp, TopAbs_WIRE);
7fd59977 1238 wir = TopoDS::Wire(aLocalShape);
f0ada3e8 1239 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
7fd59977 1240 wir.Reverse();
1241 }
f0ada3e8 1242 Spls.Add(wir, F);
7fd59977 1243 }
1244 Spls.Build();
1245
1246 TopoDS_Shape ToRotate;
1247 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1248 if (lleft.Extent() == 1) {
f0ada3e8 1249 theRFace.Init(S, lleft.First(), F, theAxis, fuse, Standard_True);
7fd59977 1250 ToRotate = lleft.First();
1251 }
1252 else {
1253 BRep_Builder B;
1254 TopoDS_Shell Sh;
1255 B.MakeShell(Sh);
1256 TopTools_ListIteratorOfListOfShape it;
f0ada3e8 1257 for (it.Initialize(lleft); it.More(); it.Next()) {
1258 B.Add(Sh, TopoDS::Face(it.Value()));
7fd59977 1259 }
f0ada3e8 1260 Sh.Closed(BRep_Tool::IsClosed(Sh));
1261 theRFace.Init(S, Sh, F, theAxis, fuse, Standard_True);
7fd59977 1262 ToRotate = Sh;
1263 }
1264
1265 // Recherche des faces de glissement
1266// for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
f0ada3e8 1267 TopExp_Explorer exp(S, TopAbs_FACE);
1268 for (; exp.More(); exp.Next()) {
7fd59977 1269 if (exp.Current().IsSame(F)) {
1270 break;
1271 }
1272 }
1273
1274 if (!exp.More()) {
1275 LocOpe_FindEdgesInFace FEIF;
f0ada3e8 1276 for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next()) {
7fd59977 1277 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1278 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1279 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
f0ada3e8 1280 Su = Handle(Geom_RectangularTrimmedSurface)::
1281 DownCast(Su)->BasisSurface();
7fd59977 1282 }
1283 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
f0ada3e8 1284 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1285 if (pl.Axis().IsParallel(theAxis, Precision::Angular())) {
1286 FEIF.Set(ToRotate, fac);
1287 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
1288 theRFace.Add(FEIF.Edge(), fac);
1289 }
1290 }
7fd59977 1291 }
1292 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
f0ada3e8 1293 gp_Cylinder cy =
1294 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1295 if (cy.Axis().IsCoaxial(theAxis,
1296 Precision::Angular(), Precision::Confusion())) {
1297 FEIF.Set(ToRotate, fac);
1298 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
1299 theRFace.Add(FEIF.Edge(), fac);
1300 }
1301 }
7fd59977 1302 }
1303 }
1304 }
1305
1306 if (borne == 11) {
1307 if (FUntil.IsNull()) {
1308 theRFace.Perform(Angle);
1309 }
1310 else {
1311 theRFace.Perform(FUntil);
1312 }
1313 }
1314 else { // borne == 12
f0ada3e8 1315 theRFace.Perform(FFrom, FUntil);
7fd59977 1316 }
1317
1318 if (!theRFace.IsDone()) {
1319 theCommands << "Local operation not done";
1320 return 1;
1321 }
1322
f0ada3e8 1323 DBRep::Set(a[2], theRFace);
7fd59977 1324 dout.Flush();
1325 return 0;
1326}
1327
1328
1329//=======================================================================
1330//function : ROF
1331//purpose :
1332//=======================================================================
1333
1334static Standard_Integer ROF(Draw_Interpretor& theCommands,
f0ada3e8 1335 Standard_Integer narg, const char** a)
7fd59977 1336{
f0ada3e8 1337 if (narg < 12) return 1;
7fd59977 1338 TopoDS_Shape S = DBRep::Get(a[3]);
1339 BRepFeat_MakeRevol theRFace;
1340 gp_Dir D;
1341 gp_Pnt Or;
f0ada3e8 1342 Standard_Real Angle = 0;
1343 TopoDS_Shape FFrom, FUntil;
1344 Standard_Integer i, borne;
7fd59977 1345 Standard_Boolean fuse;
1346
1347 if (a[1][0] == 'f' || a[1][0] == 'F') {
1348 fuse = Standard_True;
1349 }
1350 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1351 fuse = Standard_False;
1352 }
1353 else {
1354 return 1;
1355 }
1356
f0ada3e8 1357 FFrom = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 1358 if (FFrom.IsNull()) {
91322f44 1359 Angle = Draw::Atof(a[4]);
f0ada3e8 1360 Angle *= M_PI / 180.;
7fd59977 1361 i = 5;
1362 }
1363 else {
f0ada3e8 1364 FUntil = DBRep::Get(a[5], TopAbs_SHAPE);
7fd59977 1365 if (FUntil.IsNull()) {
1366 i = 5;
1367 FUntil = FFrom;
1368 FFrom.Nullify();
f0ada3e8 1369
7fd59977 1370 }
1371 else {
1372 if (narg < 13) {
f0ada3e8 1373 return 1;
7fd59977 1374 }
1375 i = 6;
1376 }
1377 }
1378
f0ada3e8 1379 borne = i + 6;
1380 Or.SetCoord(Draw::Atof(a[i]), Draw::Atof(a[i + 1]), Draw::Atof(a[i + 2]));
1381 D.SetCoord(Draw::Atof(a[i + 3]), Draw::Atof(a[i + 4]), Draw::Atof(a[i + 5]));
1382 gp_Ax1 theAxis(Or, D);
7fd59977 1383
1384 TopoDS_Shape ToRotate;
f0ada3e8 1385 if (narg == borne + 1) {
1386 TopoDS_Shape aLocalShape(DBRep::Get(a[borne], TopAbs_FACE));
1387 TopoDS_Face F = TopoDS::Face(aLocalShape);
1388 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1389 theRFace.Init(S, F, F, theAxis, fuse, Standard_True);
7fd59977 1390 ToRotate = F;
1391 }
1392 else {
1393 TopoDS_Shell She;
1394 BRep_Builder B;
1395 B.MakeShell(She);
f0ada3e8 1396
1397 for (i = borne; i < narg; i++) {
1398 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_FACE));
1399 TopoDS_Face F = TopoDS::Face(aLocalShape);
1400 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
7fd59977 1401 if (!F.IsNull()) {
f0ada3e8 1402 B.Add(She, F);
7fd59977 1403 }
1404 }
f0ada3e8 1405 She.Closed(BRep_Tool::IsClosed(She));
1406 theRFace.Init(S, She, TopoDS_Face(), theAxis, fuse, Standard_False);
7fd59977 1407 ToRotate = She;
1408 }
1409
f0ada3e8 1410 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1411 TopExp_Explorer exp(ToRotate, TopAbs_FACE);
1412 for (; exp.More(); exp.Next()) {
1413 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1414 TopExp_Explorer exp2(S, TopAbs_FACE);
1415 for (; exp2.More(); exp2.Next()) {
7fd59977 1416 if (exp2.Current().IsSame(exp.Current())) {
f0ada3e8 1417 break;
7fd59977 1418 }
1419 }
1420 if (exp2.More()) {
1421 break;
1422 }
1423 }
1424
1425 if (!exp.More()) {
1426 LocOpe_FindEdgesInFace FEIF;
f0ada3e8 1427 for (exp.Init(S, TopAbs_FACE); exp.More(); exp.Next()) {
7fd59977 1428 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1429 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1430 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
f0ada3e8 1431 Su = Handle(Geom_RectangularTrimmedSurface)::
1432 DownCast(Su)->BasisSurface();
7fd59977 1433 }
1434 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
f0ada3e8 1435 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1436 if (pl.Axis().IsParallel(theAxis, Precision::Angular())) {
1437 FEIF.Set(ToRotate, fac);
1438 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
1439 theRFace.Add(FEIF.Edge(), fac);
1440 }
1441 }
7fd59977 1442 }
1443 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
f0ada3e8 1444 gp_Cylinder cy =
1445 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1446 if (cy.Axis().IsCoaxial(theAxis,
1447 Precision::Angular(), Precision::Confusion())) {
1448 FEIF.Set(ToRotate, fac);
1449 for (FEIF.Init(); FEIF.More(); FEIF.Next()) {
1450 theRFace.Add(FEIF.Edge(), fac);
1451 }
1452 }
7fd59977 1453 }
1454 }
1455 }
1456
1457 if (borne == 11) {
1458 if (FUntil.IsNull()) {
1459 theRFace.Perform(Angle);
1460 }
1461 else {
1462 theRFace.Perform(FUntil);
1463 }
1464 }
1465 else { // borne == 12
f0ada3e8 1466 theRFace.Perform(FFrom, FUntil);
7fd59977 1467 }
1468
1469 if (!theRFace.IsDone()) {
1470 theCommands << "Local operation not done";
1471 return 1;
1472 }
1473
f0ada3e8 1474 DBRep::Set(a[2], theRFace);
7fd59977 1475 dout.Flush();
1476 return 0;
1477}
1478
1479
1480//=======================================================================
1481//function : GLU
1482//purpose : Commande glue
1483//=======================================================================
1484
f0ada3e8 1485static Standard_Integer GLU(Draw_Interpretor&,
1486 Standard_Integer narg, const char** a)
7fd59977 1487{
f0ada3e8 1488 if (narg < 6 || narg % 2 != 0) return 1;
7fd59977 1489 TopoDS_Shape Sne = DBRep::Get(a[2]);
1490 TopoDS_Shape Sba = DBRep::Get(a[3]);
f0ada3e8 1491
7fd59977 1492 Standard_Boolean pick;
f0ada3e8 1493
1494 BRepFeat_Gluer theGl(Sne, Sba);
1495 TopoDS_Shape Fne, Fba;
1496
7fd59977 1497 LocOpe_FindEdges fined;
1498
1499 Standard_Integer i = 4;
1500 Standard_Boolean first = Standard_True;
f0ada3e8 1501 while (i < narg) {
7fd59977 1502 pick = (a[i][0] == '.');
1503 Fne = DBRep::Get(a[i]);
1504 if (Fne.IsNull()) {
1505 return 1;
1506 }
1507 TopAbs_ShapeEnum sht = Fne.ShapeType();
1508 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
f0ada3e8 1509 Standard_Real u, v;
1510 DBRep_DrawableShape::LastPick(Fne, u, v);
7fd59977 1511 sht = Fne.ShapeType();
1512 }
1513 if (first && sht != TopAbs_FACE) {
1514 return 1;
1515 }
1516 first = Standard_False;
f0ada3e8 1517 pick = (a[i + 1][0] == '.');
1518 Fba = DBRep::Get(a[i + 1]);
7fd59977 1519 if (Fba.IsNull()) {
1520 return 1;
1521 }
1522 if (pick && Fba.ShapeType() != sht) {
f0ada3e8 1523 Standard_Real u, v;
1524 DBRep_DrawableShape::LastPick(Fba, u, v);
7fd59977 1525 }
1526 if (Fba.ShapeType() != sht) {
1527 return 1;
1528 }
1529 if (sht == TopAbs_FACE) {
1530 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1531 const TopoDS_Face& f2 = TopoDS::Face(Fba);
f0ada3e8 1532 theGl.Bind(f1, f2);
1533 fined.Set(Fne, Fba);
7fd59977 1534 for (fined.InitIterator(); fined.More(); fined.Next()) {
f0ada3e8 1535 theGl.Bind(fined.EdgeFrom(), fined.EdgeTo());
7fd59977 1536 }
1537 }
1538 else {
f0ada3e8 1539 theGl.Bind(TopoDS::Edge(Fne), TopoDS::Edge(Fba));
7fd59977 1540 }
f0ada3e8 1541 i += 2;
7fd59977 1542 }
f0ada3e8 1543
1544 DBRep::Set(a[1], theGl);
7fd59977 1545 dout.Flush();
1546 return 0;
1547}
1548
1549static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
f0ada3e8 1550 Standard_Integer narg, const char** a)
7fd59977 1551{
1552
f0ada3e8 1553 if (strcasecmp(a[0], "FEATPRISM") &&
1554 strcasecmp(a[0], "FEATDPRISM") &&
1555 strcasecmp(a[0], "FEATREVOL") &&
1556 strcasecmp(a[0], "FEATPIPE") &&
1557 strcasecmp(a[0], "FEATLF") &&
1558 strcasecmp(a[0], "FEATRF")) {
7fd59977 1559 return 1;
1560 }
1561
f0ada3e8 1562 if ((!strcasecmp(a[0], "FEATPRISM") && narg != 9) ||
1563 (!strcasecmp(a[0], "FEATREVOL") && narg != 12) ||
1564 (!strcasecmp(a[0], "FEATDPRISM") && narg != 7) ||
1565 (!strcasecmp(a[0], "FEATPIPE") && narg != 7) ||
1566 (!strcasecmp(a[0], "FEATLF") && narg != 12) ||
1567 (!strcasecmp(a[0], "FEATRF") && narg != 14)) {
7fd59977 1568 theCommands << "invalid number of arguments";
1569 return 1;
1570 }
1571
1572 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1573 if (Sbase.IsNull()) {
1574 theCommands << "null basis shape";
1575 return 1;
1576 }
f0ada3e8 1577 Standard_Integer Ifuse = Draw::Atoi(a[narg - 2]);
1578 Standard_Integer Imodif = Draw::Atoi(a[narg - 1]);
1579
7fd59977 1580 Standard_Integer Fuse = Ifuse;
f0ada3e8 1581 Standard_Boolean Modify = (Imodif != 0);
7fd59977 1582
1583 TopoDS_Shape Pbase;
1584 TopoDS_Face Skface;
1585 TopoDS_Wire W;
1586
1587 Handle(Geom_Plane) P;
1588
1589 BRepFeat_StatusError se;
1590
f0ada3e8 1591 if (strcasecmp(a[0], "FEATLF") && strcasecmp(a[0], "FEATRF")) {
7fd59977 1592 Pbase = DBRep::Get(a[2]);
1593 if (Pbase.IsNull()) {
1594 theCommands << "null shape to transform";
1595 return 1;
1596 }
f0ada3e8 1597 TopoDS_Shape aLocalShape(DBRep::Get(a[3], TopAbs_FACE));
7fd59977 1598 Skface = TopoDS::Face(aLocalShape);
f0ada3e8 1599 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
7fd59977 1600 if (Skface.IsNull()) {
1601 theCommands << "null face of Sketch";
1602 return 1;
1603 }
1604 }
1605 else {
1606 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1607 W = TopoDS::Wire(aLocalShape);
f0ada3e8 1608 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1609 if (W.IsNull()) {
7fd59977 1610 theCommands << "null profile for rib or slot";
1611 return 1;
1612 }
1613 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1614 P = Handle(Geom_Plane)::DownCast(s);
f0ada3e8 1615 if (P.IsNull()) {
7fd59977 1616 theCommands << "null plane to transform";
1617 return 1;
1618 }
1619 }
1620 if (narg == 9 || narg == 12 || narg == 14) {
f0ada3e8 1621 // Standard_Real X,Y,Z,X1,Y1,Z1;
1622 Standard_Real X, Y, Z;
91322f44 1623 X = Draw::Atof(a[4]);
1624 Y = Draw::Atof(a[5]);
1625 Z = Draw::Atof(a[6]);
f0ada3e8 1626
7fd59977 1627 if (narg == 9) { // prism
f0ada3e8 1628 prdef = Standard_True;
1629 theSbase = Sbase;
1630 thePbase = Pbase;
1631 theSkface = Skface;
1632 thePrism.Init(Sbase, Pbase, Skface, gp_Dir(X, Y, Z), Fuse, Modify);
7fd59977 1633 }
f0ada3e8 1634 else if (narg == 14) {
7fd59977 1635 rfdef = Standard_True;
1636 gp_Pnt Or(X, Y, Z);
91322f44 1637 X = Draw::Atof(a[7]);
1638 Y = Draw::Atof(a[8]);
1639 Z = Draw::Atof(a[9]);
1640 Standard_Real H1 = Draw::Atof(a[10]);
1641 Standard_Real H2 = Draw::Atof(a[11]);
7fd59977 1642 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1643 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1644 if (!theRF.IsDone()) {
f0ada3e8 1645 se = theRF.CurrentStatusError();
1646 //BRepFeat::Print(se,std::cout) << std::endl;
1647 Standard_SStream aSStream;
1648 BRepFeat::Print(se, aSStream);
1649 theCommands << aSStream << "\n";
1650 return 1;
7fd59977 1651 }
1652 }
f0ada3e8 1653 else if (narg == 12 && strcasecmp(a[0], "FEATLF")) {
7fd59977 1654 rvdef = Standard_True;
f0ada3e8 1655 gp_Pnt Or(X, Y, Z);
91322f44 1656 X = Draw::Atof(a[7]);
1657 Y = Draw::Atof(a[8]);
1658 Z = Draw::Atof(a[9]);
f0ada3e8 1659 theSbase = Sbase;
1660 thePbase = Pbase;
1661 theSkface = Skface;
1662 theRevol.Init(Sbase, Pbase, Skface, gp_Ax1(Or, gp_Dir(X, Y, Z)),
1663 Fuse, Modify);
7fd59977 1664 }
1665 else {
1666 lfdef = Standard_True;
f0ada3e8 1667 gp_Vec Direct(X, Y, Z);
91322f44 1668 X = Draw::Atof(a[7]);
1669 Y = Draw::Atof(a[8]);
1670 Z = Draw::Atof(a[9]);
f0ada3e8 1671 theLF.Init(Sbase, W, P, Direct, gp_Vec(X, Y, Z), Fuse, Modify);
7fd59977 1672 if (!theLF.IsDone()) {
f0ada3e8 1673 se = theLF.CurrentStatusError();
1674 //BRepFeat::Print(se,std::cout) << std::endl;
1675 Standard_SStream aSStream;
1676 BRepFeat::Print(se, aSStream);
1677 theCommands << aSStream << "\n";
1678 return 1;
7fd59977 1679 }
1680 }
1681 }
1682 else if (narg == 7) {
f0ada3e8 1683 if (!strcasecmp(a[0], "FEATDPRISM")) {
7fd59977 1684 if (Pbase.ShapeType() != TopAbs_FACE) {
f0ada3e8 1685 theCommands << "Invalid DPrism base";
1686 return 1;
7fd59977 1687 }
f0ada3e8 1688 Standard_Real Angle = Draw::Atof(a[4])*M_PI / 360;
7fd59977 1689 dprdef = Standard_True;
f0ada3e8 1690 theSbase = Sbase;
1691 thePbase = Pbase;
1692 theSkface = Skface;
1693 theDPrism.Init(Sbase, TopoDS::Face(Pbase), Skface, Angle, Fuse, Modify);
7fd59977 1694 }
1695 else { // FEATPIPE
f0ada3e8 1696 TopoDS_Shape aLocalShape(DBRep::Get(a[4], TopAbs_WIRE));
7fd59977 1697 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
f0ada3e8 1698 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
7fd59977 1699 if (Spine.IsNull()) {
f0ada3e8 1700 TopoDS_Shape Edspine = DBRep::Get(a[4], TopAbs_EDGE);
1701 if (Edspine.IsNull()) {
1702 theCommands << "null spine";
1703 return 1;
1704 }
1705 BRep_Builder B;
1706 B.MakeWire(Spine);
1707 B.Add(Spine, Edspine);
7fd59977 1708 }
1709 pidef = Standard_True;
f0ada3e8 1710 theSbase = Sbase;
1711 thePbase = Pbase;
1712 theSkface = Skface;
1713 thePipe.Init(Sbase, Pbase, Skface, Spine, Fuse, Modify);
7fd59977 1714 }
1715 }
1716 return 0;
1717}
1718
1719
1720
f0ada3e8 1721static Standard_Integer ADD(Draw_Interpretor&,
1722 Standard_Integer narg, const char** a)
7fd59977 1723{
f0ada3e8 1724 Standard_Integer i;
1725 if (narg < 4 || narg % 2 != 0) {
7fd59977 1726 return 1;
1727 }
f0ada3e8 1728 if (!strcasecmp("PRISM", a[1])) {
7fd59977 1729 if (!prdef) {
1730 return 1;
1731 }
f0ada3e8 1732 for (i = 2; i < narg; i += 2) {
1733 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_EDGE));
7fd59977 1734 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
f0ada3e8 1735 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
7fd59977 1736 if (edg.IsNull()) {
f0ada3e8 1737 return 1;
7fd59977 1738 }
f0ada3e8 1739 aLocalShape = DBRep::Get(a[i + 1], TopAbs_FACE);
7fd59977 1740 TopoDS_Face fac = TopoDS::Face(aLocalShape);
f0ada3e8 1741 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
7fd59977 1742 if (fac.IsNull()) {
f0ada3e8 1743 return 1;
7fd59977 1744 }
f0ada3e8 1745 thePrism.Add(edg, fac);
7fd59977 1746 }
1747 }
f0ada3e8 1748 else if (!strcasecmp("REVOL", a[1])) {
7fd59977 1749 if (!rvdef) {
1750 return 1;
1751 }
f0ada3e8 1752 for (i = 2; i < narg; i += 2) {
1753 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_EDGE));
7fd59977 1754 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
f0ada3e8 1755 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
7fd59977 1756 if (edg.IsNull()) {
f0ada3e8 1757 return 1;
7fd59977 1758 }
f0ada3e8 1759 aLocalShape = DBRep::Get(a[i + 1], TopAbs_FACE);
7fd59977 1760 TopoDS_Face fac = TopoDS::Face(aLocalShape);
f0ada3e8 1761 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
7fd59977 1762 if (fac.IsNull()) {
f0ada3e8 1763 return 1;
7fd59977 1764 }
f0ada3e8 1765 theRevol.Add(edg, fac);
7fd59977 1766 }
1767 }
f0ada3e8 1768 else if (!strcasecmp("PIPE", a[1])) {
7fd59977 1769 if (!pidef) {
1770 return 1;
1771 }
f0ada3e8 1772 for (i = 2; i < narg; i += 2) {
1773 TopoDS_Shape aLocalShape(DBRep::Get(a[i], TopAbs_EDGE));
7fd59977 1774 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
f0ada3e8 1775 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
7fd59977 1776 if (edg.IsNull()) {
f0ada3e8 1777 return 1;
7fd59977 1778 }
f0ada3e8 1779 aLocalShape = DBRep::Get(a[i + 1], TopAbs_FACE);
7fd59977 1780 TopoDS_Face fac = TopoDS::Face(aLocalShape);
f0ada3e8 1781 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
7fd59977 1782 if (fac.IsNull()) {
f0ada3e8 1783 return 1;
7fd59977 1784 }
f0ada3e8 1785 thePipe.Add(edg, fac);
7fd59977 1786 }
1787 }
1788 else {
1789 return 1;
1790 }
1791 return 0;
1792}
1793
1794
1795
1796static Standard_Integer PERF(Draw_Interpretor& theCommands,
f0ada3e8 1797 Standard_Integer narg, const char** a)
7fd59977 1798{
1799 if (narg < 3) {
1800 return 1;
1801 }
f0ada3e8 1802 if (strcasecmp(a[0], "FEATPERFORM") &&
1803 strcasecmp(a[0], "FEATPERFORMVAL")) {
7fd59977 1804 return 1;
1805 }
1806
f0ada3e8 1807 TopTools_ListOfShape anArgs;
7fd59977 1808 Standard_Integer Kas;
f0ada3e8 1809 if (!strcasecmp("PRISM", a[1])) {
7fd59977 1810 Kas = 1;
1811 if (!prdef) {
1812 theCommands << "prism not defined";
1813 return 1;
1814 }
1815 }
f0ada3e8 1816 else if (!strcasecmp("REVOL", a[1])) {
7fd59977 1817 Kas = 2;
1818 if (!rvdef) {
1819 theCommands << "revol not defined";
1820 return 1;
1821 }
1822 }
f0ada3e8 1823 else if (!strcasecmp("PIPE", a[1])) {
7fd59977 1824 Kas = 3;
1825 if (!pidef) {
1826 theCommands << "pipe not defined";
1827 return 1;
1828 }
f0ada3e8 1829 if (!strcasecmp(a[0], "FEATPERFORMVAL")) {
7fd59977 1830 theCommands << "invalid command for pipe";
1831 return 1;
1832 }
1833 }
f0ada3e8 1834 else if (!strcasecmp("DPRISM", a[1])) {
7fd59977 1835 Kas = 4;
1836 if (!dprdef) {
1837 theCommands << "dprism not defined";
1838 return 1;
1839 }
1840 }
f0ada3e8 1841 else if (!strcasecmp("LF", a[1])) {
7fd59977 1842 Kas = 5;
1843 if (!lfdef) {
1844 theCommands << "lf not defined";
1845 return 1;
1846 }
f0ada3e8 1847 if (!strcasecmp(a[0], "FEATPERFORMVAL")) {
7fd59977 1848 theCommands << "invalid command for lf";
1849 return 1;
1850 }
1851 }
f0ada3e8 1852 else if (!strcasecmp("RF", a[1])) {
7fd59977 1853 Kas = 6;
1854 if (!rfdef) {
1855 theCommands << "rf not defined";
1856 return 1;
1857 }
f0ada3e8 1858 if (!strcasecmp(a[0], "FEATPERFORMVAL")) {
7fd59977 1859 theCommands << "invalid command for rf";
1860 return 1;
1861 }
1862 }
1863 else {
1864 theCommands << "unknown argument : " << a[1];
1865 return 1;
1866 }
1867
f0ada3e8 1868 if (!strcasecmp(a[0], "FEATPERFORMVAL")) {
1869 if (narg != 4 && narg != 5) {
7fd59977 1870 theCommands << "invalid number of arguments";
1871 return 1;
1872 }
1873 if (narg == 4) {
91322f44 1874 Standard_Real Val = Draw::Atof(a[3]);
7fd59977 1875 if (Kas == 1) {
f0ada3e8 1876 thePrism.Perform(Val);
7fd59977 1877 }
1878 else if (Kas == 2) {
f0ada3e8 1879 Val *= (M_PI / 180.);
1880 theRevol.Perform(Val);
7fd59977 1881 }
1882 else if (Kas == 4) {
f0ada3e8 1883 theDPrism.Perform(Val);
7fd59977 1884 }
1885 else if (Kas == 5) {
f0ada3e8 1886 theCommands << "invalid command for lf";
1887 return 1;
7fd59977 1888 }
1889 else if (Kas == 6) {
f0ada3e8 1890 theCommands << "invalid command for rf";
1891 return 1;
7fd59977 1892 }
1893 }
f0ada3e8 1894 else if (narg == 5) {
91322f44 1895 Standard_Real Val = Draw::Atof(a[3]);
f0ada3e8 1896 TopoDS_Shape FUntil = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 1897 if (Kas == 1) {
f0ada3e8 1898 thePrism.PerformUntilHeight(FUntil, Val);
7fd59977 1899 }
1900 else if (Kas == 2) {
f0ada3e8 1901 Val *= (M_PI / 180.);
1902 theRevol.PerformUntilAngle(FUntil, Val);
7fd59977 1903 }
1904 else if (Kas == 4) {
f0ada3e8 1905 theDPrism.PerformUntilHeight(FUntil, Val);
1906 }
7fd59977 1907 else {
f0ada3e8 1908 theCommands << "invalid command for ribs or slots";
1909 return 1;
7fd59977 1910 }
1911 }
1912 }
f0ada3e8 1913 else if (!strcasecmp(a[0], "FEATPERFORM")) {
7fd59977 1914 if (narg == 3) { // Thru all
1915 switch (Kas) {
1916 case 1:
f0ada3e8 1917 thePrism.PerformThruAll();
1918 break;
7fd59977 1919 case 2:
f0ada3e8 1920 theRevol.PerformThruAll();
1921 break;
7fd59977 1922 case 3:
f0ada3e8 1923 thePipe.Perform();
1924 break;
7fd59977 1925 case 4:
1926 theDPrism.PerformThruAll();
1927 break;
1928 case 5:
f0ada3e8 1929 theLF.Perform();
7fd59977 1930 break;
1931 case 6:
f0ada3e8 1932 theRF.Perform();
7fd59977 1933 break;
1934 default:
1935
f0ada3e8 1936 return 1;
7fd59977 1937 }
1938 }
1939 else if (narg == 4) { // Until
f0ada3e8 1940 TopoDS_Shape Funtil = DBRep::Get(a[3], TopAbs_SHAPE);
7fd59977 1941 switch (Kas) {
1942 case 1:
f0ada3e8 1943 {
1944 if (Funtil.IsNull()) {
1945 thePrism.PerformUntilEnd();
1946 }
1947 else {
1948 thePrism.Perform(Funtil);
1949 }
1950 }
1951 break;
7fd59977 1952 case 2:
f0ada3e8 1953 {
1954 if (!Funtil.IsNull()) {
1955 theRevol.Perform(Funtil);
1956 }
1957 else {
1958 return 1;
1959 }
1960 }
1961 break;
7fd59977 1962 case 3:
f0ada3e8 1963 {
1964 if (!Funtil.IsNull()) {
1965 thePipe.Perform(Funtil);
1966 }
1967 else {
1968 theCommands << "invalid command for ribs pipe";
1969 return 1;
1970 }
1971 }
1972 break;
7fd59977 1973 case 4:
f0ada3e8 1974 {
1975 if (!Funtil.IsNull()) {
1976 theDPrism.Perform(Funtil);
1977 }
1978 else {
1979 theDPrism.PerformUntilEnd();
1980 }
1981 }
1982 break;
7fd59977 1983 case 5:
f0ada3e8 1984 {
1985 theCommands << "invalid command for lf";
1986 return 1;
1987 }
1988 break;
7fd59977 1989 case 6:
f0ada3e8 1990 {
1991 theCommands << "invalid command for rf";
1992 return 1;
1993 }
1994 break;
7fd59977 1995 default:
f0ada3e8 1996 return 1;
7fd59977 1997 }
1998 }
1999 else if (narg == 5) {
f0ada3e8 2000 TopoDS_Shape Ffrom = DBRep::Get(a[3], TopAbs_SHAPE);
2001 TopoDS_Shape Funtil = DBRep::Get(a[4], TopAbs_SHAPE);
7fd59977 2002 if (Funtil.IsNull()) {
f0ada3e8 2003 return 1;
7fd59977 2004 }
2005 switch (Kas) {
2006 case 1:
f0ada3e8 2007 {
2008 if (Ffrom.IsNull()) {
2009 thePrism.PerformFromEnd(Funtil);
2010 }
2011 else {
2012 thePrism.Perform(Ffrom, Funtil);
2013 }
2014 }
2015 break;
7fd59977 2016 case 2:
f0ada3e8 2017 {
2018 if (Ffrom.IsNull()) {
2019 return 1;
2020 }
2021 theRevol.Perform(Ffrom, Funtil);
2022 }
2023 break;
7fd59977 2024 case 3:
f0ada3e8 2025 {
2026 if (Ffrom.IsNull()) {
2027 return 1;
2028 }
2029 thePipe.Perform(Ffrom, Funtil);
2030 }
2031 break;
7fd59977 2032 case 4:
f0ada3e8 2033 {
2034 if (Ffrom.IsNull()) {
2035 theDPrism.PerformFromEnd(Funtil);
2036 }
2037 else {
2038 theDPrism.Perform(Ffrom, Funtil);
2039 }
2040 }
2041 break;
7fd59977 2042
2043 default:
f0ada3e8 2044 return 1;
7fd59977 2045 }
2046 }
2047 }
2048
2049 BRepFeat_StatusError se;
2050 switch (Kas) {
2051 case 1:
2052 if (!thePrism.IsDone()) {
2053 se = thePrism.CurrentStatusError();
04232180 2054 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2055 Standard_SStream aSStream;
f0ada3e8 2056 BRepFeat::Print(se, aSStream);
7fd59977 2057 theCommands << aSStream << "\n";
2058 return 1;
2059 }
f0ada3e8 2060 DBRep::Set(a[2], thePrism);
7fd59977 2061 dout.Flush();
f0ada3e8 2062 //History
2063 if (BRepTest_Objects::IsHistoryNeeded())
2064 {
2065 anArgs.Clear();
2066 anArgs.Append(theSbase);
2067 anArgs.Append(thePbase);
2068 anArgs.Append(theSkface);
2069 BRepTest_Objects::SetHistory(anArgs, thePrism);
2070 }
7fd59977 2071 return 0;
2072 case 2:
2073 if (!theRevol.IsDone()) {
2074 se = theRevol.CurrentStatusError();
04232180 2075 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2076 Standard_SStream aSStream;
f0ada3e8 2077 BRepFeat::Print(se, aSStream);
7fd59977 2078 theCommands << aSStream << "\n";
2079 return 1;
2080 }
f0ada3e8 2081 //History
2082 if (BRepTest_Objects::IsHistoryNeeded())
2083 {
2084 anArgs.Clear();
2085 anArgs.Append(theSbase);
2086 anArgs.Append(thePbase);
2087 anArgs.Append(theSkface);
2088 BRepTest_Objects::SetHistory(anArgs, theRevol);
2089 }
2090 DBRep::Set(a[2], theRevol);
7fd59977 2091 dout.Flush();
2092 return 0;
2093 case 3:
2094 if (!thePipe.IsDone()) {
2095 se = thePipe.CurrentStatusError();
04232180 2096 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2097 Standard_SStream aSStream;
f0ada3e8 2098 BRepFeat::Print(se, aSStream);
7fd59977 2099 theCommands << aSStream << "\n";
2100 return 1;
2101 }
f0ada3e8 2102 //History
2103 if (BRepTest_Objects::IsHistoryNeeded())
2104 {
2105 anArgs.Clear();
2106 anArgs.Append(theSbase);
2107 anArgs.Append(thePbase);
2108 anArgs.Append(theSkface);
2109 BRepTest_Objects::SetHistory(anArgs, thePipe);
2110 }
2111 DBRep::Set(a[2], thePipe);
7fd59977 2112 dout.Flush();
2113 return 0;
2114 case 4:
2115 if (!theDPrism.IsDone()) {
2116 se = theDPrism.CurrentStatusError();
04232180 2117 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2118 Standard_SStream aSStream;
f0ada3e8 2119 BRepFeat::Print(se, aSStream);
7fd59977 2120 theCommands << aSStream << "\n";
2121 return 1;
2122 }
f0ada3e8 2123 //History
2124 if (BRepTest_Objects::IsHistoryNeeded())
2125 {
2126 anArgs.Clear();
2127 anArgs.Append(theSbase);
2128 anArgs.Append(thePbase);
2129 anArgs.Append(theSkface);
2130 BRepTest_Objects::SetHistory(anArgs, theDPrism);
2131 }
2132 DBRep::Set(a[2], theDPrism);
7fd59977 2133 dout.Flush();
2134 return 0;
2135 case 5:
2136 if (!theLF.IsDone()) {
2137 se = theLF.CurrentStatusError();
04232180 2138 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2139 Standard_SStream aSStream;
f0ada3e8 2140 BRepFeat::Print(se, aSStream);
7fd59977 2141 theCommands << aSStream << "\n";
2142 return 1;
2143 }
f0ada3e8 2144 DBRep::Set(a[2], theLF);
7fd59977 2145 dout.Flush();
2146 return 0;
2147 case 6:
2148 if (!theRF.IsDone()) {
2149 se = theRF.CurrentStatusError();
04232180 2150 //BRepFeat::Print(se,std::cout) << std::endl;
7fd59977 2151 Standard_SStream aSStream;
f0ada3e8 2152 BRepFeat::Print(se, aSStream);
7fd59977 2153 theCommands << aSStream << "\n";
2154 return 1;
2155 }
f0ada3e8 2156 DBRep::Set(a[2], theRF);
7fd59977 2157 dout.Flush();
2158 return 0;
2159 default:
2160 return 1;
2161 }
2162}
2163
2164
2165static Standard_Integer BOSS(Draw_Interpretor& theCommands,
f0ada3e8 2166 Standard_Integer narg, const char** a)
7fd59977 2167{
f0ada3e8 2168 if (strcasecmp(a[0], "ENDEDGES") && strcasecmp(a[0], "FILLET")
2169 && strcasecmp(a[0], "BOSSAGE")) {
7fd59977 2170 return 1;
2171 }
2172
f0ada3e8 2173 if ((!strcasecmp(a[0], "ENDEDGES") && narg != 5) ||
2174 (!strcasecmp(a[0], "FILLET") && (narg < 5 || narg % 2 != 1)) ||
2175 (!strcasecmp(a[0], "BOSSAGE") && narg != 6)) {
4f7d41ea 2176 theCommands.PrintHelp(a[0]);
7fd59977 2177 return 1;
2178 }
2179
f0ada3e8 2180 Standard_Integer Kas = 0;
2181 Standard_Integer dprsig = 0;
2182 if (!strcasecmp("ENDEDGES", a[0])) {
7fd59977 2183 Kas = 1;
91322f44 2184 dprsig = Draw::Atoi(a[4]);
7fd59977 2185 }
f0ada3e8 2186 else if (!strcasecmp("FILLET", a[0])) {
7fd59977 2187 Kas = 2;
2188 }
f0ada3e8 2189 else if (!strcasecmp("BOSSAGE", a[0])) {
7fd59977 2190 Kas = 3;
91322f44 2191 dprsig = Draw::Atoi(a[5]);
7fd59977 2192 }
f0ada3e8 2193
2194 TopoDS_Shape theShapeTop;
7fd59977 2195 TopoDS_Shape theShapeBottom;
2196
2197 if (Kas == 1 || Kas == 3) {
f0ada3e8 2198 if (!strcasecmp("DPRISM", a[1])) {
7fd59977 2199 if (!dprdef) {
f0ada3e8 2200 theCommands << "dprism not defined";
2201 return 1;
7fd59977 2202 }
2203 }
2204 else {
2205 theCommands << "unknown argument : " << a[1];
2206 return 1;
2207 }
2208
2209 theDPrism.BossEdges(dprsig);
f0ada3e8 2210
7fd59977 2211 TopTools_ListOfShape theTopEdges, theLatEdges;
2212 theTopEdges = theDPrism.TopEdges();
2213 theLatEdges = theDPrism.LatEdges();
2214
2215 TopTools_ListIteratorOfListOfShape it;
2216 BRep_Builder B;
2217
2218 B.MakeCompound(TopoDS::Compound(theShapeTop));
2219 it.Initialize(theTopEdges);
f0ada3e8 2220 for (; it.More(); it.Next()) {
7fd59977 2221 TopExp_Explorer exp;
f0ada3e8 2222 for (exp.Init(it.Value(), TopAbs_EDGE); exp.More(); exp.Next()) {
2223 B.Add(theShapeTop, exp.Current());
7fd59977 2224 }
2225 }
f0ada3e8 2226 DBRep::Set(a[2], theShapeTop);
7fd59977 2227 dout.Flush();
2228
2229 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2230 it.Initialize(theLatEdges);
f0ada3e8 2231 for (; it.More(); it.Next()) {
2232 B.Add(theShapeBottom, it.Value());
7fd59977 2233 }
f0ada3e8 2234 DBRep::Set(a[3], theShapeBottom);
7fd59977 2235 dout.Flush();
2236 if (Kas == 1) return 0;
2237 }
2238
2239 if (Kas == 2 || Kas == 3) {
f0ada3e8 2240
2241 // Standard_Integer nrad;
7fd59977 2242 TopoDS_Shape V;
2243 if (Kas == 2) {
f0ada3e8 2244 V = DBRep::Get(a[2], TopAbs_SHAPE);
7fd59977 2245 }
2246 else if (Kas == 3) {
2247 V = theDPrism;
2248 }
2249
f0ada3e8 2250 if (V.IsNull()) return 1;
7fd59977 2251 ChFi3d_FilletShape FSh = ChFi3d_Rational;
4f7d41ea 2252 if (Rakk)
2253 delete Rakk;
f0ada3e8 2254 Rakk = new BRepFilletAPI_MakeFillet(V, FSh);
2255 Rakk->SetParams(ta, t3d, t2d, t3d, t2d, fl);
7fd59977 2256 Rakk->SetContinuity(blend_cont, tapp_angle);
2257 Standard_Real Rad;
2258 TopoDS_Shape S;
2259 TopoDS_Edge E;
2260 Standard_Integer nbedge = 0;
2261
2262 if (Kas == 2) {
f0ada3e8 2263 for (Standard_Integer ii = 1; ii < (narg - 1) / 2; ii++) {
2264 Rad = Draw::Atof(a[2 * ii + 1]);
2265 if (Rad == 0.) continue;
2266 S = DBRep::Get(a[(2 * ii + 2)], TopAbs_SHAPE);
2267 TopExp_Explorer exp;
2268 for (exp.Init(S, TopAbs_EDGE); exp.More(); exp.Next()) {
2269 E = TopoDS::Edge(exp.Current());
2270 if (!E.IsNull()) {
2271 Rakk->Add(Rad, E);
2272 nbedge++;
2273 }
2274 }
7fd59977 2275 }
2276 }
2277 else if (Kas == 3) {
91322f44 2278 Rad = Draw::Atof(a[3]);
7fd59977 2279 if (Rad != 0.) {
f0ada3e8 2280 S = theShapeTop;
2281 TopExp_Explorer exp;
2282 for (exp.Init(S, TopAbs_EDGE); exp.More(); exp.Next()) {
2283 E = TopoDS::Edge(exp.Current());
2284 if (!E.IsNull()) {
2285 Rakk->Add(Rad, E);
2286 nbedge++;
2287 }
2288 }
7fd59977 2289 }
91322f44 2290 Rad = Draw::Atof(a[4]);
7fd59977 2291 if (Rad != 0.) {
f0ada3e8 2292 S = theShapeBottom;
2293 TopExp_Explorer exp;
2294 for (exp.Init(S, TopAbs_EDGE); exp.More(); exp.Next()) {
2295 E = TopoDS::Edge(exp.Current());
2296 if (!E.IsNull()) {
2297 Rakk->Add(Rad, E);
2298 nbedge++;
2299 }
2300 }
2301 }
2302 }
2303
2304 if (!nbedge) return 1;
7fd59977 2305 Rakk->Build();
f0ada3e8 2306 if (!Rakk->IsDone()) return 1;
7fd59977 2307 TopoDS_Shape res = Rakk->Shape();
2308
2309 if (Kas == 2) {
f0ada3e8 2310 DBRep::Set(a[1], res);
2311 }
7fd59977 2312 else if (Kas == 3) {
f0ada3e8 2313 DBRep::Set(a[2], res);
7fd59977 2314 }
2315 dout.Flush();
4f7d41ea 2316
2317 // Save history for fillet
948fe6ca 2318 if (BRepTest_Objects::IsHistoryNeeded())
2319 {
2320 TopTools_ListOfShape anArg;
2321 anArg.Append(V);
2322 BRepTest_Objects::SetHistory(anArg, *Rakk);
2323 }
4f7d41ea 2324
7fd59977 2325 return 0;
2326 }
2327
2328 return 1;
2329}
2330
8013367c 2331//=============================================================================
2332//function : ComputeSimpleOffset
2333//purpose : Computes simple offset.
2334//=============================================================================
2335static Standard_Integer ComputeSimpleOffset(Draw_Interpretor& theCommands,
f0ada3e8 2336 Standard_Integer narg,
2337 const char** a)
8013367c 2338{
8574e329 2339 if (narg < 4)
8013367c 2340 {
8574e329 2341 theCommands << "offsetshapesimple result shape offsetvalue [solid] [tolerance=1e-7]\n";
8013367c 2342 return 1;
2343 }
2344
2345 // Input data.
2346 TopoDS_Shape aShape = DBRep::Get(a[2]);
2347 if (aShape.IsNull())
2348 {
2349 theCommands << "Input shape is null";
2350 return 0;
2351 }
2352 const Standard_Real anOffsetValue = Draw::Atof(a[3]);
2353 if (Abs(anOffsetValue) < gp::Resolution())
2354 {
2355 theCommands << "Null offset value";
2356 return 0;
2357 }
2358
f0ada3e8 2359 Standard_Boolean makeSolid = (narg > 4 && !strcasecmp(a[4], "solid"));
8574e329 2360 int iTolArg = (makeSolid ? 5 : 4);
2361 Standard_Real aTol = (narg > iTolArg ? Draw::Atof(a[iTolArg]) : Precision::Confusion());
8013367c 2362
8574e329 2363 BRepOffset_MakeSimpleOffset aMaker(aShape, anOffsetValue);
f0ada3e8 2364 aMaker.SetTolerance(aTol);
8574e329 2365 aMaker.SetBuildSolidFlag(makeSolid);
8013367c 2366 aMaker.Perform();
2367
2368 if (!aMaker.IsDone())
2369 {
2370 theCommands << "ERROR:" << aMaker.GetErrorMessage() << "\n";
2371 return 0;
2372 }
2373
2374 DBRep::Set(a[1], aMaker.GetResultShape());
2375
2376 return 0;
2377}
7fd59977 2378
2379//=======================================================================
2380//function : FeatureCommands
2381//purpose :
2382//=======================================================================
2383
f0ada3e8 2384void BRepTest::FeatureCommands(Draw_Interpretor& theCommands)
7fd59977 2385{
2386 static Standard_Boolean done = Standard_False;
2387 if (done) return;
2388 done = Standard_True;
2389
2390 DBRep::BasicCommands(theCommands);
2391
2392 const char* g = "TOPOLOGY Feature commands";
2393
f0ada3e8 2394 theCommands.Add("localope",
2395 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2396 __FILE__, Loc, g);
7fd59977 2397
2398 theCommands.Add("hole",
f0ada3e8 2399 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2400 __FILE__, HOLE1, g);
7fd59977 2401
2402 theCommands.Add("firsthole",
f0ada3e8 2403 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2404 __FILE__, HOLE2, g);
7fd59977 2405
2406 theCommands.Add("holend",
f0ada3e8 2407 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2408 __FILE__, HOLE3, g);
7fd59977 2409
f0ada3e8 2410 theCommands.Add("blindhole",
2411 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2412 __FILE__, HOLE4, g);
7fd59977 2413
2414 theCommands.Add("holecontrol",
f0ada3e8 2415 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2416 __FILE__, CONTROL, g);
7fd59977 2417
2418 theCommands.Add("wprism",
f0ada3e8 2419 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2420 __FILE__, PRW, g);
7fd59977 2421
2422
f0ada3e8 2423 theCommands.Add("fprism",
2424 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2425 __FILE__, PRF, g);
7fd59977 2426
2427
2428 theCommands.Add("wrotate",
f0ada3e8 2429 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2430 __FILE__, ROW, g);
7fd59977 2431
2432
f0ada3e8 2433 theCommands.Add("frotate",
2434 "Rotates a set of faces of a shape : frotate f[use]/c[ut] result shape Angle/[FaceFrom] FaceUntil OX OY OZ DX DY DZ face1 [face2...]",
2435 __FILE__, ROF, g);
7fd59977 2436
2437
2438 theCommands.Add("splitshape",
b94d4858 2439 "splitshape result shape [splitedges] [face wire/edge/compound [wire/edge/compound ...][face wire/edge/compound [wire/edge/compound...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2440 __FILE__, SPLS, g);
7fd59977 2441
2442
2443 theCommands.Add("thickshell",
f0ada3e8 2444 "thickshell r shape offset [jointype [tol] ]",
2445 __FILE__, thickshell, g);
2446
7fd59977 2447 theCommands.Add("offsetshape",
f0ada3e8 2448 "offsetshape r shape offset [tol] [face ...]",
2449 __FILE__, offsetshape, g);
2450
7fd59977 2451 theCommands.Add("offsetcompshape",
f0ada3e8 2452 "offsetcompshape r shape offset [face ...]",
2453 __FILE__, offsetshape, g);
7fd59977 2454
2455 theCommands.Add("offsetparameter",
f0ada3e8 2456 "offsetparameter Tol Inter(c/p) JoinType(a/i/t) [RemoveInternalEdges(r/k)]",
2457 __FILE__, offsetparameter);
7fd59977 2458
2459 theCommands.Add("offsetload",
f0ada3e8 2460 "offsetload shape offset bouchon1 bouchon2 ...",
2461 __FILE__, offsetload, g);
7fd59977 2462
2463 theCommands.Add("offsetonface",
f0ada3e8 2464 "offsetonface face1 offset1 face2 offset2 ...",
2465 __FILE__, offsetonface, g);
7fd59977 2466
2467 theCommands.Add("offsetperform",
f0ada3e8 2468 "offsetperform result",
2469 __FILE__, offsetperform, g);
7fd59977 2470
f0ada3e8 2471 theCommands.Add("glue",
2472 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2473 __FILE__, GLU, g);
7fd59977 2474
2475
f0ada3e8 2476 theCommands.Add("featprism",
2477 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2478 __FILE__, DEFIN);
7fd59977 2479
f0ada3e8 2480 theCommands.Add("featrevol",
2481 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2482 __FILE__, DEFIN);
7fd59977 2483
f0ada3e8 2484 theCommands.Add("featpipe",
2485 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2486 __FILE__, DEFIN);
7fd59977 2487
f0ada3e8 2488 theCommands.Add("featdprism",
2489 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2490 __FILE__, DEFIN);
7fd59977 2491
f0ada3e8 2492 theCommands.Add("featlf",
2493 "Defines the arguments for a linear rib or slot : featlf shape wire plane DirX DirY DirZ DirX DirY DirZ Fuse(0/1/2) Modify(0/1)",
2494 __FILE__, DEFIN);
7fd59977 2495
f0ada3e8 2496 theCommands.Add("featrf",
2497 "Defines the arguments for a rib or slot of revolution : featrf shape wire plane X Y Z DirX DirY DirZ Size Size Fuse(0/1/2) Modify(0/1)",
2498 __FILE__, DEFIN);
7fd59977 2499
f0ada3e8 2500 theCommands.Add("addslide",
2501 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2502 __FILE__, ADD);
7fd59977 2503
f0ada3e8 2504 theCommands.Add("featperform",
2505 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2506 __FILE__, PERF);
7fd59977 2507
f0ada3e8 2508 theCommands.Add("featperformval",
2509 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2510 __FILE__, PERF);
7fd59977 2511
f0ada3e8 2512 theCommands.Add("endedges",
2513 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2514 __FILE__, BOSS);
7fd59977 2515
f0ada3e8 2516 theCommands.Add("fillet",
2517 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2518 __FILE__, BOSS);
7fd59977 2519
f0ada3e8 2520 theCommands.Add("bossage",
2521 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",
2522 __FILE__, BOSS);
7fd59977 2523
f0ada3e8 2524 theCommands.Add("offsetshapesimple",
2525 "offsetshapesimple result shape offsetvalue [solid] [tolerance=1e-7]",
2526 __FILE__, ComputeSimpleOffset);
7fd59977 2527}