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