Integration of OCCT 6.5.0 from SVN
[occt.git] / src / MDocStd / MDocStd.cxx
CommitLineData
7fd59977 1// File: MDocStd.cxx
2// Created: Wed Nov 12 10:04:20 1997
3// Author: Guest Design
4// <g_design@salgox.paris1.matra-dtv.fr>
5
6#include <MDocStd.ixx>
7#include <MDocStd_DocumentStorageDriver.hxx>
8#include <MDocStd_DocumentRetrievalDriver.hxx>
9#include <Standard_Failure.hxx>
10#include <MDocStd_XLinkStorageDriver.hxx>
11#include <MDocStd_XLinkRetrievalDriver.hxx>
12#include <CDM_MessageDriver.hxx>
13#include <TDF_Tool.hxx>
14static Standard_GUID StandardStorageDriver ("ad696000-5b34-11d1-b5ba-00a0c9064368");
15static Standard_GUID StandardRetrievalDriver ("ad696001-5b34-11d1-b5ba-00a0c9064368");
16
17/* ======= not used functionality ======
18//#include <TDocStd_Document.hxx>
19//#include <MDocStd_PersistentMap.hxx>
20//#include <TDocStd_XLink.hxx>
21//#include <TDocStd_XLinkIterator.hxx>
22//#include <MDocStd_ListIteratorOfDocEntryList.hxx>
23//#include <TDF_Label.hxx>
24//#include <TDF_ChildIterator.hxx>
25//#include <TNaming_NamedShape.hxx>
26//#include <PNaming_NamedShape.hxx>
27//#include <PTopoDS_Shape1.hxx>
28//#include <TopoDS_Shape.hxx>
29//#include <PTopoDS_TShape1.hxx>
30//#include <PTopoDS_HArray1OfShape1.hxx>
31//#include <PBRep_TVertex1.hxx>
32//#include <PBRep_PointRepresentation.hxx>
33//#include <PBRep_TEdge1.hxx>
34//#include <PBRep_CurveRepresentation.hxx>
35//#include <PBRep_TFace1.hxx>
36//#include <PGeom_Surface.hxx>
37//#include <TColStd_ListOfAsciiString.hxx>
38//=======================================================================
39//function : WeightWatcher
40//purpose :
41//=======================================================================
42
43static void ShapeWeightWatcher (const PTopoDS_Shape1& PS,
44 MDocStd_PersistentMap& aMap)
45{
46 if (aMap.Add(PS.TShape())) {
47 Handle(PTopoDS_TShape1) TS = PS.TShape();
48 Handle(PTopoDS_HArray1OfShape1) HS = TS->Shapes();
49 if (!HS.IsNull()) {
50 for (Standard_Integer i=1;i<=HS->Length();i++) {
51 const PTopoDS_Shape1& VAL = HS->Value(i);
52 if (!VAL.TShape().IsNull())ShapeWeightWatcher(VAL,aMap);
53 }
54 Handle(PBRep_TVertex1) TV = Handle(PBRep_TVertex1)::DownCast(TS);
55 if (!TV.IsNull()) {
56 Handle(PBRep_PointRepresentation) PR;
57 TV->Points(PR);
58 return;
59 }
60 Handle(PBRep_TEdge1) TE = Handle(PBRep_TEdge1)::DownCast(TS);
61 if (!TE.IsNull()) {
62 Handle(PBRep_CurveRepresentation) CR;
63 TE->Curves(CR);
64 return;
65 }
66 Handle(PBRep_TFace1) TF = Handle(PBRep_TFace1)::DownCast(TS);
67 if (!TF.IsNull()) {
68 Handle(PGeom_Surface) PGeomS;
69 TF->Surface(PGeomS);
70 return;
71 }
72 }
73 }
74}
75//=======================================================================
76//function : AttributeWeightWatcher
77//purpose :
78//=======================================================================
79
80static void AttributeWeightWatcher(const TDF_Label& LabS,
81 const Handle(MDF_SRelocationTable)& aReloc,
82 MDocStd_PersistentMap& aMap)
83{
84 TCollection_AsciiString STR;
85 TDF_Tool::Entry(LabS,STR);
86#ifdef DEB
87 cout << "Label to process: "<<STR<<endl;
88#endif
89 Handle(TNaming_NamedShape) NS;
90 Handle(PNaming_NamedShape) PNS;
91 if (LabS.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
92 if (aReloc->HasRelocation(NS,PNS)) {
93 const Handle(PTopoDS_HArray1OfShape1)& HOldS = PNS->OldShapes();
94 if (!HOldS.IsNull()) {
95 for (Standard_Integer i=1;i<=HOldS->Length();i++) {
96 const PTopoDS_Shape1& POS = HOldS->Value(i);
97 if (!POS.TShape().IsNull()) ShapeWeightWatcher(POS,aMap);
98 }
99 }
100 const Handle(PTopoDS_HArray1OfShape1)& HNewS = PNS->NewShapes();
101 if (!HNewS.IsNull()) {
102 for (Standard_Integer j=1;j<=HNewS->Length();j++) {
103 const PTopoDS_Shape1& PTS = HNewS->Value(j);
104 if (!PTS.TShape().IsNull()) ShapeWeightWatcher(PTS,aMap);
105 }
106 }
107 }
108 }
109
110//traiter les fils
111 for (TDF_ChildIterator itr(LabS) ; itr.More(); itr.Next()) {
112 AttributeWeightWatcher(itr.Value(),aReloc,aMap);
113 }
114}
115//=======================================================================
116//function : WeightWatcher
117//purpose :
118//=======================================================================
119
120void MDocStd::WeightWatcher(const Handle(TDF_Data)& aSource,
121 const Handle(MDF_SRelocationTable)& aReloc,
122 const TColStd_ListOfAsciiString& aEntry)
123{
124 Handle(TDocStd_Document) D;
125 D = TDocStd_Document::Get(aSource->Root());
126 if (!D.IsNull()) {
127 TDocStd_XLink* xRefPtr;
128 MDocStd_PersistentMap aMap;
129 //for (TDocStd_XLinkIterator xItr(aSource); xItr.More(); xItr.Next()) {
130 for (TDocStd_XLinkIterator xItr(D); xItr.More(); xItr.Next()) {
131 xRefPtr = xItr.Value();
132 const TCollection_AsciiString & DocEntry= xRefPtr->DocumentEntry();
133 TColStd_ListIteratorOfListOfAsciiString It(aEntry);
134 for (;It.More();It.Next()) {
135 if (It.Value()==DocEntry) AttributeWeightWatcher(xRefPtr->Label(),aReloc,aMap);
136 }
137 }
138 }
139}
140
141***** */
142//=======================================================================
143//function : AddStorageDrivers
144//purpose :
145//=======================================================================
146
147void MDocStd::AddStorageDrivers(const Handle(MDF_ASDriverHSequence)& aDriverSeq,
148 const Handle(CDM_MessageDriver)& theMsgDriver)
149{ aDriverSeq->Append(new MDocStd_XLinkStorageDriver(theMsgDriver)); }
150
151
152//=======================================================================
153//function : AddRetrievalDrivers
154//purpose :
155//=======================================================================
156
157void MDocStd::AddRetrievalDrivers(const Handle(MDF_ARDriverHSequence)& aDriverSeq,
158 const Handle(CDM_MessageDriver)& theMsgDriver)
159{ aDriverSeq->Append(new MDocStd_XLinkRetrievalDriver(theMsgDriver)); }
160
161//=======================================================================
162//function : Factory
163//purpose :
164//=======================================================================
165
166Handle(Standard_Transient) MDocStd::Factory(const Standard_GUID& aGUID) {
167
168 if(aGUID == StandardStorageDriver) {
169#ifdef DEB
170 cout << "MDocStd : Storage Plugin" << endl;
171#endif
172 static Handle(MDocStd_DocumentStorageDriver) standard_sd = new MDocStd_DocumentStorageDriver;
173 return standard_sd;
174 }
175 if(aGUID == StandardRetrievalDriver) {
176#ifdef DEB
177 cout << "MDocStd : Retrieval Plugin" << endl;
178#endif
179 static Handle (MDocStd_DocumentRetrievalDriver) standard_rd = new MDocStd_DocumentRetrievalDriver;
180 return standard_rd;
181 }
182
183 Standard_Failure::Raise("MDocStd : Factory: unknown GUID");
184 Handle(Standard_Transient) t;
185 return t;
186
187}