7fd59977 |
1 | // File: MNaming_NamedShapeRetrievalDriver.cxx |
2 | // Created: Mon Apr 14 09:08:07 1997 |
3 | // Author: VAUTHIER Jean-Claude |
4 | |
5 | |
6 | #include <MNaming_NamedShapeRetrievalDriver.ixx> |
7 | |
8 | #include <MgtBRep.hxx> |
9 | |
10 | #include <PCollection_HAsciiString.hxx> |
11 | |
12 | #include <PColStd_HArray1OfInteger.hxx> |
13 | |
14 | #include <PNaming_NamedShape.hxx> |
15 | |
16 | #include <PTopoDS_HArray1OfShape1.hxx> |
17 | #include <PTopoDS_Shape1.hxx> |
18 | |
19 | #include <TDF_Data.hxx> |
20 | #include <TDF_Label.hxx> |
21 | |
22 | #include <TNaming_NamedShape.hxx> |
23 | #include <TNaming_Evolution.hxx> |
24 | #include <TNaming_Builder.hxx> |
25 | #include <CDM_MessageDriver.hxx> |
26 | #include <TopoDS_Shape.hxx> |
27 | |
28 | static TNaming_Evolution EvolutionEnum(const Standard_Integer); |
29 | |
30 | |
31 | //======================================================================= |
32 | //function : MNaming_NamedShapeRetrievalDriver |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | MNaming_NamedShapeRetrievalDriver::MNaming_NamedShapeRetrievalDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver) |
37 | {} |
38 | |
39 | |
40 | //======================================================================= |
41 | //function : VersionNumber |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | Standard_Integer MNaming_NamedShapeRetrievalDriver::VersionNumber() const |
46 | { return 0; } |
47 | |
48 | |
49 | //======================================================================= |
50 | //function : SourceType |
51 | //purpose : |
52 | //======================================================================= |
53 | |
54 | Handle(Standard_Type) MNaming_NamedShapeRetrievalDriver::SourceType() const |
55 | { |
56 | static Handle(Standard_Type) sourceType = STANDARD_TYPE(PNaming_NamedShape); |
57 | return sourceType; |
58 | } |
59 | |
60 | |
61 | //======================================================================= |
62 | //function : NewEmpty |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | Handle(TDF_Attribute) MNaming_NamedShapeRetrievalDriver::NewEmpty() const |
67 | |
68 | { |
69 | return new TNaming_NamedShape (); |
70 | } |
71 | |
72 | |
73 | |
74 | //======================================================================= |
75 | //function : Paste |
76 | //purpose : |
77 | //======================================================================= |
78 | |
79 | void MNaming_NamedShapeRetrievalDriver::Paste ( |
80 | const Handle(PDF_Attribute)& Source, |
81 | const Handle(TDF_Attribute)& Target, |
82 | const Handle(MDF_RRelocationTable)& RelocTable) const |
83 | { |
84 | Handle(PNaming_NamedShape) S = Handle(PNaming_NamedShape)::DownCast (Source); |
85 | Handle(TNaming_NamedShape) T = Handle(TNaming_NamedShape)::DownCast (Target); |
86 | Standard_Integer NbShapes = S->NbShapes(); |
87 | |
88 | //Handle (TDF_Data) TDF = RelocTable->Target (); |
89 | TDF_Label Label = Target->Label (); |
90 | //TDF_Insertor TDFIns(Label); |
91 | TNaming_Builder Bld (Label); |
92 | if (NbShapes == 0) return; |
93 | |
94 | TNaming_Evolution evol = EvolutionEnum(S->ShapeStatus()); |
95 | T->SetVersion(S->Version()); // apres creation Builder qui a mis la version a 1. |
96 | |
97 | Handle(PTopoDS_HArray1OfShape1) OldPShapes = S->OldShapes(); |
98 | Handle(PTopoDS_HArray1OfShape1) NewPShapes = S->NewShapes(); |
99 | |
100 | TopoDS_Shape OldShape; |
101 | TopoDS_Shape NewShape; |
102 | |
103 | PTColStd_PersistentTransientMap& PTMap = RelocTable->OtherTable(); |
104 | |
105 | for (Standard_Integer i = 1; i <= NbShapes; i++) { |
106 | const PTopoDS_Shape1& NewPShape = NewPShapes->Value(i); |
107 | const PTopoDS_Shape1& OldPShape = OldPShapes->Value(i); |
108 | |
109 | if ( evol != TNaming_PRIMITIVE ) { |
110 | MgtBRep::Translate1(OldPShape, PTMap, OldShape, |
111 | MgtBRep_WithoutTriangle); |
112 | } |
113 | |
114 | if (evol != TNaming_DELETE) { |
115 | MgtBRep::Translate1(NewPShape, PTMap, NewShape, |
116 | MgtBRep_WithoutTriangle); |
117 | } |
118 | |
119 | switch (evol) { |
120 | case TNaming_PRIMITIVE : { |
121 | Bld.Generated(NewShape); break; |
122 | } |
123 | case TNaming_GENERATED : { |
124 | Bld.Generated(OldShape,NewShape); break; |
125 | } |
126 | case TNaming_MODIFY : { |
127 | Bld.Modify(OldShape,NewShape); break; |
128 | } |
129 | case TNaming_DELETE : { |
130 | Bld.Delete (OldShape); break; |
131 | } |
132 | case TNaming_SELECTED : { |
133 | Bld.Select(NewShape, OldShape); break; |
134 | } |
135 | case TNaming_REPLACE :{ |
136 | Bld.Replace(OldShape,NewShape); break; |
137 | } |
138 | default : |
139 | Standard_DomainError::Raise("TNaming_Evolution; enum term unknown"); |
140 | } |
141 | OldShape.Nullify(); |
142 | NewShape.Nullify(); |
143 | } |
144 | // cout<<endl; - vbu le 28/10/1998 |
145 | } |
146 | |
147 | |
148 | |
149 | TNaming_Evolution EvolutionEnum(const Standard_Integer i) |
150 | { |
151 | switch(i) |
152 | { |
153 | case 0 : return TNaming_PRIMITIVE; |
154 | case 1 : return TNaming_GENERATED; |
155 | case 2 : return TNaming_MODIFY; |
156 | case 3 : return TNaming_DELETE; |
157 | case 4 : return TNaming_SELECTED; |
158 | case 5 : return TNaming_REPLACE; |
159 | default: |
160 | Standard_DomainError::Raise("TNaming_Evolution; integer value without enum term equivalence"); |
161 | } |
162 | return TNaming_PRIMITIVE; // To avoid compilation error message. |
163 | } |
164 | |