mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-18 14:27:39 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
38
src/XmlLDrivers/XmlLDrivers.cdl
Executable file
38
src/XmlLDrivers/XmlLDrivers.cdl
Executable file
@@ -0,0 +1,38 @@
|
||||
-- File: XmlLDrivers.cdl
|
||||
-- Created: Wed Jul 25 16:50:11 2001
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- <jfa@hotdox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 2001
|
||||
|
||||
package XmlLDrivers
|
||||
|
||||
uses
|
||||
Standard,
|
||||
TDF,
|
||||
TDocStd,
|
||||
TCollection,
|
||||
TColStd,
|
||||
CDM,
|
||||
PCDM,
|
||||
XmlObjMgt,
|
||||
XmlMDF
|
||||
|
||||
is
|
||||
class DocumentStorageDriver;
|
||||
class DocumentRetrievalDriver;
|
||||
|
||||
private class NamespaceDef;
|
||||
|
||||
private class SequenceOfNamespaceDef
|
||||
instantiates Sequence from TCollection (NamespaceDef from XmlLDrivers);
|
||||
|
||||
Factory (theGUID : GUID from Standard) returns Transient from Standard;
|
||||
|
||||
CreationDate returns AsciiString from TCollection;
|
||||
|
||||
AttributeDrivers (theMsgDriver: MessageDriver from CDM)
|
||||
returns ADriverTable from XmlMDF;
|
||||
|
||||
StorageVersion returns AsciiString from TCollection;
|
||||
|
||||
end XmlLDrivers;
|
113
src/XmlLDrivers/XmlLDrivers.cxx
Executable file
113
src/XmlLDrivers/XmlLDrivers.cxx
Executable file
@@ -0,0 +1,113 @@
|
||||
// File: XmlLDrivers.cxx
|
||||
// Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Matra Datavision 2001
|
||||
|
||||
#include <XmlLDrivers.ixx>
|
||||
|
||||
#include <XmlLDrivers_DocumentStorageDriver.hxx>
|
||||
#include <XmlLDrivers_DocumentRetrievalDriver.hxx>
|
||||
#include <XmlMDF_ADriverTable.hxx>
|
||||
#include <XmlMDF.hxx>
|
||||
#include <XmlMDataStd.hxx>
|
||||
#include <XmlMDocStd.hxx>
|
||||
#include <XmlMFunction.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
|
||||
#include <locale.h>
|
||||
#include <time.h>
|
||||
#include <Plugin_Macro.hxx>
|
||||
|
||||
// avoid warnings on 'extern "C"' functions returning C++ classes
|
||||
#ifdef WNT
|
||||
#pragma warning(4:4190)
|
||||
#endif
|
||||
|
||||
static Standard_GUID XmlLStorageDriver ("13a56820-8269-11d5-aab2-0050044b1af1");
|
||||
static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
|
||||
#define CURRENT_DOCUMENT_VERSION 6
|
||||
|
||||
//=======================================================================
|
||||
//function : Factory
|
||||
//purpose : PLUGIN FACTORY
|
||||
//=======================================================================
|
||||
Handle(Standard_Transient) XmlLDrivers::Factory(const Standard_GUID& theGUID)
|
||||
{
|
||||
if (theGUID == XmlLStorageDriver)
|
||||
{
|
||||
cout << "XmlLDrivers : Storage Plugin" << endl;
|
||||
static Handle(XmlLDrivers_DocumentStorageDriver) model_sd =
|
||||
new XmlLDrivers_DocumentStorageDriver
|
||||
("Copyright: Open Cascade, 2001-2002"); // default copyright
|
||||
return model_sd;
|
||||
}
|
||||
|
||||
if (theGUID == XmlLRetrievalDriver)
|
||||
{
|
||||
cout << "XmlLDrivers : Retrieval Plugin" << endl;
|
||||
static Handle (XmlLDrivers_DocumentRetrievalDriver) model_rd =
|
||||
new XmlLDrivers_DocumentRetrievalDriver ();
|
||||
return model_rd;
|
||||
}
|
||||
|
||||
Standard_Failure::Raise ("XmlLDrivers : unknown GUID");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define SLENGTH 80
|
||||
//=======================================================================
|
||||
//function : CreationDate
|
||||
//purpose : mm/dd/yy
|
||||
//=======================================================================
|
||||
TCollection_AsciiString XmlLDrivers::CreationDate ()
|
||||
{
|
||||
const TCollection_AsciiString anOldNumLocale =
|
||||
(Standard_CString) setlocale (LC_NUMERIC, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
Standard_Character nowstr[SLENGTH];
|
||||
time_t nowbin;
|
||||
struct tm *nowstruct;
|
||||
|
||||
if (time(&nowbin) == (time_t) - 1)
|
||||
cerr << "Storage ERROR : Could not get time of day from time()" << endl;
|
||||
|
||||
nowstruct = localtime(&nowbin);
|
||||
|
||||
if (strftime(nowstr, SLENGTH, "%Y-%m-%d", nowstruct) == (size_t) 0)
|
||||
cerr << "Storage ERROR : Could not get string from strftime()" << endl;
|
||||
|
||||
setlocale(LC_NUMERIC, (char *) anOldNumLocale.ToCString()) ;
|
||||
return nowstr;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AttributeDrivers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers
|
||||
(const Handle_CDM_MessageDriver& theMessageDriver)
|
||||
{
|
||||
Handle(XmlMDF_ADriverTable) aTable = new XmlMDF_ADriverTable();
|
||||
//
|
||||
XmlMDF ::AddDrivers (aTable, theMessageDriver);
|
||||
XmlMDataStd ::AddDrivers (aTable, theMessageDriver);
|
||||
XmlMFunction ::AddDrivers (aTable, theMessageDriver);
|
||||
XmlMDocStd ::AddDrivers (aTable, theMessageDriver);
|
||||
//
|
||||
return aTable;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : StorageVersion
|
||||
//purpose : Document storage version
|
||||
//=======================================================================
|
||||
|
||||
TCollection_AsciiString XmlLDrivers::StorageVersion()
|
||||
{
|
||||
TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION);
|
||||
return aVersionStr;
|
||||
}
|
||||
|
||||
// Declare entry point PLUGINFACTORY
|
||||
PLUGIN(XmlLDrivers)
|
74
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cdl
Executable file
74
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cdl
Executable file
@@ -0,0 +1,74 @@
|
||||
-- File: XmlDrivers_DocumentRetrievalDriver.cdl
|
||||
-- Created: Wed Jul 25 16:56:28 2001
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- <jfa@hotdox.nnov.matra-dtv.fr>
|
||||
---Copyright: Open Cascade 2001
|
||||
|
||||
class DocumentRetrievalDriver from XmlLDrivers inherits RetrievalDriver from PCDM
|
||||
|
||||
uses
|
||||
ExtendedString from TCollection,
|
||||
SequenceOfExtendedString from TColStd,
|
||||
Document from PCDM,
|
||||
Document from CDM,
|
||||
Document from TDocStd,
|
||||
Application from CDM,
|
||||
ADriver from XmlMDF,
|
||||
ADriverTable from XmlMDF,
|
||||
RRelocationTable from XmlObjMgt,
|
||||
Element from XmlObjMgt,
|
||||
MessageDriver from CDM
|
||||
|
||||
is
|
||||
Create returns mutable DocumentRetrievalDriver from XmlLDrivers;
|
||||
-- Constructor
|
||||
|
||||
SchemaName (me)
|
||||
returns ExtendedString from TCollection is redefined virtual;
|
||||
-- pure virtual method definition
|
||||
|
||||
Make (me : mutable; PD : Document from PCDM;
|
||||
TD : Document from CDM)
|
||||
is redefined virtual;
|
||||
-- pure virtual method definition
|
||||
|
||||
CreateDocument (me : mutable)
|
||||
returns Document from CDM is redefined virtual;
|
||||
-- pure virtual method definition
|
||||
|
||||
Read(me:mutable; theFileName: ExtendedString from TCollection;
|
||||
theNewDocument: Document from CDM;
|
||||
theApplication: Application from CDM) is redefined virtual;
|
||||
--
|
||||
|
||||
ReadFromDomDocument (me : mutable; theDomElement: Element from XmlObjMgt;
|
||||
theNewDocument: Document from CDM;
|
||||
theApplication: Application from CDM)
|
||||
is virtual protected;
|
||||
|
||||
MakeDocument (me : mutable; thePDoc: Element from XmlObjMgt;
|
||||
theTDoc: Document from CDM)
|
||||
returns Boolean from Standard
|
||||
is virtual protected;
|
||||
|
||||
AttributeDrivers (me : mutable; theMsgDriver: MessageDriver from CDM)
|
||||
returns ADriverTable from XmlMDF
|
||||
is virtual;
|
||||
|
||||
ReadShapeSection (me:mutable; thePDoc : Element from XmlObjMgt;
|
||||
theMsgDriver : MessageDriver from CDM)
|
||||
returns ADriver from XmlMDF
|
||||
is virtual protected;
|
||||
|
||||
ShapeSetCleaning(me:mutable; theDriver : ADriver from XmlMDF)
|
||||
is virtual protected;
|
||||
|
||||
PropagateDocumentVersion(me:mutable; theDocVersion : Integer from Standard)
|
||||
is virtual protected;
|
||||
|
||||
fields
|
||||
myDrivers : ADriverTable from XmlMDF is protected;
|
||||
myRelocTable: RRelocationTable from XmlObjMgt is protected;
|
||||
myFileName : ExtendedString from TCollection is protected;
|
||||
|
||||
end DocumentRetrievalDriver;
|
511
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx
Executable file
511
src/XmlLDrivers/XmlLDrivers_DocumentRetrievalDriver.cxx
Executable file
@@ -0,0 +1,511 @@
|
||||
// File: XmlLDrivers_DocumentRetrievalDriver.cxx
|
||||
// Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
#include <XmlLDrivers_DocumentRetrievalDriver.ixx>
|
||||
|
||||
#include <XmlLDrivers.hxx>
|
||||
#include <XmlMDF.hxx>
|
||||
#include <XmlObjMgt_RRelocationTable.hxx>
|
||||
#include <XmlObjMgt_Document.hxx>
|
||||
#include <XmlObjMgt.hxx>
|
||||
#include <XmlMDataStd.hxx>
|
||||
#include <LDOM_LDOMImplementation.hxx>
|
||||
#include <LDOM_DocumentType.hxx>
|
||||
#include <LDOMParser.hxx>
|
||||
|
||||
#include <TDF_Data.hxx>
|
||||
#include <TDocStd_Owner.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <CDM_MessageDriver.hxx>
|
||||
#include <CDM_MetaData.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <UTL.hxx>
|
||||
#include <OSD_Path.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
# include <tchar.h>
|
||||
#endif // WNT
|
||||
|
||||
#include <locale.h>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
|
||||
#define START_REF "START_REF"
|
||||
#define END_REF "END_REF"
|
||||
#define REFERENCE_COUNTER "REFERENCE_COUNTER"
|
||||
|
||||
static Standard_Integer myDocumentVersion = 0;
|
||||
|
||||
//#define TAKE_TIMES
|
||||
static void take_time (const Standard_Integer, const char *,
|
||||
const Handle(CDM_MessageDriver)&)
|
||||
#ifdef TAKE_TIMES
|
||||
;
|
||||
#else
|
||||
{}
|
||||
#endif
|
||||
|
||||
static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
|
||||
|
||||
Standard_Integer i, j, len ;
|
||||
|
||||
len = aString.Length() ;
|
||||
#ifdef WNT
|
||||
// Case of network path, such as \\MACHINE\dir
|
||||
for (i = j = 2 ; j <= len ; i++,j++) {
|
||||
#else
|
||||
for (i = j = 1 ; j <= len ; i++,j++) {
|
||||
#endif
|
||||
Standard_Character c = aString.Value(j) ;
|
||||
aString.SetValue(i,c) ;
|
||||
if (c == '/')
|
||||
while(j < len && aString.Value(j+1) == '/') j++ ;
|
||||
}
|
||||
len = i-1 ;
|
||||
if (aString.Value(len) == '/') len-- ;
|
||||
aString.Trunc(len) ;
|
||||
return len ;
|
||||
}
|
||||
static TCollection_AsciiString GetDirFromFile(const TCollection_ExtendedString& aFileName) {
|
||||
TCollection_AsciiString theCFile=UTL::CString(aFileName);
|
||||
TCollection_AsciiString theDirectory;
|
||||
Standard_Integer i=theCFile.SearchFromEnd("/");
|
||||
#ifdef WNT
|
||||
// if(i==-1) i=theCFile.SearchFromEnd("\\");
|
||||
if(theCFile.SearchFromEnd("\\") > i)
|
||||
i=theCFile.SearchFromEnd("\\");
|
||||
#endif
|
||||
if(i!=-1) theDirectory=theCFile.SubString(1,i);
|
||||
return theDirectory;
|
||||
}
|
||||
|
||||
static TCollection_AsciiString AbsolutePath(
|
||||
const TCollection_AsciiString& aDirPath,
|
||||
const TCollection_AsciiString& aRelFilePath)
|
||||
{
|
||||
TCollection_AsciiString EmptyString = "" ;
|
||||
#ifdef WNT
|
||||
if (aRelFilePath.Search(":") == 2 ||
|
||||
(aRelFilePath.Search("\\") == 1 && aRelFilePath.Value(2) == '\\'))
|
||||
#else
|
||||
if(aRelFilePath.Search("/") == 1)
|
||||
#endif
|
||||
return aRelFilePath ;
|
||||
|
||||
TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath ;
|
||||
Standard_Integer i,len ;
|
||||
|
||||
#ifdef WNT
|
||||
if(DirPath.Search(":") != 2 &&
|
||||
(DirPath.Search("\\") != 1 || DirPath.Value(2) != '\\'))
|
||||
#else
|
||||
if (DirPath.Search("/") != 1 )
|
||||
#endif
|
||||
return EmptyString ;
|
||||
|
||||
#ifdef WNT
|
||||
DirPath.ChangeAll('\\','/') ;
|
||||
RelFilePath.ChangeAll('\\','/') ;
|
||||
#endif
|
||||
|
||||
RemoveExtraSeparator(DirPath) ;
|
||||
len = RemoveExtraSeparator(RelFilePath) ;
|
||||
|
||||
while (RelFilePath.Search("../") == 1) {
|
||||
if (len == 3)
|
||||
return EmptyString ;
|
||||
RelFilePath = RelFilePath.SubString(4,len) ;
|
||||
len -= 3 ;
|
||||
if (DirPath.IsEmpty())
|
||||
return EmptyString ;
|
||||
i = DirPath.SearchFromEnd("/") ;
|
||||
if (i < 0)
|
||||
return EmptyString ;
|
||||
DirPath.Trunc(i-1) ;
|
||||
}
|
||||
TCollection_AsciiString retx;
|
||||
retx= DirPath;
|
||||
retx+= "/";
|
||||
retx+=RelFilePath ;
|
||||
return retx;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlLDrivers_DocumentRetrievalDriver
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
XmlLDrivers_DocumentRetrievalDriver::XmlLDrivers_DocumentRetrievalDriver()
|
||||
{
|
||||
myReaderStatus = PCDM_RS_OK;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateDocument
|
||||
//purpose : pure virtual method definition
|
||||
//=======================================================================
|
||||
Handle(CDM_Document) XmlLDrivers_DocumentRetrievalDriver::CreateDocument()
|
||||
{
|
||||
return new TDocStd_Document(PCDM_RetrievalDriver::GetFormat());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SchemaName
|
||||
//purpose : pure virtual method definition
|
||||
//=======================================================================
|
||||
TCollection_ExtendedString XmlLDrivers_DocumentRetrievalDriver::SchemaName() const
|
||||
{
|
||||
TCollection_ExtendedString schemaname;
|
||||
return schemaname;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Make
|
||||
//purpose : pure virtual method definition
|
||||
//=======================================================================
|
||||
void XmlLDrivers_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)&,
|
||||
const Handle(CDM_Document&))
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Read
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void XmlLDrivers_DocumentRetrievalDriver::Read
|
||||
(const TCollection_ExtendedString& theFileName,
|
||||
const Handle(CDM_Document)& theNewDocument,
|
||||
const Handle(CDM_Application)& theApplication)
|
||||
{
|
||||
myReaderStatus = PCDM_RS_DriverFailure;
|
||||
myFileName = theFileName;
|
||||
const TCollection_AsciiString anOldNumLocale =
|
||||
(Standard_CString) setlocale (LC_NUMERIC, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
Handle(CDM_MessageDriver) aMessageDriver = theApplication -> MessageDriver();
|
||||
::take_time (~0, " +++++ Start RETRIEVE procedures ++++++", aMessageDriver);
|
||||
|
||||
// 1. Read DOM_Document from file
|
||||
LDOMParser aParser;
|
||||
TCollection_AsciiString aName (theFileName,'?');
|
||||
if (aParser.parse(aName.ToCString()))
|
||||
{
|
||||
TCollection_AsciiString aData;
|
||||
cout << aParser.GetError(aData) << ": " << aData << endl;
|
||||
myReaderStatus = PCDM_RS_FormatFailure;
|
||||
return;
|
||||
}
|
||||
const XmlObjMgt_Element anElement= aParser.getDocument().getDocumentElement();
|
||||
::take_time (0, " +++++ Fin parsing XML : ", aMessageDriver);
|
||||
|
||||
ReadFromDomDocument (anElement, theNewDocument, theApplication);
|
||||
|
||||
setlocale(LC_NUMERIC, (char *) anOldNumLocale.ToCString()) ;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadFromDomDocument
|
||||
//purpose : management of the macro-structure of XML document data
|
||||
//remark : If the application needs to use myRelocTable to retrieve additional
|
||||
// data from LDOM, this method should be reimplemented
|
||||
//=======================================================================
|
||||
|
||||
void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument
|
||||
(const XmlObjMgt_Element& theElement,
|
||||
const Handle(CDM_Document)& theNewDocument,
|
||||
const Handle(CDM_Application)& theApplication)
|
||||
{
|
||||
const Handle(CDM_MessageDriver) aMsgDriver =
|
||||
theApplication -> MessageDriver();
|
||||
// 1. Read info // to be done
|
||||
TCollection_AsciiString anAbsoluteDirectory = GetDirFromFile(myFileName);
|
||||
Standard_Integer aCurDocVersion = 0;
|
||||
TCollection_ExtendedString anInfo;
|
||||
const XmlObjMgt_Element anInfoElem =
|
||||
theElement.GetChildByTagName ("info");
|
||||
if (anInfoElem != NULL) {
|
||||
XmlObjMgt_DOMString aDocVerStr = anInfoElem.getAttribute("DocVersion");
|
||||
if(aDocVerStr == NULL)
|
||||
aCurDocVersion = 2;
|
||||
else if (!aDocVerStr.GetInteger(aCurDocVersion)) {
|
||||
TCollection_ExtendedString aMsg =
|
||||
TCollection_ExtendedString ("Cannot retrieve the current Document version"
|
||||
" attribute as \"") + aDocVerStr + "\"";
|
||||
if(!aMsgDriver.IsNull())
|
||||
aMsgDriver->Write(aMsg.ToExtString());
|
||||
}
|
||||
if(aCurDocVersion < 2) aCurDocVersion = 2;
|
||||
|
||||
PropagateDocumentVersion(aCurDocVersion);
|
||||
|
||||
Standard_Boolean isRef = Standard_False;
|
||||
for (LDOM_Node aNode = anInfoElem.getFirstChild();
|
||||
aNode != NULL; aNode = aNode.getNextSibling()) {
|
||||
if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE) {
|
||||
if (XmlObjMgt::GetExtendedString ((LDOM_Element&)aNode, anInfo)) {
|
||||
|
||||
// Read ref counter
|
||||
if(anInfo.Search(REFERENCE_COUNTER) != -1) {
|
||||
try {
|
||||
OCC_CATCH_SIGNALS
|
||||
TCollection_AsciiString anInf(anInfo,'?');
|
||||
Standard_Integer aRefCounter = anInf.Token(" ",2).IntegerValue();
|
||||
//theNewDocument->SetReferenceCounter(aRefCounter);
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
// cout << "warning: could not read the reference counter in " << aFileName << endl;
|
||||
TCollection_ExtendedString aMsg("Warning: ");
|
||||
aMsg = aMsg.Cat("could not read the reference counter").Cat("\0");
|
||||
if(!aMsgDriver.IsNull())
|
||||
aMsgDriver->Write(aMsg.ToExtString());
|
||||
}
|
||||
}
|
||||
|
||||
if(anInfo == END_REF)
|
||||
isRef = Standard_False;
|
||||
if(isRef) { // Process References
|
||||
|
||||
Standard_Integer pos=anInfo.Search(" ");
|
||||
if(pos != -1) {
|
||||
// Parce RefId, DocumentVersion and FileName
|
||||
Standard_Integer aRefId;
|
||||
TCollection_ExtendedString aFileName;
|
||||
Standard_Integer aDocumentVersion;
|
||||
|
||||
|
||||
TCollection_ExtendedString aRest=anInfo.Split(pos);
|
||||
aRefId = UTL::IntegerValue(anInfo);
|
||||
|
||||
Standard_Integer pos2 = aRest.Search(" ");
|
||||
|
||||
aFileName = aRest.Split(pos2);
|
||||
aDocumentVersion = UTL::IntegerValue(aRest);
|
||||
|
||||
TCollection_AsciiString aPath = UTL::CString(aFileName);
|
||||
TCollection_AsciiString anAbsolutePath;
|
||||
if(!anAbsoluteDirectory.IsEmpty()) {
|
||||
anAbsolutePath = AbsolutePath(anAbsoluteDirectory,aPath);
|
||||
if(!anAbsolutePath.IsEmpty()) aPath=anAbsolutePath;
|
||||
}
|
||||
if(!aMsgDriver.IsNull()) {
|
||||
// cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
|
||||
TCollection_ExtendedString aMsg("Warning: ");
|
||||
aMsg = aMsg.Cat("reference found; ReferenceIdentifier: ").Cat(aRefId).Cat("; File:").Cat(aPath).Cat(", version:").Cat(aDocumentVersion).Cat("\0");
|
||||
aMsgDriver->Write(aMsg.ToExtString());
|
||||
}
|
||||
// Add new ref!
|
||||
/////////////
|
||||
TCollection_ExtendedString theFolder,theName;
|
||||
//TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
|
||||
TCollection_ExtendedString f(aPath);
|
||||
#ifndef WNT
|
||||
|
||||
Standard_Integer i= f.SearchFromEnd("/");
|
||||
TCollection_ExtendedString n = f.Split(i);
|
||||
f.Trunc(f.Length()-1);
|
||||
theFolder = f;
|
||||
theName = n;
|
||||
#else
|
||||
OSD_Path p = UTL::Path(f);
|
||||
Standard_ExtCharacter chr;
|
||||
TCollection_ExtendedString dir, dirRet, name;
|
||||
|
||||
dir = UTL::Disk(p);
|
||||
dir += UTL::Trek(p);
|
||||
|
||||
for ( int i = 1; i <= dir.Length (); ++i ) {
|
||||
|
||||
chr = dir.Value ( i );
|
||||
|
||||
switch ( chr ) {
|
||||
|
||||
case _TEXT( '|' ):
|
||||
dirRet += _TEXT( "/" );
|
||||
break;
|
||||
|
||||
case _TEXT( '^' ):
|
||||
|
||||
dirRet += _TEXT( ".." );
|
||||
break;
|
||||
|
||||
default:
|
||||
dirRet += chr;
|
||||
|
||||
}
|
||||
}
|
||||
theFolder = dirRet;
|
||||
theName = UTL::Name(p); theName+= UTL::Extension(p);
|
||||
#endif // WNT
|
||||
|
||||
Handle(CDM_MetaData) aMetaData = CDM_MetaData::LookUp(theFolder,theName,aPath,aPath,UTL::IsReadOnly(aFileName));
|
||||
////////////
|
||||
theNewDocument->CreateReference(aMetaData,aRefId,
|
||||
theApplication,aDocumentVersion,Standard_False);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
if(anInfo == START_REF)
|
||||
isRef = Standard_True;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Read comments
|
||||
TCollection_ExtendedString aComment;
|
||||
const XmlObjMgt_Element aCommentsElem =
|
||||
theElement.GetChildByTagName ("comments");
|
||||
if (aCommentsElem != NULL)
|
||||
{
|
||||
for (LDOM_Node aNode = aCommentsElem.getFirstChild();
|
||||
aNode != NULL; aNode = aNode.getNextSibling())
|
||||
{
|
||||
if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE)
|
||||
{
|
||||
if (XmlObjMgt::GetExtendedString ((LDOM_Element&)aNode, aComment))
|
||||
{
|
||||
theNewDocument->AddComment(aComment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Read Shapes section
|
||||
if (myDrivers.IsNull()) myDrivers = AttributeDrivers (aMsgDriver);
|
||||
const Handle(XmlMDF_ADriver) aNSDriver = ReadShapeSection(theElement, aMsgDriver);
|
||||
if(!aNSDriver.IsNull())
|
||||
::take_time (0, " +++++ Fin reading Shapes : ", aMsgDriver);
|
||||
|
||||
// 5. Read document contents
|
||||
try
|
||||
{
|
||||
OCC_CATCH_SIGNALS
|
||||
#if defined(DEB) && !defined(TAKE_TIMES)
|
||||
TCollection_ExtendedString aMessage ("PasteDocument");
|
||||
aMsgDriver -> Write (aMessage.ToExtString());
|
||||
#endif
|
||||
if (!MakeDocument(theElement, theNewDocument))
|
||||
myReaderStatus = PCDM_RS_MakeFailure;
|
||||
else
|
||||
myReaderStatus = PCDM_RS_OK;
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
TCollection_ExtendedString anErrorString (Standard_Failure::Caught()->GetMessageString());
|
||||
aMsgDriver -> Write (anErrorString.ToExtString());
|
||||
}
|
||||
|
||||
// Wipe off the shapes written to the <shapes> section
|
||||
ShapeSetCleaning(aNSDriver);
|
||||
|
||||
// Clean the relocation table.
|
||||
// If the application needs to use myRelocTable to retrieve additional
|
||||
// data from LDOM, this method should be reimplemented avoiding this step
|
||||
myRelocTable.Clear();
|
||||
::take_time (0, " +++++ Fin reading data OCAF : ", aMsgDriver);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlLDrivers_DocumentRetrievalDriver::MakeDocument
|
||||
(const XmlObjMgt_Element& theElement,
|
||||
const Handle(CDM_Document)& theTDoc)
|
||||
{
|
||||
Standard_Boolean aResult = Standard_False;
|
||||
Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(theTDoc);
|
||||
myRelocTable.Clear();
|
||||
if (!TDOC.IsNull())
|
||||
{
|
||||
Handle(TDF_Data) aTDF = new TDF_Data();
|
||||
aResult = XmlMDF::FromTo (theElement, aTDF, myRelocTable, myDrivers);
|
||||
if (aResult) {
|
||||
TDOC->SetData (aTDF);
|
||||
TDocStd_Owner::SetDocument (aTDF, TDOC);
|
||||
}
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AttributeDrivers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(XmlMDF_ADriverTable) XmlLDrivers_DocumentRetrievalDriver::AttributeDrivers
|
||||
(const Handle(CDM_MessageDriver)& theMessageDriver)
|
||||
{
|
||||
return XmlLDrivers::AttributeDrivers (theMessageDriver);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : take_time
|
||||
//class : static
|
||||
//purpose : output astronomical time elapsed
|
||||
//=======================================================================
|
||||
#ifdef TAKE_TIMES
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#ifndef WNT
|
||||
extern "C" int ftime (struct timeb *tp);
|
||||
#endif
|
||||
extern struct timeb tmbuf0;
|
||||
|
||||
static void take_time (const Standard_Integer isReset, const char * aHeader,
|
||||
const Handle(CDM_MessageDriver)& aMessageDriver)
|
||||
{
|
||||
struct timeb tmbuf;
|
||||
ftime (&tmbuf);
|
||||
TCollection_ExtendedString aMessage ((Standard_CString)aHeader);
|
||||
if (isReset) tmbuf0 = tmbuf;
|
||||
else {
|
||||
char take_tm_buf [64];
|
||||
sprintf (take_tm_buf, "%9.2f s ++++",
|
||||
double(tmbuf.time - tmbuf0.time) +
|
||||
double(tmbuf.millitm - tmbuf0.millitm)/1000.);
|
||||
aMessage += take_tm_buf;
|
||||
}
|
||||
aMessageDriver -> Write (aMessage.ToExtString());
|
||||
}
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : PropagateDocumentVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void XmlLDrivers_DocumentRetrievalDriver::PropagateDocumentVersion(
|
||||
const Standard_Integer theDocVersion )
|
||||
{
|
||||
#ifdef DEB
|
||||
// cout << "DocCurVersion =" << theDocVersion <<endl;
|
||||
#endif
|
||||
XmlMDataStd::SetDocumentVersion(theDocVersion);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadShapeSection
|
||||
//purpose : definition of ReadShapeSection
|
||||
//=======================================================================
|
||||
Handle(XmlMDF_ADriver) XmlLDrivers_DocumentRetrievalDriver::ReadShapeSection(
|
||||
const XmlObjMgt_Element& /*theElement*/,
|
||||
const Handle(CDM_MessageDriver)& /*aMsgDriver*/)
|
||||
{
|
||||
Handle(XmlMDF_ADriver) aDriver;
|
||||
//empty; to be redefined
|
||||
return aDriver;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ShapeSetCleaning
|
||||
//purpose : definition of ShapeSetCleaning
|
||||
//=======================================================================
|
||||
void XmlLDrivers_DocumentRetrievalDriver::ShapeSetCleaning(
|
||||
const Handle(XmlMDF_ADriver)& /*theDriver*/)
|
||||
{}
|
65
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cdl
Executable file
65
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cdl
Executable file
@@ -0,0 +1,65 @@
|
||||
-- File: XmlLDrivers_DocumentStorageDriver.cdl
|
||||
-- Created: Wed Jul 25 16:56:28 2001
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- <jfa@hotdox.nnov.matra-dtv.fr>
|
||||
---Copyright: Open Cascade 2001
|
||||
|
||||
class DocumentStorageDriver from XmlLDrivers inherits StorageDriver from PCDM
|
||||
|
||||
uses
|
||||
AsciiString from TCollection,
|
||||
ExtendedString from TCollection,
|
||||
SequenceOfExtendedString from TColStd,
|
||||
Document from CDM,
|
||||
Document from TDocStd,
|
||||
SequenceOfNamespaceDef from XmlLDrivers,
|
||||
Element from XmlObjMgt,
|
||||
SRelocationTable from XmlObjMgt,
|
||||
ADriverTable from XmlMDF,
|
||||
MessageDriver from CDM
|
||||
|
||||
is
|
||||
Create (theCopyright: ExtendedString from TCollection)
|
||||
returns mutable DocumentStorageDriver from XmlLDrivers;
|
||||
-- Constructor
|
||||
|
||||
SchemaName(me) returns ExtendedString from TCollection is redefined virtual;
|
||||
-- pure virtual method definition
|
||||
|
||||
Write (me: mutable;theDocument: Document from CDM;
|
||||
theFileName: ExtendedString from TCollection)
|
||||
is redefined virtual;
|
||||
-- Write <aDocument> to the xml file <theFileName>
|
||||
|
||||
WriteToDomDocument(me:mutable; theDocument: Document from CDM;
|
||||
thePDoc : out Element from XmlObjMgt;
|
||||
theFileName: ExtendedString from TCollection)
|
||||
returns Boolean from Standard
|
||||
is virtual protected;
|
||||
|
||||
MakeDocument (me:mutable; theDocument: Document from CDM;
|
||||
thePDoc : out Element from XmlObjMgt)
|
||||
returns Integer from Standard
|
||||
is virtual protected;
|
||||
|
||||
AddNamespace (me:mutable; thePrefix, theURI: AsciiString)
|
||||
is protected;
|
||||
|
||||
IsError (me) returns Boolean from Standard;
|
||||
|
||||
AttributeDrivers (me : mutable; theMsgDriver: MessageDriver from CDM)
|
||||
returns ADriverTable from XmlMDF
|
||||
is virtual;
|
||||
|
||||
WriteShapeSection (me:mutable; thePDoc : out Element from XmlObjMgt)
|
||||
returns Boolean from Standard
|
||||
is virtual protected;
|
||||
|
||||
fields
|
||||
myDrivers : ADriverTable from XmlMDF is protected;
|
||||
mySeqOfNS : SequenceOfNamespaceDef from XmlLDrivers;
|
||||
myCopyright : ExtendedString from TCollection;
|
||||
myRelocTable: SRelocationTable from XmlObjMgt is protected;
|
||||
myIsError : Boolean from Standard is protected;
|
||||
|
||||
end DocumentStorageDriver;
|
419
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx
Executable file
419
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx
Executable file
@@ -0,0 +1,419 @@
|
||||
// File: XmlLDrivers_DocumentStorageDriver.cxx
|
||||
// Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
#include <XmlLDrivers_DocumentStorageDriver.ixx>
|
||||
|
||||
#include <XmlLDrivers.hxx>
|
||||
#include <XmlLDrivers_NamespaceDef.hxx>
|
||||
#include <XmlMDF.hxx>
|
||||
#include <XmlMDF_ADriverTable.hxx>
|
||||
|
||||
#include <XmlObjMgt.hxx>
|
||||
#include <XmlObjMgt_SRelocationTable.hxx>
|
||||
|
||||
#include <LDOM_XmlWriter.hxx>
|
||||
#include <LDOM_LDOMImplementation.hxx>
|
||||
#include <LDOM_DocumentType.hxx>
|
||||
#include <XmlObjMgt_Document.hxx>
|
||||
|
||||
#include <Storage_Data.hxx>
|
||||
#include <PCDM.hxx>
|
||||
#include <PCDM_ReadWriter.hxx>
|
||||
#include <CDM_NullMessageDriver.hxx>
|
||||
#include <CDM_Document.hxx>
|
||||
#include <CDM_Application.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <TColStd_SequenceOfAsciiString.hxx>
|
||||
|
||||
#include <locale.h>
|
||||
#include <Standard_Failure.hxx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
|
||||
#include <OSD_File.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
|
||||
#define STORAGE_VERSION "STORAGE_VERSION: "
|
||||
#define REFERENCE_COUNTER "REFERENCE_COUNTER: "
|
||||
#define MODIFICATION_COUNTER "MODIFICATION_COUNTER: "
|
||||
#define START_REF "START_REF"
|
||||
#define END_REF "END_REF"
|
||||
|
||||
#define FAILSTR "Failed to write xsi:schemaLocation : "
|
||||
|
||||
//#define TAKE_TIMES
|
||||
static void take_time (const Standard_Integer, const char *,
|
||||
const Handle(CDM_MessageDriver)&)
|
||||
#ifdef TAKE_TIMES
|
||||
;
|
||||
#else
|
||||
{}
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlLDrivers_DocumentStorageDriver
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
XmlLDrivers_DocumentStorageDriver::XmlLDrivers_DocumentStorageDriver
|
||||
(const TCollection_ExtendedString& theCopyright)
|
||||
: myCopyright (theCopyright)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SchemaName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
TCollection_ExtendedString XmlLDrivers_DocumentStorageDriver::SchemaName() const
|
||||
{
|
||||
TCollection_ExtendedString schemaname;
|
||||
return schemaname;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddNamespace
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void XmlLDrivers_DocumentStorageDriver::AddNamespace
|
||||
(const TCollection_AsciiString& thePrefix,
|
||||
const TCollection_AsciiString& theURI)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= mySeqOfNS.Length(); i++)
|
||||
if (thePrefix == mySeqOfNS(i).Prefix()) return;
|
||||
mySeqOfNS.Append (XmlLDrivers_NamespaceDef(thePrefix, theURI));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Write
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void XmlLDrivers_DocumentStorageDriver::Write
|
||||
(const Handle(CDM_Document)& theDocument,
|
||||
const TCollection_ExtendedString& theFileName)
|
||||
{
|
||||
const TCollection_AsciiString anOldNumLocale =
|
||||
(Standard_CString) setlocale (LC_NUMERIC, NULL);
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
|
||||
Handle(CDM_MessageDriver) aMessageDriver =
|
||||
theDocument -> Application() -> MessageDriver();
|
||||
::take_time (~0, " +++++ Start STORAGE procedures ++++++", aMessageDriver);
|
||||
|
||||
// Create new DOM_Document
|
||||
XmlObjMgt_Document aDOMDoc = XmlObjMgt_Document::createDocument ("document");
|
||||
|
||||
// Fill the document with data
|
||||
XmlObjMgt_Element anElement = aDOMDoc.getDocumentElement();
|
||||
|
||||
if (WriteToDomDocument (theDocument, anElement, theFileName) == Standard_False) {
|
||||
// Write DOM_Document into XML file,
|
||||
TCollection_AsciiString aFileName (theFileName, '?');
|
||||
FILE * aFile = fopen(aFileName.ToCString(), "wt");
|
||||
|
||||
if (aFile) {
|
||||
LDOM_XmlWriter aWriter (aFile);
|
||||
aWriter.SetIndentation(1);
|
||||
aWriter << aDOMDoc;
|
||||
fclose(aFile);
|
||||
::take_time (0, " +++++ Fin formatting to XML : ", aMessageDriver);
|
||||
|
||||
}else{
|
||||
myIsError = Standard_True;
|
||||
TCollection_ExtendedString aMsg =
|
||||
TCollection_ExtendedString("Error: the file ") + aFileName +
|
||||
" cannot be opened for writing";
|
||||
aMessageDriver -> Write (aMsg.ToExtString());
|
||||
Standard_Failure::Raise("File cannot be opened for writing");
|
||||
}
|
||||
}
|
||||
setlocale(LC_NUMERIC, (char *) anOldNumLocale.ToCString()) ;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : WriteToDomDocument
|
||||
//purpose : management of the macro-structure of XML document data
|
||||
//remark : If the application needs to use myRelocTable to store additional
|
||||
// data to XML, this method should be reimplemented avoiding step 3
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean XmlLDrivers_DocumentStorageDriver::WriteToDomDocument
|
||||
(const Handle(CDM_Document)& theDocument,
|
||||
XmlObjMgt_Element& theElement,
|
||||
const TCollection_ExtendedString& theFileName)
|
||||
{
|
||||
myIsError = Standard_False;
|
||||
Handle(CDM_MessageDriver) aMessageDriver =
|
||||
theDocument -> Application() -> MessageDriver();
|
||||
// 1. Write header information
|
||||
Standard_Integer i;
|
||||
XmlObjMgt_Document aDOMDoc = theElement.getOwnerDocument();
|
||||
|
||||
// 1.a File Format
|
||||
TCollection_AsciiString aStorageFormat (theDocument->StorageFormat(), '?');
|
||||
theElement.setAttribute ("format", aStorageFormat.ToCString());
|
||||
// theElement.setAttribute ("schema", "XSD");
|
||||
|
||||
theElement.setAttribute ("xmlns" , "http://www.opencascade.org/OCAF/XML");
|
||||
for (i = 1; i <= mySeqOfNS.Length(); i++) {
|
||||
TCollection_AsciiString aPrefix =
|
||||
TCollection_AsciiString("xmlns:") + mySeqOfNS(i).Prefix().ToCString();
|
||||
theElement.setAttribute (aPrefix.ToCString(),
|
||||
mySeqOfNS(i).URI().ToCString());
|
||||
}
|
||||
theElement.setAttribute ("xmlns:xsi",
|
||||
"http://www.w3.org/2001/XMLSchema-instance");
|
||||
//mkv 15.09.05 OCC10001
|
||||
//theElement.setAttribute ("xsi:schemaLocation",
|
||||
// "http://www.opencascade.org/OCAF/XML"
|
||||
// " http://www.nnov.matra-dtv.fr/~agv/XmlOcaf.xsd");
|
||||
//
|
||||
// the order of search : by CSF_XmlOcafResource and then by CASROOT
|
||||
TCollection_AsciiString anHTTP = "http://www.opencascade.org/OCAF/XML";
|
||||
Standard_Boolean aToSetCSFVariable = Standard_False;
|
||||
const char * aCSFVariable [2] = {
|
||||
"CSF_XmlOcafResource",
|
||||
"CASROOT"
|
||||
};
|
||||
TCollection_AsciiString aResourceDir = "";
|
||||
aResourceDir = getenv (aCSFVariable[0]);
|
||||
if (aResourceDir.IsEmpty()) {
|
||||
// now try by CASROOT
|
||||
aResourceDir = getenv (aCSFVariable[1]);
|
||||
if ( !aResourceDir.IsEmpty() ) {
|
||||
aResourceDir += "/src/XmlOcafResource" ;
|
||||
aToSetCSFVariable = Standard_True; //CSF variable to be set later
|
||||
}
|
||||
#ifdef DEB
|
||||
else {
|
||||
TCollection_ExtendedString aWarn = FAILSTR "Neither ";
|
||||
aWarn = (aWarn + aCSFVariable[0] + ", nor " + aCSFVariable[1]
|
||||
+ " variables have been set");
|
||||
aMessageDriver->Write (aWarn.ToExtString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (!aResourceDir.IsEmpty()) {
|
||||
TCollection_AsciiString aResourceFileName = aResourceDir + "/XmlOcaf.xsd";
|
||||
// search directory name that has been constructed, now check whether
|
||||
// it and the file exist
|
||||
OSD_File aResourceFile ( aResourceFileName );
|
||||
if ( aResourceFile.Exists() ) {
|
||||
if (aToSetCSFVariable) {
|
||||
OSD_Environment aCSFVarEnv ( aCSFVariable[0], aResourceDir );
|
||||
aCSFVarEnv.Build();
|
||||
#ifdef DEB
|
||||
TCollection_ExtendedString aWarn1 = "Variable ";
|
||||
aWarn1 = (aWarn1 + aCSFVariable[0]
|
||||
+ " has not been explicitly defined. Set to " + aResourceDir);
|
||||
aMessageDriver->Write (aWarn1.ToExtString());
|
||||
#endif
|
||||
if ( aCSFVarEnv.Failed() ) {
|
||||
TCollection_ExtendedString aWarn = FAILSTR "Failed to initialize ";
|
||||
aWarn = aWarn + aCSFVariable[0] + " with " + aResourceDir;
|
||||
aMessageDriver->Write (aWarn.ToExtString());
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEB
|
||||
else {
|
||||
TCollection_ExtendedString aWarn = FAILSTR "Schema definition file ";
|
||||
aWarn += (aResourceFileName + " was not found");
|
||||
aMessageDriver->Write (aWarn.ToExtString());
|
||||
}
|
||||
#endif
|
||||
anHTTP = anHTTP + ' ' + aResourceFileName;
|
||||
}
|
||||
theElement.setAttribute ("xsi:schemaLocation", anHTTP.ToCString() );
|
||||
|
||||
// 1.b Info section
|
||||
XmlObjMgt_Element anInfoElem = aDOMDoc.createElement("info");
|
||||
theElement.appendChild(anInfoElem);
|
||||
|
||||
TCollection_AsciiString aCreationDate = XmlLDrivers::CreationDate();
|
||||
|
||||
// anInfoElem.setAttribute("dbv", 0);
|
||||
anInfoElem.setAttribute("date", aCreationDate.ToCString());
|
||||
anInfoElem.setAttribute("schemav", 0);
|
||||
// anInfoElem.setAttribute("appv", anAppVersion.ToCString());
|
||||
|
||||
// Document version
|
||||
anInfoElem.setAttribute("DocVersion", XmlLDrivers::StorageVersion().ToCString());
|
||||
|
||||
// User info with Copyright
|
||||
TColStd_SequenceOfAsciiString aUserInfo;
|
||||
if (myCopyright.Length() > 0)
|
||||
aUserInfo.Append (TCollection_AsciiString(myCopyright,'?'));
|
||||
|
||||
Handle(Storage_Data) theData = new Storage_Data;
|
||||
//PCDM_ReadWriter::WriteFileFormat( theData, theDocument );
|
||||
PCDM_ReadWriter::Writer()->WriteReferenceCounter(theData,theDocument);
|
||||
PCDM_ReadWriter::Writer()->WriteReferences(theData,theDocument,theFileName);
|
||||
PCDM_ReadWriter::Writer()->WriteExtensions(theData,theDocument);
|
||||
PCDM_ReadWriter::Writer()->WriteVersion(theData,theDocument);
|
||||
|
||||
const TColStd_SequenceOfAsciiString& aRefs = theData->UserInfo();
|
||||
for(i = 1; i <= aRefs.Length(); i++)
|
||||
aUserInfo.Append(aRefs.Value(i));
|
||||
|
||||
for (i = 1; i <= aUserInfo.Length(); i++)
|
||||
{
|
||||
XmlObjMgt_Element aUIItem = aDOMDoc.createElement ("iitem");
|
||||
anInfoElem.appendChild (aUIItem);
|
||||
LDOM_Text aUIText = aDOMDoc.createTextNode (aUserInfo(i).ToCString());
|
||||
aUIItem.appendChild (aUIText);
|
||||
}
|
||||
|
||||
// 1.c Comments section
|
||||
TColStd_SequenceOfExtendedString aComments;
|
||||
theDocument->Comments(aComments);
|
||||
|
||||
XmlObjMgt_Element aCommentsElem = aDOMDoc.createElement ("comments");
|
||||
theElement.appendChild (aCommentsElem);
|
||||
|
||||
for (i = 1; i <= aComments.Length(); i++)
|
||||
{
|
||||
XmlObjMgt_Element aCItem = aDOMDoc.createElement ("citem");
|
||||
aCommentsElem.appendChild (aCItem);
|
||||
XmlObjMgt::SetExtendedString (aCItem, aComments(i));
|
||||
}
|
||||
|
||||
// 2a. Write document contents
|
||||
Standard_Integer anObjNb = 0;
|
||||
{
|
||||
try
|
||||
{
|
||||
OCC_CATCH_SIGNALS
|
||||
anObjNb = MakeDocument(theDocument, theElement);
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
myIsError = Standard_True;
|
||||
TCollection_ExtendedString anErrorString (Standard_Failure::Caught()->GetMessageString());
|
||||
aMessageDriver -> Write (anErrorString.ToExtString());
|
||||
}
|
||||
}
|
||||
if (anObjNb <= 0 && myIsError == Standard_False) {
|
||||
myIsError = Standard_True;
|
||||
TCollection_ExtendedString anErrorString ("error occurred");
|
||||
aMessageDriver -> Write (anErrorString.ToExtString());
|
||||
}
|
||||
// 2b. Write number of objects into the info section
|
||||
anInfoElem.setAttribute("objnb", anObjNb);
|
||||
::take_time (0, " +++++ Fin DOM data for OCAF : ", aMessageDriver);
|
||||
|
||||
// 3. Clear relocation table
|
||||
// If the application needs to use myRelocTable to store additional
|
||||
// data to XML, this method should be reimplemented avoiding this step
|
||||
myRelocTable.Clear();
|
||||
|
||||
// 4. Write Shapes section
|
||||
if(WriteShapeSection(theElement))
|
||||
::take_time (0, " +++ Fin DOM data for Shapes : ", aMessageDriver);
|
||||
return myIsError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer XmlLDrivers_DocumentStorageDriver::MakeDocument
|
||||
(const Handle(CDM_Document)& theTDoc,
|
||||
XmlObjMgt_Element& theElement)
|
||||
{
|
||||
TCollection_ExtendedString aMessage;
|
||||
Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(theTDoc);
|
||||
myRelocTable.Clear();
|
||||
if (!TDOC.IsNull())
|
||||
{
|
||||
// myRelocTable.SetDocument (theElement.getOwnerDocument());
|
||||
Handle(TDF_Data) aTDF = TDOC->GetData();
|
||||
|
||||
// Find MessageDriver and pass it to AttributeDrivers()
|
||||
Handle(CDM_Application) anApplication= theTDoc -> Application();
|
||||
Handle(CDM_MessageDriver) aMessageDriver;
|
||||
if (anApplication.IsNull())
|
||||
aMessageDriver = new CDM_NullMessageDriver;
|
||||
else
|
||||
aMessageDriver = anApplication -> MessageDriver();
|
||||
if (myDrivers.IsNull()) myDrivers = AttributeDrivers (aMessageDriver);
|
||||
|
||||
// Retrieve from DOM_Document
|
||||
XmlMDF::FromTo (aTDF, theElement, myRelocTable, myDrivers);
|
||||
#if defined(DEB) && !defined(TAKE_TIMES)
|
||||
aMessage = "First step successfull";
|
||||
aMessageDriver -> Write (aMessage.ToExtString());
|
||||
#endif
|
||||
return myRelocTable.Extent();
|
||||
}
|
||||
#ifdef DEB
|
||||
cout << "First step failed" << endl; // No MessageDriver available
|
||||
#endif
|
||||
return -1; // error
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsError
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean XmlLDrivers_DocumentStorageDriver::IsError () const
|
||||
{
|
||||
return myIsError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AttributeDrivers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(XmlMDF_ADriverTable) XmlLDrivers_DocumentStorageDriver::AttributeDrivers
|
||||
(const Handle(CDM_MessageDriver)& theMessageDriver)
|
||||
{
|
||||
return XmlLDrivers::AttributeDrivers (theMessageDriver);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : take_time
|
||||
//class : static
|
||||
//purpose : output astronomical time elapsed
|
||||
//=======================================================================
|
||||
#ifdef TAKE_TIMES
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#ifndef WNT
|
||||
extern "C" int ftime (struct timeb *tp);
|
||||
#endif
|
||||
struct timeb tmbuf0;
|
||||
|
||||
static void take_time (const Standard_Integer isReset, const char * aHeader,
|
||||
const Handle(CDM_MessageDriver)& aMessageDriver)
|
||||
{
|
||||
struct timeb tmbuf;
|
||||
ftime (&tmbuf);
|
||||
TCollection_ExtendedString aMessage ((Standard_CString)aHeader);
|
||||
if (isReset) tmbuf0 = tmbuf;
|
||||
else {
|
||||
char take_tm_buf [64];
|
||||
sprintf (take_tm_buf, "%9.2f s ++++",
|
||||
double(tmbuf.time - tmbuf0.time) +
|
||||
double(tmbuf.millitm - tmbuf0.millitm)/1000.);
|
||||
aMessage += take_tm_buf;
|
||||
}
|
||||
aMessageDriver -> Write (aMessage.ToExtString());
|
||||
}
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : WriteShapeSection
|
||||
//purpose : defines WriteShapeSection
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlLDrivers_DocumentStorageDriver::WriteShapeSection
|
||||
(XmlObjMgt_Element& /*theElement*/)
|
||||
{
|
||||
// empty; should be redefined in subclasses
|
||||
return Standard_False;
|
||||
}
|
||||
|
29
src/XmlLDrivers/XmlLDrivers_NamespaceDef.cdl
Executable file
29
src/XmlLDrivers/XmlLDrivers_NamespaceDef.cdl
Executable file
@@ -0,0 +1,29 @@
|
||||
-- File: XmlLDrivers_NamespaceDef.cdl
|
||||
-- Created: Wed Sep 19 15:14:48 2001
|
||||
-- Author: admin of fao FACTORY
|
||||
-- <fao@renox.nnov.matra-dtv.fr>
|
||||
---Copyright: Matra Datavision 2001
|
||||
|
||||
private class NamespaceDef from XmlLDrivers
|
||||
|
||||
uses AsciiString from TCollection
|
||||
|
||||
is
|
||||
Create returns NamespaceDef from XmlLDrivers;
|
||||
|
||||
Create (thePrefix: AsciiString from TCollection;
|
||||
theURI : AsciiString from TCollection)
|
||||
returns NamespaceDef from XmlLDrivers;
|
||||
|
||||
Prefix (me) returns AsciiString from TCollection;
|
||||
---C++: return const &
|
||||
|
||||
URI (me) returns AsciiString from TCollection;
|
||||
---C++: return const &
|
||||
|
||||
fields
|
||||
|
||||
myPrefix : AsciiString from TCollection;
|
||||
myURI : AsciiString from TCollection;
|
||||
|
||||
end NamespaceDef;
|
46
src/XmlLDrivers/XmlLDrivers_NamespaceDef.cxx
Executable file
46
src/XmlLDrivers/XmlLDrivers_NamespaceDef.cxx
Executable file
@@ -0,0 +1,46 @@
|
||||
// File: XmlLDrivers_NamespaceDef.cxx
|
||||
// Created: Wed Sep 19 15:18:44 2001
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
// History:
|
||||
|
||||
#include <XmlLDrivers_NamespaceDef.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlLDrivers_NamespaceDef
|
||||
//purpose : Empty constructor
|
||||
//=======================================================================
|
||||
|
||||
XmlLDrivers_NamespaceDef::XmlLDrivers_NamespaceDef ()
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlLDrivers_NamespaceDef
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
XmlLDrivers_NamespaceDef::XmlLDrivers_NamespaceDef
|
||||
(const TCollection_AsciiString& thePrefix,
|
||||
const TCollection_AsciiString& theURI)
|
||||
: myPrefix (thePrefix), myURI (theURI)
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : Prefix
|
||||
//purpose : Query
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_AsciiString& XmlLDrivers_NamespaceDef::Prefix () const
|
||||
{
|
||||
return myPrefix;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : URI
|
||||
//purpose : Query
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_AsciiString& XmlLDrivers_NamespaceDef::URI () const
|
||||
{
|
||||
return myURI;
|
||||
}
|
Reference in New Issue
Block a user