0025418: Debug output to be limited to OCC development environment
[occt.git] / src / MDocStd / MDocStd.cxx
1 // Created on: 1997-11-12
2 // Created by: Guest Design
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <MDocStd.ixx>
18 #include <MDocStd_DocumentStorageDriver.hxx>
19 #include <MDocStd_DocumentRetrievalDriver.hxx>
20 #include <Standard_Failure.hxx>
21 #include <MDocStd_XLinkStorageDriver.hxx>
22 #include <MDocStd_XLinkRetrievalDriver.hxx>
23 #include <CDM_MessageDriver.hxx>
24 #include <TDF_Tool.hxx>
25 static Standard_GUID StandardStorageDriver ("ad696000-5b34-11d1-b5ba-00a0c9064368");
26 static Standard_GUID StandardRetrievalDriver ("ad696001-5b34-11d1-b5ba-00a0c9064368");
27
28 /* ======= not used functionality ======
29 //#include <TDocStd_Document.hxx>
30 //#include <MDocStd_PersistentMap.hxx>
31 //#include <TDocStd_XLink.hxx>
32 //#include <TDocStd_XLinkIterator.hxx>
33 //#include <MDocStd_ListIteratorOfDocEntryList.hxx>
34 //#include <TDF_Label.hxx>
35 //#include <TDF_ChildIterator.hxx>
36 //#include <TNaming_NamedShape.hxx>
37 //#include <PNaming_NamedShape.hxx>
38 //#include <PTopoDS_Shape1.hxx>
39 //#include <TopoDS_Shape.hxx>
40 //#include <PTopoDS_TShape1.hxx>
41 //#include <PTopoDS_HArray1OfShape1.hxx>
42 //#include <PBRep_TVertex1.hxx>
43 //#include <PBRep_PointRepresentation.hxx>
44 //#include <PBRep_TEdge1.hxx>
45 //#include <PBRep_CurveRepresentation.hxx>
46 //#include <PBRep_TFace1.hxx>
47 //#include <PGeom_Surface.hxx>
48 //#include <TColStd_ListOfAsciiString.hxx>
49 //=======================================================================
50 //function : WeightWatcher
51 //purpose  : 
52 //=======================================================================
53
54 static void ShapeWeightWatcher (const PTopoDS_Shape1& PS,
55                                 MDocStd_PersistentMap& aMap)
56 {
57   if (aMap.Add(PS.TShape())) {
58     Handle(PTopoDS_TShape1) TS = PS.TShape();
59     Handle(PTopoDS_HArray1OfShape1) HS = TS->Shapes();
60     if (!HS.IsNull()) {
61       for (Standard_Integer i=1;i<=HS->Length();i++) {
62         const PTopoDS_Shape1& VAL = HS->Value(i);
63         if (!VAL.TShape().IsNull())ShapeWeightWatcher(VAL,aMap);
64       }
65       Handle(PBRep_TVertex1) TV = Handle(PBRep_TVertex1)::DownCast(TS);
66       if (!TV.IsNull()) {
67         Handle(PBRep_PointRepresentation) PR;
68         TV->Points(PR);
69         return;
70       }
71       Handle(PBRep_TEdge1) TE = Handle(PBRep_TEdge1)::DownCast(TS);
72       if (!TE.IsNull()) {
73         Handle(PBRep_CurveRepresentation) CR;
74         TE->Curves(CR);
75         return;
76       }
77       Handle(PBRep_TFace1) TF = Handle(PBRep_TFace1)::DownCast(TS);
78       if (!TF.IsNull()) {
79         Handle(PGeom_Surface) PGeomS;
80         TF->Surface(PGeomS);
81         return;
82       }
83     }
84   }
85 }
86 //=======================================================================
87 //function : AttributeWeightWatcher
88 //purpose  : 
89 //=======================================================================
90
91 static void  AttributeWeightWatcher(const TDF_Label& LabS,
92                                     const Handle(MDF_SRelocationTable)& aReloc,
93                                     MDocStd_PersistentMap& aMap)
94 {
95   TCollection_AsciiString STR;
96   TDF_Tool::Entry(LabS,STR);
97 #ifdef OCCT_DEBUG
98   cout << "Label to process: "<<STR<<endl;
99 #endif
100   Handle(TNaming_NamedShape) NS;
101   Handle(PNaming_NamedShape) PNS;
102   if (LabS.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
103     if (aReloc->HasRelocation(NS,PNS)) {
104       const Handle(PTopoDS_HArray1OfShape1)& HOldS = PNS->OldShapes();  
105       if (!HOldS.IsNull()) {
106         for (Standard_Integer i=1;i<=HOldS->Length();i++) {
107           const PTopoDS_Shape1& POS = HOldS->Value(i);
108           if (!POS.TShape().IsNull()) ShapeWeightWatcher(POS,aMap);
109         }
110       }
111       const Handle(PTopoDS_HArray1OfShape1)& HNewS = PNS->NewShapes();    
112       if (!HNewS.IsNull()) {
113         for (Standard_Integer j=1;j<=HNewS->Length();j++) {
114           const PTopoDS_Shape1& PTS = HNewS->Value(j);
115           if (!PTS.TShape().IsNull()) ShapeWeightWatcher(PTS,aMap);
116         }
117       }
118     }
119   }  
120
121 //traiter les fils
122   for (TDF_ChildIterator itr(LabS) ; itr.More(); itr.Next()) {
123     AttributeWeightWatcher(itr.Value(),aReloc,aMap);
124   }
125 }
126 //=======================================================================
127 //function : WeightWatcher
128 //purpose  : 
129 //=======================================================================
130
131 void MDocStd::WeightWatcher(const Handle(TDF_Data)& aSource,
132                             const Handle(MDF_SRelocationTable)& aReloc,
133                             const TColStd_ListOfAsciiString& aEntry) 
134 {
135   Handle(TDocStd_Document) D;
136   D = TDocStd_Document::Get(aSource->Root());
137   if (!D.IsNull()) {
138     TDocStd_XLink* xRefPtr;
139     MDocStd_PersistentMap aMap;
140     //for (TDocStd_XLinkIterator xItr(aSource); xItr.More(); xItr.Next()) {
141     for (TDocStd_XLinkIterator xItr(D); xItr.More(); xItr.Next()) {
142       xRefPtr = xItr.Value();
143       const TCollection_AsciiString & DocEntry=  xRefPtr->DocumentEntry();
144       TColStd_ListIteratorOfListOfAsciiString It(aEntry);
145       for (;It.More();It.Next()) {
146         if (It.Value()==DocEntry) AttributeWeightWatcher(xRefPtr->Label(),aReloc,aMap);
147       }
148     }
149   }
150 }
151
152 ***** */
153 //=======================================================================
154 //function : AddStorageDrivers
155 //purpose  : 
156 //=======================================================================
157
158 void MDocStd::AddStorageDrivers(const Handle(MDF_ASDriverHSequence)& aDriverSeq, 
159                                 const Handle(CDM_MessageDriver)& theMsgDriver) 
160 { aDriverSeq->Append(new MDocStd_XLinkStorageDriver(theMsgDriver)); }
161
162
163 //=======================================================================
164 //function : AddRetrievalDrivers
165 //purpose  : 
166 //=======================================================================
167
168 void MDocStd::AddRetrievalDrivers(const Handle(MDF_ARDriverHSequence)& aDriverSeq,
169                                   const Handle(CDM_MessageDriver)& theMsgDriver) 
170 { aDriverSeq->Append(new MDocStd_XLinkRetrievalDriver(theMsgDriver)); }
171
172 //=======================================================================
173 //function : Factory
174 //purpose  : 
175 //=======================================================================
176
177 Handle(Standard_Transient) MDocStd::Factory(const Standard_GUID& aGUID) {
178
179   if(aGUID == StandardStorageDriver)  {
180 #ifdef OCCT_DEBUG
181     cout << "MDocStd : Storage Plugin" << endl;
182 #endif
183     static Handle(MDocStd_DocumentStorageDriver) standard_sd = new MDocStd_DocumentStorageDriver;
184     return standard_sd;
185   }
186   if(aGUID == StandardRetrievalDriver) {  
187 #ifdef OCCT_DEBUG
188     cout << "MDocStd : Retrieval Plugin" << endl;
189 #endif
190     static Handle (MDocStd_DocumentRetrievalDriver) standard_rd = new MDocStd_DocumentRetrievalDriver;
191     return standard_rd;
192   }
193
194   Standard_Failure::Raise("MDocStd : Factory: unknown GUID");
195   Handle(Standard_Transient) t;
196   return t;
197
198 }