0023205: Patch for Naming improvement
[occt.git] / src / MNaming / MNaming_NamedShapeRetrievalDriver.cxx
1 // Created on: 1997-04-14
2 // Created by: VAUTHIER Jean-Claude
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <MNaming_NamedShapeRetrievalDriver.ixx>
24
25 #include <MgtBRep.hxx>
26
27 #include <PCollection_HAsciiString.hxx>
28
29 #include <PColStd_HArray1OfInteger.hxx>
30
31 #include <PNaming_NamedShape.hxx>
32
33 #include <PTopoDS_HArray1OfShape1.hxx>
34 #include <PTopoDS_Shape1.hxx>
35
36 #include <TDF_Data.hxx>
37 #include <TDF_Label.hxx>
38
39 #include <TNaming_NamedShape.hxx>
40 #include <TNaming_Evolution.hxx>
41 #include <TNaming_Builder.hxx>
42 #include <CDM_MessageDriver.hxx>
43 #include <TopoDS_Shape.hxx>
44
45 static TNaming_Evolution EvolutionEnum(const Standard_Integer);
46
47
48 //=======================================================================
49 //function : MNaming_NamedShapeRetrievalDriver
50 //purpose  : 
51 //=======================================================================
52
53 MNaming_NamedShapeRetrievalDriver::MNaming_NamedShapeRetrievalDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
54 {}
55
56
57 //=======================================================================
58 //function : VersionNumber
59 //purpose  : 
60 //=======================================================================
61
62 Standard_Integer MNaming_NamedShapeRetrievalDriver::VersionNumber() const
63 { return 0; }
64
65
66 //=======================================================================
67 //function : SourceType
68 //purpose  : 
69 //=======================================================================
70
71 Handle(Standard_Type) MNaming_NamedShapeRetrievalDriver::SourceType() const
72 {
73   static Handle(Standard_Type) sourceType = STANDARD_TYPE(PNaming_NamedShape);
74   return sourceType;
75 }
76
77
78 //=======================================================================
79 //function : NewEmpty
80 //purpose  : 
81 //=======================================================================
82
83 Handle(TDF_Attribute) MNaming_NamedShapeRetrievalDriver::NewEmpty() const
84
85 {
86   return new TNaming_NamedShape ();
87 }
88
89
90
91 //=======================================================================
92 //function : Paste
93 //purpose  : 
94 //=======================================================================
95
96 void MNaming_NamedShapeRetrievalDriver::Paste (
97    const Handle(PDF_Attribute)&        Source,
98    const Handle(TDF_Attribute)&        Target,
99    const Handle(MDF_RRelocationTable)& RelocTable) const
100 {
101   Handle(PNaming_NamedShape) S = Handle(PNaming_NamedShape)::DownCast (Source);
102   Handle(TNaming_NamedShape) T = Handle(TNaming_NamedShape)::DownCast (Target);
103   Standard_Integer NbShapes = S->NbShapes();
104
105   //Handle (TDF_Data) TDF = RelocTable->Target ();
106   TDF_Label         Label = Target->Label ();
107   //TDF_Insertor      TDFIns(Label);
108   TNaming_Builder   Bld   (Label);
109   if (NbShapes == 0) return;
110
111   TNaming_Evolution evol  = EvolutionEnum(S->ShapeStatus());
112   T->SetVersion(S->Version()); // apres creation Builder qui a mis la version a 1.
113
114   Handle(PTopoDS_HArray1OfShape1)  OldPShapes  = S->OldShapes();
115   Handle(PTopoDS_HArray1OfShape1)  NewPShapes  = S->NewShapes();
116
117   TopoDS_Shape OldShape;
118   TopoDS_Shape NewShape;
119
120   PTColStd_PersistentTransientMap& PTMap = RelocTable->OtherTable();
121
122   for (Standard_Integer i = 1; i <= NbShapes; i++) {
123     const PTopoDS_Shape1& NewPShape = NewPShapes->Value(i);
124     const PTopoDS_Shape1& OldPShape = OldPShapes->Value(i);
125
126     if ( evol != TNaming_PRIMITIVE ) {
127       MgtBRep::Translate1(OldPShape, PTMap, OldShape,
128                           MgtBRep_WithoutTriangle);
129     }
130
131     if (evol != TNaming_DELETE) {
132       MgtBRep::Translate1(NewPShape, PTMap, NewShape,
133                           MgtBRep_WithoutTriangle);
134     }
135
136     switch (evol) {
137     case TNaming_PRIMITIVE    : {
138       Bld.Generated(NewShape); break;
139     }
140     case TNaming_GENERATED    : {
141       Bld.Generated(OldShape,NewShape); break;
142     }
143     case TNaming_MODIFY       : {
144       Bld.Modify(OldShape,NewShape); break;
145     }
146     case TNaming_DELETE       : {
147       Bld.Delete (OldShape); break;
148     }
149     case TNaming_SELECTED     : {
150       Bld.Select(NewShape, OldShape); break;
151     }
152     case TNaming_REPLACE      :{
153       //Bld.Replace(OldShape,NewShape); break;
154       Bld.Modify(OldShape,NewShape); break;// for compatibility only
155     }  
156       default :
157         Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
158     }
159     OldShape.Nullify();
160     NewShape.Nullify();
161   }
162 //  cout<<endl;  - vbu le 28/10/1998
163 }
164
165
166
167 TNaming_Evolution EvolutionEnum(const Standard_Integer i)
168 {
169   switch(i)
170     {
171     case 0 : return TNaming_PRIMITIVE;
172     case 1 : return TNaming_GENERATED;
173     case 2 : return TNaming_MODIFY;
174     case 3 : return TNaming_DELETE;
175     case 4 : return TNaming_SELECTED;
176     case 5 : return TNaming_REPLACE;
177    default:
178       Standard_DomainError::Raise("TNaming_Evolution; integer value without enum term equivalence");
179     }
180   return TNaming_PRIMITIVE; // To avoid compilation error message.
181 }
182