b311480e |
1 | // Created on: 1995-04-05 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1995-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 | #include <HLRTest.ixx> |
23 | #include <HLRTest_Projector.hxx> |
24 | #include <HLRTest_OutLiner.hxx> |
25 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
26 | #include <gp_Ax3.hxx> |
27 | #include <Draw_Appli.hxx> |
28 | #include <Draw.hxx> |
29 | #include <DBRep.hxx> |
30 | #include <HLRBRep_Algo.hxx> |
31 | #include <HLRBRep_HLRToShape.hxx> |
32 | static Handle(HLRBRep_Algo) hider; |
33 | #ifdef WNT |
34 | Standard_IMPORT Draw_Viewer dout; |
35 | #endif |
36 | |
37 | #include <BRepTopAdaptor_MapOfShapeTool.hxx> |
38 | |
39 | //======================================================================= |
40 | //function : Set |
41 | //purpose : |
42 | //======================================================================= |
43 | void HLRTest::Set (const Standard_CString Name, |
44 | const HLRAlgo_Projector& P) |
45 | { |
46 | Draw::Set(Name,new HLRTest_Projector(P)); |
47 | } |
48 | |
49 | //======================================================================= |
50 | //function : GetProjector |
51 | //purpose : |
52 | //======================================================================= |
53 | Standard_Boolean HLRTest::GetProjector (Standard_CString& Name, |
54 | HLRAlgo_Projector& P) |
55 | { |
56 | Handle(HLRTest_Projector) HP = |
57 | Handle(HLRTest_Projector)::DownCast(Draw::Get(Name)); |
58 | if (HP.IsNull()) return Standard_False; |
59 | P = HP->Projector(); |
60 | return Standard_True; |
61 | |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : Set |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void HLRTest::Set (const Standard_CString Name, |
70 | const TopoDS_Shape& S) |
71 | { |
72 | Draw::Set(Name,new HLRTest_OutLiner(S)); |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : GetOutLiner |
77 | //purpose : |
78 | //======================================================================= |
79 | Handle(HLRTopoBRep_OutLiner) HLRTest::GetOutLiner (Standard_CString& Name) |
80 | { |
81 | Handle(Draw_Drawable3D) D = Draw::Get(Name); |
82 | Handle(HLRTest_OutLiner) HS = Handle(HLRTest_OutLiner)::DownCast(D); |
83 | if (!HS.IsNull()) return HS->OutLiner(); |
84 | Handle(HLRTopoBRep_OutLiner) HO; |
85 | return HO; |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : hprj |
90 | //purpose : |
91 | //======================================================================= |
92 | |
93 | static Standard_Integer |
94 | hprj (Draw_Interpretor& , Standard_Integer n, const char** a) |
95 | { |
96 | Standard_Integer id = 1; |
97 | if (n < 2) return 1; |
98 | if (n > 2) id = atoi(a[2]); |
99 | // |
100 | gp_Ax2 anAx2 = gp::XOY(); |
101 | if (n == 11) |
102 | { |
103 | Standard_Real x = atof(a[2]); |
104 | Standard_Real y = atof(a[3]); |
105 | Standard_Real z = atof(a[4]); |
106 | |
107 | Standard_Real dx = atof(a[5]); |
108 | Standard_Real dy = atof(a[6]); |
109 | Standard_Real dz = atof(a[7]); |
110 | |
111 | Standard_Real dx1 = atof(a[8]); |
112 | Standard_Real dy1 = atof(a[9]); |
113 | Standard_Real dz1 = atof(a[10]); |
114 | |
115 | gp_Pnt anOrigin (x, y, z); |
116 | gp_Dir aNormal (dx, dy, dz); |
117 | gp_Dir aDX (dx1, dy1, dz1); |
118 | anAx2 = gp_Ax2(anOrigin, aNormal, aDX); |
119 | } |
120 | |
121 | HLRAlgo_Projector P(anAx2); |
122 | HLRTest::Set(a[1],P); |
123 | return 0; |
124 | } |
125 | |
126 | //======================================================================= |
127 | //function : hout |
128 | //purpose : |
129 | //======================================================================= |
130 | |
131 | static Standard_Integer |
132 | hout (Draw_Interpretor& di, Standard_Integer n, const char** a) |
133 | { |
134 | if (n < 2) return 1; |
135 | const char *name = a[2]; |
136 | TopoDS_Shape S = DBRep::Get(name); |
137 | if (S.IsNull()) { |
138 | di << name << " is not a shape." << "\n"; |
139 | return 1; |
140 | } |
141 | HLRTest::Set(a[1],S); |
142 | return 0; |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : hfil |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | static Standard_Integer |
151 | hfil (Draw_Interpretor& di, Standard_Integer n, const char** a) |
152 | { |
153 | Standard_Integer nbIso = 0; |
154 | if (n < 3) return 1; |
155 | if (n > 3) nbIso = atoi(a[3]); |
156 | const char *name1 = a[1]; |
157 | Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1); |
158 | if (HS.IsNull()) { |
159 | di << name1 << " is not an OutLiner." << "\n"; |
160 | return 1; |
161 | } |
162 | const char *name2 = a[2]; |
163 | HLRAlgo_Projector P; |
164 | if (!HLRTest::GetProjector(name2,P)) { |
165 | di << name2 << " is not a projector." << "\n"; |
166 | return 1; |
167 | } |
168 | BRepTopAdaptor_MapOfShapeTool MST; |
169 | HS->Fill(P,MST,nbIso); |
170 | return 0; |
171 | } |
172 | |
173 | //======================================================================= |
174 | //function : sori |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | static Standard_Integer |
179 | sori (Draw_Interpretor& di, Standard_Integer n, const char** a) |
180 | { |
181 | if (n < 3) return 1; |
182 | const char *name1 = a[1]; |
183 | const char *name2 = a[2]; |
184 | Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2); |
185 | if (HS.IsNull()) { |
186 | di << name2 << " is not an OutLiner." << "\n"; |
187 | return 1; |
188 | } |
189 | DBRep::Set(name1,HS->OriginalShape()); |
190 | return 0; |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : sout |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | static Standard_Integer |
199 | sout (Draw_Interpretor& di, Standard_Integer n, const char** a) |
200 | { |
201 | if (n < 3) return 1; |
202 | const char *name1 = a[1]; |
203 | const char *name2 = a[2]; |
204 | Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2); |
205 | if (HS.IsNull()) { |
206 | di << name2 << " is not an OutLiner." << "\n"; |
207 | return 1; |
208 | } |
209 | if (HS->OutLinedShape().IsNull()) { |
210 | di << name2 << " has no OutLinedShape." << "\n"; |
211 | return 1; |
212 | } |
213 | DBRep::Set(name1,HS->OutLinedShape()); |
214 | return 0; |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : hloa |
219 | //purpose : |
220 | //======================================================================= |
221 | |
222 | static Standard_Integer |
223 | hloa (Draw_Interpretor& di, Standard_Integer n, const char** a) |
224 | { |
225 | if (n < 2) return 1; |
226 | const char *name1 = a[1]; |
227 | Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1); |
228 | if (HS.IsNull()) { |
229 | di << name1 << " is not an OutLiner." << "\n"; |
230 | return 1; |
231 | } |
232 | hider->Load(HS); |
233 | return 0; |
234 | } |
235 | |
236 | //======================================================================= |
237 | //function : hrem |
238 | //purpose : |
239 | //======================================================================= |
240 | |
241 | static Standard_Integer |
242 | hrem (Draw_Interpretor& di, Standard_Integer n, const char** a) |
243 | { |
244 | if (n > 1) { |
245 | const char *name = a[1]; |
246 | Standard_Integer index; |
247 | Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name); |
248 | if (HS.IsNull()) { |
249 | TopoDS_Shape S = DBRep::Get(name); |
250 | if (S.IsNull()) { |
251 | di << name << " is not an OutLiner and not a shape." << "\n"; |
252 | return 1; |
253 | } |
254 | else { |
255 | index = hider->Index(S); |
256 | if (index == 0) { |
257 | di << name << " not loaded shape." << "\n"; |
258 | return 1; |
259 | } |
260 | } |
261 | } |
262 | else { |
263 | index = hider->Index(HS->OriginalShape()); |
264 | if (index == 0) { |
265 | di << name << " not loaded outliner." << "\n"; |
266 | return 1; |
267 | } |
268 | } |
269 | hider->Remove(index); |
270 | di << name << " removed" << "\n"; |
271 | } |
272 | else { |
273 | while (hider->NbShapes() > 0) { |
274 | hider->Remove(1); |
275 | } |
276 | di << " all shapes removed" << "\n"; |
277 | } |
278 | return 0; |
279 | } |
280 | |
281 | //======================================================================= |
282 | //function : sprj |
283 | //purpose : |
284 | //======================================================================= |
285 | |
286 | static Standard_Integer |
287 | sprj (Draw_Interpretor& di, Standard_Integer n, const char** a) |
288 | { |
289 | if (n < 2) return 1; |
290 | const char *name = a[1]; |
291 | HLRAlgo_Projector P; |
292 | if (!HLRTest::GetProjector(name,P)) { |
293 | di << name << " is not a projector." << "\n"; |
294 | return 1; |
295 | } |
296 | hider->Projector(P); |
297 | return 0; |
298 | } |
299 | |
300 | //======================================================================= |
301 | //function : upda |
302 | //purpose : |
303 | //======================================================================= |
304 | |
305 | static Standard_Integer |
306 | upda (Draw_Interpretor& , Standard_Integer, const char**) |
307 | { |
308 | hider->Update(); |
309 | return 0; |
310 | } |
311 | |
312 | //======================================================================= |
313 | //function : hide |
314 | //purpose : |
315 | //======================================================================= |
316 | |
317 | static Standard_Integer |
318 | hide (Draw_Interpretor& , Standard_Integer, const char**) |
319 | { |
320 | hider->Hide(); |
321 | return 0; |
322 | } |
323 | |
324 | //======================================================================= |
325 | //function : show |
326 | //purpose : |
327 | //======================================================================= |
328 | |
329 | static Standard_Integer |
330 | show (Draw_Interpretor& , Standard_Integer, const char**) |
331 | { |
332 | hider->ShowAll(); |
333 | return 0; |
334 | } |
335 | |
336 | //======================================================================= |
337 | //function : hdbg |
338 | //purpose : |
339 | //======================================================================= |
340 | |
341 | static Standard_Integer |
342 | hdbg (Draw_Interpretor& di, Standard_Integer, const char**) |
343 | { |
344 | hider->Debug(!hider->Debug()); |
345 | if (hider->Debug()) |
346 | di << "debug" << "\n"; |
347 | else |
348 | di << "no debug" << "\n"; |
349 | return 0; |
350 | } |
351 | |
352 | //======================================================================= |
353 | //function : hnul |
354 | //purpose : |
355 | //======================================================================= |
356 | |
357 | static Standard_Integer |
358 | hnul (Draw_Interpretor& , Standard_Integer, const char**) |
359 | { |
360 | hider->OutLinedShapeNullify(); |
361 | return 0; |
362 | } |
363 | |
364 | //======================================================================= |
365 | //function : hres |
366 | //purpose : |
367 | //======================================================================= |
368 | |
369 | static Standard_Integer |
370 | hres (Draw_Interpretor& , Standard_Integer n, const char** a) |
371 | { |
372 | TopoDS_Shape S,V,V1,VN,VO,VI,H,H1,HN,HO,HI; |
373 | if (n > 1) { |
374 | const char *name = a[1]; |
375 | S = DBRep::Get(name); |
376 | } |
377 | HLRBRep_HLRToShape HS(hider); |
378 | |
379 | if (S.IsNull()) { |
380 | V = HS.VCompound(); |
381 | V1 = HS.Rg1LineVCompound(); |
382 | VN = HS.RgNLineVCompound(); |
383 | VO = HS.OutLineVCompound(); |
384 | VI = HS.IsoLineVCompound(); |
385 | H = HS.HCompound(); |
386 | H1 = HS.Rg1LineHCompound(); |
387 | HN = HS.RgNLineHCompound(); |
388 | HO = HS.OutLineHCompound(); |
389 | HI = HS.IsoLineHCompound(); |
390 | } |
391 | else { |
392 | V = HS.VCompound(S); |
393 | V1 = HS.Rg1LineVCompound(S); |
394 | VN = HS.RgNLineVCompound(S); |
395 | VO = HS.OutLineVCompound(S); |
396 | VI = HS.IsoLineVCompound(S); |
397 | H = HS.HCompound(S); |
398 | H1 = HS.Rg1LineHCompound(S); |
399 | HN = HS.RgNLineHCompound(S); |
400 | HO = HS.OutLineHCompound(S); |
401 | HI = HS.IsoLineHCompound(S); |
402 | } |
403 | if (!V .IsNull()) DBRep::Set("vl",V); |
404 | if (!V1.IsNull()) DBRep::Set("v1l",V1); |
405 | if (!VN.IsNull()) DBRep::Set("vnl",VN); |
406 | if (!VO.IsNull()) DBRep::Set("vol",VO); |
407 | if (!VI.IsNull()) DBRep::Set("vil",VI); |
408 | if (!H .IsNull()) DBRep::Set("hl",H); |
409 | if (!H1.IsNull()) DBRep::Set("h1l",H1); |
410 | if (!HN.IsNull()) DBRep::Set("hnl",HN); |
411 | if (!HO.IsNull()) DBRep::Set("hol",HO); |
412 | if (!HI.IsNull()) DBRep::Set("hil",HI); |
413 | return 0; |
414 | } |
415 | |
416 | //======================================================================= |
417 | //function : Commands |
418 | //purpose : |
419 | //======================================================================= |
420 | |
421 | void HLRTest::Commands (Draw_Interpretor& theCommands) |
422 | { |
423 | const char* g = "ADVALGOS HLR Commands"; |
424 | |
425 | theCommands.Add("hprj" ,"hprj name [view-id = 1]" ,__FILE__,hprj,g); |
426 | theCommands.Add("houtl" ,"houtl name shape" ,__FILE__,hout,g); |
427 | theCommands.Add("hfill" ,"hfill name proj [nbIso]" ,__FILE__,hfil,g); |
428 | theCommands.Add("hsin" ,"hsin name outliner" ,__FILE__,sori,g); |
429 | theCommands.Add("hsout" ,"hsout name outliner" ,__FILE__,sout,g); |
430 | theCommands.Add("hload" ,"hload outliner" ,__FILE__,hloa,g); |
431 | theCommands.Add("hremove" ,"hremove [name]" ,__FILE__,hrem,g); |
432 | theCommands.Add("hsetprj" ,"hsetprj [name]" ,__FILE__,sprj,g); |
433 | theCommands.Add("hupdate" ,"hupdate" ,__FILE__,upda,g); |
434 | theCommands.Add("hhide" ,"hhide" ,__FILE__,hide,g); |
435 | theCommands.Add("hshowall" ,"hshowall" ,__FILE__,show,g); |
436 | theCommands.Add("hdebug" ,"hdebug" ,__FILE__,hdbg,g); |
437 | theCommands.Add("hnullify" ,"hnullify" ,__FILE__,hnul,g); |
438 | theCommands.Add("hres2d" ,"hres2d" ,__FILE__,hres,g); |
439 | hider = new HLRBRep_Algo(); |
440 | } |
441 | |
442 | //======================================================================= |
443 | //function : save and restore projector |
444 | //purpose : |
445 | //======================================================================= |
446 | |
447 | static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d) |
448 | { |
449 | return d->IsInstance(STANDARD_TYPE(HLRTest_Projector)); |
450 | } |
451 | |
452 | //======================================================================= |
453 | //function : ssave |
454 | //purpose : |
455 | //======================================================================= |
456 | |
457 | static void ssave (const Handle(Draw_Drawable3D)&d, ostream& OS) |
458 | { |
459 | Handle(HLRTest_Projector) HP = |
460 | Handle(HLRTest_Projector)::DownCast(d); |
461 | |
462 | const HLRAlgo_Projector& P = HP->Projector(); |
463 | OS << (P.Perspective() ? "1" : "0") << "\n"; |
464 | if (P.Perspective()) |
465 | OS << P.Focus() << "\n"; |
466 | |
467 | gp_Trsf T = P.Transformation(); |
468 | gp_XYZ V = T.TranslationPart(); |
469 | gp_Mat M = T.VectorialPart(); |
470 | |
471 | OS << M(1,1) << " "; |
472 | OS << M(1,2) << " "; |
473 | OS << M(1,3) << " "; |
474 | OS << V.Coord(1) << " "; |
475 | OS << "\n"; |
476 | OS << M(2,1) << " "; |
477 | OS << M(2,2) << " "; |
478 | OS << M(2,3) << " "; |
479 | OS << V.Coord(2) << " "; |
480 | OS << "\n"; |
481 | OS << M(3,1) << " "; |
482 | OS << M(3,2) << " "; |
483 | OS << M(3,3) << " "; |
484 | OS << V.Coord(3) << " "; |
485 | OS << "\n"; |
486 | |
487 | } |
488 | |
489 | //======================================================================= |
490 | //function : srestore |
491 | //purpose : |
492 | //======================================================================= |
493 | |
494 | static Handle(Draw_Drawable3D) srestore (istream& IS) |
495 | { |
496 | Standard_Boolean pers; |
497 | IS >> pers; |
498 | Standard_Real focus = 1; |
499 | if (pers) IS >> focus; |
500 | |
501 | gp_Trsf T; |
502 | Standard_Real V1[3],V2[3],V3[3]; |
503 | Standard_Real V[3]; |
504 | |
505 | IS >> V1[0] >> V1[1] >> V1[2] >> V[0]; |
506 | IS >> V2[0] >> V2[1] >> V2[2] >> V[1]; |
507 | IS >> V3[0] >> V3[1] >> V3[2] >> V[2]; |
508 | |
509 | gp_Dir D1(V1[0],V1[1],V1[2]); |
510 | gp_Dir D2(V2[0],V2[1],V2[2]); |
511 | gp_Dir D3(V3[0],V3[1],V3[2]); |
512 | gp_Ax3 axes(gp_Pnt(0,0,0),D3,D1); |
513 | D3.Cross(D1); |
514 | if (D3.Dot(D2) < 0) axes.YReverse(); |
515 | T.SetTransformation(axes); |
516 | |
517 | T.SetTranslationPart(gp_Vec(V[0],V[1],V[2])); |
518 | |
519 | HLRAlgo_Projector P(T,pers,focus); |
520 | Handle(HLRTest_Projector) HP = new HLRTest_Projector(P); |
521 | return HP; |
522 | } |
523 | |
524 | //======================================================================= |
525 | //function : ssr |
526 | //purpose : |
527 | //======================================================================= |
528 | |
529 | static Draw_SaveAndRestore ssr("HLRTest_Projector",stest,ssave,srestore); |
530 | |