0022627: Change OCCT memory management defaults
[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;
7fd59977 367
368 TCollection_AsciiString namedbrep; PHDSD->SectionEdgeName(ISE,SE,namedbrep);
369 TCollection_AsciiString namedisp; PHDSD->SectionEdgeDisplayName(ISE,SE,namedisp);
370 POCD->DisplayGeometry(Standard_True);
371 POCD->DisplayShape(namedbrep,namedisp,SE);
372 return 0;
373}
374
375//-----------------------------------------------------------------------
376// SeeShapeIS
377//-----------------------------------------------------------------------
378Standard_Integer SeeShapeIS(const Standard_Integer I,const TopoDS_Shape& S)
379{
380 if ( !PHDSD || !POCD) return 0;
381
382 if (S.IsNull()) return 0;
383 TCollection_AsciiString namedbrep; PHDSD->ShapeName(I,S,namedbrep);
384 TCollection_AsciiString namedisp = namedbrep;
385 // NameDisplay = *name/name* if S subshape of shape1/shape2
386 TCollection_AsciiString ast = "*";
387 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
388 // if the Shape was removed from the DS, "*" is replaced by "~"
389 if(!BDS.HasShape(S))
390 ast = "~";
391 Standard_Boolean of1 = PHDSD->SubShape(S,1);if(of1) namedisp = ast+namedisp;
392 Standard_Boolean of2 = PHDSD->SubShape(S,2);if(of2) namedisp = namedisp+ast;
393 if (SelectRankShape == 1 && !of1) return 0;
394 if (SelectRankShape == 2 && !of2) return 0;
395
396 if (S.ShapeType()==TopAbs_EDGE) POCD->DisplayGeometry(Standard_True);
397 else POCD->DisplayGeometry(DisOri);
398 if((S.ShapeType()==TopAbs_VERTEX) && TolFlag) {
399 const TopoDS_Vertex& V = TopoDS::Vertex(S);
400 Standard_Real Tol = BRep_Tool::Tolerance(V);
401 POCD->SetTol(Tol);
402 }
403 POCD->DisplayShape(namedbrep,namedisp,S);
404
405 return 0;
406}
407
408
409//-----------------------------------------------------------------------
410// SeeShape
411//-----------------------------------------------------------------------
412static Standard_Integer SeeShape(TCollection_AsciiString namedbrep)
413{
414 if ( !PHDSD || !POCD ) return 0;
415
416 const char* pname = (const char *)namedbrep.ToCString();
417 TopoDS_Shape S = DBRep::Get(pname);
418 if ( S.IsNull() ) return 0;
419 TCollection_AsciiString namedisp;
420 PHDSD->ShapeDisplayName(namedbrep,S,namedisp);
421 POCD->DisplayShape(namedbrep,namedisp,S);
422 return 0;
423}
424
425//-----------------------------------------------------------------------
426// SeePoint
427//-----------------------------------------------------------------------
428static Standard_Integer SeePoint(const Standard_Integer I)
429{
430 if ( !PHDSD ) return 0;
431
432 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
433 if (I < 1 || I > BDS.NbPoints()) return 0;
434
435 TopOpeBRepDS_PointExplorer pex(BDS);
436 Standard_Boolean isp = pex.IsPoint(I);
437 if (!isp) return 0;
438
439 const TopOpeBRepDS_Point& P = BDS.Point(I);
440 TopOpeBRepDS_Kind K = TopOpeBRepDS_POINT;
441 TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
442 TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
443 Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
444 SetPoint(namedbrep,namedisp,namecolor,P);
445 return 0;
446}
447
448//-----------------------------------------------------------------------
449// SeeCurve
450//-----------------------------------------------------------------------
451static Standard_Integer SeeCurve(const Standard_Integer I)
452{
453 if ( !PHDSD ) return 0;
454
455 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
456 if (I < 1 || I > BDS.NbCurves()) return 0;
457
458 TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
459 Standard_Boolean isc = cex.IsCurve(I);
460 if (!isc) return 0;
461
462 const TopOpeBRepDS_Curve& C = BDS.Curve(I);
463 TopOpeBRepDS_Kind K = TopOpeBRepDS_CURVE;
464 TCollection_AsciiString namedbrep; TestTopOpeDraw_TTOT::GeometryName(I,K,namedbrep);
465 TCollection_AsciiString namedisp; PHDSD->GeometryDisplayName(I,K,namedisp);
466 Draw_ColorKind namecolor = TestTopOpeDraw_TTOT::GeometryColor(K);
467 SetCurve(namedbrep,namedisp,namecolor,C,I);
468 return 0;
469}
470
471
472//-----------------------------------------------------------------------
473// SeeSurface NYI
474//-----------------------------------------------------------------------
475Standard_Integer SeeSurface(const Standard_Integer I) // NYI
476{
477 if ( !PHDSD ) return 0;
478
479 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
480 if (I < 1 || I > BDS.NbSurfaces()) return 0;
481 return 0;
482}
483
484//-----------------------------------------------------------------------
485// SeeEdgeCurve
486//-----------------------------------------------------------------------
487static Standard_Integer SeeEdgeCurve(const Standard_Integer IE,const TopoDS_Shape& SE)
488{
489 if ( !POCD ) return 0;
490
491 if (SE.IsNull()) return 0;
492 const TopoDS_Edge& E = TopoDS::Edge(SE);
493 TopLoc_Location L;Standard_Real f,l;Handle(Geom_Curve) GC=BRep_Tool::Curve(E,L,f,l);
494 TCollection_AsciiString namedbrep="E";TestTopOpeDraw_TTOT::CatCurveName(IE,namedbrep);
495 TCollection_AsciiString namedisp="E";TestTopOpeDraw_TTOT::CatCurveDisplayName(IE,GC,namedisp);
496 POCD->DisplayGeometry(Standard_True);
497 POCD->DisplayShape(namedbrep,namedisp,SE);
498 return 0;
499}
500
501//-----------------------------------------------------------------------
502// SeeGeometry
503//-----------------------------------------------------------------------
504static Standard_Integer SeeGeometry(const Standard_Integer IG,const TopOpeBRepDS_Kind TK)
505{
506 if (TK == TopOpeBRepDS_POINT) return SeePoint(IG);
507 else if (TK == TopOpeBRepDS_CURVE) return SeeCurve(IG);
508 else if (TK == TopOpeBRepDS_SURFACE) return SeeSurface(IG);
509 return 0;
510}
511
512//-----------------------------------------------------------------------
513// SeeGeometry
514//-----------------------------------------------------------------------
515// Unused :
516#ifdef DEB
517static Standard_Integer SeeGeometry(const tsee_entity& E)
518{
519 if (!E.myEOK) return 0;
520 return SeeGeometry(E.myEindex,E.myETK);
521}
522#endif
523
524//-----------------------------------------------------------------------
525// SeeGeometry
526//-----------------------------------------------------------------------
527static Standard_Integer SeeGeometry(const TopOpeBRepDS_Kind TK)
528{
529 if ( !PHDSD ) return 0;
530
531 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
532
7fd59977 533 if (TK == TopOpeBRepDS_POINT) {
534 TopOpeBRepDS_PointExplorer pex(BDS,GFindKeep);
535 for (; pex.More(); pex.Next()) {
536 Standard_Integer ig = pex.Index();
537 SeeGeometry(ig,TK);
538 }
539 }
540 else if (TK == TopOpeBRepDS_CURVE) {
541 TopOpeBRepDS_CurveExplorer cex(BDS,GFindKeep);
542 for (; cex.More(); cex.Next()) {
543 Standard_Integer ig = cex.Index();
544 SeeGeometry(ig,TK);
545 }
546 }
547 else if (TK == TopOpeBRepDS_SURFACE) { //NYI
548 }
549 return 0;
550}
551
552//-----------------------------------------------------------------------
553// TOPOPE_SeeShape
554//-----------------------------------------------------------------------
555Standard_Integer TOPOPE_SeeShape(char* name)
556{
557 TCollection_AsciiString asc = name;
558 Standard_Integer res = SeeShape(asc);
559 return res;
560}
561
562//-----------------------------------------------------------------------
563// decalargs : shift a[*] from <-d>,modify na = na - deca
564//-----------------------------------------------------------------------
565// Unused :
566#ifdef DEB
567static void decalargs(Standard_Integer& na,const char** a,const Standard_Integer d)
568{for(Standard_Integer i=1;i<na;i++)a[i]=a[i+d];na-=d;}
569#endif
570
571//-----------------------------------------------------------------------
572// suppressarg : remove a[d],modify na--
573//-----------------------------------------------------------------------
574Standard_EXPORT void suppressarg(Standard_Integer& na,const char** a,const Standard_Integer d)
575{
576 for(Standard_Integer i=d;i<na;i++) {
577 a[i]=a[i+1];
578 a[i+1]=NULL;
579 }
580 na--;
581}
582
583//-----------------------------------------------------------------------
584// suppressargs : remove a[*] from <f> to <l>,modify na = na - (l - f)
585//-----------------------------------------------------------------------
586Standard_EXPORT void suppressargs(Standard_Integer& na,const char** a,const Standard_Integer f,const Standard_Integer l)
587{
588 if(l == f)
589 suppressarg(na,a,l);
590 if(l <= f) return;
591 for(Standard_Integer i=0;i<na-l;i++) {
592 a[i+f]=a[i+l+1];
593 a[i+l+1]=NULL;
594 }
595 na -= l-f+1;
596}
597
598//-----------------------------------------------------------------------
599// SetTolFlag
600//-----------------------------------------------------------------------
601// Unused :
602#ifdef DEB
603static Standard_Boolean SetTolFlag(Standard_Integer& na,const char** a) { decalargs(na,a,1); return Standard_True; }
604#endif
605
606//-----------------------------------------------------------------------
607// tsee_flags
608//-----------------------------------------------------------------------
609static void tsee_flags(Standard_Integer& na,const char** a) {
610 GFindKeep = Standard_False;
611 PrintDistancePP = Standard_False;
612 SelectRankShape = 0;
613
614 for (Standard_Integer ia = 1; ia < na; ia++) {
615 if (!strcasecmp(a[ia],"-k")) {
616 suppressarg(na,a,ia);
617 GFindKeep = Standard_True;
618 }
619 else if (!strcasecmp(a[ia],"-d")) {
620 // tsee -d p 4 7 : display p_4,p_7 + tds p 4 7 + calculate distance (p_4,p_7)
621 suppressarg(na,a,ia);
622 PrintDistancePP = Standard_True;
623 }
624 else if (!strcasecmp(a[ia],"-1")) {
625 // tsee -1 s 4 : display s_4 <=> s_4 is subshape of the 1st argument
626 suppressarg(na,a,ia);
627 SelectRankShape = 1;
628 }
629 else if (!strcasecmp(a[ia],"-2")) {
630 // tsee -2 s 4 : display s_4 <=> s_4 is subshape of the 2nd argument
631 suppressarg(na,a,ia);
632 SelectRankShape = 2;
633 }
634 else if (!strcasecmp(a[ia],"-p") && (ia < na-1)) {
635 suppressargs(na,a,ia,ia+1);
636 Standard_Real t = atof(a[ia+1]);
637 if (t >= 0. && t <= 1.) {
638 OldParFlag = ParFlag; ParFlag = t;
639 }
640 }
641 }
642}
643
644void OthersCommands_help(const char* CommandName,const char* syntaxe = "");
645//-----------------------------------------------------------------------
646// tsee_help
647//-----------------------------------------------------------------------
648static void tsee_help(const char* CommandName, Draw_Interpretor& di)
649{
650 di<<""<<"\n";
651 di<<"tsee : Draw entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
652 di<<"DS entities are shapes and geometries accessed by a <type> and an <index>."<<"\n";
653 di<<"basic usage :"<<"\n";
654 di<<" tsee <type> <index1 index2 ...>"<<"\n";
655 di<<"<type> = so sh f w e v s for solid/shell/face/wire/edge/vertex/shape"<<"\n";
656 di<<" su cu p for surface/curve/point (N.B : su is NYI)"<<"\n";
657 di<<"<index> = integer"<<"\n";
658 di<<"example : 'tsee e 3' will draw the edge of index 3"<<"\n";
659 di<<" 'tsee e 3 6' will draw the edges of index 3 and 6"<<"\n";
660 di<<" 'tsee e' will draw all the edges."<<"\n";
661 di<<""<<"\n";
662 di<<"Index values of DS entities may be given by the 'tds' command which prints"<<"\n";
663 di<<"the content of the DS for each shape and geometry type."<<"\n";
664 di<<"Entities are drawn with a specific color according to their type."<<"\n";
665 di<<""<<"\n";
666 di<<"Naming : "<<"\n";
667 di<<"'tsee <t> <i>' creates the drawable object named <t>_<i>."<<"\n";
668 di<<"This name is displayed near the entity in one if the forms : "<<"\n";
669 di<<" *<t>_<i> meaning entity belongs to the first shape of current operation."<<"\n";
670 di<<" <t>_<i>* meaning entity belongs to the second shape of current operation."<<"\n";
671 di<<""<<"\n";
672 di<<"Same Domain shapes : "<<"\n";
673 di<<"'tsee <type> sd' to display all shapes of <type> having same domain data."<<"\n";
674 di<<"example : 'tsee e sd' to display all edges sharing a 1d geometric domain"<<"\n";
675 di<<" with other edges."<<"\n";
676 di<<""<<"\n";
677 di<<"Optional flags :"<<"\n";
678 OthersCommands_help(CommandName);
679 di<<"Other types :"<<"\n";
680 di<<"'tsee fev' : displays all faces,then edges,then vertices."<<"\n";
681 di<<"'tsee es <i>' displays edge described as section edge <i>."<<"\n";
682 di<<" The name of a section edge likes t_i<j>,where :"<<"\n";
683 di<<" - i is the edge index in the set of section edge,"<<"\n";
684 di<<" - j is edge index in the DS (as any edge)."<<"\n";
685 di<<""<<"\n";
686}
687
688static void tseei_help(Draw_Interpretor& di)
689{
690 di<<""<<"\n";
691 di<<"tseei : Draws entities of data structure (DS) loaded by TestTopOpe::CurrentDS()."<<"\n";
692 di<<"Draws the objects appearing in interferences DS objects."<<"\n";
693 di<<"See command 'tsee' for discussion about DS objects."<<"\n";
694 di<<"\n";
695}
696
697static void tki_help(Draw_Interpretor& di)
698{
699 di<<""<<"\n";
700 di<<"tki,tkig,tkis : Groups interferences of DS objects"<<"\n";
701 di<<" by geometry (g),or support (s),and index."<<"\n";
702 di<<"See command 'tsee' for discussion about DS objects."<<"\n";
703 di<<"(Test of class TopOpeBRepDS_TKI)"<<"\n";
704 di<<"\n";
705}
706
707static void tds_help(Draw_Interpretor& di)
708{
709 di<<""<<"\n";
710 di<<"tds : dump current DS (loaded by CurrentDS())"<<"\n";
711 di<<"basic usage : tds <-arg> type <index1 index2 ...>"<<"\n";
712 di<<"\n";
713 di<<"Description of curve geometry (type = c) : <-arg> = -t -k -s -l"<<"\n";
714 di<<"\t-k : print only the curve with keep = Standard_True"<<"\n";
715 di<<"\t-l : (long) print all poles and knots for BSplines curves"<<"\n";
716 di<<"\t-s : (short) print only 4 poles and 4 knots for BSplines curves"<<"\n";
717 di<<"on shapes (type = s|so|sh|f|w|e|v) : <-arg> = -ssi"<<"\n";
718 di<<"\t-ssi : print only ShapeShapeInterferences"<<"\n";
719 di<<""<<"\n";
720 di<<"See command 'tsee' for discussion about type and <index1 index2 ...>."<<"\n";
721 di<<"\n";
722}
723
724typedef Standard_Integer (*tf_SeeShape)(const Standard_Integer I,const TopoDS_Shape& S);
725Standard_IMPORT void OthersCommands_flags(Standard_Integer& na,const char** a,TestTopOpeDraw_Displayer& TD);
726void COUTNOHDS(Draw_Interpretor& di) {di<<"no current HDS"<<"\n";}
727Standard_Integer tsee_SeeShapefunc(Draw_Interpretor& di,Standard_Integer na_in,const char** a,tf_SeeShape SeeShapefunc)
728{
729 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
730 tsee_help(a[0], di);
731 return 0;
732 }
733
734 Standard_Integer na = na_in;
735 if ((PHDSD == NULL) || (POCD == NULL)) return 0;
736
737 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
738 if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
739 if (na < 2) return 1;
740 const TopOpeBRepDS_DataStructure& BDS = PHDSD->CurrentBDS();
741
742 POCD->InitDisplayer();
743 TolFlag = Standard_False;
744 tsee_flags(na,a);
745 OthersCommands_flags(na,a,*POCD);
746 TolFlag = POCD->TolIs();
747 DisOri = POCD->DisplayGeometry();
748
749 Standard_Integer i1arg = 1;
750 TSEEpar Tpar(a[i1arg]);
751
752// Standard_Integer ia,is,ig;
753 Standard_Integer ia,is;
754
755 if ( PrintDistancePP ) {
756 tsee_entity0 E1,E2;
757 if (na == 4) { // tsee p 3 4
758 if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
759 if (E2.Set(na,a,i1arg+0,i1arg+2)) return 1;
760 }
761 else if (na == 5) { // tsee p 3 v 4
762 if (E1.Set(na,a,i1arg+0,i1arg+1)) return 1;
763 if (E2.Set(na,a,i1arg+2,i1arg+3)) return 1;
764 }
765 if (!E1.myEOK || !E2.myEOK) return 1;
766
767 E1.See();E2.See();
768 E1.Dump();E2.Dump();
769 di<<"Distance "<<E1.myEnamedbrep.ToCString()<<" "<<E2.myEnamedbrep.ToCString()<<" : "<<E1.Pnt().Distance(E2.Pnt())<<"\n";
770
771 } // PrintDistancePP
772
773 else if ( Tpar.isshap() ) {
774 // na == 2 : display all DS shapes of type TS
775 // na > 2 : display DS shapes of type TS of index atoi(a[2]..a[narg-1])
776 if (na == 2 ) {
777 TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
778 for(;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
779 }
780 else {
781 if ( !strcmp(a[i1arg+1],"sd") ) { // shapes HasSameDomain of type TS
782 TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);
783 for (;x.More();x.Next()) {
784 Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
785 if (isSsd ) (*SeeShapefunc)(x.Index(),x.Current());
786 }
787 }
788 else if (Tpar.isshap() && (Tpar.TS() == TopAbs_EDGE) && (na>=2) && POCD->ParIs()) {
789 // see edges [4..na[ with of the name in t in [0..1] / range
790 if (na == 2) {
791 TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
792 for (;x.More();x.Next()) (*SeeShapefunc)(x.Index(),x.Current());
793 }
794 else {
795 for (ia = i1arg+1; ia < na; ia++) {
796 is = atoi(a[ia]);
797 (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
798 }
799 }
800 ParFlag = OldParFlag;
801 }
802 else {
803 for (ia = i1arg+1; ia < na; ia++) {
804 is = atoi(a[ia]);
805 (*SeeShapefunc)(is,GetShape(is,Tpar.TS()));
806 }
807 }
808 }
809 } // isshap
810
811 else if ( Tpar.isgeom() ) {
812 // na == 2 : display all DS geometries of type TK
813 // na > 2 : display DS geometries of type TK index atoi(a[2])..a[narg-1])
814 if (na == 2 ) SeeGeometry(Tpar.TK());
815 else for (ia = i1arg+1; ia < na; ia++) SeeGeometry(Standard_Integer(atoi(a[ia])),Tpar.TK());
816 }
817
818 else if ( Tpar.isafev() ) {
819 // faces then edges then vertices
820 TopOpeBRepDS_Explorer x;
821 for (x.Init(HDS,TopAbs_FACE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
822 for (x.Init(HDS,TopAbs_EDGE,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
823 for (x.Init(HDS,TopAbs_VERTEX,Standard_False);x.More();x.Next()) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
824 }
825
826 else if ( Tpar.isedcu() ) {
827 // na == 2 : display curves of all DS edges
828 // na > 2 : display curve of DS edges index atoi(a[2])..a[narg-1])
829 if ( na == 2 ) {
830 TopOpeBRepDS_Explorer x(HDS,TopAbs_EDGE,Standard_False);
831 for (;x.More();x.Next()) SeeEdgeCurve(x.Index(),x.Edge());
832 }
833 else {
834 for (ia = i1arg+1; ia < na; ia++) {
835 is = atoi(a[ia]);
836 SeeEdgeCurve(is,GetShape(is,TopAbs_EDGE));
837 }
838 }
839 }
840
841 else if ( Tpar.issect() ) { // na=2 all section edges,na>2 section edges (a[2]..a[na-1])
842 Standard_Integer ise,nse = BDS.NbSectionEdges();
843 if (na == 2) for (ise = 1; ise<=nse; ise++) SeeSectionEdge(ise);
844 else for (ia = i1arg+1; ia<na; ia++) SeeSectionEdge(atoi(a[ia]));
845 }
846
847 else if (Tpar.isdege()) {
848 TopOpeBRepDS_Explorer x;
849 for (x.Init(HDS,TopAbs_EDGE);x.More();x.Next()) {
850 if (BRep_Tool::Degenerated(x.Edge())) (*SeeShapefunc)(x.Index(),GetShape(x.Index()));
851 }
852 }
853
854 return 0;
855} // tsee_SeeShapefunc
856
857//-----------------------------------------------------------------------
858// tsee
859//-----------------------------------------------------------------------
860Standard_Integer tsee(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
861{
862 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
863 tsee_help(a[0],di);
864 return 0;
865 }
866 tf_SeeShape ssf = (tf_SeeShape)SeeShapeIS;
867 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
868 return r;
869} // tsee
870
871//-----------------------------------------------------------------------
872// SeeAnyKI
873//-----------------------------------------------------------------------
874Standard_Integer SeeAnyKI(const TopOpeBRepDS_Kind TK,const Standard_Integer I) {
875#ifndef DEB
876 TopAbs_ShapeEnum TS = TopAbs_COMPOUND;
877#else
878 TopAbs_ShapeEnum TS;
879#endif
880 Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
881 isshape = TopOpeBRepDS::IsTopology(TK);
882 if (isshape) TS = TopOpeBRepDS::KindToShape(TK);
883 else isgeome = TopOpeBRepDS::IsGeometry(TK);
884 if (isshape) SeeShapeIS(I,GetShape(I,TS));
885 else if (isgeome) SeeGeometry(I,TK);
886 return 0;
887}
888
889//-----------------------------------------------------------------------
890void AddShapeKI
891//-----------------------------------------------------------------------
892(TColStd_ListOfInteger& LOK,TColStd_ListOfInteger& LOI,
893 const TopOpeBRepDS_Kind K,const Standard_Integer I)
894{
895 TopAbs_ShapeEnum TS;
896 Standard_Boolean isshape,isgeome; isshape = isgeome = Standard_False;
897 isshape = TopOpeBRepDS::IsTopology(K);
898 if (isshape) TS = TopOpeBRepDS::KindToShape(K);
899 else isgeome = TopOpeBRepDS::IsGeometry(K);
900
901 if (LOK.IsEmpty() && LOI.IsEmpty()) {
902 LOK.Append((Standard_Integer)K); LOI.Append(I);
903 return;
904 }
905
906 // to sort, it is considered that :
907 // POINT == VERTEX,CURVE == EDGE,SURFACE == FACE
908
909#ifdef DEB
910 TopAbs_ShapeEnum SKtri;
911#else
912 TopAbs_ShapeEnum SKtri=TopAbs_COMPOUND;
913#endif
914 if (isshape) SKtri = TopOpeBRepDS::KindToShape(K);
915 else if (isgeome) {
916 if (K == TopOpeBRepDS_POINT) SKtri = TopAbs_VERTEX;
917 else if (K == TopOpeBRepDS_CURVE) SKtri = TopAbs_EDGE;
918 else if (K == TopOpeBRepDS_SURFACE) SKtri = TopAbs_FACE;
919 }
920 else return;
921
922 TColStd_ListIteratorOfListOfInteger ITLOK(LOK);
923 TColStd_ListIteratorOfListOfInteger ITLOI(LOI);
924 Standard_Boolean equa = Standard_False;
925 for (; ITLOK.More(),ITLOI.More(); ITLOK.Next(),ITLOI.Next()) {
926//JR/Hp
927 Standard_Integer ifK = ITLOK.Value() ;
928 TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind) ifK ;
929 TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
930// TopOpeBRepDS_Kind fK = (TopOpeBRepDS_Kind)ITLOK.Value(); TopAbs_ShapeEnum fSK = TopOpeBRepDS::KindToShape(fK);
931 Standard_Integer fI = ITLOI.Value();
932 if (SKtri == fSK && I == fI) {
933 equa = Standard_True;
934 break;
935 }
936 if (SKtri <= fSK) {
937 LOK.InsertBefore((Standard_Integer)K,ITLOK);
938 LOI.InsertBefore(I,ITLOI);
939 break;
940 }
941 }
942 if ( !ITLOK.More() && !equa) {
943 LOK.Append((Standard_Integer)K);
944 LOI.Append(I);
945 }
946}
947
948//-----------------------------------------------------------------------
949// SeeShapeISI
950//-----------------------------------------------------------------------
951Standard_Integer SeeShapeISI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
952{
953 if ( !PHDSD ) return 0;
954 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
955 if (S.IsNull()) return 0;
956 SeeShapeIS(I,S);
957
958 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
959 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
960 const TopOpeBRepDS_ListOfInterference& LOI = BDS.ShapeInterferences(S);
961 TopOpeBRepDS_ListIteratorOfListOfInterference ITLOI(LOI);
962 TColStd_ListOfInteger LOKK,LOII;
963
964 for (;ITLOI.More();ITLOI.Next()) {
965 const Handle(TopOpeBRepDS_Interference)& HI = ITLOI.Value();
966 const TopOpeBRepDS_Transition& T = HI->Transition();
967
968 TopAbs_ShapeEnum sb = T.ShapeBefore();TopOpeBRepDS_Kind sbk = TopOpeBRepDS::ShapeToKind(sb);
969 Standard_Integer sbi = T.IndexBefore();
970 TopAbs_ShapeEnum sa = T.ShapeAfter();TopOpeBRepDS_Kind sak = TopOpeBRepDS::ShapeToKind(sa);
971 Standard_Integer sai = T.IndexAfter();
972 TopOpeBRepDS_Kind gk,sk; Standard_Integer gi,si; HI->GKGSKS(gk,gi,sk,si);
973
974 AddShapeKI(LOKK,LOII,sbk,sbi);
975 AddShapeKI(LOKK,LOII,sak,sai);
976 AddShapeKI(LOKK,LOII,gk,gi);
977 AddShapeKI(LOKK,LOII,sk,si);
978 }
979
980 TColStd_ListIteratorOfListOfInteger ITLOKK,ITLOII;
981
982 ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
983 Standard_Boolean ya = ITLOKK.More();
984 TopOpeBRepDS::Print(SK,I,cout,""," : ");
985 for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
986//JR/Hp
987 Standard_Integer ikk = ITLOKK.Value() ;
988 TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
989 Standard_Integer ii = ITLOII.Value();
990// TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
991 TopOpeBRepDS::Print(kk,ii,cout,""," ");
992 }
993 if (ya) di<<"\n"; else di<<"no shape interference"<<"\n";
994
995 ITLOKK.Initialize(LOKK); ITLOII.Initialize(LOII);
996 for(; ITLOKK.More(),ITLOII.More(); ITLOKK.Next(),ITLOII.Next()) {
997//JR/Hp
998 Standard_Integer ikk =ITLOKK.Value() ;
999 TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind) ikk ;
1000 Standard_Integer ii = ITLOII.Value();
1001// TopOpeBRepDS_Kind kk = (TopOpeBRepDS_Kind)ITLOKK.Value(); Standard_Integer ii = ITLOII.Value();
1002 SeeAnyKI(kk,ii);
1003 }
1004 //POP pour WNT
1005 return 0;
1006
1007} // SeeShapeISI
1008
1009//-----------------------------------------------------------------------
1010// SeeShapeTKIG
1011//-----------------------------------------------------------------------
1012Standard_Integer SeeShapeTKIG(const Standard_Integer I,const TopoDS_Shape& S)
1013{
1014 if ( !PHDSD ) return 0;
1015 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1016 if (S.IsNull()) return 0;
1017 SeeShapeIS(I,S);
1018
1019 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
1020 const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
1021 TopOpeBRepDS_TKI tki;
1022 TCollection_AsciiString s1,s2;
1023
1024 tki.Clear();
1025 tki.FillOnGeometry(LOI);
1026 s1=TopOpeBRepDS::SPrint(SK,I,""," by G : \n");
1027 tki.Init();if (tki.More()) s2="\n";else s2="";
1028 tki.DumpTKIIterator(s1,s2);
1029
1030 return 0;
1031} // SeeShapeTKIG
1032
1033//-----------------------------------------------------------------------
1034// SeeShapeTKIS
1035//-----------------------------------------------------------------------
1036Standard_Integer SeeShapeTKIS(const Standard_Integer I,const TopoDS_Shape& S)
1037{
1038 if ( !PHDSD ) return 0;
1039 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1040 if (S.IsNull()) return 0;
1041 SeeShapeIS(I,S);
1042
1043 TopOpeBRepDS_Kind SK = TopOpeBRepDS::ShapeToKind(S.ShapeType());
1044 const TopOpeBRepDS_ListOfInterference& LOI = HDS->DS().ShapeInterferences(S);
1045 TopOpeBRepDS_TKI tki;
1046 TCollection_AsciiString s1,s2;
1047
1048 tki.Clear();
1049 tki.FillOnSupport(LOI);
1050 s1=TopOpeBRepDS::SPrint(SK,I,""," by S : \n");
1051 tki.Init();if (tki.More()) s2="\n";else s2="";
1052 tki.DumpTKIIterator(s1,s2);
1053
1054 return 0;
1055} // SeeShapeTKIS
1056
1057//-----------------------------------------------------------------------
1058// SeeShapeTKI
1059//-----------------------------------------------------------------------
1060Standard_Integer SeeShapeTKI(const Standard_Integer I,const TopoDS_Shape& S,Draw_Interpretor& di)
1061{
1062 di<<"\n";
1063 SeeShapeTKIG(I,S);
1064 SeeShapeTKIS(I,S);
1065 return 0;
1066} // SeeShapeTKI
1067
1068//-----------------------------------------------------------------------
1069// tseei
1070//-----------------------------------------------------------------------
1071Standard_Integer tseei(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1072{
1073 if (na_in == 1) { tseei_help(di); return 0; }
1074 tf_SeeShape ssf = (tf_SeeShape)SeeShapeISI;
1075 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
1076 return r;
1077} // tseei
1078
1079//-----------------------------------------------------------------------
1080// tki
1081//-----------------------------------------------------------------------
1082Standard_Integer tki(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1083{
1084 if (na_in == 1) { tki_help(di); return 0; }
1085
1086 tf_SeeShape ssf = NULL;
1087 if ( !strcasecmp(a[0],"tki") ) ssf = (tf_SeeShape)SeeShapeTKI;
1088 else if ( !strcasecmp(a[0],"tkig") ) ssf = (tf_SeeShape)SeeShapeTKIG;
1089 else if ( !strcasecmp(a[0],"tkis") ) ssf = (tf_SeeShape)SeeShapeTKIS;
1090 if (ssf == NULL) return 0;
1091
1092 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,ssf);
1093 return r;
1094} // tki
1095
1096//-----------------------------------------------------------------------
1097// 0 = tds
1098// 1 = kind of DS object to dump = [s] [so sh f w e v] [se] [su c p]
1099// 2,3 ... = [i1,i2 ...] = indices of DS object to see
1100//-----------------------------------------------------------------------
1101Standard_Integer tds(Draw_Interpretor& di,Standard_Integer na,const char** a)
1102{
1103 Standard_Boolean TDSkeep,TDScompact; TDSkeep = TDScompact = Standard_False;
1104 TopOpeBRepDS_GLOBALHDSinterfselector = 0;
1105
1106 Standard_Integer ia ;
1107 for ( ia = 0; ia < na; ia++) {
1108 if (!strcasecmp(a[ia],"-ssi")) {
1109 TopOpeBRepDS_GLOBALHDSinterfselector = 1;
1110 suppressarg(na,a,ia);
1111 continue;
1112 }
1113 else if (!strncmp(a[ia],"-",1)) {
1114 TCollection_AsciiString as = a[ia];
1115 as.Remove(1,1);
1116 for(Standard_Integer i = 1;i <= as.Length(); i++) {
1117 if (as.Value(i) == 'k') TDSkeep = Standard_True;
1118 else if(as.Value(i) == 'l') TDScompact = Standard_False;
1119 else if(as.Value(i) == 's') TDScompact = Standard_True;
1120 else if(as.Value(i) == 'h') { tds_help(di); return 0; }
1121 }
1122 suppressarg(na,a,ia);
1123 }
1124 }
1125
1126 if (PHDSD == NULL) return 0;
1127 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1128 if (HDS.IsNull()) {COUTNOHDS(di);return 0;}
6e6cd5d9 1129 PHDSD->CurrentBDS();
7fd59977 1130
1131 TopOpeBRepDS_Dumper Dumper(HDS);
1132 if ( na == 1 ) { Dumper.Dump(cout,TDSkeep,TDScompact); return 0; }
1133
1134 TDSpar Tpar(a[1]);
1135 Standard_Integer ids;
1136
1137 if (na == 2) {
1138 if (Tpar.isshap()) {
1139 if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),cout);
1140 else Dumper.DumpTopology(cout);
1141 }
1142 else if (Tpar.isgeom()) {
1143 Dumper.DumpGeometry(Tpar.TK(),cout,TDSkeep,TDScompact);
1144 }
1145 else if (Tpar.issect()) {
1146 Dumper.DumpSectionEdge(Tpar.TK(),cout);
1147 }
1148 else if (Tpar.isafev()) {
1149 TopOpeBRepDS_Explorer x;
1150 for (x.Init(HDS,TopAbs_FACE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1151 for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1152 for (x.Init(HDS,TopAbs_VERTEX,TDSkeep);x.More();x.Next()) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1153 }
1154
1155 else if (Tpar.isdege()) {
1156 TopOpeBRepDS_Explorer x;
1157 for (x.Init(HDS,TopAbs_EDGE,TDSkeep);x.More();x.Next()) {
1158 if (BRep_Tool::Degenerated(x.Edge())) Dumper.DumpTopology(x.Type(),x.Index(),cout);
1159 }
1160 }
1161 return 0;
1162 } // (na == 2)
1163
1164 // nna > 2 : dump DS entities of type TK index atoi(a[2])..a[narg-1])
1165 for (ia = 2; ia < na; ia++) {
1166
1167 if ( !strcmp(a[ia],"sd") ) { // dump all shapes HasSameDomain of type TS
1168 for (TopOpeBRepDS_Explorer x(HDS,Tpar.TS(),Standard_False);x.More();x.Next()) {
1169 Standard_Boolean isSsd = HDS->HasSameDomain(x.Current());
1170 if (isSsd ) Dumper.DumpTopology(Tpar.TK(),x.Index(),cout);
1171 }
1172 }
1173 else {
1174 ids = atoi(a[ia]);
1175 if ( Tpar.isshap() ) {
1176 if (Tpar.TS() != TopAbs_SHAPE) Dumper.DumpTopology(Tpar.TK(),ids,cout);
1177 else {
1178 TopAbs_ShapeEnum t = HDS->Shape(ids,SFindKeep).ShapeType();
1179 TopOpeBRepDS_Kind k = TopOpeBRepDS::ShapeToKind(t);
1180 Dumper.DumpTopology(k,ids,cout);
1181 }
1182 }
1183 else if ( Tpar.isgeom() ) {
1184 Dumper.DumpGeometry(Tpar.TK(),ids,cout,TDSkeep,TDScompact);
1185 }
1186 else if ( Tpar.issect() ) {
1187 Dumper.DumpSectionEdge(TopOpeBRepDS_EDGE,ids,cout);
1188 }
1189 }
1190 } // ia < na
1191
1192 return 0;
1193}
1194
1195Standard_Integer TPPE(Draw_Interpretor& di,Standard_Integer na,const char** a)
1196{
1197 if (PHDSD == NULL) return 0;
1198 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1199 if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1200
1201 if (na != 5) return 1;
1202 Standard_Boolean ok = Standard_True;
1203
1204 gp_Pnt pds;
1205 TopoDS_Edge ed;
1206
1207 Standard_Integer ip = atoi(a[2]);
1208 Standard_Integer ie = atoi(a[4]);
1209 ok = ok && (ip >= 1); ok = ok && (ie >= 1);
1210 if (!ok) {
1211 di <<" bad data"<<"\n";
1212 return 1;
1213 }
1214
1215 ok = Standard_False;
1216 if (!strcmp("p",a[1])){
1217 ok = Standard_True;
1218 ok = ok && (ip <= HDS->NbPoints());
1219 if (ok) pds = HDS->Point(ip).Point();
1220 if (!ok) di<<" geometry "<<ip<<" is not a point"<<"\n";
1221 }
1222 if (!strcmp("v",a[1])){
1223 ok = Standard_True;
1224 ok = ok && (ip <= HDS->NbShapes());
1225 if (ok) {
1226 TopoDS_Shape sh = HDS->Shape(ip,SFindKeep);
1227 ok = ok && (sh.ShapeType() == TopAbs_VERTEX);
1228 if (ok) pds =BRep_Tool::Pnt(TopoDS::Vertex(sh));
1229 }
1230 if (!ok) di<<" shape "<<ip<<" is not a vertex"<<"\n";
1231 }
1232 if (!strcmp("e",a[3])){
1233 ok = ok && (ie <= HDS->NbShapes());
1234 if (ok) {
1235 TopoDS_Shape sh = HDS->Shape(ie,SFindKeep);
1236 ok = ok && (sh.ShapeType() == TopAbs_EDGE);
1237 if (ok) ed = TopoDS::Edge(sh);
1238 }
1239 if (!ok) di<<" shape "<<ie<<" is not an edge"<<"\n";
1240
1241 } else ok = Standard_False;
1242
1243 Standard_Real dmin=0;
1244 gp_Pnt pproj;
1245 if (ok) {
1246 Standard_Real f,l;
1247 Handle(Geom_Curve) cu = BRep_Tool::Curve(ed,f,l);
1248 GeomAPI_ProjectPointOnCurve ponc(pds,cu,f,l);
1249 ok = ponc.NbPoints() >= 1;
1250
1251 if (ok) {
1252 dmin = ponc.LowerDistance();
1253 Standard_Real par = ponc.LowerDistanceParameter();
1254 BRepAdaptor_Curve bc(ed);
1255 pproj = bc.Value(par);
1256 }
1257 }
1258
1259 if (ok) {
1260 TCollection_AsciiString pp("p");
1261 pp.AssignCat(ip); pp.AssignCat("e"); pp.AssignCat(ie);
1262 char* ppp = (char *)pp.ToCString();
1263 DrawTrSurf::Set(ppp,pproj);
1264 di<<"dist point "<<ip<<" on edge "<<ie<<" = "<<dmin<<"\n";
1265 } else di<<"projection failed"<<"\n";
1266
1267 return ok;
1268} // TPPE
1269
1270void FUN_ChkIntgInterf(Draw_Interpretor& di) //***Check Integrity Interference
1271{
1272 if ( PHDSD == NULL ) return;
1273 PHDSD->CurrentHDS()->ChkIntg();
1274 di<<"Check interference integrity completed"<<"\n";
1275}
1276
1277void FUN_ChkIntgSamDomain(Draw_Interpretor& di) //***Check Integrity SameDomain
1278{
1279 if ( PHDSD == NULL ) return;
1280 TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1281 if(C.ChkIntgSamDom())
1282 di<<"Check SameDomain integrity completed"<<"\n";
1283}
1284
1285void FUN_ChkIntg(Draw_Interpretor& di) //***Check Integrity
1286{
1287 if ( PHDSD == NULL ) return;
1288 FUN_ChkIntgInterf(di);
1289 FUN_ChkIntgSamDomain(di);
1290}
1291
1292void FUN_ChkVertex(Draw_Interpretor& di) //***Check Vertex SameDomain
1293{
1294 if ( PHDSD == NULL ) return;
1295 TopOpeBRepDS_Check C(PHDSD->CurrentHDS());
1296 if(C.OneVertexOnPnt())
1297 di<<"Check Structure Vertex SameDomain Complete"<<"\n";
1298}
1299
1300//---------------------------------------------------------
1301Standard_Integer topochk(Draw_Interpretor& di,Standard_Integer na,const char** a)
1302{
1303 if (strcmp(a[0],"topochk")) return 1;
1304
1305 if(na < 2) {
1306 ::FUN_ChkIntg(di);
1307 ::FUN_ChkVertex(di);
1308 }
1309 else if(na > 2) return 1;
1310 else if(!strcmp (a[1],"-i")) ::FUN_ChkIntg(di);
1311 else if(!strncmp(a[1],"-i",2)) {
1312 if (!strcmp(a[1],"-ii")) ::FUN_ChkIntgInterf(di);
1313 else if(!strcmp(a[1],"-isd")) ::FUN_ChkIntgSamDomain(di);
1314 }
1315 else if(!strcmp (a[1],"-s")) ::FUN_ChkVertex(di);
1316 else {
1317 di<<"option : -i = check DS full integrity"<<"\n";
1318 di<<"option : -ii = check only interferences"<<"\n";
1319 di<<"option : -isd = check only SameDomain data"<<"\n"<<"\n";
1320 di<<"option : -s = check only SameDomain data on vertex"<<"\n";
1321 return 1;
1322 }
1323 return 0;
1324}
1325
1326//-----------------------------------------------------------------------
1327// SeeShapeTCX
1328//-----------------------------------------------------------------------
1329Standard_Integer SeeShapeTCX(const Standard_Integer I,const TopoDS_Shape& S)
1330{
1331 if ( !PHDSD ) return 0;
1332 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1333 if (S.IsNull()) return 0;
1334 FDSCNX_Dump(HDS,I);
1335 return 0;
1336} // SeeShapeTCX
1337
1338static void tcx_help(Draw_Interpretor& di)
1339{
1340 di<<"tcx : function not documented"<<"\n";
1341}
1342
1343//-----------------------------------------------------------------------
1344// tcx
1345//-----------------------------------------------------------------------
1346Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1347{
1348 if (na_in == 1) { tcx_help(di); return 0; }
1349 Standard_Integer r = tsee_SeeShapefunc(di,na_in,a,SeeShapeTCX);
1350 return r;
1351} // tcx
1352
1353#if 0
1354//---------------------------------------------------------
1355Standard_Integer tcx(Draw_Interpretor& di,Standard_Integer na,const char** a)
1356{
1357 if (PHDSD == NULL) return 0;
1358 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1359 if ( HDS.IsNull() ) { COUTNOHDS(di); return 0; }
1360 if (na == 1) FDSCNX_Dump(HDS);
1361 else if (na == 2) {
1362 if (ISINTEGER(a[1])) FDSCNX_Dump(HDS,atoi(a[1]));
1363 else
1364 }
1365 return 0;
1366}
1367#endif
1368
1369//-----------------------------------------------------------------------
1370Standard_Integer tdsri(Draw_Interpretor& di,Standard_Integer na_in,const char** a)
1371{
1372 if (na_in == 1 || (na_in == 2 && !strcasecmp(a[1],"-h"))) {
1373 tsee_help(a[0],di);
1374 return 0;
1375 }
1376 Standard_Integer na = na_in;
1377 if ((PHDSD == NULL) || (POCD == NULL)) return 0;
1378 const Handle(TopOpeBRepDS_HDataStructure)& HDS = PHDSD->CurrentHDS();
1379 if (HDS.IsNull()) { COUTNOHDS(di); return 0; }
1380 if (na < 5) return 1;
1381 TopOpeBRepDS_DataStructure& BDS = HDS->ChangeDS();
1382
1383 Standard_Integer i1arg = 1;
1384 TDSpar Tpar(a[i1arg]);
1385
1386 if ( strcasecmp(a[i1arg + 2],"i") ) return 0;
1387 Standard_Integer ii = atoi(a[i1arg + 3]);
1388// Standard_Integer ia,is,ig;
1389 Standard_Integer is,ig;
1390 if ( Tpar.isshap() ) {
1391 is = atoi(a[i1arg + 1]);
1392 const TopoDS_Shape& s = GetShape(is,Tpar.TS()); if (s.IsNull()) return 0;
1393 TopOpeBRepDS_ListOfInterference& li = BDS.ChangeShapeInterferences(is);
1394 Standard_Integer i=0; TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
1395 while (it.More()) {
1396 if(++i == ii) {
1397 it.Value()->Dump(cout,"\n--> remove ","\n");
1398 li.Remove(it);
1399 }
1400 else it.Next();
1401 }
1402 }
1403 else if ( Tpar.isgeom() ) {
1404 ig = atoi(a[i1arg + 1]);
1405 }
1406 return 0;
1407} // tdsri
1408
1409//=======================================================================
1410//function : DSCommands
1411//purpose :
1412//=======================================================================
1413void TestTopOpe::HDSCommands(Draw_Interpretor& theCommands)
1414{
1415 static Standard_Boolean done = Standard_False;
1416 if (done) return;
1417 done = Standard_True;
1418 PHDSD = (TestTopOpe_HDSDisplayer*) new (TestTopOpe_HDSDisplayer);
1419 POCD = (TestTopOpeDraw_Displayer*) new (TestTopOpeDraw_Displayer);
1420
1421 const char* g = "Topological operation data structure commands";
1422 theCommands.Add("tseei","no args to get help",__FILE__,tseei,g);
1423 theCommands.Add("tsee","no args to get help ",__FILE__,tsee,g);
1424 theCommands.Add("tki","no args to get help ",__FILE__,tki,g);
1425 theCommands.Add("tkig","no args to get help ",__FILE__,tki,g);
1426 theCommands.Add("tkis","no args to get help ",__FILE__,tki,g);
1427 theCommands.Add("tds","-h to get help ",__FILE__,tds,g);
1428 theCommands.Add("tppe","tppe p/v <ip> e <ie>",__FILE__,TPPE);
1429 theCommands.Add("topochk","check current DS (loaded by CurrentDS()",__FILE__,topochk,g);
1430 theCommands.Add("tcx","dump connexity information",__FILE__,tcx,g);
1431 theCommands.Add("tdsri","remove interference : tdsri type itype iinterf",__FILE__,tdsri,g);
1432}