0033018: Coding - get rid of unused headers [Plugin to ShapeAnalysis]
[occt.git] / src / QADNaming / QADNaming_ToolsCommands.cxx
1 // Created on: 1999-06-24
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DBRep.hxx>
18 #include <Draw_Interpretor.hxx>
19 #include <QADNaming.hxx>
20 #include <BRep_Builder.hxx>
21 #include <BRepTools.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TNaming_Translator.hxx>
24 #include <DNaming_DataMapIteratorOfDataMapOfShapeOfName.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopTools_MapIteratorOfMapOfShape.hxx>
27
28
29
30 //=======================================================================
31 //function : QADNaming_CheckHasSame 
32 //purpose  : CheckIsSame  Shape1 Shape2 
33 //           - for test ShapeCopy mechanism
34 //=======================================================================
35
36 static Standard_Integer QADNaming_CheckHasSame (Draw_Interpretor& di,
37                                               Standard_Integer nb, 
38                                               const char** arg)
39 {
40   if(nb < 4) return 1;
41   TopoDS_Shape S1 = DBRep::Get(arg[1]);
42   if ( S1.IsNull() ) {
43     BRep_Builder aBuilder;
44     BRepTools::Read( S1, arg[1], aBuilder);
45     }
46   
47   TopoDS_Shape S2 = DBRep::Get(arg[2]);
48   if ( S2.IsNull() ) {
49     BRep_Builder aBuilder;
50     BRepTools::Read( S2, arg[2], aBuilder);
51     }
52   char M[8];
53   strcpy(M, arg[3]);
54   strtok(M, " \t");
55   TopAbs_ShapeEnum mod = TopAbs_FACE;
56   if(M[0] == 'F' || M[0] == 'f')
57     mod = TopAbs_FACE;
58   else if(M[0] == 'E' || M[0] == 'e')
59     mod = TopAbs_EDGE;
60   else if(M[0] == 'V' || M[0] == 'v')
61     mod = TopAbs_VERTEX;
62   else 
63     return 1;
64
65   TopExp_Explorer Exp1, Exp2;
66
67   TopTools_MapOfShape M1, M2;
68   for(Exp1.Init(S1, mod);Exp1.More();Exp1.Next()) {
69     M1.Add(Exp1.Current());
70   }
71   for(Exp2.Init(S2, mod);Exp2.More();Exp2.Next()) {
72     M2.Add(Exp2.Current());
73   }
74
75   TopTools_MapIteratorOfMapOfShape itr1(M1);
76   TopTools_MapIteratorOfMapOfShape itr2;
77   for(;itr1.More();itr1.Next()) {
78     const TopoDS_Shape& s1 = itr1.Key();
79     
80     for(itr2.Initialize(M2);itr2.More();itr2.Next()) {
81       const TopoDS_Shape& s2 = itr2.Key();
82       if(s1.IsSame(s2))
83         di << "Shapes " << arg[1]<< " and "<< arg[2]<< " have SAME subshapes\n";
84     }
85   }
86
87   return 0;
88 }           
89 //=======================================================================
90 //function : QADNaming_TCopyShape
91 //purpose  : CopyShape  Shape1 [Shape2 ...] 
92 //           - for test ShapeCopy mechanism
93 //=======================================================================
94
95 static Standard_Integer QADNaming_TCopyShape (Draw_Interpretor& di,
96                                               Standard_Integer nb, 
97                                               const char** arg)
98 {
99   TNaming_Translator TR;
100   if(nb < 2) return (1);
101
102   DNaming_DataMapOfShapeOfName aDMapOfShapeOfName;
103   for(Standard_Integer i= 1;i < nb; i++) {
104     TopoDS_Shape S = DBRep::Get(arg[i]);
105     TCollection_AsciiString name(arg[i]);
106     name.AssignCat("_c");
107     if ( S.IsNull() ) {
108       BRep_Builder aBuilder;
109       BRepTools::Read( S, arg[i], aBuilder);
110     }
111     
112 // Add to Map                
113     if(S.IsNull()) return(1);
114     else {
115       aDMapOfShapeOfName.Bind(S, name);
116       TR.Add(S);
117     }
118   } // for ...
119
120 // PERFORM 
121   TR.Perform();
122
123   if(TR.IsDone()){
124 //    std::cout << "QADNaming_CopyShape:: Copy is Done " << std::endl;
125
126     DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName);
127     for(;itrn.More();itrn.Next()) {
128       TCollection_AsciiString name = itrn.Value();
129       const TopoDS_Shape Result = TR.Copied(itrn.Key());
130       DBRep::Set(name.ToCString(), Result);
131       di.AppendElement(name.ToCString());
132     }
133     return 0;
134   }
135   di << "QADNaming_CopyShape : Error\n";
136   return 1;
137 }
138
139 //=======================================================================
140 //function : ToolsCommands
141 //purpose  : 
142 //=======================================================================
143
144 void QADNaming::ToolsCommands (Draw_Interpretor& theCommands)
145 {  
146
147   static Standard_Boolean done = Standard_False;
148   if (done) return;
149   done = Standard_True;
150   const char* g = "Naming data commands" ;
151   
152   theCommands.Add ("CopyShape", 
153                    "CopyShape (Shape1 [Shape2] ...)",
154                    __FILE__, QADNaming_TCopyShape, g); 
155
156   theCommands.Add ("CheckSame", 
157                    "CheckSame (Shape1 Shape2 ExploMode{F|E|V]",
158                    __FILE__, QADNaming_CheckHasSame, g);   
159 }