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