mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
105
src/XmlMDF/XmlMDF.cdl
Executable file
105
src/XmlMDF/XmlMDF.cdl
Executable file
@@ -0,0 +1,105 @@
|
||||
-- File: XmlMDF.cdl
|
||||
-- Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
-- Author: Julia DOROVSKIKH
|
||||
---Copyright: MATRA DATAVISION 2001
|
||||
|
||||
package XmlMDF
|
||||
|
||||
---Purpose: This package provides classes and methods to
|
||||
-- translate a transient DF into a persistent one and
|
||||
-- vice versa.
|
||||
--
|
||||
-- Driver
|
||||
--
|
||||
-- A driver is a tool used to translate a transient
|
||||
-- attribute into a persistent one and vice versa.
|
||||
--
|
||||
-- Driver Table
|
||||
--
|
||||
-- A driver table is an object building links between
|
||||
-- object types and object drivers. In the
|
||||
-- translation process, a driver table is asked to
|
||||
-- give a translation driver for each current object
|
||||
-- to be translated.
|
||||
|
||||
uses
|
||||
TCollection,
|
||||
TColStd,
|
||||
TDF,
|
||||
CDM,
|
||||
XmlObjMgt
|
||||
|
||||
is
|
||||
---Category: Classes
|
||||
-- =============================================================
|
||||
|
||||
deferred class ADriver; -- Attribute Storage/Retrieve Driver.
|
||||
|
||||
private class MapOfDriver
|
||||
instantiates DataMap from TCollection (AsciiString from TCollection,
|
||||
ADriver from XmlMDF,
|
||||
AsciiString from TCollection);
|
||||
|
||||
---Purpose: Storage and Retrieval attributes drivers
|
||||
-- ========================================
|
||||
|
||||
class TagSourceDriver;
|
||||
|
||||
class ReferenceDriver;
|
||||
|
||||
---Category: Instantiations
|
||||
-- =============================================================
|
||||
|
||||
-- Map (Type, ADriver)
|
||||
class TypeADriverMap instantiates DataMap from TCollection
|
||||
(Type from Standard,
|
||||
ADriver from XmlMDF,
|
||||
MapTransientHasher from TColStd);
|
||||
|
||||
-- Attribute Storage Driver Table.
|
||||
class ADriverTable;
|
||||
|
||||
|
||||
-- Package methods
|
||||
|
||||
FromTo(aSource : Data from TDF;
|
||||
aTarget : in out Element from XmlObjMgt;
|
||||
aReloc : in out SRelocationTable from XmlObjMgt;
|
||||
aDrivers : ADriverTable from XmlMDF);
|
||||
---Purpose: Translates a transient <aSource> into a persistent
|
||||
-- <aTarget>.
|
||||
|
||||
WriteSubTree(theLabel : Label from TDF;
|
||||
theElement : in out Element from XmlObjMgt;
|
||||
aReloc : in out SRelocationTable from XmlObjMgt;
|
||||
aDrivers : ADriverTable from XmlMDF)
|
||||
returns Integer from Standard
|
||||
is private;
|
||||
---Purpose:
|
||||
|
||||
FromTo(aSource : Element from XmlObjMgt;
|
||||
aTarget : in out Data from TDF;
|
||||
aReloc : in out RRelocationTable from XmlObjMgt;
|
||||
aDrivers : ADriverTable from XmlMDF)
|
||||
returns Boolean from Standard;
|
||||
---Purpose: Translates a persistent <aSource> into a transient
|
||||
-- <aTarget>.
|
||||
-- Returns True if completed successfully (False on error)
|
||||
|
||||
ReadSubTree (theElement : Element from XmlObjMgt;
|
||||
theLabel : Label from TDF;
|
||||
aReloc : in out RRelocationTable from XmlObjMgt;
|
||||
aDrivers : MapOfDriver from XmlMDF)
|
||||
returns Integer from Standard
|
||||
is private;
|
||||
---Purpose:
|
||||
|
||||
AddDrivers (aDriverTable : ADriverTable from XmlMDF;
|
||||
theMessageDriver: MessageDriver from CDM);
|
||||
---Purpose: Adds the attribute storage drivers to <aDriverSeq>.
|
||||
|
||||
CreateDrvMap (aDriverTable : ADriverTable from XmlMDF;
|
||||
anAsciiDriverMap: out MapOfDriver from XmlMDF)
|
||||
is private;
|
||||
|
||||
end XmlMDF;
|
308
src/XmlMDF/XmlMDF.cxx
Executable file
308
src/XmlMDF/XmlMDF.cxx
Executable file
@@ -0,0 +1,308 @@
|
||||
// File: XmlMDF.cxx
|
||||
// Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Matra Datavision 2001
|
||||
|
||||
#include <XmlMDF.ixx>
|
||||
#include <XmlMDF_ADriver.hxx>
|
||||
#include <XmlMDF_TagSourceDriver.hxx>
|
||||
#include <XmlMDF_ReferenceDriver.hxx>
|
||||
#include <XmlMDF_DataMapIteratorOfTypeADriverMap.hxx>
|
||||
|
||||
#include <XmlObjMgt_Persistent.hxx>
|
||||
#include <XmlObjMgt_DOMString.hxx>
|
||||
#include <XmlObjMgt_Document.hxx>
|
||||
|
||||
#include <TDF_TagSource.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDF_Tool.hxx>
|
||||
#include <TDF_AttributeIterator.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TColStd_MapOfTransient.hxx>
|
||||
#include <Storage_Schema.hxx>
|
||||
|
||||
IMPLEMENT_DOMSTRING (TagString, "tag")
|
||||
IMPLEMENT_DOMSTRING (LabelString, "label")
|
||||
#define DATATYPE_MIGRATION
|
||||
//#define DATATYPE_MIGRATION_DEB
|
||||
//=======================================================================
|
||||
//function : UnsuppTypesMap
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
static TColStd_MapOfTransient& UnsuppTypesMap ()
|
||||
{
|
||||
static TColStd_MapOfTransient anUnsuppTypes;
|
||||
return anUnsuppTypes;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FromTo
|
||||
//purpose : Paste transient data into DOM_Element
|
||||
//=======================================================================
|
||||
void XmlMDF::FromTo (const Handle(TDF_Data)& theData,
|
||||
XmlObjMgt_Element& theElement,
|
||||
XmlObjMgt_SRelocationTable& theRelocTable,
|
||||
const Handle(XmlMDF_ADriverTable)& theDrivers)
|
||||
{
|
||||
UnsuppTypesMap().Clear();
|
||||
// Standard_Integer count =
|
||||
WriteSubTree(theData->Root(), theElement, theRelocTable, theDrivers);
|
||||
UnsuppTypesMap().Clear();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : WriteSubTree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer XmlMDF::WriteSubTree
|
||||
(const TDF_Label& theLabel,
|
||||
XmlObjMgt_Element& theElement,
|
||||
XmlObjMgt_SRelocationTable& theRelocTable,
|
||||
const Handle(XmlMDF_ADriverTable)& theDrivers)
|
||||
{
|
||||
XmlObjMgt_Document aDoc = theElement.getOwnerDocument();
|
||||
|
||||
// create element "label"
|
||||
XmlObjMgt_Element aLabElem = aDoc.createElement (::LabelString());
|
||||
|
||||
// Extraction of the driver subset.
|
||||
const XmlMDF_TypeADriverMap& aDriverMap = theDrivers->GetDrivers();
|
||||
|
||||
// write attributes
|
||||
Standard_Integer count = 0;
|
||||
TDF_AttributeIterator itr1 (theLabel);
|
||||
for ( ; itr1.More(); itr1.Next())
|
||||
{
|
||||
const Handle(TDF_Attribute)& tAtt = itr1.Value();
|
||||
const Handle(Standard_Type)& aType = tAtt->DynamicType();
|
||||
if (aDriverMap.IsBound (aType))
|
||||
{
|
||||
const Handle(XmlMDF_ADriver)& aDriver = aDriverMap.Find (aType);
|
||||
count++;
|
||||
|
||||
// Add source to relocation table
|
||||
Standard_Integer anId = theRelocTable.Add (tAtt);
|
||||
|
||||
// Create DOM data item
|
||||
XmlObjMgt_Persistent pAtt;
|
||||
pAtt.CreateElement (aLabElem, aDriver->TypeName().ToCString(), anId);
|
||||
|
||||
// Paste
|
||||
aDriver -> Paste (tAtt, pAtt, theRelocTable);
|
||||
}
|
||||
#ifdef DEB
|
||||
else if (!UnsuppTypesMap().Contains (aType))
|
||||
{
|
||||
cout << "attribute driver for type "<< aType -> Name()<< " not found"<< endl;
|
||||
UnsuppTypesMap().Add (aType);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// write sub-labels
|
||||
TDF_ChildIterator itr2 (theLabel);
|
||||
for ( ; itr2.More(); itr2.Next())
|
||||
{
|
||||
const TDF_Label& aChildLab = itr2.Value();
|
||||
count += WriteSubTree(aChildLab, aLabElem, theRelocTable, theDrivers);
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
theElement.appendChild(aLabElem);
|
||||
|
||||
// set attribute "tag"
|
||||
aLabElem.setAttribute (::TagString(), theLabel.Tag());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FromTo
|
||||
//purpose : Paste data from DOM_Element into transient document
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlMDF::FromTo (const XmlObjMgt_Element& theElement,
|
||||
Handle(TDF_Data)& theData,
|
||||
XmlObjMgt_RRelocationTable& theRelocTable,
|
||||
const Handle(XmlMDF_ADriverTable)& theDrivers)
|
||||
{
|
||||
TDF_Label aRootLab = theData->Root();
|
||||
XmlMDF_MapOfDriver aDriverMap;
|
||||
CreateDrvMap (theDrivers, aDriverMap);
|
||||
|
||||
Standard_Integer count = 0;
|
||||
|
||||
LDOM_Node theNode = theElement.getFirstChild();
|
||||
XmlObjMgt_Element anElem = (const XmlObjMgt_Element&)theNode;
|
||||
while ( !anElem.isNull() )
|
||||
{
|
||||
if ( anElem.getNodeName().equals (::LabelString()) )
|
||||
{
|
||||
Standard_Integer subcount =
|
||||
ReadSubTree(anElem, aRootLab, theRelocTable, aDriverMap);
|
||||
// check for error
|
||||
if (subcount < 0)
|
||||
return Standard_False;
|
||||
count += subcount;
|
||||
}
|
||||
//anElem = (const XmlObjMgt_Element &) anElem.getNextSibling();
|
||||
LDOM_Node theNode1 = anElem.getNextSibling();
|
||||
anElem = (const XmlObjMgt_Element &) theNode1;
|
||||
}
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadSubTree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer XmlMDF::ReadSubTree (const XmlObjMgt_Element& theElement,
|
||||
const TDF_Label& theLabel,
|
||||
XmlObjMgt_RRelocationTable& theRelocTable,
|
||||
const XmlMDF_MapOfDriver& theDriverMap)
|
||||
{
|
||||
// Extraction of the driver subset.
|
||||
Standard_Integer count = 0;
|
||||
|
||||
//XmlObjMgt_Element anElem = (const XmlObjMgt_Element &) theElement.getFirstChild();
|
||||
LDOM_Node theNode = theElement.getFirstChild();
|
||||
XmlObjMgt_Element anElem = (const XmlObjMgt_Element &) theNode;
|
||||
while ( !anElem.isNull() )
|
||||
{
|
||||
if ( anElem.getNodeType() == LDOM_Node::ELEMENT_NODE )
|
||||
{
|
||||
if ( anElem.getNodeName().equals (::LabelString()) )
|
||||
{
|
||||
// read tag
|
||||
Standard_Integer tag;
|
||||
XmlObjMgt_DOMString aTag (anElem.getAttribute(::TagString()));
|
||||
if ( !aTag.GetInteger (tag) ) {
|
||||
TCollection_ExtendedString anErrorMessage =
|
||||
TCollection_ExtendedString ("Wrong Tag value for OCAF Label: ")
|
||||
+ aTag;
|
||||
theDriverMap.Find("TDF_TagSource") -> WriteMessage (anErrorMessage);
|
||||
return -1;
|
||||
}
|
||||
// create label
|
||||
TDF_Label aLab = theLabel.FindChild(tag, Standard_True);
|
||||
|
||||
// read sub-tree
|
||||
Standard_Integer subcount =
|
||||
ReadSubTree(anElem, aLab, theRelocTable, theDriverMap);
|
||||
// check for error
|
||||
if (subcount == -1)
|
||||
return -1;
|
||||
count += subcount;
|
||||
}
|
||||
else
|
||||
{
|
||||
// read attribute
|
||||
XmlObjMgt_DOMString aName = anElem.getNodeName();
|
||||
|
||||
#ifdef DATATYPE_MIGRATION
|
||||
TCollection_AsciiString newName;
|
||||
if(Storage_Schema::CheckTypeMigration(aName, newName)) {
|
||||
#ifdef DATATYPE_MIGRATION_DEB
|
||||
cout << "CheckTypeMigration:OldType = " <<aName.GetString() << " Len = "<<strlen(aName.GetString())<<endl;
|
||||
cout << "CheckTypeMigration:NewType = " <<newName << " Len = "<< newName.Length()<<endl;
|
||||
#endif
|
||||
aName = newName.ToCString();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (theDriverMap.IsBound (aName))
|
||||
{
|
||||
count++;
|
||||
const Handle(XmlMDF_ADriver)& driver = theDriverMap.Find(aName);
|
||||
XmlObjMgt_Persistent pAtt (anElem);
|
||||
Standard_Integer anID = pAtt.Id ();
|
||||
if (anID <= 0) { // check for ID validity
|
||||
TCollection_ExtendedString anErrorMessage =
|
||||
TCollection_ExtendedString("Wrong ID of OCAF attribute with type ")
|
||||
+ aName;
|
||||
driver -> WriteMessage (anErrorMessage);
|
||||
return -1;
|
||||
}
|
||||
Handle(TDF_Attribute) tAtt;
|
||||
Standard_Boolean isBound = theRelocTable.IsBound(anID);
|
||||
if (isBound)
|
||||
tAtt = Handle(TDF_Attribute)::DownCast(theRelocTable.Find(anID));
|
||||
else
|
||||
tAtt = driver -> NewEmpty();
|
||||
if (tAtt->Label().IsNull())
|
||||
theLabel.AddAttribute (tAtt);
|
||||
else
|
||||
driver->WriteMessage
|
||||
(TCollection_ExtendedString("XmlDriver warning: ") +
|
||||
"attempt to attach attribute " +
|
||||
aName + " to a second label");
|
||||
|
||||
if (! driver -> Paste (pAtt, tAtt, theRelocTable))
|
||||
{
|
||||
// error converting persistent to transient
|
||||
driver->WriteMessage
|
||||
(TCollection_ExtendedString("XmlDriver warning: ") +
|
||||
"failure reading attribute " + aName);
|
||||
}
|
||||
else if (isBound == Standard_False)
|
||||
theRelocTable.Bind (anID, tAtt);
|
||||
}
|
||||
#ifdef DEB
|
||||
else
|
||||
{
|
||||
const TCollection_AsciiString anAsciiName = aName;
|
||||
cerr << "XmlDriver warning: "
|
||||
<< "label contains object of unknown type "<< anAsciiName<< endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
//anElem = (const XmlObjMgt_Element &) anElem.getNextSibling();
|
||||
LDOM_Node theNode1 = anElem.getNextSibling();
|
||||
anElem = (const XmlObjMgt_Element &) theNode1;
|
||||
}
|
||||
|
||||
// AfterRetrieval
|
||||
if (count > 0)
|
||||
{
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddDrivers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void XmlMDF::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable,
|
||||
const Handle(CDM_MessageDriver)& aMessageDriver)
|
||||
{
|
||||
aDriverTable->AddDriver (new XmlMDF_TagSourceDriver(aMessageDriver));
|
||||
aDriverTable->AddDriver (new XmlMDF_ReferenceDriver(aMessageDriver));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateDrvMap
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void XmlMDF::CreateDrvMap (const Handle(XmlMDF_ADriverTable)& theDrivers,
|
||||
XmlMDF_MapOfDriver& theAsciiDriverMap)
|
||||
{
|
||||
const XmlMDF_TypeADriverMap& aDriverMap = theDrivers->GetDrivers();
|
||||
XmlMDF_DataMapIteratorOfTypeADriverMap anIter (aDriverMap);
|
||||
while (anIter.More()) {
|
||||
const Handle(XmlMDF_ADriver)& aDriver = anIter.Value();
|
||||
const TCollection_AsciiString aTypeName = aDriver -> TypeName();
|
||||
if (theAsciiDriverMap.IsBound (aTypeName) == Standard_False)
|
||||
theAsciiDriverMap.Bind (aTypeName, aDriver);
|
||||
else
|
||||
aDriver -> WriteMessage
|
||||
(TCollection_ExtendedString ("Warning: skipped driver name: \"")
|
||||
+ aTypeName + '\"');
|
||||
anIter.Next();
|
||||
}
|
||||
}
|
70
src/XmlMDF/XmlMDF_ADriver.cdl
Executable file
70
src/XmlMDF/XmlMDF_ADriver.cdl
Executable file
@@ -0,0 +1,70 @@
|
||||
-- File: XmlMDF_ADriver.cdl
|
||||
-- Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- Copyright: Matra Datavision 2001
|
||||
|
||||
deferred class ADriver from XmlMDF inherits TShared from MMgt
|
||||
|
||||
---Purpose: Attribute Storage/Retrieval Driver.
|
||||
|
||||
uses
|
||||
AsciiString from TCollection,
|
||||
ExtendedString from TCollection,
|
||||
Attribute from TDF,
|
||||
MessageDriver from CDM,
|
||||
RRelocationTable from XmlObjMgt,
|
||||
SRelocationTable from XmlObjMgt,
|
||||
Persistent from XmlObjMgt,
|
||||
Element from XmlObjMgt
|
||||
|
||||
is
|
||||
Initialize (theMessageDriver : MessageDriver from CDM;
|
||||
theNamespace : CString from Standard;
|
||||
theName : CString from Standard = NULL);
|
||||
|
||||
VersionNumber(me) returns Integer from Standard
|
||||
is virtual;
|
||||
---Purpose: Returns the version number from which the driver
|
||||
-- is available.
|
||||
|
||||
NewEmpty (me)
|
||||
returns mutable Attribute from TDF
|
||||
is deferred;
|
||||
---Purpose: Creates a new attribute from TDF.
|
||||
|
||||
SourceType (me) returns Type from Standard;
|
||||
---Purpose: Returns the type of source object,
|
||||
-- inheriting from Attribute from TDF.
|
||||
|
||||
TypeName (me)
|
||||
returns AsciiString from TCollection
|
||||
is static;
|
||||
---C++: return const &
|
||||
---Purpose: Returns the full XML tag name (including NS prefix)
|
||||
|
||||
Paste (me; aSource : Persistent from XmlObjMgt;
|
||||
aTarget : mutable Attribute from TDF;
|
||||
aRelocTable : out RRelocationTable from XmlObjMgt)
|
||||
returns Boolean from Standard
|
||||
is deferred;
|
||||
---Purpose: Translate the contents of <aSource> and put it
|
||||
-- into <aTarget>, using the relocation table
|
||||
-- <aRelocTable> to keep the sharings.
|
||||
|
||||
Paste (me; aSource : Attribute from TDF;
|
||||
aTarget : in out Persistent from XmlObjMgt;
|
||||
aRelocTable : out SRelocationTable from XmlObjMgt)
|
||||
is deferred;
|
||||
---Purpose: Translate the contents of <aSource> and put it
|
||||
-- into <aTarget>, using the relocation table
|
||||
-- <aRelocTable> to keep the sharings.
|
||||
|
||||
WriteMessage (me; theMessage : ExtendedString from TCollection);
|
||||
---Purpose: Send message to Application (usually when error occurres)
|
||||
|
||||
fields
|
||||
|
||||
myMessageDriver : MessageDriver from CDM;
|
||||
myTypeName : AsciiString from TCollection is protected;
|
||||
|
||||
end ADriver;
|
69
src/XmlMDF/XmlMDF_ADriver.cxx
Executable file
69
src/XmlMDF/XmlMDF_ADriver.cxx
Executable file
@@ -0,0 +1,69 @@
|
||||
// File: XmlMDF_ADriver.cxx
|
||||
// Created: Mon Jul 9 12:29:49 MSK DST 2001
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Matra Datavision 2001
|
||||
|
||||
#include <XmlMDF_ADriver.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlMDF_ADriver
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
XmlMDF_ADriver::XmlMDF_ADriver (const Handle(CDM_MessageDriver)& theMsgDriver,
|
||||
const Standard_CString theNS,
|
||||
const Standard_CString theName)
|
||||
: myMessageDriver (theMsgDriver)
|
||||
{
|
||||
if (theNS != NULL)
|
||||
if (theNS[0] != '\0') {
|
||||
myTypeName = theNS;
|
||||
myTypeName += ':';
|
||||
}
|
||||
if (theName != NULL)
|
||||
myTypeName += theName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : VersionNumber
|
||||
//purpose : default version number from which the driver is available
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer XmlMDF_ADriver::VersionNumber () const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SourceType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Standard_Type) XmlMDF_ADriver::SourceType () const
|
||||
{
|
||||
return NewEmpty() -> DynamicType();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TypeName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_AsciiString& XmlMDF_ADriver::TypeName () const
|
||||
{
|
||||
const Standard_CString aString = myTypeName.ToCString();
|
||||
if (myTypeName.Length() == 0 || aString [myTypeName.Length() - 1] == ':')
|
||||
(TCollection_AsciiString&)myTypeName += SourceType() -> Name();
|
||||
return myTypeName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : WriteMessage
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void XmlMDF_ADriver::WriteMessage
|
||||
(const TCollection_ExtendedString& aMessage) const
|
||||
{
|
||||
myMessageDriver -> Write (aMessage.ToExtString());
|
||||
}
|
42
src/XmlMDF/XmlMDF_ADriverTable.cdl
Executable file
42
src/XmlMDF/XmlMDF_ADriverTable.cdl
Executable file
@@ -0,0 +1,42 @@
|
||||
-- File: XmlMDF_ADriverTable.cdl
|
||||
-- Created: 26.09.01 16:24:36
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- Copyright: Open Cascade 2001
|
||||
|
||||
class ADriverTable from XmlMDF inherits TShared from MMgt
|
||||
|
||||
---Purpose: A driver table is an object building links between
|
||||
-- object types and object drivers. In the
|
||||
-- translation process, a driver table is asked to
|
||||
-- give a translation driver for each current object
|
||||
-- to be translated.
|
||||
|
||||
uses
|
||||
Type from Standard,
|
||||
MapTransientHasher from TColStd,
|
||||
ADriver from XmlMDF,
|
||||
TypeADriverMap from XmlMDF
|
||||
|
||||
is
|
||||
Create returns mutable ADriverTable from XmlMDF;
|
||||
---Purpose: Creates a mutable ADriverTable from XmlMDF.
|
||||
|
||||
AddDriver(me : mutable; anHDriver : ADriver from XmlMDF);
|
||||
---Purpose: Sets a translation driver: <aDriver>.
|
||||
|
||||
GetDrivers(me)
|
||||
returns TypeADriverMap from XmlMDF;
|
||||
---Purpose: Gets a map of drivers.
|
||||
---C++: return const &
|
||||
|
||||
GetDriver(me; aType : Type from Standard;
|
||||
anHDriver : in out ADriver from XmlMDF)
|
||||
returns Boolean from Standard;
|
||||
---Purpose: Gets a driver <aDriver> according to <aType>
|
||||
--
|
||||
-- Returns True if a driver is found; false otherwise.
|
||||
|
||||
fields
|
||||
myMap : TypeADriverMap from XmlMDF;
|
||||
|
||||
end ADriverTable;
|
53
src/XmlMDF/XmlMDF_ADriverTable.cxx
Executable file
53
src/XmlMDF/XmlMDF_ADriverTable.cxx
Executable file
@@ -0,0 +1,53 @@
|
||||
// File: XmlMDF_ADriverTable.cxx
|
||||
// Created: 26.09.01 16:24:36
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
// History:
|
||||
|
||||
#include <XmlMDF_ADriverTable.ixx>
|
||||
|
||||
//=======================================================================
|
||||
//function : MDF_ADriverTable
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
XmlMDF_ADriverTable::XmlMDF_ADriverTable()
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddDriver
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void XmlMDF_ADriverTable::AddDriver (const Handle(XmlMDF_ADriver)& anHDriver)
|
||||
{
|
||||
const Handle(Standard_Type)& type = anHDriver->SourceType();
|
||||
|
||||
// to make possible for applications to redefine standard attribute drivers
|
||||
myMap.UnBind(type);
|
||||
|
||||
myMap.Bind(type,anHDriver);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDrivers
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
const XmlMDF_TypeADriverMap& XmlMDF_ADriverTable::GetDrivers() const
|
||||
{
|
||||
return myMap;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDriver
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlMDF_ADriverTable::GetDriver
|
||||
(const Handle(Standard_Type)& aType,
|
||||
Handle(XmlMDF_ADriver)& anHDriver) const
|
||||
{
|
||||
if (myMap.IsBound(aType))
|
||||
{
|
||||
anHDriver = myMap.Find(aType);
|
||||
return Standard_True;
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
32
src/XmlMDF/XmlMDF_ReferenceDriver.cdl
Executable file
32
src/XmlMDF/XmlMDF_ReferenceDriver.cdl
Executable file
@@ -0,0 +1,32 @@
|
||||
-- File: XmlMDF_ReferenceDriver.cdl
|
||||
-- Created: 04.09.01 14:47:31
|
||||
-- Author: Julia DOROVSKIKH
|
||||
-- Copyright: Open Cascade 2001
|
||||
|
||||
class ReferenceDriver from XmlMDF inherits ADriver from XmlMDF
|
||||
|
||||
---Purpose: Attribute Driver.
|
||||
|
||||
uses
|
||||
SRelocationTable from XmlObjMgt,
|
||||
RRelocationTable from XmlObjMgt,
|
||||
Persistent from XmlObjMgt,
|
||||
MessageDriver from CDM,
|
||||
Attribute from TDF
|
||||
|
||||
is
|
||||
Create (theMessageDriver:MessageDriver from CDM)
|
||||
returns mutable ReferenceDriver from XmlMDF;
|
||||
|
||||
NewEmpty (me) returns mutable Attribute from TDF;
|
||||
|
||||
Paste(me; Source : Persistent from XmlObjMgt;
|
||||
Target : mutable Attribute from TDF;
|
||||
RelocTable : out RRelocationTable from XmlObjMgt)
|
||||
returns Boolean from Standard;
|
||||
|
||||
Paste(me; Source : Attribute from TDF;
|
||||
Target : in out Persistent from XmlObjMgt;
|
||||
RelocTable : out SRelocationTable from XmlObjMgt);
|
||||
|
||||
end ReferenceDriver;
|
107
src/XmlMDF/XmlMDF_ReferenceDriver.cxx
Executable file
107
src/XmlMDF/XmlMDF_ReferenceDriver.cxx
Executable file
@@ -0,0 +1,107 @@
|
||||
// File: XmlMDF_ReferenceDriver.cxx
|
||||
// Created: 04.09.01 14:47:31
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
// History: AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
|
||||
|
||||
#include <XmlMDF_ReferenceDriver.ixx>
|
||||
#include <XmlObjMgt.hxx>
|
||||
|
||||
#include <TDF_Reference.hxx>
|
||||
#include <TDF_Tool.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlMDF_ReferenceDriver
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
|
||||
(const Handle(CDM_MessageDriver)& theMsgDriver)
|
||||
: XmlMDF_ADriver (theMsgDriver, NULL)
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
|
||||
{
|
||||
return (new TDF_Reference());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose : persistent -> transient (retrieve)
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlMDF_ReferenceDriver::Paste
|
||||
(const XmlObjMgt_Persistent& theSource,
|
||||
const Handle(TDF_Attribute)& theTarget,
|
||||
XmlObjMgt_RRelocationTable& ) const
|
||||
{
|
||||
XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
|
||||
|
||||
if (anXPath == NULL)
|
||||
{
|
||||
WriteMessage ("Cannot retrieve reference string from element");
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
TCollection_AsciiString anEntry;
|
||||
if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
|
||||
{
|
||||
TCollection_ExtendedString aMessage =
|
||||
TCollection_ExtendedString ("Cannot retrieve reference from \"")
|
||||
+ anXPath + '\"';
|
||||
WriteMessage (aMessage);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
|
||||
|
||||
// find label by entry
|
||||
TDF_Label tLab; // Null label.
|
||||
if (anEntry.Length() > 0)
|
||||
{
|
||||
TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
|
||||
}
|
||||
|
||||
// set referenced label
|
||||
aRef->Set(tLab);
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose : transient -> persistent (store)
|
||||
// <label tag='1'> <This is label entry 0:4:1>
|
||||
// ...
|
||||
// <label tag='8'> <This is label entry 0:4:1:8>
|
||||
//
|
||||
// <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
|
||||
// </TDF_Reference> <This is reference to label 0:4:1>
|
||||
//=======================================================================
|
||||
void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)& theSource,
|
||||
XmlObjMgt_Persistent& theTarget,
|
||||
XmlObjMgt_SRelocationTable& ) const
|
||||
{
|
||||
Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
|
||||
if (!aRef.IsNull())
|
||||
{
|
||||
const TDF_Label& lab = aRef->Label();
|
||||
const TDF_Label& refLab = aRef->Get();
|
||||
if (!lab.IsNull() && !refLab.IsNull())
|
||||
{
|
||||
if (lab.IsDescendant(refLab.Root()))
|
||||
{
|
||||
// Internal reference
|
||||
TCollection_AsciiString anEntry;
|
||||
TDF_Tool::Entry(refLab, anEntry);
|
||||
|
||||
XmlObjMgt_DOMString aDOMString;
|
||||
XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
|
||||
// No occurrence of '&', '<' and other irregular XML characters
|
||||
XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
src/XmlMDF/XmlMDF_TagSourceDriver.cdl
Executable file
33
src/XmlMDF/XmlMDF_TagSourceDriver.cdl
Executable file
@@ -0,0 +1,33 @@
|
||||
-- File: XmlMDF_TagSourceDriver.cdl
|
||||
-- Created: 29.08.01 18:04:51
|
||||
-- Author: Julia DOROVSKIKH
|
||||
---Copyright: Open Cascade 2001
|
||||
|
||||
class TagSourceDriver from XmlMDF inherits ADriver from XmlMDF
|
||||
|
||||
---Purpose: Attribute Driver.
|
||||
|
||||
uses
|
||||
SRelocationTable from XmlObjMgt,
|
||||
RRelocationTable from XmlObjMgt,
|
||||
Persistent from XmlObjMgt,
|
||||
Attribute from TDF,
|
||||
MessageDriver from CDM
|
||||
|
||||
is
|
||||
Create (theMessageDriver : MessageDriver from CDM)
|
||||
returns mutable TagSourceDriver from XmlMDF;
|
||||
|
||||
NewEmpty (me) returns mutable Attribute from TDF;
|
||||
|
||||
Paste(me; Source : Persistent from XmlObjMgt;
|
||||
Target : mutable Attribute from TDF;
|
||||
RelocTable : out RRelocationTable from XmlObjMgt)
|
||||
returns Boolean from Standard;
|
||||
|
||||
Paste(me; Source : Attribute from TDF;
|
||||
Target : in out Persistent from XmlObjMgt;
|
||||
RelocTable : out SRelocationTable from XmlObjMgt);
|
||||
|
||||
end TagSourceDriver;
|
||||
|
76
src/XmlMDF/XmlMDF_TagSourceDriver.cxx
Executable file
76
src/XmlMDF/XmlMDF_TagSourceDriver.cxx
Executable file
@@ -0,0 +1,76 @@
|
||||
// File: XmlMDF_TagSourceDriver.cxx
|
||||
// Created: 29.08.01 18:04:51
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
// History: AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
|
||||
|
||||
#include <XmlMDF_TagSourceDriver.ixx>
|
||||
#include <XmlObjMgt.hxx>
|
||||
#include <TDF_TagSource.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : XmlMDF_TagSourceDriver
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
XmlMDF_TagSourceDriver::XmlMDF_TagSourceDriver
|
||||
(const Handle(CDM_MessageDriver)& theMsgDriver)
|
||||
: XmlMDF_ADriver (theMsgDriver, NULL)
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(TDF_Attribute) XmlMDF_TagSourceDriver::NewEmpty() const
|
||||
{
|
||||
return (new TDF_TagSource());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose : persistent -> transient (retrieve)
|
||||
//=======================================================================
|
||||
Standard_Boolean XmlMDF_TagSourceDriver::Paste
|
||||
(const XmlObjMgt_Persistent& theSource,
|
||||
const Handle(TDF_Attribute)& theTarget,
|
||||
XmlObjMgt_RRelocationTable& ) const
|
||||
{
|
||||
Standard_Integer aTag;
|
||||
XmlObjMgt_DOMString aTagStr = XmlObjMgt::GetStringValue(theSource.Element());
|
||||
|
||||
if (aTagStr.GetInteger(aTag) == Standard_False) {
|
||||
TCollection_ExtendedString aMessageString =
|
||||
TCollection_ExtendedString ("Cannot retrieve TagSource attribute from \"")
|
||||
+ aTagStr + "\"";
|
||||
WriteMessage (aMessageString);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
if (aTag < 0) {
|
||||
TCollection_ExtendedString aMessageString =
|
||||
TCollection_ExtendedString ("Invalid value of TagSource retrieved: ")
|
||||
+ aTag;
|
||||
WriteMessage (aMessageString);
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
Handle(TDF_TagSource) aT = Handle(TDF_TagSource)::DownCast (theTarget);
|
||||
aT->Set(aTag);
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose : transient -> persistent (store)
|
||||
//=======================================================================
|
||||
void XmlMDF_TagSourceDriver::Paste (const Handle(TDF_Attribute)& theSource,
|
||||
XmlObjMgt_Persistent& theTarget,
|
||||
XmlObjMgt_SRelocationTable& ) const
|
||||
{
|
||||
Handle(TDF_TagSource) aTag = Handle(TDF_TagSource)::DownCast(theSource);
|
||||
// No occurrence of '&', '<' and other irregular XML characters
|
||||
XmlObjMgt::SetStringValue (theTarget.Element(), aTag->Get(), Standard_True);
|
||||
}
|
||||
|
Reference in New Issue
Block a user