0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / StdPersistent / StdPersistent_Naming.cxx
1 // Copyright (c) 2015 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <StdPersistent_Naming.hxx>
15 #include <StdObjMgt_ReadData.hxx>
16
17 #include <TNaming_Name.hxx>
18 #include <TNaming_Builder.hxx>
19 #include <TNaming_Iterator.hxx>
20
21
22 //=======================================================================
23 //function : Import
24 //purpose  : Import transient attribuite from the persistent data
25 //=======================================================================
26 void StdPersistent_Naming::NamedShape::Import
27   (const Handle(TNaming_NamedShape)& theAttribute) const
28 {
29   theAttribute->SetVersion (myVersion);
30
31   if (myOldShapes.IsNull() || myNewShapes.IsNull())
32     return;
33
34   TNaming_Builder aBuilder (theAttribute->Label());
35
36   StdPersistent_HArray1OfShape1::Iterator aOldShapesIter (*myOldShapes->Array());
37   StdPersistent_HArray1OfShape1::Iterator aNewShapesIter (*myNewShapes->Array());
38   for (; aNewShapesIter.More(); aOldShapesIter.Next(), aNewShapesIter.Next())
39   {
40     TopoDS_Shape aOldShape = aOldShapesIter.Value().Import();
41     TopoDS_Shape aNewShape = aNewShapesIter.Value().Import();
42
43     switch (myShapeStatus)
44     {
45     case 0: aBuilder.Generated (aNewShape);            break; // PRIMITIVE
46     case 1: aBuilder.Generated (aOldShape, aNewShape); break; // GENERATED
47     case 2: aBuilder.Modify    (aOldShape, aNewShape); break; // MODIFY
48     case 3: aBuilder.Delete    (aOldShape);            break; // DELETE
49     case 4: aBuilder.Select    (aNewShape, aOldShape); break; // SELECTED
50     case 5: aBuilder.Modify    (aOldShape, aNewShape); break; // REPLACE
51     }
52   }
53 }
54
55 //=======================================================================
56 //function : Read
57 //purpose  : Read persistent data from a file
58 //=======================================================================
59 void StdPersistent_Naming::Name::Read (StdObjMgt_ReadData& theReadData)
60 {
61   theReadData >> myType >> myShapeType >> myArgs >> myStop >> myIndex;
62 }
63
64 //=======================================================================
65 //function : Write
66 //purpose  : Write persistent data to a file
67 //=======================================================================
68 void StdPersistent_Naming::Name::Write (StdObjMgt_WriteData& theWriteData) const
69 {
70   theWriteData << myType << myShapeType << myArgs << myStop << myIndex;
71 }
72
73 //=======================================================================
74 //function : Import
75 //purpose  : Import transient object from the persistent data
76 //=======================================================================
77 void StdPersistent_Naming::Name::Import
78   (TNaming_Name& theName, const Handle(TDF_Data)&) const
79 {
80   theName.Type      (static_cast<TNaming_NameType> (myType));
81   theName.ShapeType (static_cast<TopAbs_ShapeEnum> (myShapeType));
82
83   if (myArgs)
84   {
85     StdLPersistent_HArray1OfPersistent::Iterator anIter (*myArgs->Array());
86     for (; anIter.More(); anIter.Next())
87     {
88       Handle(StdObjMgt_Persistent) aPersistent = anIter.Value();
89       if (aPersistent)
90       {
91         Handle(TDF_Attribute) anArg = aPersistent->GetAttribute();
92         theName.Append (Handle(TNaming_NamedShape)::DownCast (anArg));
93       }
94     }
95   }
96
97   if (myStop)
98   {
99     Handle(TDF_Attribute) aStop = myStop->GetAttribute();
100     theName.StopNamedShape (Handle(TNaming_NamedShape)::DownCast (aStop));
101   }
102
103   theName.Index (myIndex);
104 }
105
106 //=======================================================================
107 //function : Read
108 //purpose  : Read persistent data from a file
109 //=======================================================================
110 void StdPersistent_Naming::Name_1::Read (StdObjMgt_ReadData& theReadData)
111 {
112   Name::Read (theReadData);
113   theReadData >> myContextLabel;
114 }
115
116 //=======================================================================
117 //function : Write
118 //purpose  : Write persistent data to a file
119 //=======================================================================
120 void StdPersistent_Naming::Name_1::Write (StdObjMgt_WriteData& theWriteData) const
121 {
122   Name::Write (theWriteData);
123   theWriteData << myContextLabel;
124 }
125
126 //=======================================================================
127 //function : Import
128 //purpose  : Import transient object from the persistent data
129 //=======================================================================
130 void StdPersistent_Naming::Name_1::Import
131   (TNaming_Name& theName, const Handle(TDF_Data)& theDF) const
132 {
133   Name::Import (theName, theDF);
134   if (myContextLabel)
135     theName.ContextLabel (myContextLabel->Label (theDF));
136 }
137
138 //=======================================================================
139 //function : Read
140 //purpose  : Read persistent data from a file
141 //=======================================================================
142 void StdPersistent_Naming::Name_2::Read (StdObjMgt_ReadData& theReadData)
143 {
144   Name_1::Read (theReadData);
145   theReadData >> myOrientation;
146 }
147
148 //=======================================================================
149 //function : Write
150 //purpose  : Write persistent data to a file
151 //=======================================================================
152 void StdPersistent_Naming::Name_2::Write (StdObjMgt_WriteData& theWriteData) const
153 {
154   Name_1::Write (theWriteData);
155   theWriteData << myOrientation;
156 }
157
158 //=======================================================================
159 //function : Import
160 //purpose  : Import transient object from the persistent data
161 //=======================================================================
162 void StdPersistent_Naming::Name_2::Import
163   (TNaming_Name& theName, const Handle(TDF_Data)& theDF) const
164 {
165   Name_1::Import (theName, theDF);
166   theName.Orientation (static_cast<TopAbs_Orientation> (myOrientation));
167 }
168
169 //=======================================================================
170 //function : ImportAttribute
171 //purpose  : Import transient attribuite from the persistent data
172 //=======================================================================
173 void StdPersistent_Naming::Naming::ImportAttribute()
174 {
175   Handle(Name) aName = Handle(Name)::DownCast (myData);
176   if (aName)
177   {
178     aName->Import (myTransient->ChangeName(), myTransient->Label().Data());
179     myData.Nullify();
180   }
181 }
182
183 //=======================================================================
184 //function : ImportAttribute
185 //purpose  : Import transient attribuite from the persistent data
186 //=======================================================================
187 void StdPersistent_Naming::Naming_1::ImportAttribute()
188 {
189   Naming::ImportAttribute();
190
191   Handle(TNaming_NamedShape) aNamedShape;
192   if (myTransient->Label().FindAttribute (TNaming_NamedShape::GetID(), aNamedShape)
193    && aNamedShape->Evolution() == TNaming_SELECTED)
194   {
195     for (TNaming_Iterator anIter (aNamedShape); anIter.More(); anIter.Next())
196     {
197       const TopoDS_Shape& aOldShape = anIter.OldShape();
198       const TopoDS_Shape& aNewShape = anIter.NewShape();
199
200       if (!aOldShape.IsNull() && aOldShape.ShapeType() == TopAbs_VERTEX
201              && !aNewShape.IsNull() && aNewShape.ShapeType() != TopAbs_VERTEX)
202       {
203         myTransient->ChangeName().Orientation (aOldShape.Orientation());
204       }
205     }
206   }
207 }