0025418: Debug output to be limited to OCC development environment
[occt.git] / src / TNaming / TNaming_Translator.cxx
1 // Created on: 1999-06-30
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 <TNaming_Translator.ixx>
18
19 #include <TopoDS_Shape.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
22 #include <TopoDS_TShape.hxx>
23 #include <BRepTools.hxx>
24 #include <TopLoc_Datum3D.hxx>
25 #include <BRep_TVertex.hxx>
26 #include <BRep_TFace.hxx>
27 #include <BRep_TEdge.hxx>
28 #include <TopoDS_TWire.hxx>
29 #include <TopoDS_TShell.hxx>
30 #include <TopoDS_TSolid.hxx>
31 #include <TopoDS_TCompSolid.hxx>
32 #include <TopoDS_TCompound.hxx>
33 #include <TNaming_CopyShape.hxx>
34 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
35
36 //=======================================================================
37 //function : TNaming_Translator
38 //purpose  : 
39 //=======================================================================
40
41 TNaming_Translator::TNaming_Translator () :myIsDone(Standard_False) 
42 {
43   myDataMapOfResults.Clear();
44 }
45
46 //=======================================================================
47 //function : Add
48 //purpose  : 
49 //=======================================================================
50
51 void TNaming_Translator::Add(const TopoDS_Shape& aShape) 
52 {
53  TopoDS_Shape aResult;
54  myDataMapOfResults.Bind(aShape, aResult);
55 }
56
57 //=======================================================================
58 //function : IsDone
59 //purpose  : 
60 //=======================================================================
61
62 Standard_Boolean TNaming_Translator::IsDone() const
63 {
64   return myIsDone;
65 }
66
67 //=======================================================================
68 //function : Copied
69 //purpose  : 
70 //=======================================================================
71
72 const TopTools_DataMapOfShapeShape& TNaming_Translator::Copied() const
73 {
74   return myDataMapOfResults;
75 }
76
77 //=======================================================================
78 //function : Copied
79 //purpose  : find bind shape if it is in the Map
80 //=======================================================================
81
82 const TopoDS_Shape TNaming_Translator::Copied(const TopoDS_Shape& aShape) const
83 {
84   TopoDS_Shape aResult;
85   if(myDataMapOfResults.IsBound(aShape))
86     aResult = myDataMapOfResults.Find(aShape);
87   return aResult;
88 }
89
90 //=======================================================================
91 //function : Perform
92 //purpose  : 
93 //=======================================================================
94
95 void TNaming_Translator::Perform()
96 {
97   TopoDS_Shape Result;
98   TopTools_DataMapIteratorOfDataMapOfShapeShape itm(myDataMapOfResults);
99   for(;itm.More();itm.Next()) {
100     TNaming_CopyShape::CopyTool(itm.Key(), myMap, Result);
101       if(!Result.IsNull())
102         myDataMapOfResults(itm.Key()) = Result;
103       Result.Nullify();
104     }
105   if(myDataMapOfResults.Extent()) myIsDone = Standard_True;
106 }
107
108 //=======================================================================
109 //function : DumpMap
110 //purpose  : 
111 //=======================================================================
112
113 void TNaming_Translator::DumpMap(const Standard_Boolean isWrite) const
114 {
115   TCollection_AsciiString name("Map");
116   TCollection_AsciiString keyname;
117   TCollection_AsciiString itemname;
118   keyname  = name.Cat("_Key");
119   itemname = name.Cat("_Item");
120
121   if (!myMap.Extent()) return;
122   else 
123     cout <<"TNaming_Translator:: IndexedDataMap Extent = "<< myMap.Extent() << endl;
124   
125   for (Standard_Integer i=1; i <= myMap.Extent(); i++)
126     {
127       cout <<"TNaming_Translator::DumpMap:  Index = "<< i << " Type = "<< (myMap.FindKey(i))->DynamicType() << endl;
128       Handle(Standard_Type) T = (myMap.FindKey(i))->DynamicType();
129       if((T == STANDARD_TYPE (BRep_TVertex)) ||(T == STANDARD_TYPE (BRep_TEdge)) ||
130          T == STANDARD_TYPE (BRep_TFace)|| T == STANDARD_TYPE (TopoDS_TWire)||
131          T == STANDARD_TYPE (TopoDS_TShell) || T == STANDARD_TYPE (TopoDS_TSolid) ||
132          T == STANDARD_TYPE (TopoDS_TCompSolid)|| T == STANDARD_TYPE (TopoDS_TCompound))
133         {
134           if(isWrite) {
135             const Handle(TopoDS_TShape)& key = Handle(TopoDS_TShape)::DownCast(myMap.FindKey(i));
136             const Handle(TopoDS_TShape)& item = Handle(TopoDS_TShape)::DownCast(myMap.FindFromIndex(i));
137             TopoDS_Shape S1; S1.TShape(key);
138             TopoDS_Shape S2; S2.TShape(item);
139             BRepTools::Write(S1, keyname.Cat(i).ToCString());
140             BRepTools::Write(S2, itemname.Cat(i).ToCString());    
141           }
142         }
143       else if((myMap.FindKey(i))->DynamicType() == STANDARD_TYPE (TopLoc_Datum3D))
144         {
145           if(isWrite) {
146             const Handle(TopLoc_Datum3D) key = Handle(TopLoc_Datum3D)::DownCast(myMap.FindKey(i));
147             const Handle(TopLoc_Datum3D) Item = Handle(TopLoc_Datum3D)::DownCast(myMap.FindFromIndex(i));
148             cout << "TNaming_Translator::DumpMap: Location_Key_name  = "<< keyname.Cat(i).ToCString()<< endl;
149             key->ShallowDump(cout);
150             cout << "TNaming_Translator::DumpMap: Location_Item_name = "<< itemname.Cat(i).ToCString()<< endl;
151             Item->ShallowDump(cout);
152           }                                                    
153         }
154       else {
155         cout <<"TNaming_Translator::DumpMap: Unexpected Type >> Idex = "<< i << " Type = "<<(myMap.FindKey(i))->DynamicType()<< endl;
156         continue;
157       }
158     }
159 }