1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

38
src/XmlMNaming/XmlMNaming.cdl Executable file
View File

@@ -0,0 +1,38 @@
-- File: XmlMNaming.cdl
-- Created: Sep 14 2001
-- Author: Alexander GRIGORIEV
---Copyright: Open Cascade 2001
package XmlMNaming
---Purpose:
uses
TDF,
CDM,
BRepTools,
TopoDS,
TopAbs,
XmlMDF,
XmlObjMgt,
TopTools
is
class NamedShapeDriver;
class NamingDriver;
class Shape1;
class Array1OfShape1 instantiates Array1 from XmlObjMgt
(Shape1 from XmlMNaming);
AddDrivers (aDriverTable : ADriverTable from XmlMDF;
aMessageDriver: MessageDriver from CDM);
---Purpose: Adds the attribute drivers to <aDriverTable>.
SetDocumentVersion (DocVersion : Integer from Standard);
DocumentVersion returns Integer from Standard;
end XmlMNaming;

39
src/XmlMNaming/XmlMNaming.cxx Executable file
View File

@@ -0,0 +1,39 @@
// File: XmlMNaming.cxx
// Created: 31.07.01 20:34:58
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2001
// History:
#include <XmlMNaming.ixx>
#include <XmlMNaming_NamedShapeDriver.hxx>
#include <XmlMNaming_NamingDriver.hxx>
static Standard_Integer myDocumentVersion = -1;
//=======================================================================
//function : AddStorageDrivers
//purpose :
//=======================================================================
void XmlMNaming::AddDrivers (const Handle(XmlMDF_ADriverTable)& aDriverTable,
const Handle(CDM_MessageDriver)& aMessageDriver)
{
aDriverTable->AddDriver (new XmlMNaming_NamedShapeDriver(aMessageDriver));
aDriverTable->AddDriver (new XmlMNaming_NamingDriver(aMessageDriver));
}
//=======================================================================
//function : SetDocumentVersion
//purpose : Sets current document version
//=======================================================================
void XmlMNaming::SetDocumentVersion(const Standard_Integer theVersion)
{
myDocumentVersion = theVersion;
}
//=======================================================================
//function : DocumentVersion
//purpose : Retrieved document version
//=======================================================================
Standard_Integer XmlMNaming::DocumentVersion()
{
return myDocumentVersion;
}

View File

@@ -0,0 +1,57 @@
-- File: XmlMNaming_NamedShapeDriver.cdl
-- Created: Sep 14 2001
-- Author: Alexander GRIGORIEV
---Copyright: Open Cascade 2001
class NamedShapeDriver from XmlMNaming inherits ADriver from XmlMDF
---Purpose:
uses
RRelocationTable from XmlObjMgt,
SRelocationTable from XmlObjMgt,
Persistent from XmlObjMgt,
Element from XmlObjMgt,
Attribute from TDF,
MessageDriver from CDM,
ShapeSet from BRepTools,
LocationSet from TopTools
is
Create (aMessageDriver: MessageDriver from CDM)
returns mutable NamedShapeDriver from XmlMNaming;
NewEmpty (me)
returns mutable Attribute from TDF
is redefined;
Paste(me; theSource : Persistent from XmlObjMgt;
theTarget : mutable Attribute from TDF;
theRelocTable : out RRelocationTable from XmlObjMgt)
returns Boolean from Standard
is redefined;
Paste(me; theSource : Attribute from TDF;
theTarget : in out Persistent from XmlObjMgt;
theRelocTable : out SRelocationTable from XmlObjMgt)
is redefined;
ReadShapeSection (me: mutable; anElement: Element from XmlObjMgt);
---Purpose: Input the shapes from DOM element
WriteShapeSection (me: mutable; anElement: in out Element from XmlObjMgt);
---Purpose: Output the shapes into DOM element
Clear (me:mutable);
---Purpose: Clear myShapeSet
GetShapesLocations(me: mutable) returns LocationSet from TopTools;
---Purpose: get the format of topology
---C++: return &
---C++: inline
fields
myShapeSet : ShapeSet from BRepTools;
end NamedShapeDriver;

View File

