Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TestTopOpe / TestTopOpe_HDSCommands.cxx
CommitLineData
7fd59977 1// File: TestTopOpe_HDSCommands.cxx
2// Created: Mon Oct 24 10:33:48 1994
3// Author: Jean Yves LEBEY
4// <jyl@bravox>
5
6#ifdef HAVE_CONFIG_H
7# include <config.h>
8#endif
9#include <TestTopOpe.hxx>
10#include <TestTopOpe_HDSDisplayer.hxx>
11#include <TestTopOpeDraw_DrawableSHA.hxx>
12#include <TestTopOpeDraw_DrawableP3D.hxx>
13#include <TestTopOpeDraw_DrawableC3D.hxx>
14#include <TestTopOpeDraw_TTOT.hxx>
15#include <TestTopOpeDraw_Displayer.hxx>
16#include <TopOpeBRepDS_connex.hxx>
17#include <TopOpeBRepDS_Point.hxx>
18#include <TopOpeBRepDS_Curve.hxx>
19#include <TopOpeBRepDS_PointIterator.hxx>
20#include <TopOpeBRepDS_PointExplorer.hxx>
21#include <TopOpeBRepDS_CurveExplorer.hxx>
22#include <TopOpeBRepDS_Explorer.hxx>
23#include <TopOpeBRepDS_TKI.hxx>
24#include <TopOpeBRepDS_Check.hxx>
25#include <TopOpeBRepDS_Dumper.hxx>
26#include <TopOpeBRepDS.hxx>
27#include <Geom_TrimmedCurve.hxx>
28#include <BRep_Tool.hxx>
29#include <TopoDS.hxx>
30#include <TopLoc_Location.hxx>
31#include <Geom_Curve.hxx>
32#include <GeomAdaptor_Curve.hxx>
33#include <GeomAbs_CurveType.hxx>
34#include <GeomAdaptor_Surface.hxx>
35#include <GeomAbs_SurfaceType.hxx>
36#include <GeomAPI_ProjectPointOnCurve.hxx>
37#include <BRepAdaptor_Curve.hxx>
38#include <TColStd_ListOfInteger.hxx>
39#include <TColStd_ListIteratorOfListOfInteger.hxx>
40#include <TopOpeBRepDS_define.hxx>
41#include <DBRep.hxx>
42#include <Draw_Appli.hxx>
43#include <DrawTrSurf_Curve.hxx>
44#include <Draw_Interpretor.hxx>
45#include <DrawTrSurf.hxx>
46
47#ifdef HAVE_STRINGS_H
48# include <strings.h>
49#endif
50
51class TSEEpar {
52public:
53 TSEEpar(const TCollection_AsciiString& s) { set(s); }
54 void set(const TCollection_AsciiString& s) {
55 miskind = misshap = misgeom = missect = misdege = misafev = misedcu = Standard_False;
56 mTK = TopOpeBRepDS_UNKNOWN; mTS = TopAbs_SHAPE;
57 char* sK = (char *)s.ToCString();
58 miskind = TestTopOpeDraw_TTOT::StringToKind(s,mTK);
59 if ( miskind ) {
60 misshap = TopOpeBRepDS::IsTopology(mTK);
61 if (misshap) mTS = TopOpeBRepDS::KindToShape(mTK);
62 else misgeom = TopOpeBRepDS::IsGeometry(mTK);
63 }
64 else if ( ! strcasecmp(sK,"s") ) {
65 misshap = Standard_True; mTS = TopAbs_SHAPE;
66 }
67 else if ( ! strcasecmp(sK,"se") ) {
68 missect = Standard_True; mTK = TopOpeBRepDS_EDGE;
69 }
70 else if ( ! strcasecmp(sK,"de") ) {
71 misdege = Standard_True; mTK = TopOpeBRepDS_EDGE;
72 }
73 else if ( ! strcasecmp(sK,"fev") ) {
74 misafev = Standard_True;
75 }
76 else if ( ! strcasecmp(sK,"ec") ) {
77 misedcu = Standard_True;
78 }
79 }
80 Standard_Boolean iskind() { return miskind;}
81 Standard_Boolean isshap() { return misshap;}
82 Standard_Boolean isgeom() { return misgeom;}
83 Standard_Boolean issect() { return missect;}
84 Standard_Boolean isdege() { return misdege;}
85 Standard_Boolean isafev() { return misafev;}
86 Standard_Boolean isedcu() { return misedcu;}
87 TopOpeBRepDS_Kind TK() {return mTK;}
88 TopAbs_ShapeEnum TS() {return mTS;}
89private:
90 Standard_Boolean miskind,misshap,misgeom,missect,misdege,misafev,misedcu;
91 TopOpeBRepDS_Kind mTK; TopAbs_ShapeEnum mTS;
92};
93
94class TDSpar : public TSEEpar {
95public:
96 TDSpar(const TCollection_AsciiString& s) : TSEEpar(s) {}
97};
98
99#define ISINTEGER(MMstr) ((strspn((MMstr),"0123456789") == strlen((MMstr))))
100
101Standard_EXPORT TestTopOpe_HDSDisplayer* PHDSD = NULL;
102Standard_EXPORT TestTopOpeDraw_Displayer* POCD = NULL;
103//Standard_IMPORT extern Standard_Integer TopOpeBRepDS_GLOBALHDSinterfselector;
104Standard_IMPORT Standard_Integer TopOpeBRepDS_GLOBALHDSinterfselector;
105
106static Standard_Boolean SFindKeep = Standard_False;
107static Standard_Boolean GFindKeep = Standard_False;
108static Standard_Boolean PrintDistancePP = Standard_False;
109static Standard_Integer SelectRankShape = 0;
110static Standard_Boolean DisOri = Standard_False;
111static Standard_Boolean TolFlag = Standard_False;
112static Standard_Real OldParFlag = -1.0;
113static Standard_Real ParFlag = -1.0;
114
115class tsee_entity {
116public:
117 Standard_Boolean myEOK;
118 TestTopOpe_HDSDisplayer* myEPHDSD;
119 Handle(TopOpeBRepDS_HDataStructure) myEHDS; TopOpeBRepDS_DataStructure *myEPDS;
120 TopOpeBRepDS_Kind myETK;TopAbs_ShapeEnum myETS;Standard_Integer myEindex;
121 Standard_Boolean myEiskind,myEisshape,myEisgeome,myEissect;
122 TCollection_AsciiString myEnamedbrep,myEnamedisp; Draw_ColorKind myEnamecolor;
123
124//JR/Hp :
125 tsee_entity() {
126// tsee_entity::tsee_entity() {
127 myEOK = Standard_False;
128 if (PHDSD == NULL) return; myEPHDSD = PHDSD;
129 myEHDS = myEPHDSD->CurrentHDS(); myEPDS = (TopOpeBRepDS_DataStructure*)&myEHDS->ChangeDS();
130 myETK = TopOpeBRepDS_UNKNOWN;myETS = TopAbs_SHAPE; myEindex = 0;
131 myEiskind = myEisshape = myEisgeome = myEissect = Standard_False;
132 myEnamedbrep = ""; myEnamedisp = ""; myEnamecolor = Draw_blanc;
133 myEOK = Standard_True;
134 }
135
136 Standard_Boolean IsP() const { return (myETK == TopOpeBRepDS_POINT); }
137 Standard_Boolean IsV() const { return (myETK == TopOpeBRepDS_VERTEX); }
138 Standard_Boolean Is0() const { return IsP() || IsV(); }
139 Standard_Integer Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI);
140 void Delete() ;
141 Standard_EXPORT virtual ~tsee_entity() {Delete() ;} ;
142 void virtual Dump() const;
143 void virtual See() = 0;
144};
145
146void tsee_entity::Delete()
147{}
148
149Standard_Integer tsee_entity::Set(Standard_Integer na,const char** a,Standard_Integer iargK,Standard_Integer iargI) {
150 myEOK = Standard_False;
151 if (iargK>=na) return 1; if (iargI>=na) return 1;
152 TCollection_AsciiString ascK = a[iargK]; myEindex = atoi(a[iargI]);
153 myEiskind = TestTopOpeDraw_TTOT::StringToKind(ascK,myETK);
154 if (!myEiskind) return 1; if (myETK == TopOpeBRepDS_UNKNOWN) return 1;
155
156 myEisshape = TopOpeBRepDS::IsTopology(myETK);
157 if (myEisshape) {
158 if ((myEindex < 1) || (myEindex > myEPDS->NbShapes())) return 0;
159 myETS = TopOpeBRepDS::KindToShape(myETK);
160 const TopoDS_Shape& S = myEPDS->Shape(myEindex);
161 if (myETS != S.ShapeType()) return 0;
162 myEPHDSD->ShapeName(myEindex,S,myEnamedbrep);
163 myEPHDSD->ShapeDisplayName(myEindex,S,myEnamedisp);
164 }
165
166 myEisgeome = TopOpeBRepDS::IsGeometry(myETK);
167 if (myEisgeome) {
168 if (IsP()) {
169 TopOpeBRepDS_PointExplorer pex(myEHDS->DS());
170 if (!pex.IsPoint(myEindex)) return 1;
171 }
172 TestTopOpeDraw_TTOT::GeometryName(myEindex,myETK,myEnamedbrep);
173 myEPHDSD->GeometryDisplayName(myEindex,myETK,myEnamedisp);
174 }
175
176 myEnamecolor = TestTopOpeDraw_TTOT::GeometryColor(myETK);
177 myEOK = Standard_True;
178 return 0;
179}
180
181void tsee_entity::Dump() const {
182 TopOpeBRepDS_Dumper Dumper(myEHDS);
183 if (myEisgeome) Dumper.DumpGeometry(myETK,myEindex,cout);
184 if (myEisshape) Dumper.DumpTopology(myETK,myEindex,cout);
185}
186
187class tsee_entity0 : public tsee_entity {
188public:
189
190 gp_Pnt Pnt() const;
191 void See();
192
193};
194
195gp_Pnt tsee_entity0::Pnt() const
196{
197 if (!Is0()) Standard_Failure("not 0d");
198 gp_Pnt P;
199 if (IsP()) P = myEPDS->Point(myEindex).Point();
200 else if (IsV()) P = BRep_Tool::Pnt(TopoDS::Vertex(myEPDS->Shape(myEindex)));
201 return P;
202}
203
204static void SetPoint
205(const TCollection_AsciiString& namedbrep,const TCollection_AsciiString& namedisp,const Draw_Color& namecolor,const TopOpeBRepDS_Point& P)
206{
207 Handle(TestTopOpeDraw_DrawableP3D) D;
208 if(TolFlag) {
209 D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_CircleZoom,namecolor,
210 namedisp.ToCString(),namecolor,
211 P.Tolerance());
212 } else {
213 D = new TestTopOpeDraw_DrawableP3D(P.Point(),Draw_Square,namecolor,
214 namedisp.ToCString(),namecolor);
215 }
216 char *pname = (char *)namedbrep.ToCString();
217 Draw::Set(pname,Handle(Draw_Marker3D)::DownCast(D));
218
219}
220void tsee_entity0::See()
221{
222 if (IsP()) ::SetPoint(myEnamedbrep,myEnamedisp,myEnamecolor,myEPDS->Point(myEindex));
223 if (IsV()) POCD->DisplayShape(myEnamedbrep,myEnamedisp,myEPDS->Shape(myEindex));
224}
225
226//-----------------------------------------------
227static void SetCurve
228//-----------------------------------------------
229(const TCollection_AsciiString& namedbrep,
230 const TCollection_AsciiString& namedisp,
231 const Draw_Color& namecolor,
232 const TopOpeBRepDS_Curve& DSC,
233 const Standard_Integer iC)
234{
235 if ( !PHDSD ) return;
236 const Handle(Geom_Curve) GC = DSC.Curve();
237 if ( GC.IsNull() ) { cout<<"Curve() nulle"<<endl; return; }
238
239#ifdef DEB
240 static Standard_Integer Cdiscret = 16;
241 static Standard_Real Cdeflect = 0.01;
242 static Standard_Integer Cdrawmod = 1;
243 static Standard_Boolean Cdisplayorigin = Standard_True;
244#endif
245
246 Standard_Real f = GC->FirstParameter();
247 Standard_Real l = GC->LastParameter();
248
249 GeomAdaptor_Curve GAC(GC);
250 GeomAbs_CurveType GACt = GAC.GetType();
251 if ( GACt == GeomAbs_Line ) {
252 Standard_Real fline = RealLast(),lline = RealFirst();
253 Standard_Integer imother = DSC.Mother(),igood;
254 if(imother) igood = imother;
255 else igood = iC;
256 TopOpeBRepDS_PointIterator it = PHDSD->CurrentHDS()->CurvePoints(igood);
257 for(; it.More(); it.Next()) {
258 Standard_Real p = it.Parameter();
259 fline = Min(fline,p); lline = Max(fline,p);
260 }
261 f = fline;
262 l = lline;
263 }
264
265 Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l);
266 Handle(TestTopOpeDraw_DrawableC3D) D;
267 D = new TestTopOpeDraw_DrawableC3D(GTC,namecolor,namedisp.ToCString(),namecolor);
268 char *pname = (char *)namedbrep.ToCString();
269 Draw::Set(pname,Handle(DrawTrSurf_Curve)::DownCast(D));
270}
271
272static TopoDS_Shape bidbid;
273static const TopoDS_Shape& GetShape(const Standard_Integer IS,const TopAbs_ShapeEnum TS)
274{
275 Standard_Boolean TypeControl = Standard_True;
276 if ( !PHDSD ) return bidbid;
277
278 static TopoDS_Shape ShapeNull;
279 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
280
281 // check on shape index and on shape kind if kind differs from TopAbs_SHAPE
282 Standard_Integer ns = BDS.NbShapes();
283 if ( IS < 1 || IS > ns) {
284 TopAbs::Print(TS,cout);cout<<" "<<IS<<" does not exist in DS"<<endl;
285 return ShapeNull;
286 }
287 else if ( !PHDSD->ShapeKind(IS,TS) ) {
288 if ( TypeControl ) {
289 cout<<"Shape "<<IS;
290 cout<<" is not a ";TopAbs::Print(TS,cout);
291 cout<<" but a "; TopAbs::Print(BDS.Shape(IS,SFindKeep).ShapeType(),cout);
292 cout<<endl;
293 }
294 return ShapeNull;
295 }
296
297 const TopoDS_Shape& S = BDS.Shape(IS,SFindKeep);
298 return S;
299}
300
301static const TopoDS_Shape& GetShape(const Standard_Integer IS)
302{
303 if ( !PHDSD ) return bidbid;
304 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
305 const TopoDS_Shape& S = BDS.Shape(IS);
306 return S;
307}
308
309#ifdef DEB
310static const TopoDS_Shape& GetShapeSameDomain
311(const Standard_Integer IS,const TopAbs_ShapeEnum TS,const TCollection_AsciiString& pre = "");
312
313//-----------------------------------------------------------------------
314// GetShapeSameDomain IS = shape index,TS = shape kind
315//-----------------------------------------------------------------------
316static const TopoDS_Shape& GetShapeSameDomain(const Standard_Integer IS,const TopAbs_ShapeEnum TS,const TCollection_AsciiString& pre)
317{
318 Standard_Boolean TypeControl = Standard_True;
319 if ( !PHDSD ) return bidbid;
320
321 static TopoDS_Shape ShapeNull;
322 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
323 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
324
325 // check on shape index and on shape kind if kind differs from TopAbs_SHAPE
326 Standard_Integer ns = BDS.NbShapes();
327 if ( IS < 1 || IS > ns) {
328 TopAbs::Print(TS,cout);cout<<" "<<IS<<" does not exist in DS"<<endl;
329 return ShapeNull;
330 }
331 else if ( !PHDSD->ShapeKind(IS,TS) ) {
332 if ( TypeControl ) {
333 cout<<"Shape "<<IS<<" is not a ";TopAbs::Print(TS,cout);
334 cout<<" but a ";TopAbs::Print(BDS.Shape(IS,SFindKeep).ShapeType(),cout);
335 cout<<endl;
336 }
337 return ShapeNull;
338 }
339 else if ( !HDS->HasSameDomain(HDS->Shape(IS,SFindKeep)) ) {
340 if ( TypeControl ) cout<<"Shape "<<IS<<" is not HasSameDomain"<<endl;
341 return ShapeNull;
342 }
343
344 // shape index <IS> ok : get shape <S> of index <IS>
345 const TopoDS_Shape& S = BDS.Shape(IS,SFindKeep);
346 TopOpeBRepDS_Dumper Dumper(HDS);
347 TCollection_AsciiString sse = Dumper.SPrintShape(S);
348 TCollection_AsciiString sor = TopOpeBRepDS::SPrint(S.Orientation());
349 TCollection_AsciiString str;str=str+pre+sse+" is "+sor+"\n";
350 cout<<str;cout.flush();
351
352 return S;
353}
354#endif
355
356//-----------------------------------------------------------------------
357// SeeSectionEdge
358//-----------------------------------------------------------------------
359static Standard_Integer SeeSectionEdge(const Standard_Integer ISE)
360{
361 if ( !PHDSD || !POCD ) return 0;
362
363 Standard_Integer nse = PHDSD->CurrentBDS().NbSectionEdges();
364 if ( ISE < 1 || ISE > nse ) return 0;
365 const TopoDS_Shape& SE = PHDSD->CurrentBDS().SectionEdge(ISE);
366 if (SE.IsNull()) return 0;
367#ifdef DEB
368 Standard_Integer ids =
369#endif
370 PHDSD->CurrentBDS().Shape(SE,SFindKeep);
371
372 TCollection_AsciiString namedbrep; PHDSD->SectionEdgeName(ISE,SE,namedbrep);
373 TCollection_AsciiString namedisp; PHDSD->SectionEdgeDisplayName(ISE,SE,namedisp);
374 POCD->DisplayGeometry(Standard_True);
375 POCD->DisplayShape(namedbrep,namedisp,SE);
376 return 0;
377}
378
379//-----------------------------------------------------------------------
380// SeeShapeIS
381//-----------------------------------------------------------------------
382Standard_Integer SeeShapeIS(const Standard_Integer I,const TopoDS_Shape& S)
383{
384 if ( !PHDSD || !POCD) return 0;
385
386 if (S.IsNull()) return 0;
387 TCollection_AsciiString namedbrep; PHDSD->ShapeName(I,S,namedbrep);
388 TCollection_AsciiString namedisp = namedbrep;
389 // NameDisplay = *name/name* if S subshape of shape1/shape2
390 TCollection_AsciiString ast = "*";
391 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
392 // if the Shape was removed from the DS, "*" is replaced by "~"
393 if(!BDS.HasShape(S))
394 ast = "~";
395 Standard_Boolean of1 = PHDSD->SubShape(S,1);if(of1) namedisp = ast+namedisp;
396 Standard_Boolean of2 = PHDSD->SubShape(S,2);if(of2) namedisp = namedisp+ast;
397 if (SelectRankShape == 1 && !of1) return 0;
398 if (SelectRankShape == 2 && !of2) return 0;
399
400 if (S.ShapeType()==TopAbs_EDGE) POCD->DisplayGeometry(Standard_True);
401 else POCD->DisplayGeometry(DisOri);
402 if((S.ShapeType()==TopAbs_VERTEX) && TolFlag) {
403 const TopoDS_Vertex& V = TopoDS::Vertex(S);
404 Standard_Real Tol = BRep_Tool::Tolerance(V);
405 POCD->SetTol(Tol);
406 }
407 POCD->DisplayShape(namedbrep,namedisp,S);
408
409 return 0;
410}
411
412
413//-----------------------------------------------------------------------
414// SeeShape
415//-----------------------------------------------------------------------
416static Standard_Integer SeeShape(TCollection_AsciiString namedbrep)
417{
418 if ( !PHDSD || !POCD ) return 0;
419
420 const char* pname = (const char *)namedbrep.ToCString();
421 TopoDS_Shape S = DBRep::Get(pname);
422 if ( S.IsNull() ) return 0;
423 TCollection_AsciiString namedisp;
424 PHDSD->ShapeDisplayName(namedbrep,S,namedisp);
425 POCD->DisplayShape(namedbrep,namedisp,S);
426 return 0;
427}
428
429//-----------------------------------------------------------------------
430// SeePoint
431//-----------------------------------------------------------------------
432static Standard_Integer SeePoint(const Standard_Integer I)
433{
434 if ( !PHDSD ) return 0;
435
436 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
437 if (I < 1 || I > BDS.NbPoints()) return 0;
438
439 TopOpeBRepDS_PointExplorer pex(BDS);
440 Standard_Boolean isp = pex.IsPoint(I);
441 if (!isp) return 0;
442
443 const TopOpeBRepDS_Point& P = BDS.Point(I);
444 TopOpeBRepDS_Kind K = TopOpeBRepDS_POINT;
445 TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
446 TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
447 Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
448 SetPoint(namedbrep,namedisp,namecolor,P);
449 return 0;
450}
451
452//-----------------------------------------------------------------------
453// SeeCurve
454//-----------------------------------------------------------------------
455static Standard_Integer SeeCurve(const Standard_Integer I)
456{
457 if ( !PHDSD ) return 0;
458
459 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
460 if (I < 1 || I > BDS.NbCurves()) return 0;
461
462 TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
463 Standard_Boolean isc = cex.IsCurve(I);
464 if (!isc) return 0;
465
466 const TopOpeBRepDS_Curve& C = BDS.Curve(I);
467 TopOpeBRepDS_Kind K = TopOpeBRepDS_CURVE;
468 TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
469 TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
470 Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
471 SetCurve(namedbrep,namedisp,namecolor,C,I);
472 return 0;
473}
474
475
476//-----------------------------------------------------------------------
477// SeeSurface NYI
478//-----------------------------------------------------------------------
479Standard_Integer SeeSurface(const Standard_Integer I) // NYI
480{
481 if ( !PHDSD ) return 0;
482
483 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
484 if (I < 1 || I > BDS.NbSurfaces()) return 0;
485 return 0;
486}
487
488//-----------------------------------------------------------------------
489// SeeEdgeCurve
490//-----------------------------------------------------------------------
491static Standard_Integer SeeEdgeCurve(const Standard_Integer IE,const TopoDS_Shape& SE)
492{
493 if ( !POCD ) return 0;
494
495 if (SE.IsNull()) return 0;
496 const TopoDS_Edge& E = TopoDS::Edge(SE);
497 TopLoc_Location L;Standard_Real f,l;Handle(Geom_Curve) GC=BRep_Tool::Curve(E,L,f,l);
498 TCollection_AsciiString namedbrep="E";TestTopOpeDraw_TTOT::CatCurveName(IE,namedbrep);
499 TCollection_AsciiString namedisp="E";TestTopOpeDraw_TTOT::CatCurveDisplayName(IE,GC,namedisp);
500 POCD->DisplayGeometry(Standard_True);
501 POCD->DisplayShape(namedbrep,namedisp,SE);
502 return 0;
503}
504
505//-----------------------------------------------------------------------
506// SeeGeometry
507//-----------------------------------------------------------------------
508static Standard_Integer SeeGeometry(const Standard_Integer IG,const TopOpeBRepDS_Kind TK)
509{
510 if (TK == TopOpeBRepDS_POINT) return SeePoint(IG);
511 else if (TK == TopOpeBRepDS_CURVE) return SeeCurve(IG);
512 else if (TK == TopOpeBRepDS_SURFACE) return SeeSurface(IG);
513 return 0;
514}
515
516//-----------------------------------------------------------------------
517// SeeGeometry
518//-----------------------------------------------------------------------
519// Unused :
520#ifdef DEB
521static Standard_Integer SeeGeometry(const tsee_entity& E)
522{
523 if (!E.myEOK) return 0;
524 return SeeGeometry(E.myEindex,E.myETK);
525}
526#endif
527
528//-----------------------------------------------------------------------
529// SeeGeometry
530//-----------------------------------------------------------------------
531static Standard_Integer SeeGeometry(const TopOpeBRepDS_Kind TK)
532{
533 if ( !PHDSD ) return 0;
534
535 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
536
537#ifdef DEB
538 Standard_Integer ig,ng = 0;
539#endif
540 if (TK == TopOpeBRepDS_POINT) {
541 TopOpeBRepDS_PointExplorer pex(BDS,GFindKeep);
542 for (; pex.More(); pex.Next()) {
543 Standard_Integer ig = pex.Index();
544 SeeGeometry(ig,TK);
545 }
546 }
547 else if (TK == TopOpeBRepDS_CURVE) {
548 TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
549 for (; cex.More(); cex.Next()) {
550 Standard_Integer ig = cex.Index();
551 SeeGeometry(ig,TK);
552 }
553 }
554 else if (TK == TopOpeBRepDS_SURFACE) { //NYI
555 }
556 return 0;
557}
558
559//-----------------------------------------------------------------------
560// TOPOPE_SeeShape
561//-----------------------------------------------------------------------
562Standard_Integer TOPOPE_SeeShape(char* name)
563{
564 TCollection_AsciiString asc = name;
565 Standard_Integer res = SeeShape(asc);
566 return res;
567}
568
569//-----------------------------------------------------------------------
570// decalargs : shift a[*] from <-d>,modify na = na - deca
571//-----------------------------------------------------------------------
572// Unused :
573#ifdef DEB
574static void decalargs(Standard_Integer& na,const char** a,const Standard_Integer d)
575{for(Standard_Integer i=1;i<na;i++)a[i]=a[i+d];na-=d;}
576#endif
577
578//-----------------------------------------------------------------------
579// suppressarg : remove a[d],modify na--
580//-----------------------------------------------------------------------
581Standard_EXPORT void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
582{
583 for(Standard_Integer i=d;i<na;i++) {
584 a[i]=a[i+1];
585 a[i+1]=NULL;
586 }
587 na--;
588}
589
590//-----------------------------------------------------------------------
591// suppressargs : remove a[*] from <f> to <l>,modify na = na - (l - f)
592//-----------------------------------------------------------------------
593Standard_EXPORT void suppressargs(Standard_Integer& na,const char** a,const Standard_Integer f,const Standard_Integer l)
594{
595 if(l == f)
596 suppressarg(na,a,l);
597 if(l <= f) return;
598 for(Standard_Integer i=0;i<na-l;i++) {
599 a[i+f]=a[i+l+1];
600 a[i+l+1]=NULL;
601 }
602 na -= l-f+1;
603}
604
605//-----------------------------------------------------------------------
606// SetTolFlag
607//-----------------------------------------------------------------------
608// Unused :
609#ifdef DEB
610static Standard_Boolean SetTolFlag(Standard_Integer& na,const char** a) { decalargs(na,a,1); return Standard_True; }
611#endif
612
613//-----------------------------------------------------------------------
614// tsee_flags
615//-----------------------------------------------------------------------
616static void tsee_flags(Standard_Integer& na,const char** a) {
617 GFindKeep = Standard_False;
618 PrintDistancePP = Standard_False;
619 SelectRankShape = 0;
620
621 for (Standard_Integer ia = 1; ia < na; ia++) {
622 if (!strcasecmp(a[ia],"-k")) {
623 suppressarg(na,a,ia);
624 GFindKeep = Standard_True;
625 }
626 else if (!strcasecmp(a[ia],"-d")) {
627 // tsee -d p 4 7 : display p_4,p_7 + tds p 4 7 + calculate distance (p_4,p_7)
628 suppressarg(na,a,ia);
629 PrintDistancePP = Standard_True;
630 }
631 else if (!strcasecmp(a[ia],"-1")) {
632 // tsee -1 s 4 : display s_4 <=> s_4 is subshape of the 1st argument
633 suppressarg(na,a,ia);
634 SelectRankShape = 1;
635 }
636 else if (!strcasecmp(a[ia],"-2")) {
637 // tsee -2 s 4 : display s_4 <=> s_4 is subshape of the 2nd argument
638 suppressarg(na,a,ia);
639 SelectRankShape = 2;
640 }
641 else if (!strcasecmp(a[ia],"-p") && (ia < na-1)) {
642 suppressargs(na,a,ia,ia+1);
643 Standard_Real t = atof(a[ia+1]);
644 if (t >= 0. && t <= 1.) {
645 OldParFlag = ParFlag; ParFlag = t;
646 }
647 }
648 }
649}
650
651void OthersCommands_help(const char* CommandName,const char* syntaxe = "");
652//-----------------------------------------------------------------------
653// tsee_help
654//-----------------------------------------------------------------------
655static void tsee_help(const char* CommandName, Draw_Interpretor& di)
656{
657 di<<""<<"\n";
658 di<<"tsee : Draw entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
659 di<<"DS entities are shapes and geometries accessed by a <type> and an <index>."<<"\n";
660 di<<"basic usage :"<<"\n";
661 di<<" tsee <type> <index1 index2 ...>"<<"\n";
662 di<<"<type> = so sh f w e v s for solid/shell/face/wire/edge/vertex/shape"<<"\n";
663 di<<" su cu p for surface/curve/point (N.B : su is NYI)"<<"\n";
664 di<<"<index> = integer"<<"\n";
665 di<<"example : 'tsee e 3' will draw the edge of index 3"<<"\n";
666 di<<" 'tsee e 3 6' will draw the edges of index 3 and 6"<<"\n";
667 di<<" 'tsee e' will draw all the edges."<<"\n";
668 di<<""<<"\n";
669 di<<"Index values of DS entities may be given by the 'tds' command which prints"<<"\n";
670 di<<"the content of the DS for each shape and geometry type."<<"\n";
671 di<<"Entities are drawn with a specific color according to their type."<<"\n";
672 di<<""<<"\n";
673 di<<"Naming : "<<"\n";
674 di<<"'tsee <t> <i>' creates the drawable object named <t>_<i>."<<"\n";
675 di<<"This name is displayed near the entity in one if the forms : "<<"\n";
676 di<<" *<t>_<i> meaning entity belongs to the first shape of current operation."<<"\n";
677 di<<" <t>_<i>* meaning entity belongs to the second shape of current operation."<<"\n";
678 di<<""<<"\n";
679 di<<"Same Domain shapes : "<<"\n";
680 di<<"'tsee <type> sd' to display all shapes of <type> having same domain data."<<"\n";
681 di<<"example : 'tsee e sd' to display all edges sharing a 1d geometric domain"<<"\n";
682 di<<" with other edges."<<"\n";
683 di<<""<<"\n";
684 di<<"Optional flags :"<<"\n";
685 OthersCommands_help(CommandName);
686 di<<"Other types :"<<"\n";
687 di<<"'tsee fev' : displays all faces,then edges,then vertices."<<"\n";
688 di<<"'tsee es <i>' displays edge described as section edge <i>."<<"\n";
689 di<<" The name of a section edge likes t_i<j>,where :"<<"\n";
690 di<<" - i is the edge index in the set of section edge,"<<"\n";
691 di<<" - j is edge index in the DS (as any edge)."<<"\n";
692 di<<""<<"\n";
693}
694
695static void tseei_help(Draw_Interpretor& di)
696{
697 di<<""<<"\n";
698 di<<"tseei : Draws entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
699 di<<"Draws the objects appearing in interferences DS objects."<<"\n";
700 di<<"See command 'tsee' for discussion about DS objects."<<"\n";
701 di<<"\n";
702}
703
704static void tki_help(Draw_Interpretor& di)
705{
706 di<<""<<"\n";
707 di<<"tki,tkig,tkis : Groups interferences of DS objects"<<"\n";
708 di<<" by geometry (g),or support (s),and index."<<"\n";
709 di<<"See command 'tsee' for discussion about DS objects."<<"\n";
710 di<<"(Test of class TopOpeBRepDS_TKI)"<<"\n";
711 di<<"\n";
712}
713
714static void tds_help(Draw_Interpretor& di)
715{
716 di<<""<<"\n";
717 di<<"tds : dump current DS (loaded by CurrentDS())"<<"\n";
718 di<<"basic usage : tds <-arg> type <index1 index2 ...>"<<"\n";
719 di<<"\n";
720 di<<"Description of curve geometry (type = c) : <-arg> = -t -k -s -l"<<"\n";
721 di<<"\t-k : print only the curve with keep = Standard_True"<<"\n";
722 di<<"\t-l : (long) print all poles and knots for BSplines curves"<<"\n";
723 di<<"\t-s : (short) print only 4 poles and 4 knots for BSplines curves"<<"\n";
724 di<<"on shapes (type = s|so|sh|f|w|e|v) : <-arg> = -ssi"<<"\n";
725 di<<"\t-ssi : print only ShapeShapeInterferences"<<"\n";
726 di<<""<<"\n";
727 di<<"See command 'tsee' for discussion about type and <index1 index2 ...>."<<"\n";
728 di<<"\n";
729}
730
731typedef Standard_Integer (*tf_SeeShape)(const Standard_Integer I,const TopoDS_Shape& S);
732Standard_IMPORT void OthersCommands_flags(Standard_Integer& na,const char** a,TestTopOpeDraw_Displayer& TD);
733void COUTNOHDS(Draw_Interpretor& di) {di<<"no current HDS"<<"\n";}
734Standard_Integer tsee_SeeShapefunc(Draw_Interpretor& di,Standard_Integer na_in,const char** a,tf_SeeShape SeeShapefunc)
735{
736 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
737 tsee_help(a[0], di);
738 return 0;
739 }
740
741 Standard_Integer na = na_in;
742 if ((PHDSD == NULL) || (POCD == NULL)) return 0;
743
744 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
745 if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
746 if (na < 2) return 1;
747 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
748
749 POCD->InitDisplayer();
750 TolFlag = Standard_False;
751 tsee_flags(na,a);
752 OthersCommands_flags(na,a,*POCD);
753 TolFlag = POCD->TolIs();
754 DisOri = POCD->DisplayGeometry();
755
756 Standard_Integer i1arg = 1;
757 TSEEpar Tpar(a[i1arg]);
758
759// Standard_Integer ia,is,ig;
760 Standard_Integer ia,is;
761
762 if ( PrintDistancePP ) {
763 tsee_entity0 E1,E2;
764 if (na == 4) { // tsee p 3 4
765 if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
766 if (E2.Set(na,a,i1arg+0,i1arg+2)) return 1;
767 }
768 else if (na == 5) { // tsee p 3 v 4
769 if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
770 if (E2.Set(na,a,i1arg+2,i1arg+3)) return 1;
771 }
772 if (!E1.myEOK || !E2.myEOK) return 1;
773
774 E1.See();E2.See();
775 E1.Dump();E2.Dump();
776 di<<"Distance "<<E1.myEnamedbrep.ToCString()<<" "<<E2.myEnamedbrep.ToCString()<<" : "<<E1.Pnt().Distance(E2.Pnt())<<"\n";
777
778 } // PrintDistancePP
779
780 else if ( Tpar.isshap() ) {
781 // na == 2 : display all DS shapes of type TS
782 // na > 2 : display DS shapes of type TS of index atoi(a[2]..a[narg-1])
783 if (na == 2 ) {
784 TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
785 for(;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
786 }
787 else {
788 if ( !strcmp(a[i1arg+1],"sd") ) { // shapes HasSameDomain of type TS
789 TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
790 for (;x.More();x.Next()) {
791 Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
792 if (isSsd ) (*SeeShapefunc)(x.Index(),x.Current());
793 }
794 }
795 else if (Tpar.isshap() && (Tpar.TS() == TopAbs_EDGE) && (na>=2) && POCD->ParIs()) {
796 // see edges [4..na[ with of the name in t in [0..1] / range
797 if (na == 2) {
798 TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
799 for (;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
800 }
801 else {
802 for (ia = i1arg+1; ia < na; ia++) {
803 is = atoi(a[ia]);
804 (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
805 }
806 }
807 ParFlag = OldParFlag;
808 }
809 else {
810 for (ia = i1arg+1; ia < na; ia++) {
811 is = atoi(a[ia]);
812 (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
813 }
814 }
815 }
816 } // isshap
817
818 else if ( Tpar.isgeom() ) {
819 // na == 2 : display all DS geometries of type TK
820 // na > 2 : display DS geometries of type TK index atoi(a[2])..a[narg-1])
821 if (na == 2 ) SeeGeometry(Tpar.TK());
822 else for (ia = i1arg+1; ia < na; ia++) SeeGeometry(Standard_Integer(atoi(a[ia])),Tpar.TK());
823 }
824
825 else if ( Tpar.isafev() ) {
826 // faces then edges then vertices
827 TopOpeBRepDS_Explorer x;
828 for (x.Init(HDS,TopAbs_FACE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
829 for (x.Init(HDS,TopAbs_EDGE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
830 for (x.Init(HDS,TopAbs_VERTEX,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
831 }
832
833 else if ( Tpar.isedcu() ) {
834 // na == 2 : display curves of all DS edges
835 // na > 2 : display curve of DS edges index atoi(a[2])..a[narg-1])
836 if ( na == 2 ) {
837 TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
838 for (;x.More();x.Next()) SeeEdgeCurve(x.Index(),x.Edge());
839 }
840 else {
841 for (ia = i1arg+1; ia < na; ia++) {
842 is = atoi(a[ia]);
843 SeeEdgeCurve(is,GetShape(is,TopAbs_EDGE));
844 }
845 }
846 }
847
848 else if ( Tpar.issect() ) { // na=2 all section edges,na>2 section edges (a[2]..a[na-1])
849 Standard_Integer ise,nse = BDS.NbSectionEdges();
850 if (na == 2) for (ise = 1; ise<=nse; ise++) SeeSectionEdge(ise);
851 else for (ia = i1arg+1; ia<na; ia++) SeeSectionEdge(atoi(a[ia]));
852 }
853
854 else if (Tpar.isdege()) {
855 TopOpeBRepDS_Explorer x;
856 for (x.Init(HDS,TopAbs_EDGE);x.More();x.Next()) {
857 if (BRep_Tool::Degenerated(x.Edge())) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
858 }
859 }
860
861 return 0;
862} // tsee_SeeShapefunc
863
864//-----------------------------------------------------------------------
865// tsee
866//-----------------------------------------------------------------------
867Standard_Integer tsee(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
868{
869 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
870 tsee_help(a[0],di);
871 return 0;
872 }
873 tf_SeeShape ssf = (tf_SeeShape)SeeShapeIS;
874 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
875 return r;
876} // tsee
877
878//-----------------------------------------------------------------------
879// SeeAnyKI
880//-----------------------------------------------------------------------
881Standard_Integer SeeAnyKI(const TopOpeBRepDS_Kind TK,const Standard_Integer I) {
882#ifndef DEB
883 TopAbs_ShapeEnum TS = TopAbs_COMPOUND;
884#else
885 TopAbs_ShapeEnum TS;
886#endif
887 Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
888 isshape = TopOpeBRepDS::IsTopology(TK);
889 if (isshape) TS = TopOpeBRepDS::KindToShape(TK);
890 else isgeome = TopOpeBRepDS::IsGeometry(TK);
891 if (isshape) SeeShapeIS(I,GetShape(I,TS));
892 else if (isgeome) SeeGeometry(I,TK);
893 return 0;
894}
895
896//-----------------------------------------------------------------------
897void AddShapeKI
898//-----------------------------------------------------------------------
899(TColStd_ListOfInteger& LOK,TColStd_ListOfInteger& LOI,
900 const TopOpeBRepDS_Kind K,const Standard_Integer I)
901{
902 TopAbs_ShapeEnum TS;
903 Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
904 isshape = TopOpeBRepDS::IsTopology(K);
905 if (isshape) TS = TopOpeBRepDS::KindToShape(K);
906 else isgeome = TopOpeBRepDS::IsGeometry(K);
907
908 if (LOK.IsEmpty() && LOI.IsEmpty()) {
909 LOK.Append((Standard_Integer)K); LOI.Append(I);
910 return;
911 }
912
913 // to sort, it is considered that :
914 // POINT == VERTEX,CURVE == EDGE,SURFACE == FACE
915
916#ifdef DEB
917 TopAbs_ShapeEnum SKtri;
918#else
919 TopAbs_ShapeEnum SKtri=TopAbs_COMPOUND;
920#endif
921 if (isshape) SKtri = TopOpeBRepDS::KindToShape(K);
922 else if (isgeome) {
923 if (K == TopOpeBRepDS_POINT) SKtri = TopAbs_VERTEX;
924 else if (K == TopOpeBRepDS_CURVE) SKtri = TopAbs_EDGE;
925 else if (K == TopOpeBRepDS_SURFACE) SKtri = TopAbs_FACE;
926 }
927 else return;
928
929 TColStd_ListIteratorOfListOfInteger ITLOK(LOK);
930 TColStd_ListIteratorOfListOfInteger ITLOI(LOI);
931 Standard_Boolean equa = Standard_False;
932 for (; ITLOK.More(),ITLOI.More(); ITLOK.Next(),ITLOI.Next()) {
933//JR/Hp
934 Standard_Integer ifK = ITLOK.Value() ;
935 TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind) ifK ;
936 TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
937// TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind)ITLOK.Value(); TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
938 Standard_Integer fI = ITLOI.Value();
939 if (SKtri == fSK && I == fI) {
940 equa = Standard_True;
941 break;
942 }
943 if (SKtri <= fSK) {
944 LOK.InsertBefore((Standard_Integer)K,ITLOK);
945 LOI.InsertBefore(I,ITLOI);
946 break;
947 }
948 }
949 if ( !ITLOK.More() && !equa) {
950 LOK.Append((Standard_Integer)K);
951 LOI.Append(I);
952 }
953}
954
955//-----------------------------------------------------------------------
956// SeeShapeISI
957//-----------------------------------------------------------------------
958Standard_Integer SeeShapeISI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
959{
960 if ( !PHDSD ) return 0;
961 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
962 if (S.IsNull()) return 0;
963 SeeShapeIS(I,S);
964
965 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
966 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
967 const TopOpeBRepDS_ListOfInterference& LOI = BDS.ShapeInterferences(S);
968 TopOpeBRepDS_ListIteratorOfListOfInterference ITLOI(LOI);
969 TColStd_ListOfInteger LOKK,LOII;
970
971 for (;ITLOI.More();ITLOI.Next()) {
972 const Handle(TopOpeBRepDS_Interference)& HI = ITLOI.Value();
973 const TopOpeBRepDS_Transition& T = HI->Transition();
974
975 TopAbs_ShapeEnum sb = T.ShapeBefore();TopOpeBRepDS_Kind sbk = TopOpeBRepDS::ShapeToKind(sb);
976 Standard_Integer sbi = T.IndexBefore();
977 TopAbs_ShapeEnum sa = T.ShapeAfter();TopOpeBRepDS_Kind sak = TopOpeBRepDS::ShapeToKind(sa);
978 Standard_Integer sai = T.IndexAfter();
979 TopOpeBRepDS_Kind gk,sk; Standard_Integer gi,si; HI->GKGSKS(gk,gi,sk,si);
980
981 AddShapeKI(LOKK,LOII,sbk,sbi);
982 AddShapeKI(LOKK,LOII,sak,sai);
983 AddShapeKI(LOKK,LOII,gk,gi);
984 AddShapeKI(LOKK,LOII,sk,si);
985 }
986
987 TColStd_ListIteratorOfListOfInteger ITLOKK,ITLOII;
988
989 ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
990 Standard_Boolean ya = ITLOKK.More();
991 TopOpeBRepDS::Print(SK,I,cout,""," : ");
992 for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
993//JR/Hp
994 Standard_Integer ikk = ITLOKK.Value() ;
995 TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
996 Standard_Integer ii = ITLOII.Value();
997// TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
998 TopOpeBRepDS::Print(kk,ii,cout,""," ");
999 }
1000 if (ya) di<<"\n"; else di<<"no shape interference"<<"\n";
1001
1002 ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
1003 for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
1004//JR/Hp
1005 Standard_Integer ikk =ITLOKK.Value() ;
1006 TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
1007 Standard_Integer ii = ITLOII.Value();
1008// TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
1009 SeeAnyKI(kk,ii);
1010 }
1011 //POP pour WNT
1012 return 0;
1013
1014} // SeeShapeISI
1015
1016//-----------------------------------------------------------------------
1017// SeeShapeTKIG
1018//-----------------------------------------------------------------------
1019Standard_Integer SeeShapeTKIG(const Standard_Integer I,const TopoDS_Shape& S)
1020{
1021 if ( !PHDSD ) return 0;
1022 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1023 if (S.IsNull()) return 0;
1024 SeeShapeIS(I,S);
1025
1026 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
1027 const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
1028 TopOpeBRepDS_TKI tki;
1029 TCollection_AsciiString s1,s2;
1030
1031 tki.Clear();
1032 tki.FillOnGeometry(LOI);
1033 s1=TopOpeBRepDS::SPrint(SK,I,""," by G : \n");
1034 tki.Init();if (tki.More()) s2="\n";else s2="";
1035 tki.DumpTKIIterator(s1,s2);
1036
1037 return 0;
1038} // SeeShapeTKIG
1039
1040//-----------------------------------------------------------------------
1041// SeeShapeTKIS
1042//-----------------------------------------------------------------------
1043Standard_Integer SeeShapeTKIS(const Standard_Integer I,const TopoDS_Shape& S)
1044{
1045 if ( !PHDSD ) return 0;
1046 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1047 if (S.IsNull()) return 0;
1048 SeeShapeIS(I,S);
1049
1050 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
1051 const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
1052 TopOpeBRepDS_TKI tki;
1053 TCollection_AsciiString s1,s2;
1054
1055 tki.Clear();
1056 tki.FillOnSupport(LOI);
1057 s1=TopOpeBRepDS::SPrint(SK,I,""," by S : \n");
1058 tki.Init();if (tki.More()) s2="\n";else s2="";
1059 tki.DumpTKIIterator(s1,s2);
1060
1061 return 0;
1062} // SeeShapeTKIS
1063
1064//-----------------------------------------------------------------------
1065// SeeShapeTKI
1066//-----------------------------------------------------------------------
1067Standard_Integer SeeShapeTKI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
1068{
1069 di<<"\n";
1070 SeeShapeTKIG(I,S);
1071 SeeShapeTKIS(I,S);
1072 return 0;
1073} // SeeShapeTKI
1074
1075//-----------------------------------------------------------------------
1076// tseei
1077//-----------------------------------------------------------------------
1078Standard_Integer tseei(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1079{
1080 if (na_in == 1) { tseei_help(di); return 0; }
1081 tf_SeeShape ssf = (tf_SeeShape)SeeShapeISI;
1082 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
1083 return r;
1084} // tseei
1085
1086//-----------------------------------------------------------------------
1087// tki
1088//-----------------------------------------------------------------------
1089Standard_Integer tki(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1090{
1091 if (na_in == 1) { tki_help(di); return 0; }
1092
1093 tf_SeeShape ssf = NULL;
1094 if ( !strcasecmp(a[0],"tki") ) ssf = (tf_SeeShape)SeeShapeTKI;
1095 else if ( !strcasecmp(a[0],"tkig") ) ssf = (tf_SeeShape)SeeShapeTKIG;
1096 else if ( !strcasecmp(a[0],"tkis") ) ssf = (tf_SeeShape)SeeShapeTKIS;
1097 if (ssf == NULL) return 0;
1098
1099 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
1100 return r;
1101} // tki
1102
1103//-----------------------------------------------------------------------
1104// 0 = tds
1105// 1 = kind of DS object to dump = [s] [so sh f w e v] [se] [su c p]
1106// 2,3 ... = [i1,i2 ...] = indices of DS object to see
1107//-----------------------------------------------------------------------
1108Standard_Integer tds(Draw_Interpretor& di,Standard_Integer na,const char** a)
1109{
1110 Standard_Boolean TDSkeep,TDScompact; TDSkeep = TDScompact = Standard_False;
1111 TopOpeBRepDS_GLOBALHDSinterfselector = 0;
1112
1113 Standard_Integer ia ;
1114 for ( ia = 0; ia < na; ia++) {
1115 if (!strcasecmp(a[ia],"-ssi")) {
1116 TopOpeBRepDS_GLOBALHDSinterfselector = 1;
1117 suppressarg(na,a,ia);
1118 continue;
1119 }
1120 else if (!strncmp(a[ia],"-",1)) {
1121 TCollection_AsciiString as = a[ia];
1122 as.Remove(1,1);
1123 for(Standard_Integer i = 1;i <= as.Length(); i++) {
1124 if (as.Value(i) == 'k') TDSkeep = Standard_True;
1125 else if(as.Value(i) == 'l') TDScompact = Standard_False;
1126 else if(as.Value(i) == 's') TDScompact = Standard_True;
1127 else if(as.Value(i) == 'h') { tds_help(di); return 0; }
1128 }
1129 suppressarg(na,a,ia);
1130 }
1131 }
1132
1133 if (PHDSD == NULL) return 0;
1134 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1135 if (HDS.IsNull()) {COUTNOHDS(di);return 0;}
1136#ifdef DEB
1137 const TopOpeBRepDS_DataStructure& BDS =
1138#endif
1139 PHDSD->CurrentBDS();
1140
1141 TopOpeBRepDS_Dumper Dumper(HDS);
1142 if ( na == 1 ) { Dumper.Dump(cout,TDSkeep,TDScompact); return 0; }
1143
1144 TDSpar Tpar(a[1]);
1145 Standard_Integer ids;
1146
1147 if (na == 2) {
1148 if (Tpar.isshap()) {
1149 if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),cout);
1150 else Dumper.DumpTopology(cout);
1151 }
1152 else if (Tpar.isgeom()) {
1153 Dumper.DumpGeometry(Tpar.TK(),cout,TDSkeep,TDScompact);
1154 }
1155 else if (Tpar.issect()) {
1156 Dumper.DumpSectionEdge(Tpar.TK(),cout);
1157 }
1158 else if (Tpar.isafev()) {
1159 TopOpeBRepDS_Explorer x;
1160 for (x.Init(HDS,TopAbs_FACE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1161 for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1162 for (x.Init(HDS,TopAbs_VERTEX,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1163 }
1164
1165 else if (Tpar.isdege()) {
1166 TopOpeBRepDS_Explorer x;
1167 for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) {
1168 if (BRep_Tool::Degenerated(x.Edge())) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1169 }
1170 }
1171 return 0;
1172 } // (na == 2)
1173
1174 // nna > 2 : dump DS entities of type TK index atoi(a[2])..a[narg-1])
1175 for (ia = 2; ia < na; ia++) {
1176
1177 if ( !strcmp(a[ia],"sd") ) { // dump all shapes HasSameDomain of type TS
1178 for (TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);x.More();x.Next()) {
1179 Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
1180 if (isSsd ) Dumper.DumpTopology(Tpar.TK(),x.Index(),cout);
1181 }
1182 }
1183 else {
1184 ids = atoi(a[ia]);
1185 if ( Tpar.isshap() ) {
1186 if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),ids,cout);
1187 else {
1188 TopAbs_ShapeEnum t = HDS->Shape(ids,SFindKeep).ShapeType();
1189 TopOpeBRepDS_Kind k = TopOpeBRepDS::ShapeToKind(t);
1190 Dumper.DumpTopology(k,ids,cout);
1191 }
1192 }
1193 else if ( Tpar.isgeom() ) {
1194 Dumper.DumpGeometry(Tpar.TK(),ids,cout,TDSkeep,TDScompact);
1195 }
1196 else if ( Tpar.issect() ) {
1197 Dumper.DumpSectionEdge(TopOpeBRepDS_EDGE,ids,cout);
1198 }
1199 }
1200 } // ia < na
1201
1202 return 0;
1203}
1204
1205Standard_Integer TPPE(Draw_Interpretor& di,Standard_Integer na,const char** a)
1206{
1207 if (PHDSD == NULL) return 0;
1208 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1209 if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1210
1211 if (na != 5) return 1;
1212 Standard_Boolean ok = Standard_True;
1213
1214 gp_Pnt pds;
1215 TopoDS_Edge ed;
1216
1217 Standard_Integer ip = atoi(a[2]);
1218 Standard_Integer ie = atoi(a[4]);
1219 ok = ok && (ip >= 1); ok = ok && (ie >= 1);
1220 if (!ok) {
1221 di <<" bad data"<<"\n";
1222 return 1;
1223 }
1224
1225 ok = Standard_False;
1226 if (!strcmp("p",a[1])){
1227 ok = Standard_True;
1228 ok = ok && (ip <= HDS->NbPoints());
1229 if (ok) pds = HDS->Point(ip).Point();
1230 if (!ok) di<<" geometry "<<ip<<" is not a point"<<"\n";
1231 }
1232 if (!strcmp("v",a[1])){
1233 ok = Standard_True;
1234 ok = ok && (ip <= HDS->NbShapes());
1235 if (ok) {
1236 TopoDS_Shape sh = HDS->Shape(ip,SFindKeep);
1237 ok = ok && (sh.ShapeType() == TopAbs_VERTEX);
1238 if (ok) pds =BRep_Tool::Pnt(TopoDS::Vertex(sh));
1239 }
1240 if (!ok) di<<" shape "<<ip<<" is not a vertex"<<"\n";
1241 }
1242 if (!strcmp("e",a[3])){
1243 ok = ok && (ie <= HDS->NbShapes());
1244 if (ok) {
1245 TopoDS_Shape sh = HDS->Shape(ie,SFindKeep);
1246 ok = ok && (sh.ShapeType() == TopAbs_EDGE);
1247 if (ok) ed = TopoDS::Edge(sh);
1248 }
1249 if (!ok) di<<" shape "<<ie<<" is not an edge"<<"\n";
1250
1251 } else ok = Standard_False;
1252
1253 Standard_Real dmin=0;
1254 gp_Pnt pproj;
1255 if (ok) {
1256 Standard_Real f,l;
1257 Handle(Geom_Curve) cu = BRep_Tool::Curve(ed,f,l);
1258 GeomAPI_ProjectPointOnCurve ponc(pds,cu,f,l);
1259 ok = ponc.NbPoints() >= 1;
1260
1261 if (ok) {
1262 dmin = ponc.LowerDistance();
1263 Standard_Real par = ponc.LowerDistanceParameter();
1264 BRepAdaptor_Curve bc(ed);
1265 pproj = bc.Value(par);
1266 }
1267 }
1268
1269 if (ok) {
1270 TCollection_AsciiString pp("p");
1271 pp.AssignCat(ip); pp.AssignCat("e"); pp.AssignCat(ie);
1272 char* ppp = (char *)pp.ToCString();
1273 DrawTrSurf::Set(ppp,pproj);
1274 di<<"dist point "<<ip<<" on edge "<<ie<<" = "<<dmin<<"\n";
1275 } else di<<"projection failed"<<"\n";
1276
1277 return ok;
1278} // TPPE
1279
1280void FUN_ChkIntgInterf(Draw_Interpretor& di) //***Check Integrity Interference
1281{
1282 if ( PHDSD == NULL ) return;
1283 PHDSD->CurrentHDS()->ChkIntg();
1284 di<<"Check interference integrity completed"<<"\n";
1285}
1286
1287void FUN_ChkIntgSamDomain(Draw_Interpretor& di) //***Check Integrity SameDomain
1288{
1289 if ( PHDSD == NULL ) return;
1290 TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1291 if(C.ChkIntgSamDom())
1292 di<<"Check SameDomain integrity completed"<<"\n";
1293}
1294
1295void FUN_ChkIntg(Draw_Interpretor& di) //***Check Integrity
1296{
1297 if ( PHDSD == NULL ) return;
1298 FUN_ChkIntgInterf(di);
1299 FUN_ChkIntgSamDomain(di);
1300}
1301
1302void FUN_ChkVertex(Draw_Interpretor& di) //***Check Vertex SameDomain
1303{
1304 if ( PHDSD == NULL ) return;
1305 TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1306 if(C.OneVertexOnPnt())
1307 di<<"Check Structure Vertex SameDomain Complete"<<"\n";
1308}
1309
1310//---------------------------------------------------------
1311Standard_Integer topochk(Draw_Interpretor& di,Standard_Integer na,const char** a)
1312{
1313 if (strcmp(a[0],"topochk")) return 1;
1314
1315 if(na < 2) {
1316 ::FUN_ChkIntg(di);
1317 ::FUN_ChkVertex(di);
1318 }
1319 else if(na > 2) return 1;
1320 else if(!strcmp (a[1],"-i")) ::FUN_ChkIntg(di);
1321 else if(!strncmp(a[1],"-i",2)) {
1322 if (!strcmp(a[1],"-ii")) ::FUN_ChkIntgInterf(di);
1323 else if(!strcmp(a[1],"-isd")) ::FUN_ChkIntgSamDomain(di);
1324 }
1325 else if(!strcmp (a[1],"-s")) ::FUN_ChkVertex(di);
1326 else {
1327 di<<"option : -i = check DS full integrity"<<"\n";
1328 di<<"option : -ii = check only interferences"<<"\n";
1329 di<<"option : -isd = check only SameDomain data"<<"\n"<<"\n";
1330 di<<"option : -s = check only SameDomain data on vertex"<<"\n";
1331 return 1;
1332 }
1333 return 0;
1334}
1335
1336//-----------------------------------------------------------------------
1337// SeeShapeTCX
1338//-----------------------------------------------------------------------
1339Standard_Integer SeeShapeTCX(const Standard_Integer I,const TopoDS_Shape& S)
1340{
1341 if ( !PHDSD ) return 0;
1342 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1343 if (S.IsNull()) return 0;
1344 FDSCNX_Dump(HDS,I);
1345 return 0;
1346} // SeeShapeTCX
1347
1348static void tcx_help(Draw_Interpretor& di)
1349{
1350 di<<"tcx : function not documented"<<"\n";
1351}
1352
1353//-----------------------------------------------------------------------
1354// tcx
1355//-----------------------------------------------------------------------
1356Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1357{
1358 if (na_in == 1) { tcx_help(di); return 0; }
1359 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,SeeShapeTCX);
1360 return r;
1361} // tcx
1362
1363#if 0
1364//---------------------------------------------------------
1365Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na,const char** a)
1366{
1367 if (PHDSD == NULL) return 0;
1368 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1369 if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1370 if (na == 1) FDSCNX_Dump(HDS);
1371 else if (na == 2) {
1372 if (ISINTEGER(a[1])) FDSCNX_Dump(HDS,atoi(a[1]));
1373 else
1374 }
1375 return 0;
1376}
1377#endif
1378
1379//-----------------------------------------------------------------------
1380Standard_Integer tdsri(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1381{
1382 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
1383 tsee_help(a[0],di);
1384 return 0;
1385 }
1386 Standard_Integer na = na_in;
1387 if ((PHDSD == NULL) || (POCD == NULL)) return 0;
1388 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1389 if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
1390 if (na < 5) return 1;
1391 TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
1392
1393 Standard_Integer i1arg = 1;
1394 TDSpar Tpar(a[i1arg]);
1395
1396 if ( strcasecmp(a[i1arg + 2],"i") ) return 0;
1397 Standard_Integer ii = atoi(a[i1arg + 3]);
1398// Standard_Integer ia,is,ig;
1399 Standard_Integer is,ig;
1400 if ( Tpar.isshap() ) {
1401 is = atoi(a[i1arg + 1]);
1402 const TopoDS_Shape& s = GetShape(is,Tpar.TS()); if (s.IsNull()) return 0;
1403 TopOpeBRepDS_ListOfInterference& li = BDS.ChangeShapeInterferences(is);
1404 Standard_Integer i=0; TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
1405 while (it.More()) {
1406 if(++i == ii) {
1407 it.Value()->Dump(cout,"\n--> remove ","\n");
1408 li.Remove(it);
1409 }
1410 else it.Next();
1411 }
1412 }
1413 else if ( Tpar.isgeom() ) {
1414 ig = atoi(a[i1arg + 1]);
1415 }
1416 return 0;
1417} // tdsri
1418
1419//=======================================================================
1420//function : DSCommands
1421//purpose :
1422//=======================================================================
1423void TestTopOpe::HDSCommands(Draw_Interpretor& theCommands)
1424{
1425 static Standard_Boolean done = Standard_False;
1426 if (done) return;
1427 done = Standard_True;
1428 PHDSD = (TestTopOpe_HDSDisplayer*) new (TestTopOpe_HDSDisplayer);
1429 POCD = (TestTopOpeDraw_Displayer*) new (TestTopOpeDraw_Displayer);
1430
1431 const char* g = "Topological operation data structure commands";
1432 theCommands.Add("tseei","no args to get help",__FILE__,tseei,g);
1433 theCommands.Add("tsee","no args to get help ",__FILE__,tsee,g);
1434 theCommands.Add("tki","no args to get help ",__FILE__,tki,g);
1435 theCommands.Add("tkig","no args to get help ",__FILE__,tki,g);
1436 theCommands.Add("tkis","no args to get help ",__FILE__,tki,g);
1437 theCommands.Add("tds","-h to get help ",__FILE__,tds,g);
1438 theCommands.Add("tppe","tppe p/v <ip> e <ie>",__FILE__,TPPE);
1439 theCommands.Add("topochk","check current DS (loaded by CurrentDS()",__FILE__,topochk,g);
1440 theCommands.Add("tcx","dump connexity information",__FILE__,tcx,g);
1441 theCommands.Add("tdsri","remove interference : tdsri type itype iinterf",__FILE__,tdsri,g);
1442}