b311480e |
1 | // Created on: 1997-12-01 |
2 | // Created by: Jean-Louis Frenkel |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <CDM_Application.hxx> |
42cf5bc1 |
19 | #include <CDM_Document.hxx> |
83ae3591 |
20 | #include <Message_Messenger.hxx> |
42cf5bc1 |
21 | #include <CDM_MetaData.hxx> |
7fd59977 |
22 | #include <OSD_Path.hxx> |
42cf5bc1 |
23 | #include <PCDM_Reference.hxx> |
24 | #include <PCDM_ReferenceIterator.hxx> |
25 | #include <PCDM_RetrievalDriver.hxx> |
26 | #include <Standard_Type.hxx> |
27 | #include <Storage_Data.hxx> |
28 | #include <UTL.hxx> |
7fd59977 |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(PCDM_ReferenceIterator,Standard_Transient) |
31 | |
57c28b61 |
32 | #ifdef _MSC_VER |
7fd59977 |
33 | # include <tchar.h> |
57c28b61 |
34 | #endif // _MSC_VER |
7fd59977 |
35 | |
36 | //======================================================================= |
37 | //function : PCDM_ReferenceIterator |
38 | //purpose : |
39 | //======================================================================= |
40 | |
83ae3591 |
41 | PCDM_ReferenceIterator::PCDM_ReferenceIterator (const Handle(Message_Messenger)& theMsgDriver) : |
c24d4017 |
42 | myIterator(0) |
43 | { |
7fd59977 |
44 | myMessageDriver = theMsgDriver; |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : LoadReferences |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocument, |
53 | const Handle(CDM_MetaData)& aMetaData, |
54 | const Handle(CDM_Application)& anApplication, |
55 | const Standard_Boolean UseStorageConfiguration) { |
56 | for (Init(aMetaData);More();Next()) { |
57 | aDocument->CreateReference(MetaData(UseStorageConfiguration),ReferenceIdentifier(), |
58 | anApplication,DocumentVersion(),UseStorageConfiguration); |
59 | } |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : Init |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | void PCDM_ReferenceIterator::Init(const Handle(CDM_MetaData)& theMetaData) { |
68 | |
69 | myReferences.Clear(); |
70 | // mod. by szy |
71 | PCDM_RetrievalDriver::References(theMetaData->FileName(), myReferences, |
72 | myMessageDriver); |
73 | myIterator=1; |
74 | } |
75 | |
76 | //======================================================================= |
77 | //function : More |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | Standard_Boolean PCDM_ReferenceIterator::More() const { |
82 | return myIterator <= myReferences.Length(); |
83 | } |
84 | |
85 | //======================================================================= |
86 | //function : Next |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void PCDM_ReferenceIterator::Next() { |
91 | myIterator++; |
92 | } |
93 | |
94 | //======================================================================= |
95 | //function : MetaData |
96 | //purpose : |
97 | //======================================================================= |
98 | |
99 | Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) const { |
100 | |
101 | TCollection_ExtendedString theFolder,theName; |
102 | TCollection_ExtendedString theFile=myReferences(myIterator).FileName(); |
103 | TCollection_ExtendedString f(theFile); |
57c28b61 |
104 | #ifndef _WIN32 |
7fd59977 |
105 | |
106 | Standard_Integer i= f.SearchFromEnd("/"); |
107 | TCollection_ExtendedString n = f.Split(i); |
108 | f.Trunc(f.Length()-1); |
109 | theFolder = f; |
110 | theName = n; |
111 | #else |
112 | OSD_Path p = UTL::Path(f); |
113 | Standard_ExtCharacter chr; |
114 | TCollection_ExtendedString dir, dirRet, name; |
115 | |
116 | dir = UTL::Disk(p); |
117 | dir += UTL::Trek(p); |
118 | |
119 | for ( int i = 1; i <= dir.Length (); ++i ) { |
120 | |
121 | chr = dir.Value ( i ); |
122 | |
123 | switch ( chr ) { |
7c65581d |
124 | |
125 | case '|': |
126 | dirRet += "/"; |
7fd59977 |
127 | break; |
7c65581d |
128 | |
129 | case '^': |
130 | |
131 | dirRet += ".."; |
7fd59977 |
132 | break; |
133 | |
134 | default: |
135 | dirRet += chr; |
136 | |
137 | } |
138 | } |
139 | theFolder = dirRet; |
140 | theName = UTL::Name(p); theName+= UTL::Extension(p); |
57c28b61 |
141 | #endif // _WIN32 |
7fd59977 |
142 | |
143 | return CDM_MetaData::LookUp(theFolder,theName,theFile,theFile,UTL::IsReadOnly(theFile)); |
144 | } |
145 | //======================================================================= |
146 | //function : ReferenceIdentifier |
147 | //purpose : |
148 | //======================================================================= |
149 | |
150 | Standard_Integer PCDM_ReferenceIterator::ReferenceIdentifier() const { |
151 | return myReferences(myIterator).ReferenceIdentifier(); |
152 | } |
153 | //======================================================================= |
154 | //function : DocumentVersion |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | Standard_Integer PCDM_ReferenceIterator::DocumentVersion() const { |
159 | return myReferences(myIterator).DocumentVersion(); |
160 | } |