summaryrefslogtreecommitdiff
path: root/src/MNaming/MNaming_NamedShapeRetrievalDriver.cxx
blob: ec216aa06e996e3c8695e70b463c28027088dcc5 (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
// File:	MNaming_NamedShapeRetrievalDriver.cxx
// Created:	Mon Apr 14 09:08:07 1997
// Author:	VAUTHIER Jean-Claude


#include <MNaming_NamedShapeRetrievalDriver.ixx>

#include <MgtBRep.hxx>

#include <PCollection_HAsciiString.hxx>

#include <PColStd_HArray1OfInteger.hxx>

#include <PNaming_NamedShape.hxx>

#include <PTopoDS_HArray1OfShape1.hxx>
#include <PTopoDS_Shape1.hxx>

#include <TDF_Data.hxx>
#include <TDF_Label.hxx>

#include <TNaming_NamedShape.hxx>
#include <TNaming_Evolution.hxx>
#include <TNaming_Builder.hxx>
#include <CDM_MessageDriver.hxx>
#include <TopoDS_Shape.hxx>

static TNaming_Evolution EvolutionEnum(const Standard_Integer);


//=======================================================================
//function : MNaming_NamedShapeRetrievalDriver
//purpose  : 
//=======================================================================

MNaming_NamedShapeRetrievalDriver::MNaming_NamedShapeRetrievalDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
{}


//=======================================================================
//function : VersionNumber
//purpose  : 
//=======================================================================

Standard_Integer MNaming_NamedShapeRetrievalDriver::VersionNumber() const
{ return 0; }


//=======================================================================
//function : SourceType
//purpose  : 
//=======================================================================

Handle(Standard_Type) MNaming_NamedShapeRetrievalDriver::SourceType() const
{
  static Handle(Standard_Type) sourceType = STANDARD_TYPE(PNaming_NamedShape);
  return sourceType;
}


//=======================================================================
//function : NewEmpty
//purpose  : 
//=======================================================================

Handle(TDF_Attribute) MNaming_NamedShapeRetrievalDriver::NewEmpty() const

{
  return new TNaming_NamedShape ();
}



//=======================================================================
//function : Paste
//purpose  : 
//=======================================================================

void MNaming_NamedShapeRetrievalDriver::Paste (
   const Handle(PDF_Attribute)&        Source,
   const Handle(TDF_Attribute)&        Target,
   const Handle(MDF_RRelocationTable)& RelocTable) const
{
  Handle(PNaming_NamedShape) S = Handle(PNaming_NamedShape)::DownCast (Source);
  Handle(TNaming_NamedShape) T = Handle(TNaming_NamedShape)::DownCast (Target);
  Standard_Integer NbShapes = S->NbShapes();

  //Handle (TDF_Data) TDF = RelocTable->Target ();
  TDF_Label         Label = Target->Label ();
  //TDF_Insertor      TDFIns(Label);
  TNaming_Builder   Bld   (Label);
  if (NbShapes == 0) return;

  TNaming_Evolution evol  = EvolutionEnum(S->ShapeStatus());
  T->SetVersion(S->Version()); // apres creation Builder qui a mis la version a 1.

  Handle(PTopoDS_HArray1OfShape1)  OldPShapes  = S->OldShapes();
  Handle(PTopoDS_HArray1OfShape1)  NewPShapes  = S->NewShapes();

  TopoDS_Shape OldShape;
  TopoDS_Shape NewShape;

  PTColStd_PersistentTransientMap& PTMap = RelocTable->OtherTable();

  for (Standard_Integer i = 1; i <= NbShapes; i++) {
    const PTopoDS_Shape1& NewPShape = NewPShapes->Value(i);
    const PTopoDS_Shape1& OldPShape = OldPShapes->Value(i);

    if ( evol != TNaming_PRIMITIVE ) {
      MgtBRep::Translate1(OldPShape, PTMap, OldShape,
			  MgtBRep_WithoutTriangle);
    }

    if (evol != TNaming_DELETE) {
      MgtBRep::Translate1(NewPShape, PTMap, NewShape,
			  MgtBRep_WithoutTriangle);
    }

    switch (evol) {
    case TNaming_PRIMITIVE    : {
      Bld.Generated(NewShape); break;
    }
    case TNaming_GENERATED    : {
      Bld.Generated(OldShape,NewShape); break;
    }
    case TNaming_MODIFY       : {
      Bld.Modify(OldShape,NewShape); break;
    }
    case TNaming_DELETE       : {
      Bld.Delete (OldShape); break;
    }
    case TNaming_SELECTED     : {
      Bld.Select(NewShape, OldShape); break;
    }
    case TNaming_REPLACE      :{
      Bld.Replace(OldShape,NewShape); break;
    }  
      default :
	Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
    }
    OldShape.Nullify();
    NewShape.Nullify();
  }
//  cout<<endl;  - vbu le 28/10/1998
}



TNaming_Evolution EvolutionEnum(const Standard_Integer i)
{
  switch(i)
    {
    case 0 : return TNaming_PRIMITIVE;
    case 1 : return TNaming_GENERATED;
    case 2 : return TNaming_MODIFY;
    case 3 : return TNaming_DELETE;
    case 4 : return TNaming_SELECTED;
    case 5 : return TNaming_REPLACE;
   default:
      Standard_DomainError::Raise("TNaming_Evolution; integer value without enum term equivalence");
    }
  return TNaming_PRIMITIVE; // To avoid compilation error message.
}