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