b311480e |
1 | // Created on: 1999-03-09 |
2 | // Created by: data exchange team |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <DBRep.hxx> |
7fd59977 |
19 | #include <ShapeExtend_Explorer.hxx> |
42cf5bc1 |
20 | #include <SWDRAW.hxx> |
21 | #include <SWDRAW_ShapeExtend.hxx> |
7fd59977 |
22 | #include <TopoDS_Shape.hxx> |
42cf5bc1 |
23 | #include <TopTools_HSequenceOfShape.hxx> |
7fd59977 |
24 | |
25 | static Standard_Integer sortcompound (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
26 | { |
27 | Standard_CString arg1 = argv[1]; |
28 | if (argc < 2) { |
586db386 |
29 | di<<"Give shape name. As is, just displays shape type\n"; |
30 | di<<" or add result_name type [mode]\n"; |
31 | di<<" Type : v (vertex) e (edge) w (wire) f (face) s (shell) so (solid)\n"; |
32 | di<<" Mode : n (normal, by default) e (explore) c (compound) x (explore+comp)\n"; |
7fd59977 |
33 | return 0; |
34 | } |
35 | TopoDS_Shape Shape = DBRep::Get(arg1); |
36 | if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; } |
37 | |
38 | if (argc < 4) { |
39 | ShapeExtend_Explorer sbx; |
40 | for (int i = 0; i < 2; i ++) { |
dde68833 |
41 | Standard_Boolean viaCompound = (i != 0); |
42 | TopAbs_ShapeEnum ts = sbx.ShapeType(Shape, viaCompound); |
7fd59977 |
43 | //cout<<" Type "<<(i ? " (via Compound) : " : "(True) : "); |
dde68833 |
44 | if (!viaCompound) { |
586db386 |
45 | di<<" Type (True) : "; |
7fd59977 |
46 | } else { |
586db386 |
47 | di<<" Type (via Compound) : "; |
7fd59977 |
48 | } |
49 | switch (ts) { |
50 | case TopAbs_SHAPE : di<<"SHAPE (empty)"; break; |
51 | case TopAbs_VERTEX : di<<"VERTEX"; break; |
52 | case TopAbs_EDGE : di<<"EDGE"; break; |
53 | case TopAbs_WIRE : di<<"WIRE"; break; |
54 | case TopAbs_FACE : di<<"FACE"; break; |
55 | case TopAbs_SHELL : di<<"SHELL"; break; |
56 | case TopAbs_SOLID : di<<"SOLID"; break; |
57 | case TopAbs_COMPSOLID : di<<"COMPSOLID"; break; |
58 | case TopAbs_COMPOUND : di<<"COMPOUND"; if (i>0) di<<" (heterogeneous)"; break; |
59 | } |
60 | } |
61 | di<<"\n"; |
62 | return 0; |
63 | } |
64 | |
65 | TopAbs_ShapeEnum tse = TopAbs_COMPOUND; |
66 | char tsc = argv[3][0]; |
67 | switch (tsc) { |
68 | case 'v' : tse = TopAbs_VERTEX; break; |
69 | case 'e' : tse = TopAbs_EDGE; break; |
70 | case 'w' : tse = TopAbs_WIRE; break; |
71 | case 'f' : tse = TopAbs_FACE; break; |
c48e2889 |
72 | case 's' : tse = (argv[3][1] == 'o' ? TopAbs_SOLID : TopAbs_SHELL); |
73 | break; |
7fd59977 |
74 | default : break; |
75 | } |
76 | Standard_Boolean modexp = Standard_False; |
77 | Standard_Boolean modcom = Standard_False; |
78 | if (argc > 4) { |
79 | switch (argv[4][0]) { |
80 | case 'e' : modexp = Standard_True; break; |
81 | case 'c' : modcom = Standard_True; break; |
82 | case 'x' : modexp = modcom = Standard_True; break; |
83 | default : break; |
84 | } |
85 | ShapeExtend_Explorer sbx; |
86 | Shape = sbx.SortedCompound (Shape,tse,modexp,modcom); |
586db386 |
87 | if ( Shape.IsNull()) { di<<"Empty result\n"; return 0; } |
7fd59977 |
88 | DBRep::Set(argv[2],Shape); |
89 | } |
90 | return 0; // Done |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : InitCommands |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void SWDRAW_ShapeExtend::InitCommands(Draw_Interpretor& theCommands) |
99 | { |
100 | static Standard_Integer initactor = 0; |
c48e2889 |
101 | if (initactor) |
102 | { |
103 | return; |
104 | } |
105 | initactor = 1; |
106 | |
7fd59977 |
107 | Standard_CString g = SWDRAW::GroupName(); |
108 | theCommands.Add ("sortcompound","shape_entree shape_result type=v-e-w-f-s-so [mode=n-e-c-x]", |
109 | __FILE__,sortcompound,g); |
110 | } |