1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <StdPersistent_Naming.hxx>
15 #include <StdObjMgt_ReadData.hxx>
17 #include <TNaming_Name.hxx>
18 #include <TNaming_Builder.hxx>
19 #include <TNaming_Iterator.hxx>
22 //=======================================================================
24 //purpose : Import transient attribuite from the persistent data
25 //=======================================================================
26 void StdPersistent_Naming::NamedShape::Import
27 (const Handle(TNaming_NamedShape)& theAttribute) const
29 theAttribute->SetVersion (myVersion);
31 if (myOldShapes.IsNull() || myNewShapes.IsNull())
34 TNaming_Builder aBuilder (theAttribute->Label());
36 StdPersistent_HArray1OfShape1::Iterator aOldShapesIter (*myOldShapes->Array());
37 StdPersistent_HArray1OfShape1::Iterator aNewShapesIter (*myNewShapes->Array());
38 for (; aNewShapesIter.More(); aOldShapesIter.Next(), aNewShapesIter.Next())
40 TopoDS_Shape aOldShape = aOldShapesIter.Value().Import();
41 TopoDS_Shape aNewShape = aNewShapesIter.Value().Import();
43 switch (myShapeStatus)
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
55 //=======================================================================
57 //purpose : Read persistent data from a file
58 //=======================================================================
59 void StdPersistent_Naming::Name::Read (StdObjMgt_ReadData& theReadData)
61 theReadData >> myType >> myShapeType >> myArgs >> myStop >> myIndex;
64 //=======================================================================
66 //purpose : Write persistent data to a file
67 //=======================================================================
68 void StdPersistent_Naming::Name::Write (StdObjMgt_WriteData& theWriteData) const
70 theWriteData << myType << myShapeType << myArgs << myStop << myIndex;
73 //=======================================================================
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
80 theName.Type (static_cast<TNaming_NameType> (myType));
81 theName.ShapeType (static_cast<TopAbs_ShapeEnum> (myShapeType));
85 StdLPersistent_HArray1OfPersistent::Iterator anIter (*myArgs->Array());
86 for (; anIter.More(); anIter.Next())
88 Handle(StdObjMgt_Persistent) aPersistent = anIter.Value();
91 Handle(TDF_Attribute) anArg = aPersistent->GetAttribute();
92 theName.Append (Handle(TNaming_NamedShape)::DownCast (anArg));
99 Handle(TDF_Attribute) aStop = myStop->GetAttribute();
100 theName.StopNamedShape (Handle(TNaming_NamedShape)::DownCast (aStop));
103 theName.Index (myIndex);
106 //=======================================================================
108 //purpose : Read persistent data from a file
109 //=======================================================================
110 void StdPersistent_Naming::Name_1::Read (StdObjMgt_ReadData& theReadData)
112 Name::Read (theReadData);
113 theReadData >> myContextLabel;
116 //=======================================================================
118 //purpose : Write persistent data to a file
119 //=======================================================================
120 void StdPersistent_Naming::Name_1::Write (StdObjMgt_WriteData& theWriteData) const
122 Name::Write (theWriteData);
123 theWriteData << myContextLabel;
126 //=======================================================================
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
133 Name::Import (theName, theDF);
135 theName.ContextLabel (myContextLabel->Label (theDF));
138 //=======================================================================
140 //purpose : Read persistent data from a file
141 //=======================================================================
142 void StdPersistent_Naming::Name_2::Read (StdObjMgt_ReadData& theReadData)
144 Name_1::Read (theReadData);
145 theReadData >> myOrientation;
148 //=======================================================================
150 //purpose : Write persistent data to a file
151 //=======================================================================
152 void StdPersistent_Naming::Name_2::Write (StdObjMgt_WriteData& theWriteData) const
154 Name_1::Write (theWriteData);
155 theWriteData << myOrientation;
158 //=======================================================================
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
165 Name_1::Import (theName, theDF);
166 theName.Orientation (static_cast<TopAbs_Orientation> (myOrientation));
169 //=======================================================================
170 //function : ImportAttribute
171 //purpose : Import transient attribuite from the persistent data
172 //=======================================================================
173 void StdPersistent_Naming::Naming::ImportAttribute()
175 Handle(Name) aName = Handle(Name)::DownCast (myData);
178 aName->Import (myTransient->ChangeName(), myTransient->Label().Data());
183 //=======================================================================
184 //function : ImportAttribute
185 //purpose : Import transient attribuite from the persistent data
186 //=======================================================================
187 void StdPersistent_Naming::Naming_1::ImportAttribute()
189 Naming::ImportAttribute();
191 Handle(TNaming_NamedShape) aNamedShape;
192 if (myTransient->Label().FindAttribute (TNaming_NamedShape::GetID(), aNamedShape)
193 && aNamedShape->Evolution() == TNaming_SELECTED)
195 for (TNaming_Iterator anIter (aNamedShape); anIter.More(); anIter.Next())
197 const TopoDS_Shape& aOldShape = anIter.OldShape();
198 const TopoDS_Shape& aNewShape = anIter.NewShape();
200 if (!aOldShape.IsNull() && aOldShape.ShapeType() == TopAbs_VERTEX
201 && !aNewShape.IsNull() && aNewShape.ShapeType() != TopAbs_VERTEX)
203 myTransient->ChangeName().Orientation (aOldShape.Orientation());