0023024: Update headers of OCCT files
[occt.git] / src / BRepFeat / BRepFeat_MakePrism.cxx
CommitLineData
b311480e 1// Created on: 1996-02-13
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <BRepFeat_MakePrism.ixx>
24
25#include <BRepFeat.hxx>
26#include <LocOpe.hxx>
27#include <LocOpe_Prism.hxx>
28#include <LocOpe_CSIntersector.hxx>
29#include <LocOpe_PntFace.hxx>
30
31#include <gp_Vec.hxx>
32#include <gp_Pnt.hxx>
33#include <gp_Ax1.hxx>
34#include <gp_Pnt2d.hxx>
35#include <Geom_Curve.hxx>
36#include <Geom_Line.hxx>
37#include <Geom_RectangularTrimmedSurface.hxx>
38#include <Geom_Surface.hxx>
39
40#include <BRepLib_MakeFace.hxx>
41
42#include <TColgp_SequenceOfPnt.hxx>
43#include <TColGeom_SequenceOfCurve.hxx>
44#include <Bnd_Box.hxx>
45
46#include <BRep_Tool.hxx>
47
48#include <BRepTools.hxx>
49
50
51#include <TopExp_Explorer.hxx>
52#include <TopTools_MapOfShape.hxx>
53#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
54#include <TopTools_ListIteratorOfListOfShape.hxx>
55#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
56#include <TopTools_ListIteratorOfListOfShape.hxx>
57#include <TopTools_ListOfShape.hxx>
58
59#include <BRepBuilderAPI.hxx>
60#include <BRepPrimAPI_MakeBox.hxx>
61
62//modified by NIZNHY-PKV Thu Mar 21 18:14:23 2002 f
63//#include <BRepAlgo_Cut.hxx>
64//#include <BRepAlgo_Fuse.hxx>
65#include <BRepAlgoAPI_Cut.hxx>
66#include <BRepAlgoAPI_Fuse.hxx>
67//modified by NIZNHY-PKV Thu Mar 21 18:14:26 2002 t
68
69#include <Standard_ConstructionError.hxx>
70#include <TopoDS.hxx>
71
72
73#include <TopoDS_Face.hxx>
74#include <TopoDS_Solid.hxx>
75#include <TopoDS_Compound.hxx>
76
77#include <TopExp.hxx>
78#include <BRepBndLib.hxx>
79
80#include <Precision.hxx>
81#include <gp_Pln.hxx>
82#include <Geom_Plane.hxx>
83
84#ifdef DEB
85Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
86#endif
87
88static void MajMap(const TopoDS_Shape&, // base
89 const LocOpe_Prism&,
90 TopTools_DataMapOfShapeListOfShape&, // myMap
91 TopoDS_Shape&, // myFShape
92 TopoDS_Shape&); // myLShape
93
94static Standard_Boolean ToFuse(const TopoDS_Face& ,
95 const TopoDS_Face&);
96
97
98static void SetGluedFaces(const TopoDS_Face& theSkface,
99 const TopoDS_Shape& theSbase,
100 const TopoDS_Shape& thePbase,
101 const TopTools_DataMapOfShapeListOfShape& theSlmap,
102 LocOpe_Prism&,
103 TopTools_DataMapOfShapeShape&);
104
105#ifdef DEB
106static void VerifGluedFaces(const TopoDS_Face& theSkface,
107 const TopoDS_Shape& thePbase,
108 Handle(Geom_Curve)& theBCurve,
109 TColGeom_SequenceOfCurve& theCurves,
110 LocOpe_Prism& thePrism,
111 TopTools_DataMapOfShapeShape& theMap);
112#endif
113
114static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
115 const TopoDS_Face& theSkface,
116 const TopoDS_Shape& theSFrom,
117 const TopoDS_Shape& theSUntil);
118
119static Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
120 const TopoDS_Shape& Until);
121
122static Handle(Geom_Curve) TestCurve(const TopoDS_Shape&,
123 const gp_Vec&);
124
125
126//=======================================================================
127//function : Init
128//purpose :
129//=======================================================================
130
131void BRepFeat_MakePrism::Init(const TopoDS_Shape& Sbase,
132 const TopoDS_Shape& Pbase,
133 const TopoDS_Face& Skface,
134 const gp_Dir& Direc,
135 const Standard_Integer Mode,
136 const Standard_Boolean Modify)
137{
138#ifdef DEB
139 Standard_Boolean trc = BRepFeat_GettraceFEAT();
140 if (trc) cout << "BRepFeat_MakePrism::Init" << endl;
141#endif
142 mySkface = Skface;
143 SketchFaceValid();
144 mySbase = Sbase;
145 BasisShapeValid();
146 myPbase = Pbase;
147 mySlface.Clear();
148 myDir = Direc;
149 if(Mode == 0) {
150 myFuse = Standard_False;
151 myJustFeat = Standard_False;
152 }
153 else if(Mode == 1) {
154 myFuse = Standard_True;
155 myJustFeat = Standard_False;
156 }
157 else if(Mode == 2) {
158 myFuse = Standard_True;
159 myJustFeat = Standard_True;
160 }
161 else {
162 }
163 myModify = Modify;
164 myJustGluer = Standard_False;
165
166
167 //-------------- ifv
168 //mySkface.Nullify();
169 //-------------- ifv
170
171
172 myShape.Nullify();
173 myNewEdges.Clear();
174 myTgtEdges.Clear();
175 myMap.Clear();
176 myFShape.Nullify();
177 myLShape.Nullify();
178 TopExp_Explorer exp;
179 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
180 TopTools_ListOfShape thelist;
181 myMap.Bind(exp.Current(), thelist);
182 myMap(exp.Current()).Append(exp.Current());
183 }
184#ifdef DEB
185 if (trc) {
186 if (myJustFeat) cout << " Just Feature" << endl;
187 if (myFuse) cout << " Fuse" << endl;
188 if (!myFuse) cout << " Cut" << endl;
189 if (!myModify) cout << " Modify = 0" << endl;
190 }
191#endif
192}
193
194
195//=======================================================================
196//function : Add
0d969553 197//purpose : add elements of sliding (edge on face)
7fd59977 198//=======================================================================
199
200void BRepFeat_MakePrism::Add(const TopoDS_Edge& E,
201 const TopoDS_Face& F)
202{
203#ifdef DEB
204 Standard_Boolean trc = BRepFeat_GettraceFEAT();
205 if (trc) cout << "BRepFeat_MakePrism::Add(Edge,face)" << endl;
206#endif
207 TopExp_Explorer exp;
208 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
209 if (exp.Current().IsSame(F)) {
210 break;
211 }
212 }
213 if (!exp.More()) {
214 Standard_ConstructionError::Raise();
215 }
216
217 for (exp.Init(myPbase,TopAbs_EDGE);exp.More();exp.Next()) {
218 if (exp.Current().IsSame(E)) {
219 break;
220 }
221 }
222 if (!exp.More()) {
223 Standard_ConstructionError::Raise();
224 }
225
226 if (!mySlface.IsBound(F)) {
227 TopTools_ListOfShape thelist1;
228 mySlface.Bind(F, thelist1);
229 }
230 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
231 for (; itl.More();itl.Next()) {
232 if (itl.Value().IsSame(E)) {
233 break;
234 }
235 }
236 if (!itl.More()) {
237 mySlface(F).Append(E);
238 }
239}
240
241
242//=======================================================================
243//function : Perform
0d969553
Y
244//purpose : construction of prism of length Length and
245// call of reconstruction topo
7fd59977 246//=======================================================================
247
248void BRepFeat_MakePrism::Perform(const Standard_Real Length)
249{
250#ifdef DEB
251 Standard_Boolean trc = BRepFeat_GettraceFEAT();
252 if (trc) cout << "BRepFeat_MakePrism::Perform(Length)" << endl;
253#endif
254 mySFrom.Nullify();
255 ShapeFromValid();
256 mySUntil.Nullify();
257 ShapeUntilValid();
258 myGluedF.Clear();
259 myPerfSelection = BRepFeat_NoSelection;
260 PerfSelectionValid();
261 gp_Vec V(Length*myDir);
262
0d969553 263//construction of prism of height Length
7fd59977 264
265 LocOpe_Prism thePrism(myPbase,V);
266 TopoDS_Shape VraiPrism = thePrism.Shape();
267
0d969553 268// management of descendants
7fd59977 269 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
270
271
0d969553 272 myGShape = VraiPrism; // the primitive
7fd59977 273 GeneratedShapeValid();
274
275 TopoDS_Face FFace;
276
277 Standard_Boolean found = Standard_False;
278
0d969553
Y
279// try to detect the faces of gluing
280// in case if the top of the prism is tangent to the initial shape
7fd59977 281
282 if(!mySkface.IsNull() || !mySlface.IsEmpty()) {
283 if(myLShape.ShapeType() == TopAbs_WIRE) {
284 TopExp_Explorer ex1(VraiPrism, TopAbs_FACE);
285 for(; ex1.More(); ex1.Next()) {
286 TopExp_Explorer ex2(ex1.Current(), TopAbs_WIRE);
287 for(; ex2.More(); ex2.Next()) {
288 if(ex2.Current().IsSame(myLShape)) {
289 FFace = TopoDS::Face(ex1.Current());
290 found = Standard_True;
291 break;
292 }
293 }
294 if(found) break;
295 }
296 }
297
298 TopExp_Explorer exp(mySbase, TopAbs_FACE);
299 for(; exp.More(); exp.Next()) {
300 const TopoDS_Face& ff = TopoDS::Face(exp.Current());
301 if(ToFuse(ff, FFace)) {
302 TopTools_DataMapOfShapeListOfShape sl;
303 if(!FFace.IsSame(myPbase) && BRepFeat::IsInside(ff, FFace))
304// SetGluedFaces(ff, mySbase, FFace, sl, thePrism, myGluedF);
305 break;
306 }
307 }
308 }
309
0d969553 310// management of faces of gluing given by the user
7fd59977 311
312// SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
313 GluedFacesValid();
314// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
315
0d969553 316 if(!myGluedF.IsEmpty()) { // case gluing
7fd59977 317 myJustGluer = Standard_True;
318 thePrism.Curves(myCurves);
319 myBCurve = thePrism.BarycCurve();
0d969553 320 GlobalPerform(); // topological reconstruction
7fd59977 321 }
322
0d969553 323// if there is no gluing -> call of ope topo
7fd59977 324 if(!myJustGluer) {
325 if(myFuse == 1 && !myJustFeat) {
326 //modified by NIZNHY-PKV Thu Mar 21 17:55:30 2002 f
327 //BRepAlgo_Fuse f(mySbase, myGShape);
328 //myShape = f.Shape();
329 //UpdateDescendants(f.Builder(), myShape, Standard_False);
330 BRepAlgoAPI_Fuse f(mySbase, myGShape);
331 myShape = f.Shape();
332 UpdateDescendants(f, myShape, Standard_False);
333 //modified by NIZNHY-PKV Thu Mar 21 17:55:34 2002 t
334 Done();
335 }
336 else if(myFuse == 0) {
337 //modified by NIZNHY-PKV Thu Mar 21 17:55:59 2002 f
338 //BRepAlgo_Cut c(mySbase, myGShape);
339 //myShape = c.Shape();
340 //UpdateDescendants(c.Builder(), myShape, Standard_False);
341 BRepAlgoAPI_Cut c(mySbase, myGShape);
342 myShape = c.Shape();
343 UpdateDescendants(c, myShape, Standard_False);
344 //modified by NIZNHY-PKV Thu Mar 21 17:56:02 2002 t
345 Done();
346 }
347 else {
348 myShape = myGShape;
349 Done();
350 }
351 }
352}
353
354
355//=======================================================================
356//function : Perform
0d969553
Y
357//purpose : construction of prism oriented at the face Until, sufficiently
358// long; call of topological reconstruction
7fd59977 359//=======================================================================
360
361void BRepFeat_MakePrism::Perform(const TopoDS_Shape& Until)
362{
363#ifdef DEB
364 Standard_Boolean trc = BRepFeat_GettraceFEAT();
365 if (trc) cout << "BRepFeat_MakePrism::Perform(Until)" << endl;
366#endif
367 if (Until.IsNull()) {
368 Standard_ConstructionError::Raise();
369 }
370 TopExp_Explorer exp(Until, TopAbs_FACE);
371 if (!exp.More()) {
372 Standard_ConstructionError::Raise();
373 }
374 myGluedF.Clear();
375 myPerfSelection = BRepFeat_SelectionU;
376 PerfSelectionValid();
377 mySFrom.Nullify();
378 ShapeFromValid();
379 mySUntil = Until;
380 Standard_Boolean Trf = TransformShapeFU(1);
381 ShapeUntilValid();
382 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
383 Standard_Integer sens = SensOfPrism(C, mySUntil);
384 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
385 gp_Vec V(2*sens*Height*myDir);
386
0d969553 387// construction of long prism
7fd59977 388 LocOpe_Prism thePrism(myPbase,V);
389 TopoDS_Shape VraiPrism = thePrism.Shape();
390
0d969553 391// in case of support of face Until
7fd59977 392 if(!Trf) {
393 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
394 myGShape = VraiPrism;
395 GeneratedShapeValid();
396
397 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
398 GluedFacesValid();
399// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
400
401 thePrism.Curves(myCurves);
402 myBCurve = thePrism.BarycCurve();
403 GlobalPerform();
404 }
0d969553 405 else { // until support -> passage to topological operations
7fd59977 406 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
407 TColGeom_SequenceOfCurve scur;
408 scur.Clear();
409 scur.Append(C);
410
0d969553 411// direction of the prism depending on Until
7fd59977 412
413 LocOpe_CSIntersector ASI(mySUntil);
414 ASI.Perform(scur);
415 TopAbs_Orientation Or;
416 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
417 if (myFuse == 1) {
418 Or = ASI.Point(1,1).Orientation();
419 }
420 else {
421 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
422 }
423 if(sens==-1) Or=TopAbs::Reverse(Or);
424 TopoDS_Face FUntil = ASI.Point(1,1).Face();
425 TopoDS_Shape Comp;
426 BRep_Builder B;
427 B.MakeCompound(TopoDS::Compound(Comp));
428 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
429 if (!S.IsNull()) B.Add(Comp,S);
430 //modified by NIZNHY-PKV Thu Mar 21 17:56:31 2002 f
431 //BRepAlgo_Cut trP(VraiPrism,Comp);
432 //UpdateDescendants(trP.Builder(),trP.Shape(), Standard_False);
433 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
434 UpdateDescendants(trP, trP.Shape(), Standard_False);
435 //modified by NIZNHY-PKV Thu Mar 21 17:56:38 2002 t
436 TopExp_Explorer ex(trP.Shape(), TopAbs_SOLID);
437 TopoDS_Shape Cutsh = ex.Current();
438 if(myFuse == 1 && !myJustFeat) {
439 //modified by NIZNHY-PKV Thu Mar 21 17:57:49 2002 f
440 //BRepAlgo_Fuse f(mySbase, Cutsh);
441 //myShape = f.Shape();
442 //UpdateDescendants(f.Builder(), myShape, Standard_False);
443 BRepAlgoAPI_Fuse f(mySbase, Cutsh);
444 myShape = f.Shape();
445 UpdateDescendants(f, myShape, Standard_False);
446 //modified by NIZNHY-PKV Thu Mar 21 17:57:53 2002 t
447 Done();
448 }
449 else if(myFuse == 0) {
450 //modified by NIZNHY-PKV Thu Mar 21 17:59:33 2002 f
451 //BRepAlgo_Cut c(mySbase, Cutsh);
452 //myShape = c.Shape();
453 //UpdateDescendants(c.Builder(), myShape, Standard_False);
454 BRepAlgoAPI_Cut c(mySbase, Cutsh);
455 myShape = c.Shape();
456 UpdateDescendants(c, myShape, Standard_False);
457 //modified by NIZNHY-PKV Thu Mar 21 17:59:43 2002 t
458 Done();
459 }
460 else {
461 myShape = Cutsh;
462 Done();
463 }
464 }
465 }
0d969553 466/* // loop of control of descendance
7fd59977 467
468 TopExp_Explorer expr(mySbase, TopAbs_FACE);
469 char nom1[20], nom2[20];
470 Standard_Integer ii = 0;
471 for(; expr.More(); expr.Next()) {
472 ii++;
473 sprintf(nom1, "faceinitial_%d", ii);
474 DBRep::Set(nom1, expr.Current());
475 Standard_Integer jj = 0;
476 const TopTools_ListOfShape& list = Modified(expr.Current());
477 TopTools_ListIteratorOfListOfShape ite(list);
478 for(; ite.More(); ite.Next()) {
479 jj++;
480 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
481 DBRep::Set(nom2, ite.Value());
482 }
483 }
484
485 expr.Init(myPbase, TopAbs_EDGE);
486 ii=0;
487 for(; expr.More(); expr.Next()) {
488 ii++;
489 sprintf(nom1, "edgeinitial_%d", ii);
490 DBRep::Set(nom1, expr.Current());
491 Standard_Integer jj = 0;
492 const TopTools_ListOfShape& list = Generated(expr.Current());
493 TopTools_ListIteratorOfListOfShape ite(list);
494 for(; ite.More(); ite.Next()) {
495 jj++;
496 sprintf(nom2, "facegeneree_%d_%d", ii, jj);
497 DBRep::Set(nom2, ite.Value());
498 }
499 }
500*/
501}
502
503
504//=======================================================================
505//function : Perform
0d969553
Y
506//purpose : construction of a sufficiently long and properly oriented prism
507// call of topological reconstruction
7fd59977 508//=======================================================================
509
510void BRepFeat_MakePrism::Perform(const TopoDS_Shape& From,
511 const TopoDS_Shape& Until)
512{
513#ifdef DEB
514 Standard_Boolean trc = BRepFeat_GettraceFEAT();
515 if (trc) cout << "BRepFeat_MakePrism::Perform(From,Until)" << endl;
516#endif
517 if (From.IsNull() || Until.IsNull()) {
518 Standard_ConstructionError::Raise();
519 }
520
521 if (!mySkface.IsNull()) {
522 if (From.IsSame(mySkface)) {
523 myJustGluer = Standard_True;
524 Perform(Until);
525 if (myJustGluer) return;
526 }
527 else if (Until.IsSame(mySkface)) {
528 myJustGluer = Standard_True;
529 Perform(From);
530 if (myJustGluer) return;
531 }
532 }
533
534 myGluedF.Clear();
535 myPerfSelection = BRepFeat_SelectionFU;
536 PerfSelectionValid();
537
538 TopExp_Explorer exp(From, TopAbs_FACE);
539 if (!exp.More()) {
540 Standard_ConstructionError::Raise();
541 }
542 exp.Init(Until, TopAbs_FACE);
543 if (!exp.More()) {
544 Standard_ConstructionError::Raise();
545 }
546 mySFrom = From;
547 Standard_Boolean Trff = TransformShapeFU(0);
548 ShapeFromValid();
549 mySUntil = Until;
550 Standard_Boolean Trfu = TransformShapeFU(1);
551 ShapeUntilValid();
552 if(Trfu != Trff) {
553 NotDone();
554 myStatusError = BRepFeat_IncTypes;
555 return;
556 }
557
0d969553 558// length depending on bounding boxes
7fd59977 559
560 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
561 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
0d969553
Y
562 Standard_Integer sens; // direction of prism
563 Standard_Integer tran; // transfer of prism
7fd59977 564 if(From.IsSame(Until)) {
565 sens = 1;
566 tran = -1;
567 }
568 else {
569 sens = SensOfPrism(C, mySUntil);
570 tran = sens*SensOfPrism(C, mySFrom);
571 }
572 LocOpe_Prism thePrism;
573 if(tran < 0) {
574 gp_Vec Vtra(-3*Height*sens/2.*myDir);
575 thePrism.Perform(myPbase,3*sens*Height*myDir,Vtra);
576 }
577 else {
578 thePrism.Perform(myPbase,2*sens*Height*myDir);
579 }
580 TopoDS_Shape VraiPrism = thePrism.Shape();
581
582 if(!Trff) {
583 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
584
585 myGShape = VraiPrism;
586 GeneratedShapeValid();
587
588 //SetGluedFaces(TopoDS_Face(), // on ne veut pas binder mySkface
589 // mySbase, myPbase, mySlface, thePrism, myGluedF);
590 GluedFacesValid();
591//// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
592
593 thePrism.Curves(myCurves);
594 myBCurve = thePrism.BarycCurve();
595 GlobalPerform();
596 }
0d969553 597 else { // case until support -> topological operation
7fd59977 598 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
599 TColGeom_SequenceOfCurve scur;
600 scur.Clear();
601 scur.Append(C);
602 LocOpe_CSIntersector ASI1(mySUntil);
603 LocOpe_CSIntersector ASI2(mySFrom);
604 ASI1.Perform(scur);
605 ASI2.Perform(scur);
606 TopAbs_Orientation OrU, OrF;
607 TopoDS_Face FFrom, FUntil;
608 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
609 if (myFuse == 1) {
610 OrU = ASI1.Point(1,1).Orientation();
611 }
612 else {
613 OrU = ASI1.Point(1,ASI1.NbPoints(1)).Orientation();
614 }
615 if(sens==-1) OrU = TopAbs::Reverse(OrU);
616 FUntil = ASI1.Point(1,1).Face();
617 }
618 else {
619 NotDone();
620 myStatusError = BRepFeat_NoIntersectU;
621 return;
622 }
623 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
624 OrF = ASI2.Point(1,1).Orientation();
625 if(sens==1) OrF = TopAbs::Reverse(OrF);
626 FFrom = ASI2.Point(1,1).Face();
627 }
628 else {
629 NotDone();
630 myStatusError = BRepFeat_NoIntersectF;
631 return;
632 }
633 TopoDS_Shape Comp;
634 BRep_Builder B;
635 B.MakeCompound(TopoDS::Compound(Comp));
636 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, OrU);
637 if (!S.IsNull()) {
638 B.Add(Comp,S);
639 }
640 else {
641 NotDone();
642 myStatusError = BRepFeat_NullToolU;
643 return;
644 }
645 TopoDS_Solid SS = BRepFeat::Tool(mySFrom, FFrom, OrF);
646 if (!SS.IsNull()) {
647 B.Add(Comp,SS);
648 }
649 else {
650 NotDone();
651 myStatusError = BRepFeat_NullToolF;
652 return;
653 }
654 //modified by NIZNHY-PKV Thu Mar 21 18:00:10 2002 f
655 //BRepAlgo_Cut trP(VraiPrism,Comp);
656 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
657 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
658 UpdateDescendants(trP, trP.Shape(), Standard_False);
659 //modified by NIZNHY-PKV Thu Mar 21 18:00:16 2002 t
660 if(myFuse == 1 && !myJustFeat) {
661 //modified by NIZNHY-PKV Thu Mar 21 18:00:35 2002 f
662 //BRepAlgo_Fuse f(mySbase, trP.Shape());
663 //myShape = f.Shape();
664 //UpdateDescendants(f.Builder(), myShape, Standard_False);
665 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
666 myShape = f.Shape();
667 UpdateDescendants(f, myShape, Standard_False);
668 //modified by NIZNHY-PKV Thu Mar 21 18:00:40 2002 t
669 Done();
670 }
671 else if(myFuse == 0) {
672 //modified by NIZNHY-PKV Thu Mar 21 18:01:01 2002 f
673 //BRepAlgo_Cut c(mySbase, trP.Shape());
674 //myShape = c.Shape();
675 //UpdateDescendants(c.Builder(), myShape, Standard_False);
676 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
677 myShape = c.Shape();
678 UpdateDescendants(c, myShape, Standard_False);
679 //modified by NIZNHY-PKV Thu Mar 21 18:01:13 2002 t
680 Done();
681 }
682 else {
683 myShape = trP.Shape();
684 Done();
685 }
686 }
0d969553 687// control history
7fd59977 688/*
689 TopExp_Explorer expr(mySbase, TopAbs_FACE);
690 char nom1[20], nom2[20];
691 Standard_Integer ii = 0;
692 for(; expr.More(); expr.Next()) {
693 ii++;
694 sprintf(nom1, "faceinitial_%d", ii);
695 DBRep::Set(nom1, expr.Current());
696 Standard_Integer jj = 0;
697 const TopTools_ListOfShape& list = Modified(expr.Current());
698 TopTools_ListIteratorOfListOfShape ite(list);
699 for(; ite.More(); ite.Next()) {
700 jj++;
701 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
702 DBRep::Set(nom2, ite.Value());
703 }
704 }
705
706 expr.Init(myPbase, TopAbs_EDGE);
707 ii=0;
708 for(; expr.More(); expr.Next()) {
709 ii++;
710 sprintf(nom1, "edgeinitial_%d", ii);
711 DBRep::Set(nom1, expr.Current());
712 Standard_Integer jj = 0;
713 const TopTools_ListOfShape& list = Generated(expr.Current());
714 TopTools_ListIteratorOfListOfShape ite(list);
715 for(; ite.More(); ite.Next()) {
716 jj++;
717 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
718 DBRep::Set(nom2, ite.Value());
719 }
720 }
721*/
722}
723
724
725
726//=======================================================================
727//function : PerformUntilEnd
0d969553 728//purpose : construction of a prism and reconstruction
7fd59977 729//=======================================================================
730
731void BRepFeat_MakePrism::PerformUntilEnd()
732{
733#ifdef DEB
734 Standard_Boolean trc = BRepFeat_GettraceFEAT();
735 if (trc) cout << "BRepFeat_MakePrism::PerformUntilEnd()" << endl;
736#endif
737 myPerfSelection = BRepFeat_SelectionSh;
738 PerfSelectionValid();
739 myGluedF.Clear();
740 mySUntil.Nullify();
741 ShapeUntilValid();
742 mySFrom.Nullify();
743 ShapeFromValid();
744 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
745 gp_Vec V(2*Height*myDir);
746
747 LocOpe_Prism thePrism(myPbase,V);
748 TopoDS_Shape VraiPrism = thePrism.Shape();
749
750 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
751
752 myGShape = VraiPrism;
753 GeneratedShapeValid();
754 GluedFacesValid();
755
756 if(myFuse == 0) {
757 //modified by NIZNHY-PKV Thu Mar 21 18:02:46 2002 f
758 //BRepAlgo_Cut c(mySbase, myGShape);
759 BRepAlgoAPI_Cut c(mySbase, myGShape);
760 //modified by NIZNHY-PKV Thu Mar 21 18:03:15 2002 t
761 if (c.IsDone()) {
762 myShape = c.Shape();
763 //modified by NIZNHY-PKV Thu Mar 21 18:03:38 2002 f
764 //UpdateDescendants(c.Builder(), myShape, Standard_False);
765 UpdateDescendants(c, myShape, Standard_False);
766 //modified by NIZNHY-PKV Thu Mar 21 18:03:42 2002 t
767 Done();
768 }
769 }
770 else {
771 thePrism.Curves(myCurves);
772 myBCurve = thePrism.BarycCurve();
773 GlobalPerform();
774 }
775}
776
777//=======================================================================
778//function : PerformFromEnd
779//purpose :
780//=======================================================================
781
782void BRepFeat_MakePrism::PerformFromEnd(const TopoDS_Shape& Until)
783{
784#ifdef DEB
785 Standard_Boolean trc = BRepFeat_GettraceFEAT();
786 if (trc) cout << "BRepFeat_MakePrism::PerformFromEnd(From,Until)" << endl;
787#endif
788 if (Until.IsNull()) {
789 Standard_ConstructionError::Raise();
790 }
791 if (!mySkface.IsNull() && Until.IsSame(mySkface)) {
792 myDir.Reverse();
793 PerformUntilEnd();
794 return;
795 }
796 TopExp_Explorer exp;
797 exp.Init(Until, TopAbs_FACE);
798 if (!exp.More()) {
799 Standard_ConstructionError::Raise();
800 }
801 myPerfSelection = BRepFeat_SelectionShU;
802 PerfSelectionValid();
803 mySFrom.Nullify();
804 ShapeFromValid();
805 mySUntil = Until;
806 Standard_Boolean Trf = TransformShapeFU(1);
807 ShapeUntilValid();
808 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
809 Standard_Integer sens = SensOfPrism(C, mySUntil);
810 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
811 gp_Vec Vtra(-3*Height*sens/2.*myDir);
812 gp_Vec Vect(3*sens*Height*myDir);
813 LocOpe_Prism thePrism(myPbase,Vect,Vtra);
814 TopoDS_Shape VraiPrism = thePrism.Shape();
815
0d969553 816 if(!Trf) { // case face until
7fd59977 817 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
818 myGShape = VraiPrism;
819 GeneratedShapeValid();
820 myGluedF.Clear();
821 GluedFacesValid();
822 thePrism.Curves(myCurves);
823 myBCurve = thePrism.BarycCurve();
824 GlobalPerform();
825 }
0d969553 826 else { // case support
7fd59977 827 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
828 TColGeom_SequenceOfCurve scur;
829 scur.Clear();
830 scur.Append(C);
831 LocOpe_CSIntersector ASI1(mySUntil);
832 LocOpe_CSIntersector ASI2(mySbase);
833 ASI1.Perform(scur);
834 ASI2.Perform(scur);
835#ifndef DEB
836 TopAbs_Orientation OrU = TopAbs_FORWARD, OrF = TopAbs_FORWARD;
837#else
838 TopAbs_Orientation OrU, OrF;
839#endif
840 TopoDS_Face FUntil, FFrom;
841 if (ASI1.IsDone() && ASI1.NbPoints(1) >=1) {
842 OrU = ASI1.Point(1,1).Orientation();
843 if(sens==-1) {
844 OrU = TopAbs::Reverse(OrU);
845 }
846 FUntil = ASI1.Point(1,1).Face();
847 }
848 if (ASI2.IsDone() && ASI2.NbPoints(1) >=1) {
849 OrF = ASI2.Point(1,1).Orientation();
850// if(sens==1) OrF = TopAbs::Reverse(OrF);
851 FFrom = ASI2.Point(1 ,1).Face();
852 Handle(Geom_Surface) S = BRep_Tool::Surface(FFrom);
853 if (S->DynamicType() ==
854 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
855 S = Handle(Geom_RectangularTrimmedSurface)::
856 DownCast(S)->BasisSurface();
857 }
1c72dff6 858 BRepLib_MakeFace fac(S, Precision::Confusion());
7fd59977 859 mySFrom = fac.Face();
860 Trf = TransformShapeFU(0);
861 FFrom = TopoDS::Face(mySFrom);
862 }
863// else {
864// NotDone();
865// return;
866// }
867 TopoDS_Shape Comp;
868 BRep_Builder B;
869 B.MakeCompound(TopoDS::Compound(Comp));
870 TopoDS_Solid Sol = BRepFeat::Tool(mySUntil, FUntil, OrU);
871 if (!Sol.IsNull()) {
872 B.Add(Comp,Sol);
873 }
874 else {
875 NotDone();
876 myStatusError = BRepFeat_NullToolU;
877 return;
878 }
879
880 TopoDS_Solid Sol1 = BRepFeat::Tool(mySFrom, FFrom, OrF);
881 if (!Sol1.IsNull()) {
882 B.Add(Comp,Sol1);
883 }
884 else {
885 NotDone();
886 myStatusError = BRepFeat_NullToolF;
887 return;
888 }
889 //modified by NIZNHY-PKV Thu Mar 21 18:03:57 2002 f
890 //BRepAlgo_Cut trP(VraiPrism,Comp);
891 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
892 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
893 UpdateDescendants(trP, trP.Shape(), Standard_False);
894 //modified by NIZNHY-PKV Thu Mar 21 18:04:08 2002 t
895 if(myFuse == 1 && !myJustFeat) {
896 //modified by NIZNHY-PKV Thu Mar 21 18:04:33 2002 f
897 //BRepAlgo_Fuse f(mySbase, trP.Shape());
898 //myShape = f.Shape();
899 //UpdateDescendants(f.Builder(), myShape, Standard_False);
900 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
901 myShape = f.Shape();
902 UpdateDescendants(f, myShape, Standard_False);
903 //modified by NIZNHY-PKV Thu Mar 21 18:04:41 2002 t
904 Done();
905 }
906 else if(myFuse == 0) {
907 //modified by NIZNHY-PKV Thu Mar 21 18:04:54 2002 f
908 //BRepAlgo_Cut c(mySbase, trP.Shape());
909 //myShape = c.Shape();
910 //UpdateDescendants(c.Builder(), myShape, Standard_False);
911 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
912 myShape = c.Shape();
913 UpdateDescendants(c, myShape, Standard_False);
914 //modified by NIZNHY-PKV Thu Mar 21 18:05:00 2002 t
915 Done();
916 }
917 else {
918 myShape = trP.Shape();
919 Done();
920 }
921 }
922}
923
924
925
926//=======================================================================
927//function : PerformThruAll
928//purpose :
929//=======================================================================
930
931void BRepFeat_MakePrism::PerformThruAll()
932{
933#ifdef DEB
934 Standard_Boolean trc = BRepFeat_GettraceFEAT();
935 if (trc) cout << "BRepFeat_MakePrism::PerformThruAll()" << endl;
936#endif
937 mySUntil.Nullify();
938 ShapeUntilValid();
939 mySFrom.Nullify();
940 ShapeFromValid();
941 if(myFuse == 0) {
942 myPerfSelection = BRepFeat_NoSelection;
943 }
944 else {
945 myPerfSelection = BRepFeat_SelectionSh;
946 }
947 PerfSelectionValid();
948 myGluedF.Clear();
949 GluedFacesValid();
950
951 Standard_Real Height = HeightMax(mySbase, mySkface, mySFrom, mySUntil);
952 gp_Vec V(3*Height*myDir);
953 gp_Vec Vtra(-3*Height/2.*myDir);
954 LocOpe_Prism thePrism(myPbase,V,Vtra);
955 TopoDS_Shape VraiPrism = thePrism.Shape();
956 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
957
958 myGShape = VraiPrism;
959 GeneratedShapeValid();
960
961 if(myFuse == 0) {
962 //modified by NIZNHY-PKV Thu Mar 21 18:05:31 2002 f
963 //BRepAlgo_Cut c(mySbase, myGShape);
964 BRepAlgoAPI_Cut c(mySbase, myGShape);
965 //modified by NIZNHY-PKV Thu Mar 21 18:05:33 2002 t
966 if (c.IsDone()) {
967 myShape = c.Shape();
968 //modified by NIZNHY-PKV Thu Mar 21 18:05:46 2002 f
969 //UpdateDescendants(c.Builder(), myShape, Standard_False);
970 UpdateDescendants(c, myShape, Standard_False);
971 //modified by NIZNHY-PKV Thu Mar 21 18:05:50 2002 t
972 Done();
973 }
974 }
975 else {
976 thePrism.Curves(myCurves);
977 myBCurve = thePrism.BarycCurve();
978 GlobalPerform();
979 }
980}
981
982
983//=======================================================================
984//function : PerformUntilHauteur
985//purpose :
986//=======================================================================
987
988void BRepFeat_MakePrism::PerformUntilHeight(const TopoDS_Shape& Until,
989 const Standard_Real Length)
990{
991#ifdef DEB
992 Standard_Boolean trc = BRepFeat_GettraceFEAT();
993 if (trc) cout << "BRepFeat_MakePrism::PerformUntilHeight(Until,Length)" << endl;
994#endif
995 if (Until.IsNull()) {
996 Perform(Length);
997 }
998 if(Length == 0) {
999 Perform(Until);
1000 }
1001 TopExp_Explorer exp(Until, TopAbs_FACE);
1002 if (!exp.More()) {
1003 Standard_ConstructionError::Raise();
1004 }
1005 myGluedF.Clear();
1006 myPerfSelection = BRepFeat_NoSelection;
1007 PerfSelectionValid();
1008 mySFrom.Nullify();
1009 ShapeFromValid();
1010 mySUntil = Until;
1011 Standard_Boolean Trf = TransformShapeFU(1);
1012 ShapeUntilValid();
1013 Handle(Geom_Curve) C = TestCurve(myPbase,myDir);
1014 Standard_Integer sens = SensOfPrism(C, mySUntil);
1015 gp_Vec V(sens*Length*myDir);
1016 LocOpe_Prism thePrism(myPbase,V);
1017 TopoDS_Shape VraiPrism = thePrism.Shape();
1018
1019 if(!Trf) {
1020 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1021
1022 myGShape = VraiPrism;
1023 GeneratedShapeValid();
1024
1025 //SetGluedFaces(mySkface, mySbase, myPbase, mySlface, thePrism, myGluedF);
1026 GluedFacesValid();
1027// VerifGluedFaces(mySkface, myPbase, myBCurve, myCurves, thePrism, myGluedF);
1028
1029 thePrism.Curves(myCurves);
1030 myBCurve = thePrism.BarycCurve();
1031 GlobalPerform();
1032 }
1033 else {
1034 MajMap(myPbase,thePrism,myMap,myFShape,myLShape);
1035 TColGeom_SequenceOfCurve scur;
1036 scur.Clear();
1037 scur.Append(C);
1038 LocOpe_CSIntersector ASI(mySUntil);
1039 ASI.Perform(scur);
1040 TopAbs_Orientation Or;
1041 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1042 if (myFuse == 1) {
1043 Or = ASI.Point(1,1).Orientation();
1044 }
1045 else {
1046 Or = ASI.Point(1,ASI.NbPoints(1)).Orientation();
1047 }
1048 if(sens==-1) Or=TopAbs::Reverse(Or);
1049 TopoDS_Face FUntil = ASI.Point(1,1).Face();
1050 TopoDS_Shape Comp;
1051 BRep_Builder B;
1052 B.MakeCompound(TopoDS::Compound(Comp));
1053 TopoDS_Solid S = BRepFeat::Tool(mySUntil, FUntil, Or);
1054 if (!S.IsNull()) B.Add(Comp,S);
1055
1056 //modified by NIZNHY-PKV Thu Mar 21 18:06:09 2002 f
1057 //BRepAlgo_Cut trP(VraiPrism,Comp);
1058 //UpdateDescendants(trP.Builder(), trP.Shape(), Standard_False);
1059 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1060 UpdateDescendants(trP, trP.Shape(), Standard_False);
1061 //modified by NIZNHY-PKV Thu Mar 21 18:06:15 2002 t
1062 if(myFuse == 1 && !myJustFeat) {
1063 //modified by NIZNHY-PKV Thu Mar 21 18:06:36 2002 f
1064 //BRepAlgo_Fuse f(mySbase, trP.Shape());
1065 //myShape = f.Shape();
1066 //UpdateDescendants(f.Builder(), myShape, Standard_False);
1067 BRepAlgoAPI_Fuse f(mySbase, trP.Shape());
1068 myShape = f.Shape();
1069 UpdateDescendants(f, myShape, Standard_False);
1070 //modified by NIZNHY-PKV Thu Mar 21 18:06:41 2002 t
1071 Done();
1072 }
1073 else if(myFuse == 0) {
1074 //modified by NIZNHY-PKV Thu Mar 21 18:07:06 2002 f
1075 //BRepAlgo_Cut c(mySbase, trP.Shape());
1076 //myShape = c.Shape();
1077 //UpdateDescendants(c.Builder(), myShape, Standard_False);
1078 BRepAlgoAPI_Cut c(mySbase, trP.Shape());
1079 myShape = c.Shape();
1080 UpdateDescendants(c, myShape, Standard_False);
1081 //modified by NIZNHY-PKV Thu Mar 21 18:07:12 2002 t
1082 Done();
1083 }
1084 else {
1085 myShape = trP.Shape();
1086 Done();
1087 }
1088 }
1089 }
1090}
1091
1092//=======================================================================
1093//function : Curves
0d969553 1094//purpose : sequence of curves parallel to the axis of prism
7fd59977 1095//=======================================================================
1096
1097void BRepFeat_MakePrism::Curves(TColGeom_SequenceOfCurve& scur)
1098{
1099 scur = myCurves;
1100}
1101
1102//=======================================================================
1103//function : BarycCurve
0d969553
Y
1104//purpose : curve parallel to the axis of the prism passing through the center
1105// of masses
7fd59977 1106//=======================================================================
1107
1108Handle(Geom_Curve) BRepFeat_MakePrism::BarycCurve()
1109{
1110 return myBCurve;
1111}
1112
1113
1114//=======================================================================
1115//function : HeightMax
0d969553
Y
1116//purpose : Calculate the height of the prism following the parameters of
1117// bounding box
7fd59977 1118//=======================================================================
1119
1120static Standard_Real HeightMax(const TopoDS_Shape& theSbase,
1121 const TopoDS_Face& theSkface,
1122 const TopoDS_Shape& theSFrom,
1123 const TopoDS_Shape& theSUntil)
1124{
1125 Bnd_Box Box;
1126 BRepBndLib::Add(theSbase,Box);
1127 BRepBndLib::Add(theSkface,Box);
1128 if(!theSFrom.IsNull()) {
1129#ifndef DEB
1130 Standard_Boolean FacRevolInfini = Standard_False;
1131#else
1132 Standard_Boolean FacRevolInfini;
1133#endif
1134 TopExp_Explorer exp;
1135 exp.Init(theSFrom, TopAbs_EDGE);
1136 for(; exp.More(); exp.Next()) {
1137 TopExp_Explorer exp1;
1138 exp1.Init(exp.Current(), TopAbs_VERTEX);
1139 if(!exp1.More()) {
1140 FacRevolInfini = Standard_True;
1141 break;
1142 }
1143 }
1144 if(!FacRevolInfini)
1145 BRepBndLib::Add(theSFrom,Box);
1146 }
1147 if(!theSUntil.IsNull()) {
1148#ifndef DEB
1149 Standard_Boolean FacRevolInfini = Standard_False;
1150#else
1151 Standard_Boolean FacRevolInfini;
1152#endif
1153 TopExp_Explorer exp;
1154 exp.Init(theSUntil, TopAbs_EDGE);
1155 for(; exp.More(); exp.Next()) {
1156 TopExp_Explorer exp1;
1157 exp1.Init(exp.Current(), TopAbs_VERTEX);
1158 if(!exp1.More()) {
1159 FacRevolInfini = Standard_True;
1160 break;
1161 }
1162 }
1163 if(!FacRevolInfini)
1164 BRepBndLib::Add(theSUntil,Box);
1165 }
1166
1167 Standard_Real c[6];
1168
1169 Box.Get(c[0],c[2],c[4],c[1],c[3],c[5]);
1170 Standard_Real parmin=c[0], parmax = c[0];
1171 for(Standard_Integer i = 0 ; i < 6; i++) {
1172 if(c[i] > parmax) parmax = c[i];
1173 if(c[i] < parmin ) parmin = c[i];
1174 }
1175//#ifndef DEB
1176 Standard_Real Height = fabs(2.*(parmax - parmin));
1177//#else
1178// Standard_Real Height = abs(2.*(parmax - parmin));
1179//#endif
1180 return(Height);
1181}
1182
1183
1184//=======================================================================
1185//function : SensOfPrism
0d969553 1186//purpose : Direction of the prism depending on the shape Until
7fd59977 1187//=======================================================================
1188Standard_Integer SensOfPrism(const Handle(Geom_Curve) C,
1189 const TopoDS_Shape& Until)
1190{
1191 LocOpe_CSIntersector ASI1(Until);
1192 TColGeom_SequenceOfCurve scur;
1193 scur.Append(C);
1194 ASI1.Perform(scur);
1195 Standard_Integer sens = 1;
1196 if(ASI1.IsDone() && ASI1.NbPoints(1) >= 1) {
1197 if(ASI1.Point(1, 1).Parameter() < 0. &&
1198 ASI1.Point(1, ASI1.NbPoints(1)).Parameter() < 0.) {
1199 sens = -1;
1200 }
1201 }
1202 else if(BRepFeat::ParametricBarycenter(Until,C) < 0) {
1203 sens = -1;
1204 }
1205 else {}
1206 return sens;
1207}
1208
1209
1210//=======================================================================
1211//function : SetGluedFaces
0d969553 1212//purpose : management of gluing faces
7fd59977 1213//=======================================================================
1214
1215static void SetGluedFaces(const TopoDS_Face& theSkface,
1216 const TopoDS_Shape& theSbase,
1217 const TopoDS_Shape& thePbase,
1218 const TopTools_DataMapOfShapeListOfShape& theSlmap,
1219 LocOpe_Prism& thePrism,
1220 TopTools_DataMapOfShapeShape& theMap)
1221{
1222 TopExp_Explorer exp;
1223 if (!theSkface.IsNull() && thePbase.ShapeType() == TopAbs_FACE) {
1224 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1225 if (exp.Current().IsSame(theSkface)) {
1226 theMap.Bind(thePbase,theSkface);
1227 break;
1228 }
1229 }
1230 }
1231 else {
1232 for (exp.Init(theSbase,TopAbs_FACE); exp.More(); exp.Next()) {
1233 if (exp.Current().IsSame(theSkface)) {
1234 TopExp_Explorer exp2;
1235 for (exp2.Init(thePbase,TopAbs_FACE);exp2.More();exp2.Next()) {
1236 theMap.Bind(exp2.Current(),theSkface);
1237 }
1238 break;
1239 }
1240 }
1241 }
1242
0d969553 1243 // Sliding
7fd59977 1244 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1245 if(!theSlmap.IsEmpty()) {
1246 for (; itm.More(); itm.Next()) {
1247 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1248 const TopTools_ListOfShape& ledg = itm.Value();
1249 TopTools_ListIteratorOfListOfShape it;
1250 for (it.Initialize(ledg); it.More(); it.Next()) {
1251 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1252 if (gfac.Extent() != 1) {
1253#ifdef DEB
1254 Standard_Boolean trc = BRepFeat_GettraceFEAT();
1255 if (trc) cout << " BRepFeat_MakePrism : Pb SetGluedFace" << endl;
1256#endif
1257 }
1258 theMap.Bind(gfac.First(),fac);
1259 }
1260 }
1261 }
1262}
1263
1264
1265//=======================================================================
1266//function : VerifGluedFaces
0d969553
Y
1267//purpose : Verification intersection Tool/theSkface = thePbase
1268// If yes -> OK otherwise -> case without gluing
7fd59977 1269//=======================================================================
1270#ifdef DEB
1271static void VerifGluedFaces(const TopoDS_Face& theSkface,
1272 const TopoDS_Shape& thePbase,
1273 Handle(Geom_Curve)& theBCurve,
1274 TColGeom_SequenceOfCurve& theCurves,
1275 LocOpe_Prism& thePrism,
1276 TopTools_DataMapOfShapeShape& theMap)
1277{
1278 Standard_Boolean GluedFaces = Standard_True;
1279 TopoDS_Shape VraiPrism = thePrism.Shape();
1280
1281 TColGeom_SequenceOfCurve scur;
1282 thePrism.Curves(theCurves);
1283 theBCurve = thePrism.BarycCurve();
1284 scur.Clear();
1285 scur.Append(theBCurve);
1286 LocOpe_CSIntersector ASI(theSkface);
1287 ASI.Perform(scur);
1288 if (ASI.IsDone() && ASI.NbPoints(1) >=1) {
1289 TopAbs_Orientation Or = ASI.Point(1,1).Orientation();
1290 TopoDS_Face FSk = ASI.Point(1,1).Face();
1291 TopoDS_Shape Comp;
1292 BRep_Builder B;
1293 B.MakeCompound(TopoDS::Compound(Comp));
1294 TopoDS_Solid S = BRepFeat::Tool(theSkface, FSk, Or);
1295 if (!S.IsNull()) B.Add(Comp,S);
1296 //modified by NIZNHY-PKV Thu Mar 21 18:07:35 2002 f
1297 //BRepAlgo_Cut trP(VraiPrism,Comp);
1298 BRepAlgoAPI_Cut trP(VraiPrism,Comp);
1299 //modified by NIZNHY-PKV Thu Mar 21 18:07:39 2002 t
1300 TopoDS_Shape Cutsh = trP.Shape();
1301 TopExp_Explorer ex(Cutsh, TopAbs_SOLID);
1302 for(; ex.More(); ex.Next()) {
1303 TopExp_Explorer ex1(ex.Current(), TopAbs_FACE);
1304 for(; ex1.More(); ex1.Next()) {
1305 const TopoDS_Face& fac1 = TopoDS::Face(ex1.Current());
1306 TopExp_Explorer ex2(thePbase, TopAbs_FACE);
1307 for(; ex2.More(); ex2.Next()) {
1308 const TopoDS_Face& fac2 = TopoDS::Face(ex2.Current());
1309 if(fac1.IsSame(fac2)) break;
1310 }
1311 if (ex2.More()) break;
1312 }
1313 if (ex1.More()) continue;
1314 GluedFaces = Standard_False;
1315 break;
1316 }
1317 if (!GluedFaces) {
1318#ifdef DEB
1319 Standard_Boolean trc = BRepFeat_GettraceFEAT();
0d969553 1320 if (trc) cout << " Intersection Prism/skface : no gluing" << endl;
7fd59977 1321#endif
1322 theMap.Clear();
1323 }
1324 }
1325}
1326#endif
1327
1328//=======================================================================
1329//function : MajMap
0d969553 1330//purpose : management of descendants
7fd59977 1331//=======================================================================
1332
1333static void MajMap(const TopoDS_Shape& theB,
1334 const LocOpe_Prism& theP,
1335 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1336 TopoDS_Shape& theFShape, // myFShape
1337 TopoDS_Shape& theLShape) // myLShape
1338{
1339 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1340 if (exp.More()) {
1341 theFShape = exp.Current();
1342 TopTools_ListOfShape thelist2;
1343 theMap.Bind(theFShape, thelist2);
1344 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1345 theMap(theFShape).Append(exp.Current());
1346 }
1347 }
1348
1349 exp.Init(theP.LastShape(),TopAbs_WIRE);
1350 if (exp.More()) {
1351 theLShape = exp.Current();
1352 TopTools_ListOfShape thelist3;
1353 theMap.Bind(theLShape, thelist3);
1354 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1355 theMap(theLShape).Append(exp.Current());
1356 }
1357 }
1358
1359 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1360 if (!theMap.IsBound(exp.Current())) {
1361 TopTools_ListOfShape thelist4;
1362 theMap.Bind(exp.Current(), thelist4);
1363 theMap(exp.Current()) = theP.Shapes(exp.Current());
1364 }
1365 }
1366}
1367
1368
1369//=======================================================================
1370//function : MajMap
0d969553 1371//purpose : management of descendants
7fd59977 1372//=======================================================================
1373
1374static Handle(Geom_Curve) TestCurve(const TopoDS_Shape& Base,
1375 const gp_Vec& V)
1376{
1377 gp_Pnt bar(0., 0., 0.);
1378 TColgp_SequenceOfPnt spt;
1379 LocOpe::SampleEdges(Base,spt);
1380 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
1381 const gp_Pnt& pvt = spt(jj);
1382 bar.ChangeCoord() += pvt.XYZ();
1383 }
1384 bar.ChangeCoord().Divide(spt.Length());
1385 gp_Ax1 newAx(bar,V);
1386 Handle(Geom_Line) theLin = new Geom_Line(newAx);
1387 return theLin;
1388}
1389
1390
1391
1392
1393//=======================================================================
1394//function : ToFuse
0d969553 1395//purpose : face SameDomaine or not
7fd59977 1396//=======================================================================
1397
1398Standard_Boolean ToFuse(const TopoDS_Face& F1,
1399 const TopoDS_Face& F2)
1400{
1401 if (F1.IsNull() || F2.IsNull()) {
1402 return Standard_False;
1403 }
1404
1405 Handle(Geom_Surface) S1,S2;
1406 TopLoc_Location loc1, loc2;
1407 Handle(Standard_Type) typS1,typS2;
1408 const Standard_Real tollin = Precision::Confusion();
1409 const Standard_Real tolang = Precision::Angular();
1410
1411 S1 = BRep_Tool::Surface(F1,loc1);
1412 S2 = BRep_Tool::Surface(F2,loc2);
1413
1414 typS1 = S1->DynamicType();
1415 typS2 = S2->DynamicType();
1416
1417 if (typS1 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1418 S1 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S1))->BasisSurface();
1419 typS1 = S1->DynamicType();
1420 }
1421
1422 if (typS2 == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1423 S2 = (*((Handle(Geom_RectangularTrimmedSurface)*)&S2))->BasisSurface();
1424 typS2 = S2->DynamicType();
1425 }
1426
1427 if (typS1 != typS2) {
1428 return Standard_False;
1429 }
1430
1431
1432 Standard_Boolean ValRet = Standard_False;
1433 if (typS1 == STANDARD_TYPE(Geom_Plane)) {
0d969553 1434 S1 = BRep_Tool::Surface(F1); // to apply the location.
7fd59977 1435 S2 = BRep_Tool::Surface(F2);
1436 gp_Pln pl1( (*((Handle(Geom_Plane)*)&S1))->Pln());
1437 gp_Pln pl2( (*((Handle(Geom_Plane)*)&S2))->Pln());
1438
1439 if (pl1.Position().IsCoplanar(pl2.Position(),tollin,tolang)) {
1440 ValRet = Standard_True;
1441 }
1442 }
1443
1444 return ValRet;
1445}
1446
1447
1448
1449
1450
1451