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