b311480e |
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 | |
7fd59977 |
21 | |
22 | |
23 | #include <MNaming_NamedShapeStorageDriver.ixx> |
24 | |
25 | #include <MgtBRep.hxx> |
26 | |
27 | #include <PNaming_NamedShape.hxx> |
28 | |
29 | #include <PColStd_HArray1OfInteger.hxx> |
30 | #include <PTColStd_TransientPersistentMap.hxx> |
31 | |
32 | #include <PTopoDS_HArray1OfShape1.hxx> |
33 | |
34 | #include <Standard_DomainError.hxx> |
35 | |
36 | #include <TNaming_NamedShape.hxx> |
37 | #include <TNaming_Evolution.hxx> |
38 | #include <TNaming_Iterator.hxx> |
39 | #include <CDM_MessageDriver.hxx> |
40 | #include <TopoDS_Shape.hxx> |
41 | |
42 | static Standard_Integer EvolutionInt (const TNaming_Evolution); |
43 | |
44 | |
45 | //======================================================================= |
46 | //function : MNaming_NamedShapeStorageDriver |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | MNaming_NamedShapeStorageDriver::MNaming_NamedShapeStorageDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ASDriver(theMsgDriver) |
51 | {} |
52 | |
53 | |
54 | //======================================================================= |
55 | //function : VersionNumber |
56 | //purpose : |
57 | //======================================================================= |
58 | |
59 | Standard_Integer MNaming_NamedShapeStorageDriver::VersionNumber() const |
60 | { return 0; } |
61 | |
62 | |
63 | //======================================================================= |
64 | //function : SourceType |
65 | //purpose : |
66 | //======================================================================= |
67 | |
68 | Handle(Standard_Type) MNaming_NamedShapeStorageDriver::SourceType() const |
69 | { |
70 | static Handle(Standard_Type) sourceType = STANDARD_TYPE(TNaming_NamedShape); |
71 | return sourceType; |
72 | } |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : NewEmpty |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Handle(PDF_Attribute) MNaming_NamedShapeStorageDriver::NewEmpty() const |
81 | { |
82 | return new PNaming_NamedShape (); |
83 | } |
84 | |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : Paste |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | void MNaming_NamedShapeStorageDriver::Paste ( |
93 | const Handle(TDF_Attribute)& Source, |
94 | const Handle(PDF_Attribute)& Target, |
95 | const Handle(MDF_SRelocationTable)& RelocTable) const |
96 | |
97 | { |
98 | Handle(TNaming_NamedShape) S = |
99 | Handle(TNaming_NamedShape)::DownCast (Source); |
100 | Handle(PNaming_NamedShape) PAttribute = |
101 | Handle(PNaming_NamedShape)::DownCast(Target); |
102 | |
103 | PTColStd_TransientPersistentMap& TPMap = RelocTable->OtherTable(); |
104 | |
105 | TNaming_Evolution evol = S->Evolution(); |
106 | |
107 | //-------------------------------------------------------------- |
108 | //Provisoire pour avoir le nombre de shapes et initialiser Target |
109 | Standard_Integer NbShapes = 0; |
110 | for (TNaming_Iterator SItr (S); SItr.More (); SItr.Next ()) NbShapes++; |
111 | //-------------------------------------------------------------- |
112 | |
113 | if (NbShapes == 0) return; |
114 | |
115 | Handle(PTopoDS_HArray1OfShape1) OldPShapes = |
116 | new PTopoDS_HArray1OfShape1(1,NbShapes); |
117 | Handle(PTopoDS_HArray1OfShape1) NewPShapes = |
118 | new PTopoDS_HArray1OfShape1(1,NbShapes); |
119 | |
120 | PTopoDS_Shape1 NewPShape; |
121 | PTopoDS_Shape1 OldPShape; |
122 | Standard_Integer i = 1; |
123 | |
124 | for (TNaming_Iterator SIterator(S) ;SIterator.More(); SIterator.Next()) { |
125 | const TopoDS_Shape& OldShape = SIterator.OldShape(); |
126 | const TopoDS_Shape& NewShape = SIterator.NewShape(); |
127 | |
128 | if ( evol != TNaming_PRIMITIVE ) { |
129 | MgtBRep::Translate1(OldShape, TPMap, OldPShape, |
130 | MgtBRep_WithoutTriangle); |
131 | } |
132 | else OldPShape.Nullify(); |
133 | OldPShapes->SetValue(i,OldPShape); |
134 | |
135 | if (evol != TNaming_DELETE) { |
136 | MgtBRep::Translate1(NewShape, TPMap, NewPShape, |
137 | MgtBRep_WithoutTriangle); |
138 | } |
139 | else NewPShape.Nullify(); |
140 | NewPShapes->SetValue(i,NewPShape); |
141 | i++; |
142 | } |
143 | PAttribute->OldShapes(OldPShapes); |
144 | PAttribute->NewShapes(NewPShapes); |
145 | PAttribute->ShapeStatus(EvolutionInt(evol)); |
146 | PAttribute->Version (S->Version()); |
147 | |
148 | NewPShape.Nullify(); |
149 | OldPShape.Nullify(); |
150 | } |
151 | |
152 | |
153 | Standard_Integer EvolutionInt(const TNaming_Evolution i) |
154 | { |
155 | switch(i) { |
156 | case TNaming_PRIMITIVE : return 0; |
157 | case TNaming_GENERATED : return 1; |
158 | case TNaming_MODIFY : return 2; |
159 | case TNaming_DELETE : return 3; |
160 | case TNaming_SELECTED : return 4; |
566f8441 |
161 | case TNaming_REPLACE : return 2; //case TNaming_REPLACE : return 5; for compatibility |
7fd59977 |
162 | default: |
163 | Standard_DomainError::Raise("TNaming_Evolution; enum term unknown"); |
164 | } |
165 | return 0; // To avoid compilation error message. |
166 | } |
167 | |