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