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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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");
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
52 //=======================================================================
54 static void ShapeWeightWatcher (const PTopoDS_Shape1& PS,
55 MDocStd_PersistentMap& aMap)
57 if (aMap.Add(PS.TShape())) {
58 Handle(PTopoDS_TShape1) TS = PS.TShape();
59 Handle(PTopoDS_HArray1OfShape1) HS = TS->Shapes();
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);
65 Handle(PBRep_TVertex1) TV = Handle(PBRep_TVertex1)::DownCast(TS);
67 Handle(PBRep_PointRepresentation) PR;
71 Handle(PBRep_TEdge1) TE = Handle(PBRep_TEdge1)::DownCast(TS);
73 Handle(PBRep_CurveRepresentation) CR;
77 Handle(PBRep_TFace1) TF = Handle(PBRep_TFace1)::DownCast(TS);
79 Handle(PGeom_Surface) PGeomS;
86 //=======================================================================
87 //function : AttributeWeightWatcher
89 //=======================================================================
91 static void AttributeWeightWatcher(const TDF_Label& LabS,
92 const Handle(MDF_SRelocationTable)& aReloc,
93 MDocStd_PersistentMap& aMap)
95 TCollection_AsciiString STR;
96 TDF_Tool::Entry(LabS,STR);
98 cout << "Label to process: "<<STR<<endl;
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);
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);
122 for (TDF_ChildIterator itr(LabS) ; itr.More(); itr.Next()) {
123 AttributeWeightWatcher(itr.Value(),aReloc,aMap);
126 //=======================================================================
127 //function : WeightWatcher
129 //=======================================================================
131 void MDocStd::WeightWatcher(const Handle(TDF_Data)& aSource,
132 const Handle(MDF_SRelocationTable)& aReloc,
133 const TColStd_ListOfAsciiString& aEntry)
135 Handle(TDocStd_Document) D;
136 D = TDocStd_Document::Get(aSource->Root());
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);
153 //=======================================================================
154 //function : AddStorageDrivers
156 //=======================================================================
158 void MDocStd::AddStorageDrivers(const Handle(MDF_ASDriverHSequence)& aDriverSeq,
159 const Handle(CDM_MessageDriver)& theMsgDriver)
160 { aDriverSeq->Append(new MDocStd_XLinkStorageDriver(theMsgDriver)); }
163 //=======================================================================
164 //function : AddRetrievalDrivers
166 //=======================================================================
168 void MDocStd::AddRetrievalDrivers(const Handle(MDF_ARDriverHSequence)& aDriverSeq,
169 const Handle(CDM_MessageDriver)& theMsgDriver)
170 { aDriverSeq->Append(new MDocStd_XLinkRetrievalDriver(theMsgDriver)); }
172 //=======================================================================
175 //=======================================================================
177 Handle(Standard_Transient) MDocStd::Factory(const Standard_GUID& aGUID) {
179 if(aGUID == StandardStorageDriver) {
181 cout << "MDocStd : Storage Plugin" << endl;
183 static Handle(MDocStd_DocumentStorageDriver) standard_sd = new MDocStd_DocumentStorageDriver;
186 if(aGUID == StandardRetrievalDriver) {
188 cout << "MDocStd : Retrieval Plugin" << endl;
190 static Handle (MDocStd_DocumentRetrievalDriver) standard_rd = new MDocStd_DocumentRetrievalDriver;
194 Standard_Failure::Raise("MDocStd : Factory: unknown GUID");
195 Handle(Standard_Transient) t;