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