904e82a3bdc5129eeb250212f907ae1c6119e47c
[occt.git] / src / TestTopOpe / TestTopOpe_HDSDisplayer.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TestTopOpe_HDSDisplayer.hxx>
18
19 #include <TopOpeBRepDS_Curve.hxx>
20 #include <Draw_Appli.hxx>
21 #include <TopExp.hxx>
22 #include <TestTopOpeDraw_Displayer.hxx>
23 #include <TestTopOpeDraw_TTOT.hxx>
24
25 //=======================================================================
26 //function : TestTopOpe_HDSDisplayer
27 //purpose  : 
28 //=======================================================================
29
30 TestTopOpe_HDSDisplayer::TestTopOpe_HDSDisplayer() : 
31 myPMap1(NULL),myPMap2(NULL)
32 {}
33
34 //=======================================================================
35 //function : TestTopOpe_HDSDisplayer
36 //purpose  : 
37 //=======================================================================
38
39 TestTopOpe_HDSDisplayer::TestTopOpe_HDSDisplayer(const Handle(TopOpeBRepDS_HDataStructure)& HDS) :
40 myPMap1(NULL),myPMap2(NULL)
41 {
42   SetCurrentHDS(HDS);
43 }
44
45 //=======================================================================
46 //function : Init
47 //purpose  : 
48 //=======================================================================
49
50 void TestTopOpe_HDSDisplayer::Init()
51 {
52   if ( myHDS.IsNull() ) return; 
53   myHDS->ChangeDS().Init();
54 }
55
56 //=======================================================================
57 //function : SetCurrentHDS
58 //purpose  : 
59 //=======================================================================
60
61 void TestTopOpe_HDSDisplayer::SetCurrentHDS(const Handle(TopOpeBRepDS_HDataStructure)& HDS)
62 {
63   if ( !myHDS.IsNull() ) Init();
64   myHDS = HDS;
65 }
66
67 //=======================================================================
68 //function : CurrentHDS
69 //purpose  : 
70 //=======================================================================
71
72 const Handle(TopOpeBRepDS_HDataStructure)& TestTopOpe_HDSDisplayer::CurrentHDS() const 
73 {
74   return myHDS;
75 }
76
77 //=======================================================================
78 //function : DS
79 //purpose  : 
80 //=======================================================================
81
82 const TopOpeBRepDS_DataStructure& TestTopOpe_HDSDisplayer::CurrentBDS() const 
83 {
84   if ( !myHDS.IsNull() ) return myHDS->DS();
85   else {
86     static TopOpeBRepDS_DataStructure* dummypbid = NULL;
87     if (!dummypbid) dummypbid = 
88       (TopOpeBRepDS_DataStructure*) new (TopOpeBRepDS_DataStructure);
89     return (*dummypbid);
90   }
91 }
92
93 //=======================================================================
94 //function : SetShape1
95 //purpose  : 
96 //=======================================================================
97
98 void TestTopOpe_HDSDisplayer::SetShape1(const TopoDS_Shape& S1)
99 {
100   myS1 = S1;
101   if (myPMap1) myPMap1->Clear();
102 }
103
104 //=======================================================================
105 //function : Shape2
106 //purpose  : 
107 //=======================================================================
108
109 void TestTopOpe_HDSDisplayer::SetShape2(const TopoDS_Shape& S2)
110 {
111   myS2 = S2;
112   if (myPMap2) myPMap2->Clear();
113 }
114
115 #define FindKeep Standard_False
116
117 //=======================================================================
118 //function : SubShape
119 //purpose  : 
120 //=======================================================================
121
122 Standard_Boolean TestTopOpe_HDSDisplayer::SubShape(const TopoDS_Shape& S,const Standard_Integer I12)
123 {
124   Standard_Integer h = myHDS->DS().HasShape(S,FindKeep);
125   if ( !h ) return Standard_False;
126   
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;
131     return r;
132   }
133
134 #ifdef OCCT_DEBUG
135   Standard_Integer iS = myHDS->Shape(S,FindKeep);
136   cout<<endl<<"***** shape "<<iS<<" has no ancestor index : use shapemaps"<<endl;
137 #endif
138   
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;
144   switch (I12) {
145   case 1 : r = myPMap1->Contains(S); break;
146   case 2 : r = myPMap2->Contains(S); break;
147   }
148   return r;
149 }
150
151 //=======================================================================
152 //function : ShapeName
153 //purpose  : 
154 //=======================================================================
155
156 void TestTopOpe_HDSDisplayer::ShapeName(const Standard_Integer I,const TopoDS_Shape& S,TCollection_AsciiString& N) const 
157 {
158   TestTopOpeDraw_TTOT::ShapeEnumToString(S.ShapeType(),N);
159   N = N + "_" + TCollection_AsciiString(I);
160 }
161
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;
168 //  }
169
170 //=======================================================================
171 //function : AncestorMark
172 //purpose  : 
173 //=======================================================================
174
175 TCollection_AsciiString TestTopOpe_HDSDisplayer::AncestorMark(const TopoDS_Shape& S,const TCollection_AsciiString& Nin)
176 {
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+"*";
180   return N;
181 }
182
183 //=======================================================================
184 //function : ShapeDisplayName
185 //purpose  : 
186 //=======================================================================
187
188 void TestTopOpe_HDSDisplayer::ShapeDisplayName(const Standard_Integer I,const TopoDS_Shape& S,TCollection_AsciiString& N)
189 {
190   TCollection_AsciiString name; 
191   ShapeName(I,S,name);
192   N = AncestorMark(S,name);
193 }
194
195 //=======================================================================
196 //function : ShapeDisplayName
197 //purpose  : 
198 //=======================================================================
199
200 void TestTopOpe_HDSDisplayer::ShapeDisplayName(const TCollection_AsciiString& NameNBRep,const TopoDS_Shape& S,TCollection_AsciiString& N)
201 {
202   // get subshape information on S
203   Standard_Boolean of1 = SubShape(S,1);
204   Standard_Boolean of2 = SubShape(S,2);
205
206   // namedisp = "*name" if shape S is a subshape of first shape
207   // namedisp = "name*" if shape S is a subshape of second shape
208   N = ""; 
209   if (S.ShapeType()==TopAbs_VERTEX) N = N + "  ";
210   if (of1) N = N + "*";
211   N = N + NameNBRep;
212   if (of2) N = N + "*";
213 }
214
215 //=======================================================================
216 //function : SectionEdgeName
217 //purpose  : 
218 //=======================================================================
219
220 void TestTopOpe_HDSDisplayer::SectionEdgeName(const Standard_Integer ISE,const TopoDS_Shape& S,TCollection_AsciiString& N) const 
221 {
222   TestTopOpeDraw_TTOT::ShapeEnumToString(S.ShapeType(),N);
223   N = N + "s" + "_" + TCollection_AsciiString(ISE);
224 }
225
226 //=======================================================================
227 //function : SectionEdgeDisplayName
228 //purpose  : 
229 //=======================================================================
230
231 void TestTopOpe_HDSDisplayer::SectionEdgeDisplayName(const Standard_Integer ISE,const TopoDS_Shape& S,TCollection_AsciiString& N)  
232 {
233   TCollection_AsciiString name;
234   SectionEdgeName(ISE,S,name);
235
236   Standard_Integer ids = CurrentBDS().Shape(S,FindKeep);
237   name = name + "<" + TCollection_AsciiString(ids) + ">";
238
239   N = AncestorMark(S,name); 
240 }
241
242 //=======================================================================
243 //function : GeometryDisplayName
244 //purpose  : 
245 //=======================================================================
246
247 void TestTopOpe_HDSDisplayer::GeometryDisplayName(const Standard_Integer  I,const TopOpeBRepDS_Kind K,TCollection_AsciiString& N) 
248 {
249   if (K == TopOpeBRepDS_CURVE) {
250     const Handle(Geom_Curve) GC = CurrentBDS().Curve(I).Curve();
251     TestTopOpeDraw_TTOT::CurveDisplayName(I,GC,N);
252   }
253   else {
254     TCollection_AsciiString n;
255     TestTopOpeDraw_TTOT::GeometryName(I,K,n);
256     N = " "; N = N + n;
257   }
258 }
259
260 //=======================================================================
261 //function : ShapeKind
262 //purpose  : 
263 //=======================================================================
264
265 Standard_Boolean TestTopOpe_HDSDisplayer::ShapeKind(const Standard_Integer IS,const TopAbs_ShapeEnum TS) const 
266
267   const TopoDS_Shape& S = CurrentBDS().Shape(IS,FindKeep);
268   Standard_Boolean b = TestTopOpeDraw_TTOT::ShapeKind(S,TS);
269   return b;
270 }