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