7fd59977 |
1 | // File: DNaming_ToolsCommands.cxx |
2 | // Created: Thu Jun 24 18:38:25 1999 |
3 | // Author: Sergey ZARITCHNY |
4 | // <szy@philipox.nnov.matra-dtv.fr> |
5 | |
6 | #include <Draw_Interpretor.hxx> |
7 | #include <Draw.hxx> |
8 | #include <DBRep.hxx> |
9 | #include <DNaming.hxx> |
10 | #include <BRepTools.hxx> |
11 | #include <TopoDS_Face.hxx> |
12 | #include <TopLoc_Location.hxx> |
13 | #include <BRep_Builder.hxx> |
14 | #include <gp_Pnt.hxx> |
15 | #include <TopExp_Explorer.hxx> |
16 | #include <TCollection_AsciiString.hxx> |
17 | #include <TopAbs.hxx> |
18 | #include <TNaming_Translator.hxx> |
19 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> |
20 | #include <DNaming_DataMapOfShapeOfName.hxx> |
21 | #include <DNaming_DataMapIteratorOfDataMapOfShapeOfName.hxx> |
22 | #include <TopTools_MapOfShape.hxx> |
23 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
24 | //======================================================================= |
25 | //function : DNaming_CheckHasSame |
26 | //purpose : CheckIsSame Shape1 Shape2 |
27 | // - for test ShapeCopy mechanism |
28 | //======================================================================= |
29 | |
30 | static Standard_Integer DNaming_CheckHasSame (Draw_Interpretor& di, |
31 | Standard_Integer nb, |
32 | const char** arg) |
33 | { |
34 | if(nb < 4) return 1; |
35 | TopoDS_Shape S1 = DBRep::Get(arg[1]); |
36 | if ( S1.IsNull() ) { |
37 | BRep_Builder aBuilder; |
38 | BRepTools::Read( S1, arg[1], aBuilder); |
39 | } |
40 | |
41 | TopoDS_Shape S2 = DBRep::Get(arg[2]); |
42 | if ( S2.IsNull() ) { |
43 | BRep_Builder aBuilder; |
44 | BRepTools::Read( S2, arg[2], aBuilder); |
45 | } |
46 | char M[8]; |
47 | strcpy(M, arg[3]); |
48 | strtok(M, " \t"); |
49 | TopAbs_ShapeEnum mod = TopAbs_FACE; |
50 | if(M[0] == 'F' || M[0] == 'f') |
51 | mod = TopAbs_FACE; |
52 | else if(M[0] == 'E' || M[0] == 'e') |
53 | mod = TopAbs_EDGE; |
54 | else if(M[0] == 'V' || M[0] == 'v') |
55 | mod = TopAbs_VERTEX; |
56 | else |
57 | return 1; |
58 | |
59 | TopExp_Explorer Exp1, Exp2; |
60 | |
61 | TopTools_MapOfShape M1, M2; |
62 | for(Exp1.Init(S1, mod);Exp1.More();Exp1.Next()) { |
63 | M1.Add(Exp1.Current()); |
64 | } |
65 | for(Exp2.Init(S2, mod);Exp2.More();Exp2.Next()) { |
66 | M2.Add(Exp2.Current()); |
67 | } |
68 | |
69 | TopTools_MapIteratorOfMapOfShape itr1(M1); |
70 | TopTools_MapIteratorOfMapOfShape itr2; |
71 | for(;itr1.More();itr1.Next()) { |
72 | const TopoDS_Shape& s1 = itr1.Key(); |
73 | |
74 | for(itr2.Initialize(M2);itr2.More();itr2.Next()) { |
75 | const TopoDS_Shape& s2 = itr2.Key(); |
76 | if(s1.IsSame(s2)) |
77 | di << "Shapes " << arg[1]<< " and "<< arg[2]<< " have SAME subshapes" <<"\n"; |
78 | } |
79 | } |
80 | |
81 | return 0; |
82 | } |
83 | //======================================================================= |
84 | //function : DNaming_TCopyShape |
85 | //purpose : CopyShape Shape1 [Shape2 ...] |
86 | // - for test ShapeCopy mechanism |
87 | //======================================================================= |
88 | |
89 | static Standard_Integer DNaming_TCopyShape (Draw_Interpretor& di, |
90 | Standard_Integer nb, |
91 | const char** arg) |
92 | { |
93 | TNaming_Translator TR; |
94 | if(nb < 2) return (1); |
95 | |
96 | DNaming_DataMapOfShapeOfName aDMapOfShapeOfName; |
97 | for(Standard_Integer i= 1;i < nb; i++) { |
98 | TopoDS_Shape S = DBRep::Get(arg[i]); |
99 | TCollection_AsciiString name(arg[i]); |
100 | name.AssignCat("_c"); |
101 | if ( S.IsNull() ) { |
102 | BRep_Builder aBuilder; |
103 | BRepTools::Read( S, arg[i], aBuilder); |
104 | } |
105 | |
106 | // Add to Map |
107 | if(S.IsNull()) return(1); |
108 | else { |
109 | aDMapOfShapeOfName.Bind(S, name); |
110 | TR.Add(S); |
111 | } |
112 | } // for ... |
113 | |
114 | // PERFORM |
115 | TR.Perform(); |
116 | |
117 | if(TR.IsDone()){ |
118 | di << "DNaming_CopyShape:: Copy is Done " << "\n"; |
119 | |
120 | DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName); |
121 | for(;itrn.More();itrn.Next()) { |
122 | TCollection_AsciiString name = itrn.Value(); |
123 | const TopoDS_Shape& Result = TR.Copied(itrn.Key()); |
124 | DBRep::Set(name.ToCString(), Result); |
125 | di.AppendElement(name.ToCString()); |
126 | } |
127 | return 0; |
128 | } |
129 | di << "DNaming_CopyShape : Error" << "\n"; |
130 | return 1; |
131 | } |
132 | |
133 | //======================================================================= |
134 | //function : ToolsCommands |
135 | //purpose : |
136 | //======================================================================= |
137 | |
138 | void DNaming::ToolsCommands (Draw_Interpretor& theCommands) |
139 | { |
140 | |
141 | static Standard_Boolean done = Standard_False; |
142 | if (done) return; |
143 | done = Standard_True; |
144 | const char* g = "Naming data commands " ; |
7fd59977 |
145 | |
146 | theCommands.Add ("CopyShape", |
147 | "CopyShape (Shape1 [Shape2] ...)", |
148 | __FILE__, DNaming_TCopyShape, g); |
149 | |
150 | theCommands.Add ("CheckSame", |
151 | "CheckSame (Shape1 Shape2 ExploMode[F|E|V])", |
152 | __FILE__, DNaming_CheckHasSame, g); |
153 | |
154 | } |
155 | |
156 | |