0026961: Recover possibility to read files in old persistence format
[occt.git] / src / ShapePersistent / ShapePersistent_TopoDS.cxx
CommitLineData
ff205346 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 <ShapePersistent_TopoDS.hxx>
15
16#include <BRep_Builder.hxx>
17
18
19enum
20{
21 ModifiedMask = 2,
22 CheckedMask = 4,
23 OrientableMask = 8,
24 ClosedMask = 16,
25 InfiniteMask = 32,
26 ConvexMask = 64
27};
28
29
30//=======================================================================
31//function : Read
32//purpose : Read persistent data from a file
33//=======================================================================
34void ShapePersistent_TopoDS::Shape::Read (StdObjMgt_ReadData& theReadData)
35{
36 theReadData >> myEntry;
37 myShape.Read (theReadData);
38}
39
40void ShapePersistent_TopoDS::pTBase::setFlags
41 (const Handle(TopoDS_TShape)& theTShape) const
42{
43 theTShape->Free (Standard_False); // Always frozen when coming from DB
44 theTShape->Modified (myFlags & ModifiedMask);
45 theTShape->Checked (myFlags & CheckedMask);
46 theTShape->Orientable (myFlags & OrientableMask);
47 theTShape->Closed (myFlags & ClosedMask);
48 theTShape->Infinite (myFlags & InfiniteMask);
49 theTShape->Convex (myFlags & ConvexMask);
50}
51
52static inline void AddShape
53 (TopoDS_Shape& theParent, const Handle(StdObjMgt_Persistent)& theRef)
54{
55 Handle(ShapePersistent_TopoDS::Shape) aShape =
56 Handle(ShapePersistent_TopoDS::Shape)::DownCast (theRef);
57
58 if (aShape)
59 BRep_Builder().Add (theParent, aShape->Import());
60}
61
62static inline void AddShape
63 (TopoDS_Shape& theParent, const StdObject_Shape& theShape)
64{
65 BRep_Builder().Add (theParent, theShape.Import());
66}
67
68template <class ShapesArray>
69void ShapePersistent_TopoDS::pTBase::addShapesT
70 (TopoDS_Shape& theParent) const
71{
72 Handle(ShapesArray) aShapes;
73 if (myShapes.Cast (aShapes))
74 {
75 typename ShapesArray::Iterator anIter (*aShapes->Array());
76 for (; anIter.More(); anIter.Next())
77 AddShape (theParent, anIter.Value());
78 }
79}
80
81template void ShapePersistent_TopoDS::pTBase::addShapesT
82 <StdLPersistent_HArray1::Persistent> (TopoDS_Shape& theParent) const;
83
84template void ShapePersistent_TopoDS::pTBase::addShapesT
85 <StdPersistent_HArray1::Shape1> (TopoDS_Shape& theParent) const;
86
87template <class Target>
88Handle(TopoDS_TShape)
89 ShapePersistent_TopoDS::pTSimple<Target>::createTShape() const
90 { return new Target; }
91
92template class ShapePersistent_TopoDS::pTSimple<TopoDS_TWire>;
93template class ShapePersistent_TopoDS::pTSimple<TopoDS_TShell>;
94template class ShapePersistent_TopoDS::pTSimple<TopoDS_TSolid>;
95template class ShapePersistent_TopoDS::pTSimple<TopoDS_TCompSolid>;
96template class ShapePersistent_TopoDS::pTSimple<TopoDS_TCompound>;