@@ -0,0 +1,389 @@
// File: XmlMNaming_NamedShapeDriver.cxx
// Created: 11.07.01 12:20:33
// Author: Julia DOROVSKIKH
// Copyright: Matra Datavision 2001,02
// History: AGV 150202: Changed prototype LDOM_Node::getOwnerDocument()
#include <XmlMNaming_NamedShapeDriver.ixx>
#include <XmlObjMgt.hxx>
#include <XmlMNaming_Array1OfShape1.hxx>
#include <XmlMNaming_Shape1.hxx>
#include <TDF_Label.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Iterator.hxx>
#include <TopoDS_Shape.hxx>
#include <BRepTools.hxx>
#include <LDOM_Text.hxx>
#include <LDOM_OSStream.hxx>
#include <Standard_SStream.hxx>
static TNaming_Evolution EvolutionEnum (const XmlObjMgt_DOMString&);
static const XmlObjMgt_DOMString& EvolutionString (const TNaming_Evolution);
static void doTranslate (const TopoDS_Shape&,
XmlMNaming_Shape1&,
BRepTools_ShapeSet&);
static int doTranslate (const XmlMNaming_Shape1&,
TopoDS_Shape&,
BRepTools_ShapeSet&);
IMPLEMENT_DOMSTRING (OldsString, "olds")
IMPLEMENT_DOMSTRING (NewsString, "news")
IMPLEMENT_DOMSTRING (StatusString, "evolution")
IMPLEMENT_DOMSTRING (VersionString, "version")
IMPLEMENT_DOMSTRING (ShapesString, "shapes")
IMPLEMENT_DOMSTRING (EvolPrimitiveString, "primitive")
IMPLEMENT_DOMSTRING (EvolGeneratedString, "generated")
IMPLEMENT_DOMSTRING (EvolModifyString, "modify")
IMPLEMENT_DOMSTRING (EvolDeleteString, "delete")
IMPLEMENT_DOMSTRING (EvolSelectedString, "selected")
IMPLEMENT_DOMSTRING (EvolReplaceString, "replace")
//=======================================================================
//function : XmlMNaming_NamedShapeDriver
//purpose : Constructor
//=======================================================================
XmlMNaming_NamedShapeDriver::XmlMNaming_NamedShapeDriver
(const Handle(CDM_MessageDriver&) theMessageDriver)
: XmlMDF_ADriver (theMessageDriver, NULL),
myShapeSet (Standard_False) // triangles mode
{}
//=======================================================================
//function : NewEmpty()
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMNaming_NamedShapeDriver::NewEmpty () const
{
return (new TNaming_NamedShape());
}
//=======================================================================
//function : Paste()
//purpose : retrieval of TNaming_NamedShape
//=======================================================================
Standard_Boolean XmlMNaming_NamedShapeDriver::Paste
(const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable&) const
{
Handle(TNaming_NamedShape) aTarget =
Handle(TNaming_NamedShape)::DownCast(theTarget);
TDF_Label Label = aTarget -> Label();
TNaming_Builder aBld (Label);
// Get Version
Standard_Integer aVersion = 0;
const XmlObjMgt_Element& anElement = theSource;
XmlObjMgt_DOMString aVerString = anElement.getAttribute (::VersionString());
if (aVerString != NULL)
aVerString.GetInteger (aVersion);
// Get Evolution status
XmlObjMgt_DOMString aStatus = anElement.getAttribute (::StatusString());
TNaming_Evolution evol = EvolutionEnum (aStatus);
// apres creation Builder qui a mis la version a 1 :
aTarget -> SetVersion (aVersion);
const XmlMNaming_Array1OfShape1 OldPShapes (anElement, ::OldsString());
const XmlMNaming_Array1OfShape1 NewPShapes (anElement, ::NewsString());
if (NewPShapes.Length() == 0 && OldPShapes.Length() == 0)
return Standard_True;
TopoDS_Shape anOldShape;
TopoDS_Shape aNewShape;
BRepTools_ShapeSet& aShapeSet = (BRepTools_ShapeSet&) myShapeSet;
Standard_Integer lower = NewPShapes.Lower();
if (OldPShapes.Lower() < lower) lower = OldPShapes.Lower();
Standard_Integer upper = NewPShapes.Upper();
if (OldPShapes.Upper() > upper) upper = OldPShapes.Upper();
for (Standard_Integer i = lower; i <= upper; i++)
{
const XmlMNaming_Shape1 aNewPShape = NewPShapes.Value(i);
const XmlMNaming_Shape1 anOldPShape = OldPShapes.Value(i);
if ( evol != TNaming_PRIMITIVE && anOldPShape.Element() != NULL )
{
if (::doTranslate (anOldPShape, anOldShape, aShapeSet)) {
WriteMessage ("NamedShapeDriver: Error reading a shape from array");
return Standard_False;
}
}
if (evol != TNaming_DELETE && aNewPShape.Element() != NULL )
{
if (::doTranslate (aNewPShape, aNewShape, aShapeSet)) {
WriteMessage ("NamedShapeDriver: Error reading a shape from array");
return Standard_False;
}
}
switch (evol)
{
case TNaming_PRIMITIVE:
aBld.Generated(aNewShape);
break;
case TNaming_GENERATED:
aBld.Generated(anOldShape,aNewShape);
break;
case TNaming_MODIFY:
aBld.Modify(anOldShape,aNewShape);
break;
case TNaming_DELETE:
aBld.Delete(anOldShape);
break;
case TNaming_SELECTED:
aBld.Select(aNewShape, anOldShape);
break;
case TNaming_REPLACE:
aBld.Replace(anOldShape,aNewShape);
break;
default:
Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
}
anOldShape.Nullify();
aNewShape.Nullify();
}
return Standard_True;
}
//=======================================================================
//function : Paste()
//purpose : storage of TNaming_NamedShape
//=======================================================================
void XmlMNaming_NamedShapeDriver::Paste (const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable&) const
{
//AGV XmlObjMgt_Document& aDoc =
//AGV (XmlObjMgt_Document&) theTarget.Element().getOwnerDocument();
XmlObjMgt_Document aDoc =
XmlObjMgt_Document (theTarget.Element().getOwnerDocument());
Handle(TNaming_NamedShape) aNamedShape =
Handle(TNaming_NamedShape)::DownCast(theSource);
TNaming_Evolution evol = aNamedShape->Evolution();
// Create arrays
Standard_Integer NbShapes = 0;
TNaming_Iterator SItr (aNamedShape);
while (SItr.More()) {
NbShapes++;
SItr.Next ();
}
BRepTools_ShapeSet& aShapeSet = (BRepTools_ShapeSet&) myShapeSet;
XmlMNaming_Array1OfShape1 OldPShapes (1,NbShapes), NewPShapes (1,NbShapes);
OldPShapes.CreateArrayElement (theTarget, ::OldsString());
NewPShapes.CreateArrayElement (theTarget, ::NewsString());
// Fill arrays
Standard_Integer i = 1;
TNaming_Iterator SIterator(aNamedShape);
while (SIterator.More())
{
const TopoDS_Shape& OldShape = SIterator.OldShape();
const TopoDS_Shape& NewShape = SIterator.NewShape();
if ( evol != TNaming_PRIMITIVE )
{
XmlMNaming_Shape1 anOldPShape (aDoc);
::doTranslate (OldShape, anOldPShape, aShapeSet);
OldPShapes.SetValue (i, anOldPShape.Element());
}
if (evol != TNaming_DELETE)
{
XmlMNaming_Shape1 aNewPShape (aDoc);
::doTranslate (NewShape, aNewPShape, aShapeSet);
NewPShapes.SetValue (i, aNewPShape.Element());
}
i++;
SIterator.Next();
}
theTarget.Element().setAttribute (::StatusString(), EvolutionString(evol));
Standard_Integer aVersion = aNamedShape -> Version();
if (aVersion != 0)
theTarget.Element().setAttribute (::VersionString(), aVersion);
}
//=======================================================================
//function : EvolutionEnum
//purpose : static
//=======================================================================
static const XmlObjMgt_DOMString& EvolutionString(const TNaming_Evolution i)
{
switch(i) {
case TNaming_PRIMITIVE : return ::EvolPrimitiveString();
case TNaming_GENERATED : return ::EvolGeneratedString();
case TNaming_MODIFY : return ::EvolModifyString();
case TNaming_DELETE : return ::EvolDeleteString();
case TNaming_SELECTED : return ::EvolSelectedString();
case TNaming_REPLACE : return ::EvolReplaceString();
default:
Standard_DomainError::Raise("TNaming_Evolution; enum term unknown");
}
static XmlObjMgt_DOMString aNullString;
return aNullString; // To avoid compilation error message.
}
//=======================================================================
//function : EvolutionEnum
//purpose : static
//=======================================================================
static TNaming_Evolution EvolutionEnum (const XmlObjMgt_DOMString& theString)
{
TNaming_Evolution aResult = TNaming_PRIMITIVE;
if (theString.equals (::EvolPrimitiveString()) == Standard_False) {
if (theString.equals (::EvolGeneratedString()))
aResult = TNaming_GENERATED;
else if (theString.equals (::EvolModifyString()))
aResult = TNaming_MODIFY;
else if (theString.equals (::EvolDeleteString()))
aResult = TNaming_DELETE;
else if (theString.equals (::EvolSelectedString()))
aResult = TNaming_SELECTED;
else if (theString.equals (::EvolReplaceString()))
aResult = TNaming_REPLACE;
else
Standard_DomainError::Raise
("TNaming_Evolution; string value without enum term equivalence");
}
return aResult;
}
//=======================================================================
//function : doTranslate
//purpose : shape storage to XML
//=======================================================================
static void doTranslate (const TopoDS_Shape& theShape,
XmlMNaming_Shape1& theResult,
BRepTools_ShapeSet& theShapeSet)
{
// Check for empty shape
if (theShape.IsNull()) return;
// Add to shape set both TShape and Location contained in theShape
const Standard_Integer aTShapeId = theShapeSet.Add (theShape);
const Standard_Integer aLocId =
theShapeSet.Locations().Index (theShape.Location());
// Fill theResult with shape parameters: TShape ID, Location, Orientation
theResult.SetShape (aTShapeId, aLocId, theShape.Orientation());
if (theShape.ShapeType() == TopAbs_VERTEX)
{
theResult.SetVertex(theShape);
}
}
//=======================================================================
//function : doTranslate
//purpose : shape retrieval from XML
//=======================================================================
static int doTranslate (const XmlMNaming_Shape1& thePShape,
TopoDS_Shape& theResult,
BRepTools_ShapeSet& theShapeSet)
{
const Standard_Integer aShapeId = thePShape.TShapeId();
// Read TShape and Orientation
if (aShapeId <= 0 || aShapeId > theShapeSet.NbShapes())
return 1;
theResult.TShape (theShapeSet.Shape(aShapeId).TShape());
theResult.Orientation (thePShape.Orientation());
theResult.Location (theShapeSet.Locations().Location (thePShape.LocId()));
return 0;
}
//=======================================================================
//function : ReadShapeSection
//purpose :
//=======================================================================
void XmlMNaming_NamedShapeDriver::ReadShapeSection
(const XmlObjMgt_Element& theElement)
{
XmlObjMgt_Element anElement =
XmlObjMgt::FindChildByName (theElement, ::ShapesString());
if (anElement != NULL) {
for (LDOM_Node aNode = anElement.getFirstChild();
aNode != NULL;
aNode = anElement.getNextSibling())
{
if (aNode.getNodeType() == LDOM_Node::TEXT_NODE) {
LDOM_Text aText = (LDOM_Text&) aNode;
LDOMString aData = aText.getData();
#ifdef USE_STL_STREAM
std::stringstream aStream (std::string(aData.GetString()));
#else
istrstream aStream (Standard_CString(aData.GetString()));
#endif
myShapeSet.Clear();
myShapeSet.Read (aStream);
break;
}
}
}
}
//=======================================================================
//function : WriteShapeSection
//purpose :
//=======================================================================
void XmlMNaming_NamedShapeDriver::WriteShapeSection
(XmlObjMgt_Element& theElement)
{
// Create "shapes" element and append it as child
XmlObjMgt_Document aDoc = theElement.getOwnerDocument();
XmlObjMgt_Element anElement = aDoc.createElement (::ShapesString());
theElement.appendChild (anElement);
// Add text to the "shapes" element
if (myShapeSet.NbShapes() > 0) {
myShapeSet.SetFormatNb(2);
LDOM_OSStream aStream (1024);
// ostrstream aStream;
// aStream.rdbuf() -> setbuf (0, 16380);
myShapeSet.Write (aStream);
aStream << ends;
char * aStr = (char *)aStream.str();
LDOM_Text aText = aDoc.createTextNode (aStr);
delete [] aStr;
aText.SetValueClear(); // There are no characters '<' and '&' and like
// aStream.rdbuf() -> freeze(0); // release the buffer
anElement.appendChild (aText);
// Clear the shape set to avoid appending to it on the next write
BRepTools_ShapeSet& aShapeSet = (BRepTools_ShapeSet&) myShapeSet;
aShapeSet.Clear();
}
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void XmlMNaming_NamedShapeDriver::Clear()
{
myShapeSet.Clear();
}

View File

@@ -0,0 +1,14 @@
// File: XmlMNaming_NamedShapeDriver.lxx
// Created: Thu Feb 10 14:43:51 2011
// Author: Oleg AGASHIN <oan@opencascade.com>
// Copyright: Open CasCade S.A. 2011
//=======================================================================
//function : GetShapesLocations
//purpose :
//=======================================================================
inline TopTools_LocationSet& XmlMNaming_NamedShapeDriver::GetShapesLocations()
{
return myShapeSet.ChangeLocations();
}

View File

@@ -0,0 +1,32 @@
-- File: XmlMNaming_NamingDriver.cdl
class NamingDriver from XmlMNaming inherits ADriver from XmlMDF
---Purpose:
uses
RRelocationTable from XmlObjMgt,
SRelocationTable from XmlObjMgt,
Persistent from XmlObjMgt,
Element from XmlObjMgt,
Attribute from TDF,
MessageDriver from CDM,
ShapeSet from BRepTools
is
Create (aMessageDriver: MessageDriver from CDM)
returns mutable NamingDriver from XmlMNaming;
NewEmpty (me)
returns mutable Attribute from TDF;
Paste(me; theSource : Persistent from XmlObjMgt;
theTarget : mutable Attribute from TDF;
theRelocTable : out RRelocationTable from XmlObjMgt)
returns Boolean from Standard;
Paste(me; theSource : Attribute from TDF;
theTarget : in out Persistent from XmlObjMgt;
theRelocTable : out SRelocationTable from XmlObjMgt);
end NamingDriver;

View File

@@ -0,0 +1,391 @@
// File: XmlMNaming_NamingDriver.cxx
// Created: 31.08.01 10:09:46
// Author: Julia DOROVSKIKH
// Copyright: Open Cascade 2001
// History:
#include <XmlMNaming_NamingDriver.ixx>
#include <XmlObjMgt.hxx>
#include <XmlMNaming.hxx>
#include <TNaming_Name.hxx>
#include <TNaming_Naming.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
#include <TDF_Tool.hxx>
//=======================================================================
static TopAbs_ShapeEnum ShapeEnumFromString (const XmlObjMgt_DOMString&);
static TNaming_NameType NameTypeFromString (const XmlObjMgt_DOMString&);
static const XmlObjMgt_DOMString& ShapeEnumToString (const TopAbs_ShapeEnum);
static const XmlObjMgt_DOMString& NameTypeToString (const TNaming_NameType);
IMPLEMENT_DOMSTRING (IndexString, "index")
IMPLEMENT_DOMSTRING (StopNamedShapeString, "stopNS")
IMPLEMENT_DOMSTRING (TypeString, "nametype")
IMPLEMENT_DOMSTRING (ShapeTypeString, "shapetype")
IMPLEMENT_DOMSTRING (ArgumentsString, "arguments")
IMPLEMENT_DOMSTRING (ContextLabelString, "contextlabel")
IMPLEMENT_DOMSTRING (NTUnknownString, "unknown")
IMPLEMENT_DOMSTRING (NTIdentityString, "identity")
IMPLEMENT_DOMSTRING (NTModifUntilString, "modifuntil")
IMPLEMENT_DOMSTRING (NTGenerationString, "generation")
IMPLEMENT_DOMSTRING (NTIntersectionString, "intersection")
IMPLEMENT_DOMSTRING (NTUnionString, "union")
IMPLEMENT_DOMSTRING (NTSubtractionString, "subtraction")
IMPLEMENT_DOMSTRING (NTConstShapeString, "constshape")
IMPLEMENT_DOMSTRING (NTFilterByNeighString, "filterbyneigh")
IMPLEMENT_DOMSTRING (NTOrientationString, "orientation")
IMPLEMENT_DOMSTRING (NTWireInString, "wirein")
IMPLEMENT_DOMSTRING (ShCompoundString, "compound")
IMPLEMENT_DOMSTRING (ShCompsolidString, "compsolid")
IMPLEMENT_DOMSTRING (ShSolidString, "solid")
IMPLEMENT_DOMSTRING (ShShellString, "shell")
IMPLEMENT_DOMSTRING (ShFaceString, "face")
IMPLEMENT_DOMSTRING (ShWireString, "wire")
IMPLEMENT_DOMSTRING (ShEdgeString, "edge")
IMPLEMENT_DOMSTRING (ShVertexString, "vertex")
IMPLEMENT_DOMSTRING (ShShapeString, "shape")
//=======================================================================
//function : XmlMNaming_NamingDriver
//purpose : Constructor
//=======================================================================
XmlMNaming_NamingDriver::XmlMNaming_NamingDriver
(const Handle(CDM_MessageDriver)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, NULL)
{}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMNaming_NamingDriver::NewEmpty() const
{
return (new TNaming_Naming());
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMNaming_NamingDriver::Paste
(const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& theRelocTable) const
{
const XmlObjMgt_Element& anElem = theSource;
Handle(TNaming_Naming) aNg = Handle(TNaming_Naming)::DownCast(theTarget);
TNaming_Name& aNgName = aNg->ChangeName();
// type and shape type
aNgName.Type (NameTypeFromString (anElem.getAttribute(::TypeString())));
aNgName.ShapeType(ShapeEnumFromString(anElem.getAttribute(::ShapeTypeString())));
Standard_Integer aNb;
Handle(TNaming_NamedShape) NS;
TCollection_ExtendedString aMsgString;
XmlObjMgt_DOMString aDOMStr = anElem.getAttribute(::ArgumentsString());
if (aDOMStr != NULL)
{
Standard_CString aGs = Standard_CString(aDOMStr.GetString());
// first argument
if (!XmlObjMgt::GetInteger(aGs, aNb))
{
aMsgString = TCollection_ExtendedString
("XmlMNaming_NamingDriver: Cannot retrieve reference "
"on first Argument from \"") + aDOMStr + "\"";
WriteMessage (aMsgString);
return Standard_False;
}
while (aNb > 0)
{
if (theRelocTable.IsBound(aNb))
NS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
else
{
NS = new TNaming_NamedShape;
theRelocTable.Bind(aNb, NS);
}
aNgName.Append(NS);
// next argument
if (!XmlObjMgt::GetInteger(aGs, aNb)) aNb = 0;
}
}
// stop named shape
aDOMStr = anElem.getAttribute(::StopNamedShapeString());
if (aDOMStr != NULL)
{
if (!aDOMStr.GetInteger(aNb))
{
aMsgString = TCollection_ExtendedString
("XmlMNaming_NamingDriver: Cannot retrieve reference "
"on StopNamedShape from \"") + aDOMStr + "\"";
WriteMessage (aMsgString);
return Standard_False;
}
if (aNb > 0)
{
if (theRelocTable.IsBound(aNb))
NS = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
else
{
NS = new TNaming_NamedShape;
theRelocTable.Bind(aNb, NS);
}
aNgName.StopNamedShape(NS);
}
}
// index
aDOMStr = anElem.getAttribute(::IndexString());
if (!aDOMStr.GetInteger(aNb))
{
aMsgString = TCollection_ExtendedString
("XmlMNaming_NamingDriver: Cannot retrieve "
"integer value of Index from \"") + aDOMStr + "\"";
WriteMessage (aMsgString);
return Standard_False;
}
aNgName.Index(aNb);
//
#ifdef DEB
//cout << "CurDocVersion = " << XmlMNaming::DocumentVersion() <<endl;
#endif
if(XmlMNaming::DocumentVersion() > 3) {
XmlObjMgt_DOMString aDomEntry = anElem.getAttribute(::ContextLabelString());
if (aDomEntry != NULL)
{
TCollection_AsciiString anEntry;
if (XmlObjMgt::GetTagEntryString (aDomEntry, anEntry) == Standard_False)
{
TCollection_ExtendedString aMessage =
TCollection_ExtendedString ("Cannot retrieve Entry from \"")
+ aDomEntry + '\"';
WriteMessage (aMessage);
return Standard_False;
}
// find label by entry
TDF_Label tLab; // Null label.
if (anEntry.Length() > 0) {
TDF_Tool::Label(aNg->Label().Data(), anEntry, tLab, Standard_True);
aNgName.ContextLabel(tLab);
#ifdef DEB
cout << "Retrieving Context Label = " << anEntry.ToCString() <<endl;
#endif
}
}
#ifdef DEB
else
cout << "Retrieving Context Label is NULL" <<endl;
#endif
}
#ifdef DEB
else if(XmlMNaming::DocumentVersion() == -1)
cout << "Current DocVersion field is not initialized. " <<endl;
else
cout << "Current DocVersion = " << XmlMNaming::DocumentVersion() <<endl;
#endif
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void XmlMNaming_NamingDriver::Paste
(const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable& theRelocTable) const
{
Handle(TNaming_Naming) aNg = Handle(TNaming_Naming)::DownCast(theSource);
XmlObjMgt_Element& anElem = theTarget;
const TNaming_Name& aNgName = aNg->GetName();
// type and shape type
anElem.setAttribute(::TypeString(), NameTypeToString(aNgName.Type()));
anElem.setAttribute(::ShapeTypeString(), ShapeEnumToString(aNgName.ShapeType()));
Standard_Integer aNb;
// arguments
Standard_Integer NbArgs = aNgName.Arguments().Extent();
if (NbArgs > 0)
{
TCollection_AsciiString anArgsStr;
for (TNaming_ListIteratorOfListOfNamedShape it (aNgName.Arguments()); it.More(); it.Next())
{
Handle(TNaming_NamedShape) anArg = it.Value();
aNb = 0;
if (!anArg.IsNull())
{
aNb = theRelocTable.FindIndex(anArg);
if (aNb == 0)
{
aNb = theRelocTable.Add(anArg);
}
anArgsStr += TCollection_AsciiString(aNb) + " ";
}
else anArgsStr += "0 ";
}
anElem.setAttribute(::ArgumentsString(), anArgsStr.ToCString());
}
// stop named shape
Handle(TNaming_NamedShape) aSNS = aNgName.StopNamedShape();
if (!aSNS.IsNull())
{
aNb = theRelocTable.FindIndex(aSNS);
if (aNb == 0)
{
aNb = theRelocTable.Add(aSNS);
}
anElem.setAttribute(::StopNamedShapeString(), aNb);
}
// index
anElem.setAttribute(::IndexString(), aNgName.Index());
// context label
TCollection_AsciiString anEntry;
if(!aNgName.ContextLabel().IsNull())
TDF_Tool::Entry(aNgName.ContextLabel(), anEntry);
XmlObjMgt_DOMString aDOMString;
XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
anElem.setAttribute(::ContextLabelString(), aDOMString);
#ifdef DEB
cout << "XmlMNaming_NamingDriver::Store: ContextLabel Entry = " << anEntry << endl;
if (aDOMString != NULL)
{
Standard_CString aStr = Standard_CString(aDOMString.GetString());
cout << "XmlMNaming_NamingDriver::Store: ContextLabel DOMString = " << aStr << endl;
} else
cout << "XmlMNaming_NamingDriver::Store: aDOMString is NULL" <<endl;
#endif
}
//=======================================================================
//function : ShapeEnumToString
//purpose :
//=======================================================================
static const XmlObjMgt_DOMString& ShapeEnumToString (const TopAbs_ShapeEnum theE)
{
switch (theE)
{
case TopAbs_COMPOUND : return ::ShCompoundString();
case TopAbs_COMPSOLID : return ::ShCompsolidString();
case TopAbs_SOLID : return ::ShSolidString();
case TopAbs_SHELL : return ::ShShellString();
case TopAbs_FACE : return ::ShFaceString();
case TopAbs_WIRE : return ::ShWireString();
case TopAbs_EDGE : return ::ShEdgeString();
case TopAbs_VERTEX : return ::ShVertexString();
case TopAbs_SHAPE : return ::ShShapeString();
}
static XmlObjMgt_DOMString aNullString;
return aNullString; // To avoid compilation error message.
}
//=======================================================================
//function : NameTypeToString
//purpose :
//=======================================================================
static const XmlObjMgt_DOMString& NameTypeToString (const TNaming_NameType theE)
{
switch (theE)
{
case TNaming_UNKNOWN : return ::NTUnknownString();
case TNaming_IDENTITY : return ::NTIdentityString();
case TNaming_MODIFUNTIL : return ::NTModifUntilString();
case TNaming_GENERATION : return ::NTGenerationString();
case TNaming_INTERSECTION : return ::NTIntersectionString();
case TNaming_UNION : return ::NTUnionString();
case TNaming_SUBSTRACTION : return ::NTSubtractionString();
case TNaming_CONSTSHAPE : return ::NTConstShapeString();
case TNaming_FILTERBYNEIGHBOURGS : return ::NTFilterByNeighString();
case TNaming_ORIENTATION : return ::NTOrientationString();
case TNaming_WIREIN : return ::NTWireInString();
default:
Standard_DomainError::Raise("TNaming_NameType; enum term unknown ");
}
static XmlObjMgt_DOMString aNullString;
return aNullString; // To avoid compilation error message.
}
//=======================================================================
//function : ShapeEnumFromString
//purpose :
//=======================================================================
static TopAbs_ShapeEnum ShapeEnumFromString (const XmlObjMgt_DOMString& theString)
{
TopAbs_ShapeEnum aResult = TopAbs_SHAPE;
if (!theString.equals (::ShShapeString()))
{
if (theString.equals (::ShCompoundString()))
aResult = TopAbs_COMPOUND;
else if (theString.equals (::ShCompsolidString()))
aResult = TopAbs_COMPSOLID;
else if (theString.equals (::ShSolidString()))
aResult = TopAbs_SOLID;
else if (theString.equals (::ShShellString()))
aResult = TopAbs_SHELL;
else if (theString.equals (::ShFaceString()))
aResult = TopAbs_FACE;
else if (theString.equals (::ShWireString()))
aResult = TopAbs_WIRE;
else if (theString.equals (::ShEdgeString()))
aResult = TopAbs_EDGE;
else if (theString.equals (::ShVertexString()))
aResult = TopAbs_VERTEX;
else
Standard_DomainError::Raise
("TopAbs_ShapeEnum; string value without enum term equivalence");
}
return aResult;
}
//=======================================================================
//function : NameTypeFromString
//purpose :
//=======================================================================
static TNaming_NameType NameTypeFromString (const XmlObjMgt_DOMString& theString)
{
TNaming_NameType aResult = TNaming_UNKNOWN;
if (!theString.equals (::NTUnknownString()))
{
if (theString.equals (::NTIdentityString()))
aResult = TNaming_IDENTITY;
else if (theString.equals (::NTModifUntilString()))
aResult = TNaming_MODIFUNTIL;
else if (theString.equals (::NTGenerationString()))
aResult = TNaming_GENERATION;
else if (theString.equals (::NTIntersectionString()))
aResult = TNaming_INTERSECTION;
else if (theString.equals (::NTUnionString()))
aResult = TNaming_UNION;
else if (theString.equals (::NTSubtractionString()))
aResult = TNaming_SUBSTRACTION;
else if (theString.equals (::NTConstShapeString()))
aResult = TNaming_CONSTSHAPE;
else if (theString.equals (::NTFilterByNeighString()))
aResult = TNaming_FILTERBYNEIGHBOURGS;
else if (theString.equals (::NTOrientationString()))
aResult = TNaming_ORIENTATION;
else if (theString.equals (::NTWireInString()))
aResult = TNaming_WIREIN;
else
Standard_DomainError::Raise
("TNaming_NameType; string value without enum term equivalence");
}
return aResult;
}

View File

@@ -0,0 +1,65 @@
-- File: XmlMNaming_Shape1.cdl
-- Created: Sep 14 2001
-- Author: Alexander GRIGORIEV
---Copyright: Open Cascade 2001
class Shape1 from XmlMNaming inherits Storable
---Purpose: The XmlMNaming_Shape1 is the Persistent view of a TopoDS_Shape.
--
-- a Shape1 contains :
-- - a reference to a TShape
-- - a reference to Location
-- - an Orientation.
uses
Shape from TopoDS,
Orientation from TopAbs,
Document from XmlObjMgt,
Element from XmlObjMgt,
DOMString from XmlObjMgt
is
Create(Doc : out Document from XmlObjMgt) returns Shape1 from XmlMNaming;
---Level: Internal
Create(E : Element from XmlObjMgt) returns Shape1 from XmlMNaming;
---Level: Internal
Element (me) returns Element from XmlObjMgt;
---Purpose: return myElement
---C++: return const &
Element (me:in out) returns Element from XmlObjMgt;
---Purpose: return myElement
---C++: return &
TShapeId(me) returns Integer from Standard
---Level: Internal
is static;
LocId(me) returns Integer from Standard
---Level: Internal
is static;
Orientation(me) returns Orientation from TopAbs
---Level: Internal
is static;
SetShape (me: in out; ID, LocID : Integer from Standard;
Orient : Orientation from TopAbs)
---Level: Internal
is static;
SetVertex (me: in out; theVertex : Shape from TopoDS)
---Level: Internal
is static;
fields
myElement : Element from XmlObjMgt;
myTShapeID : Integer from Standard;
myLocID : Integer from Standard;
myOrientation : Orientation from TopAbs;
end Shape1;

View File

@@ -0,0 +1,157 @@
// File: XmlMNaming_Shape1.cxx
// Created: 01.08.01 18:26:53
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2001
// History:
#include <XmlMNaming_Shape1.ixx>
#include <XmlObjMgt.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <gp_Pnt.hxx>
#include <BRep_Tool.hxx>
#include <stdio.h>
IMPLEMENT_DOMSTRING (TShapeString, "tshape")
IMPLEMENT_DOMSTRING (LocationString, "location")
IMPLEMENT_DOMSTRING (XCoordString, "x")
IMPLEMENT_DOMSTRING (YCoordString, "y")
IMPLEMENT_DOMSTRING (ZCoordString, "z")
//=======================================================================
//function : XmlMNaming_Shape1
//purpose :
//=======================================================================
XmlMNaming_Shape1::XmlMNaming_Shape1 (XmlObjMgt_Document& theDoc)
: myTShapeID (0),
myLocID (0),
myOrientation (TopAbs_FORWARD)
{
myElement = theDoc.createElement(XmlObjMgt_DOMString("shape"));
}
//=======================================================================
//function : XmlMNaming_Shape1
//purpose :
//=======================================================================
XmlMNaming_Shape1::XmlMNaming_Shape1 (const XmlObjMgt_Element& theEl)
: myElement(theEl),
myTShapeID (0),
myLocID (0),
myOrientation (TopAbs_FORWARD)
{
if (myElement != NULL)
{
myElement.getAttribute(::LocationString()).GetInteger (myLocID);
XmlObjMgt_DOMString aString = myElement.getAttribute(::TShapeString());
const char * aPtr = aString.GetString();
switch (* aPtr) {
case '+' : myOrientation = TopAbs_FORWARD; break;
case '-' : myOrientation = TopAbs_REVERSED; break;
case 'i' : myOrientation = TopAbs_INTERNAL; break;
case 'e' : myOrientation = TopAbs_EXTERNAL; break;
default: Standard_DomainError::Raise
("XmlMNaming_Shape1; orientation value without enum term equivalence");
}
Standard_CString anIntPtr = (Standard_CString) &aPtr[1];
if (XmlObjMgt::GetInteger (anIntPtr, myTShapeID) == Standard_False)
Standard_DomainError::Raise
("XmlMNaming_Shape1; tshape value cannot be initialised by integer");
}
}
//=======================================================================
//function : Element
//purpose :
//=======================================================================
const XmlObjMgt_Element& XmlMNaming_Shape1::Element() const
{
return myElement;
}
//=======================================================================
//function : Element
//purpose :
//=======================================================================
XmlObjMgt_Element& XmlMNaming_Shape1::Element()
{
return myElement;
}
//=======================================================================
//function : TShapeId
//purpose :
//=======================================================================
Standard_Integer XmlMNaming_Shape1::TShapeId() const
{
return myTShapeID;
}
//=======================================================================
//function : LocId
//purpose :
//=======================================================================
Standard_Integer XmlMNaming_Shape1::LocId() const
{
return myLocID;
}
//=======================================================================
//function : Orientation
//purpose :
//=======================================================================
TopAbs_Orientation XmlMNaming_Shape1::Orientation() const
{
return myOrientation;
}
//=======================================================================
//function : SetShape
//purpose :
//=======================================================================
void XmlMNaming_Shape1::SetShape (const Standard_Integer theID,
const Standard_Integer theLocID,
const TopAbs_Orientation theOrient)
{
myTShapeID = theID;
myLocID = theLocID;
myOrientation = theOrient;
char aBuffer[16], anOr;
switch (theOrient) {
case TopAbs_FORWARD : anOr = '+'; break;
case TopAbs_REVERSED : anOr = '-'; break;
case TopAbs_INTERNAL : anOr = 'i'; break;
case TopAbs_EXTERNAL : anOr = 'e'; break;
default : anOr = '\0';
}
sprintf (aBuffer, "%c%i", anOr, theID);
Element().setAttribute (::TShapeString(), aBuffer);
if (theLocID > 0)
Element().setAttribute (::LocationString(), theLocID);
}
//=======================================================================
//function : SetVertex
//purpose :
//=======================================================================
void XmlMNaming_Shape1::SetVertex (const TopoDS_Shape& theVertex)
{
TopoDS_Vertex aV = TopoDS::Vertex(theVertex);
gp_Pnt aPos = BRep_Tool::Pnt(aV);
char buf [16];
sprintf (buf, "%.8g", aPos.X());
Element().setAttribute (::XCoordString(), buf);
sprintf (buf, "%.8g", aPos.Y());
Element().setAttribute (::YCoordString(), buf);
sprintf (buf, "%.8g", aPos.Z());
Element().setAttribute (::ZCoordString(), buf);
}