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


#include <MNaming_NamedShapeStorageDriver.ixx>

#include <MgtBRep.hxx>

#include <PNaming_NamedShape.hxx>

#include <PColStd_HArray1OfInteger.hxx>
#include <PTColStd_TransientPersistentMap.hxx>

#include <PTopoDS_HArray1OfShape1.hxx>

#include <Standard_DomainError.hxx>

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

static Standard_Integer EvolutionInt (const TNaming_Evolution);


//=======================================================================
//function : MNaming_NamedShapeStorageDriver
//purpose  : 
//=======================================================================

MNaming_NamedShapeStorageDriver::MNaming_NamedShapeStorageDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ASDriver(theMsgDriver)
{}


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

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


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

Handle(Standard_Type) MNaming_NamedShapeStorageDriver::SourceType() const
{
  static Handle(Standard_Type) sourceType = STANDARD_TYPE(TNaming_NamedShape);
  return sourceType;
}


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

Handle(PDF_Attribute) MNaming_NamedShapeStorageDriver::NewEmpty() const
{
  return new PNaming_NamedShape ();
}



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

void MNaming_NamedShapeStorageDriver::Paste (
   const Handle(TDF_Attribute)&        Source,
   const Handle(PDF_Attribute)&        Target,
   const Handle(MDF_SRelocationTable)& RelocTable) const

{
  Handle(TNaming_NamedShape) S =
    Handle(TNaming_NamedShape)::DownCast (Source);
  Handle(PNaming_NamedShape) PAttribute =
    Handle(PNaming_NamedShape)::DownCast(Target);

  PTColStd_TransientPersistentMap& TPMap = RelocTable->OtherTable();

  TNaming_Evolution evol = S->Evolution();

  //--------------------------------------------------------------
  //Provisoire pour avoir le nombre de shapes et initialiser Target
  Standard_Integer NbShapes = 0;
  for (TNaming_Iterator SItr (S); SItr.More (); SItr.Next ()) NbShapes++;
  //--------------------------------------------------------------

  if (NbShapes == 0) return;

  Handle(PTopoDS_HArray1OfShape1)  OldPShapes =
    new PTopoDS_HArray1OfShape1(1,NbShapes);
  Handle(PTopoDS_HArray1OfShape1)  NewPShapes =
    new PTopoDS_HArray1OfShape1(1,NbShapes);

  PTopoDS_Shape1 NewPShape;
  PTopoDS_Shape1 OldPShape;
  Standard_Integer i = 1;
  
  for (TNaming_Iterator SIterator(S) ;SIterator.More(); SIterator.Next()) {
    const TopoDS_Shape& OldShape = SIterator.OldShape();
    const TopoDS_Shape& NewShape = SIterator.NewShape();

    if ( evol != TNaming_PRIMITIVE ) {
      MgtBRep::Translate1(OldShape, TPMap, OldPShape,
			  MgtBRep_WithoutTriangle);
    }
    else OldPShape.Nullify();
    OldPShapes->SetValue(i,OldPShape);

    if (evol != TNaming_DELETE) {
      MgtBRep::Translate1(NewShape, TPMap, NewPShape,
			  MgtBRep_WithoutTriangle);
    }
    else NewPShape.Nullify();
    NewPShapes->SetValue(i,NewPShape);
    i++;
  }
  PAttribute->OldShapes(OldPShapes);
  PAttribute->NewShapes(NewPShapes);
  PAttribute->ShapeStatus(EvolutionInt(evol));
  PAttribute->Version    (S->Version());

  NewPShape.Nullify();
  OldPShape.Nullify();
}


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