1 // Created on: 1993-06-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepCheck_Analyzer.hxx>
19 #include <Standard_ProgramError.hxx>
20 #include <TCollection_AsciiString.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRepBuild_define.hxx>
24 #include <TopOpeBRepBuild_ShapeSet.hxx>
28 #include <DBRep_DrawableShape.hxx>
29 #include <TestTopOpeDraw_DrawableSHA.hxx>
30 #include <TestTopOpeDraw_TTOT.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopTools_IndexedMapOfShape.hxx>
33 static TCollection_AsciiString PRODINS("dins ");
37 extern Standard_Boolean TopOpeBRepBuild_GettraceCHK();
38 extern Standard_Boolean TopOpeBRepBuild_GettraceCHKOK();
39 extern Standard_Boolean TopOpeBRepBuild_GettraceCHKNOK();
40 Standard_EXPORT void debaddss(){}
41 Standard_IMPORT TopOpeBRepBuild_Builder* LOCAL_PBUILDER_DEB;
44 //=======================================================================
45 //function : TopOpeBRepBuild_ShapeSet
47 //=======================================================================
48 TopOpeBRepBuild_ShapeSet::TopOpeBRepBuild_ShapeSet(const TopAbs_ShapeEnum SubShapeType,const Standard_Boolean checkshape) :
49 mySubShapeType(SubShapeType), myCheckShape(checkshape)
51 if (SubShapeType == TopAbs_EDGE) myShapeType = TopAbs_FACE;
52 else if (SubShapeType == TopAbs_VERTEX) myShapeType = TopAbs_EDGE;
53 else throw Standard_ProgramError("ShapeSet : bad ShapeType");
56 myCheckShape = Standard_False; // temporary NYI
59 TopOpeBRepBuild_ShapeSet::~TopOpeBRepBuild_ShapeSet()
62 //=======================================================================
65 //=======================================================================
66 void TopOpeBRepBuild_ShapeSet::AddShape(const TopoDS_Shape& S)
68 Standard_Boolean chk = CheckShape(S);
70 DumpCheck(cout," AddShape",S,chk);
77 //=======================================================================
78 //function : AddStartElement
80 //=======================================================================
81 void TopOpeBRepBuild_ShapeSet::AddStartElement(const TopoDS_Shape& S)
83 Standard_Boolean chk = CheckShape(S);
85 DumpCheck(cout," AddStartElement",S,chk);
89 ProcessAddStartElement(S);
92 //=======================================================================
93 //function : AddElement
95 //=======================================================================
96 void TopOpeBRepBuild_ShapeSet::AddElement(const TopoDS_Shape& S)
98 Standard_Boolean chk = CheckShape(S);
100 DumpCheck(cout," AddElement",S,chk);
104 ProcessAddElement(S);
107 //=======================================================================
108 //function : ProcessAddShape
110 //=======================================================================
111 void TopOpeBRepBuild_ShapeSet::ProcessAddShape(const TopoDS_Shape& S)
113 if ( !myOMSH.Contains(S) ) {
119 //=======================================================================
120 //function : ProcessStartElement
122 //=======================================================================
123 void TopOpeBRepBuild_ShapeSet::ProcessAddStartElement(const TopoDS_Shape& S)
125 if ( !myOMSS.Contains(S) ) {
127 myStartShapes.Append(S);
128 ProcessAddElement(S);
132 //=======================================================================
133 //function : ProcessAddElement
135 //=======================================================================
136 void TopOpeBRepBuild_ShapeSet::ProcessAddElement(const TopoDS_Shape& S)
138 if ( !myOMES.Contains(S) ) {
140 TopTools_ListOfShape Lemp;
141 TopOpeBRepTool_ShapeExplorer Ex(S,mySubShapeType);
142 for (; Ex.More(); Ex.Next()) {
143 const TopoDS_Shape& subshape = Ex.Current();
144 Standard_Boolean b = ( ! mySubShapeMap.Contains(subshape) );
145 if ( b ) mySubShapeMap.Add(subshape,Lemp);
146 mySubShapeMap.ChangeFromKey(subshape).Append(S);
151 //=======================================================================
152 //function : StartElements
154 //=======================================================================
155 const TopTools_ListOfShape& TopOpeBRepBuild_ShapeSet::StartElements()const
157 return myStartShapes;
160 //=======================================================================
161 //function : InitShapes
163 //=======================================================================
164 void TopOpeBRepBuild_ShapeSet::InitShapes()
166 myShapesIter.Initialize(myShapes);
169 //=======================================================================
170 //function : MoreShapes
172 //=======================================================================
173 Standard_Boolean TopOpeBRepBuild_ShapeSet::MoreShapes()const
175 Standard_Boolean b = myShapesIter.More();
179 //=======================================================================
180 //function : NextShape
182 //=======================================================================
183 void TopOpeBRepBuild_ShapeSet::NextShape()
188 //=======================================================================
191 //=======================================================================
192 const TopoDS_Shape& TopOpeBRepBuild_ShapeSet::Shape()const
194 const TopoDS_Shape& S = myShapesIter.Value();
198 //=======================================================================
199 //function : InitStartElements
201 //=======================================================================
202 void TopOpeBRepBuild_ShapeSet::InitStartElements()
204 myStartShapesIter.Initialize(myStartShapes);
207 //=======================================================================
208 //function : MoreStartElements
210 //=======================================================================
211 Standard_Boolean TopOpeBRepBuild_ShapeSet::MoreStartElements()const
213 Standard_Boolean b = myStartShapesIter.More();
217 //=======================================================================
218 //function : NextStartElement
220 //=======================================================================
221 void TopOpeBRepBuild_ShapeSet::NextStartElement()
223 myStartShapesIter.Next();
226 //=======================================================================
227 //function : StartElement
229 //=======================================================================
230 const TopoDS_Shape& TopOpeBRepBuild_ShapeSet::StartElement()const
232 const TopoDS_Shape& S = myStartShapesIter.Value();
236 //=======================================================================
237 //function : InitNeighbours
239 //=======================================================================
240 void TopOpeBRepBuild_ShapeSet::InitNeighbours(const TopoDS_Shape& S)
242 mySubShapeExplorer.Init(S,mySubShapeType);
247 //=======================================================================
248 //function : MoreNeighbours
250 //=======================================================================
251 Standard_Boolean TopOpeBRepBuild_ShapeSet::MoreNeighbours()
253 Standard_Boolean b = myIncidentShapesIter.More();
257 //=======================================================================
258 //function : NextNeighbour
260 //=======================================================================
261 void TopOpeBRepBuild_ShapeSet::NextNeighbour()
263 myIncidentShapesIter.Next();
264 Standard_Boolean noisimore = ! myIncidentShapesIter.More();
266 Standard_Boolean ssemore = mySubShapeExplorer.More();
268 mySubShapeExplorer.Next();
274 //=======================================================================
275 //function : Neighbour
277 //=======================================================================
278 const TopoDS_Shape& TopOpeBRepBuild_ShapeSet::Neighbour()const
280 const TopoDS_Shape& S = myIncidentShapesIter.Value();
284 //=======================================================================
285 //function : ChangeStartShapes
287 //=======================================================================
288 TopTools_ListOfShape& TopOpeBRepBuild_ShapeSet::ChangeStartShapes()
290 return myStartShapes;
293 //=======================================================================
294 //function : FindNeighbours
296 //=======================================================================
297 void TopOpeBRepBuild_ShapeSet::FindNeighbours()
299 while (mySubShapeExplorer.More()) {
301 // l = list of edges neighbour of edge myCurrentShape trough
302 // the vertex mySubShapeExplorer.Current(), which is a vertex of the
303 // edge myCurrentShape.
304 const TopoDS_Shape& V = mySubShapeExplorer.Current();
305 const TopTools_ListOfShape & l = MakeNeighboursList(myCurrentShape,V);
307 // myIncidentShapesIter iterates on the neighbour edges of the edge
308 // given as InitNeighbours() argument (this edge has been stored
309 // in the field myCurrentShape).
311 myIncidentShapesIter.Initialize(l);
312 if (myIncidentShapesIter.More()) break;
313 else mySubShapeExplorer.Next();
317 //=======================================================================
318 //function : MakeNeighboursList
319 //purpose : // (Earg = Edge, Varg = Vertex) to find connected to Earg by Varg
320 //=======================================================================
321 const TopTools_ListOfShape & TopOpeBRepBuild_ShapeSet::MakeNeighboursList(const TopoDS_Shape& /*Earg*/, const TopoDS_Shape& Varg)
323 const TopTools_ListOfShape& l = mySubShapeMap.FindFromKey(Varg);
327 //=======================================================================
328 //function : MaxNumberSubShape
330 //=======================================================================
331 Standard_Integer TopOpeBRepBuild_ShapeSet::MaxNumberSubShape(const TopoDS_Shape& Shape)
333 Standard_Integer i, m = 0;
334 TopOpeBRepTool_ShapeExplorer SE(Shape, mySubShapeType);
335 TopTools_ListIteratorOfListOfShape LI;
337 const TopoDS_Shape& SubShape = SE.Current();
338 if(!mySubShapeMap.Contains(SubShape)) {
342 const TopTools_ListOfShape& l = mySubShapeMap.FindFromKey(SubShape);
344 for(i = 0;LI.More();LI.Next(), i++) {}
351 //=======================================================================
352 //function : CheckShape
354 //=======================================================================
355 void TopOpeBRepBuild_ShapeSet::CheckShape(const Standard_Boolean checkshape)
357 myCheckShape = checkshape;
360 if (TopOpeBRepBuild_GettraceCHK() && !myCheckShape) {
361 DumpName(cout,"no checkshape set on ");cout<<endl;
366 //=======================================================================
367 //function : CheckShape
369 //=======================================================================
370 Standard_Boolean TopOpeBRepBuild_ShapeSet::CheckShape() const
375 //=======================================================================
376 //function : CheckShape
378 //=======================================================================
379 Standard_Boolean TopOpeBRepBuild_ShapeSet::CheckShape(const TopoDS_Shape& S,const Standard_Boolean checkgeom)
381 if (!myCheckShape) return Standard_True;
383 BRepCheck_Analyzer ana(S,checkgeom);
384 Standard_Boolean val = ana.IsValid();
386 return Standard_True;
389 return Standard_False;
393 //=======================================================================
394 //function : DumpName
396 //=======================================================================
397 void TopOpeBRepBuild_ShapeSet::DumpName(Standard_OStream& OS,const TCollection_AsciiString& str) const
399 OS<<str<<"("<<myDEBName<<","<<myDEBNumber<<")";
402 //=======================================================================
403 //function : DumpCheck
405 //=======================================================================
408 void TopOpeBRepBuild_ShapeSet::DumpCheck(Standard_OStream& OS,
409 const TCollection_AsciiString& str,
410 const TopoDS_Shape& S,
411 const Standard_Boolean chk
413 void TopOpeBRepBuild_ShapeSet::DumpCheck(Standard_OStream&,
414 const TCollection_AsciiString&,
416 const Standard_Boolean
420 if (!myCheckShape) return;
423 TopAbs_ShapeEnum t = S.ShapeType();
425 if (TopOpeBRepBuild_GettraceCHK() ||
426 TopOpeBRepBuild_GettraceCHKNOK() ) {
427 DumpName(OS,"*********************** ");
428 OS<<str<<" ";TopAbs::Print(t,OS);OS<<" : incorrect"<<endl;
432 if (TopOpeBRepBuild_GettraceCHK() ||
433 TopOpeBRepBuild_GettraceCHKOK() ) {
435 OS<<str<<" ";TopAbs::Print(t,OS);OS<<" : correct"<<endl;
438 if (!chk) debaddss();
442 //=======================================================================
445 //=======================================================================
446 void TopOpeBRepBuild_ShapeSet::DumpSS()
449 DumpName(cout,"\nDumpSS start ");
450 TopTools_ListIteratorOfListOfShape it;
451 Standard_Integer i,j,ne;
452 TCollection_AsciiString s1(" ");
454 cout<<endl<<"#Shapes : ";if (!MoreShapes()) cout<<0;cout<<endl;
455 for (i=1;MoreShapes();NextShape(),i++) {
456 TCollection_AsciiString ns = SNameori(Shape());
457 cout<<PRODINS<<ns<<"; # "<<i<<" draw"<<endl;
458 DBRep::Set(ns.ToCString(),Shape());
462 cout<<"#StartElements : ";if (!MoreStartElements()) cout<<0;cout<<endl;
463 for (i=1;MoreStartElements();NextStartElement(),i++) {
464 cout<<PRODINS<<SNameori(StartElement())<<"; # "<<i<<" draw"<<endl;
468 cout<<"#Neighbours of StartElements : ";if (!MoreStartElements()) cout<<0;cout<<endl;
469 for (i=1;MoreStartElements();NextStartElement(),i++) {
470 const TopoDS_Shape& e = StartElement();
471 TCollection_AsciiString enam = SNameori(e);
473 if (MoreNeighbours()) {
474 TCollection_AsciiString sne("clear; ");sne=sne+PRODINS+enam;
475 for (ne=1; MoreNeighbours(); NextNeighbour(),ne++) {
476 const TopoDS_Shape& N = Neighbour();
477 sne=sne+" "+SNameori(N);
479 sne=sne+"; wclick; #draw";
484 Standard_Integer ism,nsm=mySubShapeMap.Extent();
485 cout<<"#Incident shapes : ";if (!nsm) cout<<0;cout<<endl;
486 for (i=1,ism=1;ism<=nsm;ism++,i++) {
487 const TopoDS_Shape& v = mySubShapeMap.FindKey(ism);
488 const TopTools_ListOfShape& lsv = mySubShapeMap.FindFromIndex(ism);
489 TopTools_ListIteratorOfListOfShape itle(lsv);
491 TCollection_AsciiString vnam = SName(v);
492 TCollection_AsciiString sle("clear; ");sle=sle+PRODINS+vnam;
493 for (j=1;itle.More();itle.Next(),j++) {
494 const TopoDS_Shape& e = itle.Value();
495 sle=sle+" "+SNameori(e);
497 sle=sle+"; wclick; #draw";
501 DumpName(cout,"DumpSS end ");
505 //=======================================================================
508 //=======================================================================
509 void TopOpeBRepBuild_ShapeSet::DumpBB()
512 DumpName(cout,"\nDumpBB ");
513 TopTools_ListIteratorOfListOfShape it;
514 Standard_Integer i,j,ne = 0, nb = 1, curr, currloc;
515 TCollection_AsciiString s1(" "),stt,enam,nnam,vnam;
518 cout<<endl<<"#Shapes : (block old) ";if (!MoreShapes()) cout<<0;cout<<endl;
519 for (i=1;MoreShapes();NextShape(),i++, nb++) {
520 cout<<"Block number"<<nb<<" (old)."<<endl;
521 const TopoDS_Shape& e = Shape();
522 TopoDS_Iterator ShapIter(e);
523 for(ne = 1;ShapIter.More();ShapIter.Next(), ne++) {
524 const TopoDS_Shape& subsha = ShapIter.Value();
525 TestTopOpeDraw_TTOT::ShapeEnumToString(subsha.ShapeType(),stt);
526 enam = stt+ne+"ShaB"+nb;
527 DBRep::Set(enam.ToCString(),subsha);
528 cout<<"clear; "<<PRODINS<<enam<<"; #draw"<<endl;
533 TopTools_IndexedMapOfShape mos;
534 cout<<"#Elements : (block new) : ";if (!MoreStartElements()) cout<<0;cout<<endl;
536 for (;MoreStartElements();NextStartElement()) {
537 const TopoDS_Shape& e = StartElement();
539 if(mos.Add(e) > curr) {
540 cout<<"#Block number"<<nb<<" (new)."<<endl;
543 enam = enam+"ste"+ne+"newB"+nb;
544 DBRep::Set(enam.ToCString(),e);
545 // char* name = enam.ToCString();
546 // Handle(TestTopOpeDraw_DrawableSHA) D = new TestTopOpeDraw_DrawableSHA
547 // (e, Draw_blanc, Draw_blanc, Draw_blanc, Draw_blanc, 100., 2, 30, name, Draw_blanc);
548 // Draw::Set(name,D);
549 // cout<<"wclick; clear; "<<PRODINS<<enam<<"; #draw"<<endl;
550 while(curr < mos.Extent()) {
553 InitNeighbours(mos.FindKey(curr));
554 for (; MoreNeighbours(); NextNeighbour()) {
555 const TopoDS_Shape& N = Neighbour();
556 if(mos.Add(N) > currloc) {
558 // to know if ste or ele is displayed; start
559 const TopTools_ListOfShape& LSE = StartElements();
568 enam = enam+"ste"+ne+"newB"+nb;
569 // name = enam.ToCString();
570 // Handle(TestTopOpeDraw_DrawableSHA) Dloc =
571 // new TestTopOpeDraw_DrawableSHA
572 // (N, Draw_blanc, Draw_blanc, Draw_blanc, Draw_blanc,
573 // 100., 2, 30, name, Draw_blanc);
574 // Draw::Set(name,Dloc);
575 DBRep::Set(enam.ToCString(),N);
576 // cout<<PRODINS<<enam<<"; #draw"<<endl;
578 enam = enam+"ele"+ne+"newB"+nb;
579 DBRep::Set(enam.ToCString(),N);
580 cout<<PRODINS<<enam<<"; #draw"<<endl;
590 //=======================================================================
593 //=======================================================================
594 void TopOpeBRepBuild_ShapeSet::DEBName(const TCollection_AsciiString& N)
599 //=======================================================================
602 //=======================================================================
603 const TCollection_AsciiString& TopOpeBRepBuild_ShapeSet::DEBName() const
608 //=======================================================================
609 //function : DEBNumber
611 //=======================================================================
612 void TopOpeBRepBuild_ShapeSet::DEBNumber(const Standard_Integer I)
617 //=======================================================================
618 //function : DEBNumber
620 //=======================================================================
621 Standard_Integer TopOpeBRepBuild_ShapeSet::DEBNumber() const
626 //=======================================================================
629 //=======================================================================
631 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SName(const TopoDS_Shape& /*S*/,
632 const TCollection_AsciiString& sb,
633 const TCollection_AsciiString& sa) const
635 TCollection_AsciiString str;
638 TCollection_AsciiString WESi=myDEBName.SubString(1,1)+myDEBNumber;
640 TopAbs_ShapeEnum t = S.ShapeType();
641 TCollection_AsciiString sts;TestTopOpeDraw_TTOT::ShapeEnumToString(t,sts);
642 sts.UpperCase();str=str+sts.SubString(1,1);
643 Standard_Integer isub = mySubShapeMap.FindIndex(S);
644 Standard_Integer ista = myOMSS.FindIndex(S);
645 Standard_Integer iele = myOMES.FindIndex(S);
646 Standard_Integer isha = myOMSH.FindIndex(S);
647 if (isub) str=str+"sub"+isub;
648 if (ista) str=str+"sta"+ista;
649 else if (iele) str=str+"ele"+iele;
650 if (isha) str=str+"sha"+isha;
656 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SName(const TopoDS_Shape&,
657 const TCollection_AsciiString&,
658 const TCollection_AsciiString&) const
660 TCollection_AsciiString str;
665 //=======================================================================
666 //function : SNameori
668 //=======================================================================
670 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SNameori(const TopoDS_Shape& S,
671 const TCollection_AsciiString& sb,
672 const TCollection_AsciiString& sa) const
674 TCollection_AsciiString str;
676 TopAbs_Orientation o = S.Orientation();
677 TCollection_AsciiString sto;TestTopOpeDraw_TTOT::OrientationToString(o,sto);
678 str=str+sto.SubString(1,1);
683 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SNameori(const TopoDS_Shape&,
684 const TCollection_AsciiString&,
685 const TCollection_AsciiString&) const
687 TCollection_AsciiString str;
692 //=======================================================================
695 //=======================================================================
697 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SName(const TopTools_ListOfShape& L,
698 const TCollection_AsciiString& sb,
699 const TCollection_AsciiString& /*sa*/) const
701 TCollection_AsciiString str;
702 for (TopTools_ListIteratorOfListOfShape it(L);it.More();it.Next()) str=str+sb+SName(it.Value())+sa+" ";
706 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SName(const TopTools_ListOfShape&,
707 const TCollection_AsciiString&,
708 const TCollection_AsciiString&) const
710 TCollection_AsciiString str;
715 //=======================================================================
716 //function : SNameori
718 //=======================================================================
719 TCollection_AsciiString TopOpeBRepBuild_ShapeSet::SNameori(const TopTools_ListOfShape& /*L*/,
720 const TCollection_AsciiString& /*sb*/,
721 const TCollection_AsciiString& /*sa*/) const
723 TCollection_AsciiString str;
725 for (TopTools_ListIteratorOfListOfShape it(L);it.More();it.Next()) str=str+sb+SNameori(it.Value())+sa+" ";