summaryrefslogtreecommitdiff
path: root/src/TNaming/TNaming_CopyShape.cxx
blob: b3fc044ec3ae396e5f1a682dd1864b8f1991b83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// File:	TNaming_CopyShape.cxx
// Created:	Mon Feb 14 16:50:36 2000
// Author:	Denis PASCAL
//		<dp@dingox.paris1.matra-dtv.fr>


#include <TNaming_CopyShape.ixx>
#include <TopAbs.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopLoc_Datum3D.hxx>

//=======================================================================
//function : CopyTool
//purpose  : Tool to copy a set of shape(s), using the aMap
//=======================================================================

void TNaming_CopyShape::CopyTool( const TopoDS_Shape& aShape,
				 TColStd_IndexedDataMapOfTransientTransient&  aMap,
				 TopoDS_Shape&       aResult)
{

  Handle(TNaming_TranslateTool) TrTool = new TNaming_TranslateTool();
  TNaming_CopyShape::Translate (aShape, aMap, aResult, TrTool) ;
}

//=======================================================================
//function : Translate
//purpose  : TNaming
//=======================================================================

void TNaming_CopyShape::Translate( const TopoDS_Shape& aShape,		         
				  TColStd_IndexedDataMapOfTransientTransient&  aMap,
				  TopoDS_Shape& aResult,
				  const Handle(TNaming_TranslateTool)& TrTool)
{

  if (aShape.IsNull()) return;

  if (aMap.Contains(aShape.TShape())) {
    // get the translated TShape
    Handle(TopoDS_TShape) TS =
       *((Handle(TopoDS_TShape)*) &aMap.FindFromKey(aShape.TShape()));
    aResult.TShape(TS);
  }
  else {

    // create if not translated and update
    
    switch (aShape.ShapeType()) {
      
    case TopAbs_VERTEX :
      TrTool->MakeVertex(aResult);
      TrTool->UpdateVertex(aShape,aResult,aMap);
      break;
      
    case TopAbs_EDGE :
      TrTool->MakeEdge(aResult);
      TrTool->UpdateEdge(aShape,aResult,aMap);
      break;
      
    case TopAbs_WIRE :
      TrTool->MakeWire(aResult);
      TrTool->UpdateShape(aShape,aResult);
      break;
      
    case TopAbs_FACE :
      TrTool->MakeFace(aResult);
      TrTool->UpdateFace(aShape,aResult,aMap);
      break;
    
    case TopAbs_SHELL :
      TrTool->MakeShell(aResult);
      TrTool->UpdateShape(aShape,aResult);
      break;
    
    case TopAbs_SOLID :
      TrTool->MakeSolid(aResult);
      TrTool->UpdateShape(aShape,aResult);
      break;
      
    case TopAbs_COMPSOLID :
      TrTool->MakeCompSolid(aResult);
      TrTool->UpdateShape(aShape,aResult);
      break;
      
  case TopAbs_COMPOUND :
      TrTool->MakeCompound(aResult);
      TrTool->UpdateShape(aShape,aResult);
      break;

    default:
      break;
    }
  
    // bind and copy the sub-elements
    aMap.Add(aShape.TShape(),aResult.TShape()); //TShapes
    TopoDS_Shape S = aShape;
    S.Orientation(TopAbs_FORWARD);
    S.Location(TopLoc_Location()); //Identity
    // copy current Shape
    TopoDS_Iterator itr(S, Standard_False);
    Standard_Boolean wasFree = aResult.Free();
    aResult.Free(Standard_True);
    // translate <sub-shapes>
    for (;itr.More();itr.Next()) {
      TopoDS_Shape subShape;
      TNaming_CopyShape::Translate(itr.Value(), aMap, subShape, TrTool);
      TrTool->Add(aResult, subShape);// add subshapes
    }

    aResult.Free(wasFree);
  }
  
  aResult.Orientation(aShape.Orientation());
  aResult.Location(TNaming_CopyShape::Translate(aShape.Location(), aMap));
  TrTool->UpdateShape(aShape,aResult);
// #ifdef DEB
//     if(fShar) {
//       cout << "=== Shareable shape ===" << endl;
//       cout << "aShape Type = " <<(aShape.TShape())->DynamicType() << endl;
//       if(aShape.Orientation() == aResult.Orientation())
// 	cout<<"\tSource and result shapes have the same Orientation"<< endl;
//       if((aShape.Location().IsEqual(aResult.Location())))
// 	cout <<"\tSource and result shapes have the same Locations" << endl;
//       if((aShape.IsSame(aResult)))
// 	 cout <<"\tShapes arew the same (i.e. the same TShape and the same Locations)" << endl;
//     }	    
// #endif
}

//=======================================================================
// static TranslateDatum3D
//=======================================================================
static Handle(TopLoc_Datum3D) TranslateDatum3D(const Handle(TopLoc_Datum3D)& D,
					       TColStd_IndexedDataMapOfTransientTransient&  aMap)
{
  Handle(TopLoc_Datum3D) TD;
  if(aMap.Contains(D))
       TD = Handle(TopLoc_Datum3D)::DownCast(aMap.FindFromKey(D));
  else {
    TD = new TopLoc_Datum3D(D->Transformation());
    aMap.Add(D, TD);
  }
  return TD;
}
//=======================================================================
//function : Translates
//purpose  : Topological Location
//=======================================================================

TopLoc_Location TNaming_CopyShape::Translate(const TopLoc_Location& L,
					     TColStd_IndexedDataMapOfTransientTransient&  aMap)
{
  TopLoc_Location result;

 if (!L.IsIdentity()) {
   result = Translate(L.NextLocation(),aMap) * 
     TopLoc_Location(TranslateDatum3D(L.FirstDatum(),aMap)).Powered(L.FirstPower());

 }
  return result;
}