1 // Created on: 1996-09-19
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TestTopOpe_HDSDisplayer.hxx>
19 #include <TopOpeBRepDS_Curve.hxx>
20 #include <Draw_Appli.hxx>
22 #include <TestTopOpeDraw_Displayer.hxx>
23 #include <TestTopOpeDraw_TTOT.hxx>
25 //=======================================================================
26 //function : TestTopOpe_HDSDisplayer
28 //=======================================================================
30 TestTopOpe_HDSDisplayer::TestTopOpe_HDSDisplayer() :
31 myPMap1(NULL),myPMap2(NULL)
34 //=======================================================================
35 //function : TestTopOpe_HDSDisplayer
37 //=======================================================================
39 TestTopOpe_HDSDisplayer::TestTopOpe_HDSDisplayer(const Handle(TopOpeBRepDS_HDataStructure)& HDS) :
40 myPMap1(NULL),myPMap2(NULL)
45 //=======================================================================
48 //=======================================================================
50 void TestTopOpe_HDSDisplayer::Init()
52 if ( myHDS.IsNull() ) return;
53 myHDS->ChangeDS().Init();
56 //=======================================================================
57 //function : SetCurrentHDS
59 //=======================================================================
61 void TestTopOpe_HDSDisplayer::SetCurrentHDS(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
63 if ( !myHDS.IsNull() ) Init();
67 //=======================================================================
68 //function : CurrentHDS
70 //=======================================================================
72 const Handle(TopOpeBRepDS_HDataStructure)& TestTopOpe_HDSDisplayer::CurrentHDS() const
77 //=======================================================================
80 //=======================================================================
82 const TopOpeBRepDS_DataStructure& TestTopOpe_HDSDisplayer::CurrentBDS() const
84 if ( !myHDS.IsNull() ) return myHDS->DS();
86 static TopOpeBRepDS_DataStructure* dummypbid = NULL;
87 if (!dummypbid) dummypbid =
88 (TopOpeBRepDS_DataStructure*) new (TopOpeBRepDS_DataStructure);
93 //=======================================================================
94 //function : SetShape1
96 //=======================================================================
98 void TestTopOpe_HDSDisplayer::SetShape1(const TopoDS_Shape& S1)
101 if (myPMap1) myPMap1->Clear();
104 //=======================================================================
107 //=======================================================================
109 void TestTopOpe_HDSDisplayer::SetShape2(const TopoDS_Shape& S2)
112 if (myPMap2) myPMap2->Clear();
115 #define FindKeep Standard_False
117 //=======================================================================
118 //function : SubShape
120 //=======================================================================
122 Standard_Boolean TestTopOpe_HDSDisplayer::SubShape(const TopoDS_Shape& S,const Standard_Integer I12)
124 Standard_Integer h = myHDS->DS().HasShape(S,FindKeep);
125 if ( !h ) return Standard_False;
127 // returns True if <S> is a subshape of loaded shape <I12> = 1,2
128 Standard_Integer rankS = myHDS->DS().AncestorRank(S);
129 if ( rankS == 1 || rankS == 2 ) {
130 Standard_Boolean r = rankS == I12;
135 Standard_Integer iS = myHDS->Shape(S,FindKeep);
136 cout<<endl<<"***** shape "<<iS<<" has no ancestor index : use shapemaps"<<endl;
139 if (myPMap1 == NULL) myPMap1 = new TopTools_IndexedMapOfShape();
140 if ( !myS1.IsNull() ) TopExp::MapShapes(myS1,*myPMap1);
141 if (myPMap2 == NULL) myPMap2 = new TopTools_IndexedMapOfShape();
142 if ( !myS2.IsNull() ) TopExp::MapShapes(myS2,*myPMap2);
143 Standard_Boolean r = Standard_False;
145 case 1 : r = myPMap1->Contains(S); break;
146 case 2 : r = myPMap2->Contains(S); break;
151 //=======================================================================
152 //function : ShapeName
154 //=======================================================================
156 void TestTopOpe_HDSDisplayer::ShapeName(const Standard_Integer I,const TopoDS_Shape& S,TCollection_AsciiString& N) const
158 TestTopOpeDraw_TTOT::ShapeEnumToString(S.ShapeType(),N);
159 N = N + "_" + TCollection_AsciiString(I);
162 // if (S.ShapeType()==TopAbs_VERTEX) N = N + " ";
163 // switch (S.Orientation()) {
164 // case TopAbs_FORWARD : N = N + "F"; break;
165 // case TopAbs_REVERSED : N = N + "R"; break;
166 // case TopAbs_INTERNAL : N = N + "I"; break;
167 // case TopAbs_EXTERNAL : N = N + "E"; break;
170 //=======================================================================
171 //function : AncestorMark
173 //=======================================================================
175 TCollection_AsciiString TestTopOpe_HDSDisplayer::AncestorMark(const TopoDS_Shape& S,const TCollection_AsciiString& Nin)
177 Standard_Boolean of1 = SubShape(S,1),of2 = SubShape(S,2);
178 // N = "*Nin" / "Nin*" if S is subshape of first / second shape
179 TCollection_AsciiString N = ""; if (of1) N="*"; N=N+Nin; if (of2) N=N+"*";
183 //=======================================================================
184 //function : ShapeDisplayName
186 //=======================================================================
188 void TestTopOpe_HDSDisplayer::ShapeDisplayName(const Standard_Integer I,const TopoDS_Shape& S,TCollection_AsciiString& N)
190 TCollection_AsciiString name;
192 N = AncestorMark(S,name);
195 //=======================================================================
196 //function : ShapeDisplayName
198 //=======================================================================
200 void TestTopOpe_HDSDisplayer::ShapeDisplayName(const TCollection_AsciiString& NameNBRep,const TopoDS_Shape& S,TCollection_AsciiString& N)
202 // get subshape information on S
203 Standard_Boolean of1 = SubShape(S,1);
204 Standard_Boolean of2 = SubShape(S,2);
206 // namedisp = "*name" if shape S is a subshape of first shape
207 // namedisp = "name*" if shape S is a subshape of second shape
209 if (S.ShapeType()==TopAbs_VERTEX) N = N + " ";
210 if (of1) N = N + "*";
212 if (of2) N = N + "*";
215 //=======================================================================
216 //function : SectionEdgeName
218 //=======================================================================
220 void TestTopOpe_HDSDisplayer::SectionEdgeName(const Standard_Integer ISE,const TopoDS_Shape& S,TCollection_AsciiString& N) const
222 TestTopOpeDraw_TTOT::ShapeEnumToString(S.ShapeType(),N);
223 N = N + "s" + "_" + TCollection_AsciiString(ISE);
226 //=======================================================================
227 //function : SectionEdgeDisplayName
229 //=======================================================================
231 void TestTopOpe_HDSDisplayer::SectionEdgeDisplayName(const Standard_Integer ISE,const TopoDS_Shape& S,TCollection_AsciiString& N)
233 TCollection_AsciiString name;
234 SectionEdgeName(ISE,S,name);
236 Standard_Integer ids = CurrentBDS().Shape(S,FindKeep);
237 name = name + "<" + TCollection_AsciiString(ids) + ">";
239 N = AncestorMark(S,name);
242 //=======================================================================
243 //function : GeometryDisplayName
245 //=======================================================================
247 void TestTopOpe_HDSDisplayer::GeometryDisplayName(const Standard_Integer I,const TopOpeBRepDS_Kind K,TCollection_AsciiString& N)
249 if (K == TopOpeBRepDS_CURVE) {
250 const Handle(Geom_Curve) GC = CurrentBDS().Curve(I).Curve();
251 TestTopOpeDraw_TTOT::CurveDisplayName(I,GC,N);
254 TCollection_AsciiString n;
255 TestTopOpeDraw_TTOT::GeometryName(I,K,n);
260 //=======================================================================
261 //function : ShapeKind
263 //=======================================================================
265 Standard_Boolean TestTopOpe_HDSDisplayer::ShapeKind(const Standard_Integer IS,const TopAbs_ShapeEnum TS) const
267 const TopoDS_Shape& S = CurrentBDS().Shape(IS,FindKeep);
268 Standard_Boolean b = TestTopOpeDraw_TTOT::ShapeKind(S,TS);