1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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

132
src/TDocStd/TDocStd.cdl Executable file
View File

@@ -0,0 +1,132 @@
-- File: TDocStd.cdl
-- Created: Wed Apr 7 11:01:24 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
package TDocStd
---Purpose: This package define CAF main classes.
--
-- * The standard application root class
--
-- * The standard document wich contains data
--
-- * The external reference mechanism between documents
--
-- * Attributes for Document management
-- Standard documents offer you a ready-to-use
-- document containing a TDF-based data
-- structure. The documents themselves are
-- contained in a class inheriting from
-- TDocStd_Application which manages creation,
-- storage and retrieval of documents.
-- You can implement undo and redo in your
-- document, and refer from the data framework of
-- one document to that of another one. This is
-- done by means of external link attributes, which
-- store the path and the entry of external links. To
-- sum up, standard documents alone provide
-- access to the data framework. They also allow
-- you to:
-- - Update external links
-- - Manage the saving and opening of data
-- - Manage undo/redo functionality.
-- Note
-- For information on the relations between this
-- component of OCAF and the others, refer to the
-- OCAF User's Guide.
uses
Standard,
CDF,
CDM,
MDF,
TDF,
TColStd,
TCollection,
Resource
is
---Purpose: standard Application/Document
-- =============================
deferred class Application;
class Document;
class Context;
---Purpose: External reference Attribute
-- ============================
class XLink;
---Purpose: This attribute, when setted, store an external
-- reference . An external reference is a memorized link
-- between attributes wich originate from different
-- documents.
class XLinkIterator;
---Purpose: This is an iterator giving all the external references
-- of a Document.
class XLinkTool;
---Purpose: This class provide services to set, update and perform
-- external references.
---Purpose: Attributes for Document Management
-- ==================================
private class Owner;
---Purpose: This attribute located at the root label of the
-- framework contains a back reference to the owner
-- TDocStd_Document, providing acces to the document from
-- any label. private class Owner;
private class Modified;
---Purpose: This attribute located at the root label provide
-- services to register modified labels in a document.
pointer XLinkPtr to XLink from TDocStd;
private class XLinkRoot;
---Purpose: This attribute is the root of all external references
-- setted in a document.
class PathParser;
class CompoundDelta;
class LabelIDMapDataMap instantiates DataMap from TCollection (Label from TDF,
IDMap from TDF,
LabelMapHasher from TDF);
class ApplicationDelta;
class MultiTransactionManager;
class SequenceOfApplicationDelta instantiates
Sequence from TCollection(ApplicationDelta from TDocStd);
class SequenceOfDocument instantiates
Sequence from TCollection(Document from TDocStd);
---Purpose: specific GUID of this package
-- =============================
IDList (anIDList : in out IDList from TDF);
---Purpose: Appends to <anIDList> the list of the attributes
-- IDs of this package. CAUTION: <anIDList> is NOT
-- cleared before use.
end TDocStd;

70
src/TDocStd/TDocStd.cxx Executable file
View File

@@ -0,0 +1,70 @@
//=======================================================================
// File: TDocStd.cxx
// Language: C++
// Version: QDF
// Design:
// Purpose:
// Copyright: Matra-Datavision 1997
//=======================================================================
// Declarations:
#include <TDocStd.ixx>
#include <CDF.hxx>
//#include <LCTLOFF.h>
#include <OSD_Environment.hxx>
#include <TDocStd_XLink.hxx>
//=======================================================================
//function : Application
//purpose :
//=======================================================================
// Handle(TDocStd_Application) TDocStd::Application
// (const Standard_Boolean UseDocAPI)
// {
// static Handle(TDocStd_Application) theAppli;
// if (theAppli.IsNull()) theAppli = new TDocStd_Application(UseDocAPI);
// OSD_Environment CSFLicense("CSF_EngineName");
// TCollection_AsciiString LicenseAscii = CSFLicense .Value();
// Standard_Boolean HasLicense = Standard_False;
// if (!LicenseAscii.IsEmpty()) {
// if (LicenseAscii=="DsgPEngine")
// HasLicense = Standard_True;
// }
// if (HasLicense) {
// CDF::GetLicense(AED100) ;
// CDF::GetLicense(AED300) ;
// }
// return theAppli;
// }
//=======================================================================
//function : InitApplication
//purpose :
//=======================================================================
// Handle(TDocStd_Application) TDocStd::InitApplication
// (const Standard_Boolean UseDocAPI)
// {
// // No init yet.
// return TDocStd::Application(UseDocAPI);
// }
//=======================================================================
//function : IDList
//purpose :
//=======================================================================
void TDocStd::IDList(TDF_IDList& anIDList)
{ anIDList.Append(TDocStd_XLink::GetID()); }

View File

@@ -0,0 +1,238 @@
-- File: TDocStd_Application.cdl
-- Created: Wed Jun 30 12:40:07 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
deferred class Application from TDocStd inherits Application from CDF
---Purpose:
-- The abstract root class for all application classes.
-- They are in charge of:
-- - Creating documents
-- - Storing documents and retrieving them
-- - Initializing document views.
-- To create a useful OCAF-based application, you
-- derive a class from Application and implement
-- the methods below. You will have to redefine the
-- deferred (virtual) methods Formats,
-- InitDocument, and Resources, and override others.
-- The application is a container for a document,
-- which in its turn is the container of the data
-- framework made up of labels and attributes.
-- Besides furnishing a container for documents,
-- TDocStd_Application provides the following
-- services for them:
-- - Creation of new documents
-- - Activation of documents in sessions of an application
-- - Storage and retrieval of documents
-- - Initialization of document views.
-- Note:
-- If a client needs detailed information concerning
-- the events during the Open/Store operation, MessageDriver
-- inherited from CDM_MessageDriver of the
-- corresponding application has to be implemented.
-- If the MessageDriver is not defined all messages
-- will be (by default) directed to
-- CDM_NullMessageDriver and will be lost.
uses Manager from Resource,
Document from TDocStd,
CString from Standard,
ExtendedString from TCollection,
SequenceOfExtendedString from TColStd,
RetrievableStatus from CDF,
StoreStatus from CDF
raises NoSuchObject from Standard
is
Initialize;
IsDriverLoaded (me)
---Purpose: Check if meta data driver was successfully loaded
-- by the application constructor
returns Boolean from Standard;
Resources (me: mutable)
---Purpose: create (if not done) a Manager using ResourcesName
-- method.
returns Manager from Resource
is redefined virtual;
ResourcesName (me: mutable)
---Purpose: Returns the name of the file containing the
-- resources of this application.
-- In a resource file, the application associates the schema name
-- of the document with the storage and
-- retrieval plug-ins that are to be loaded for each
-- document. On retrieval, the application reads the
-- schema name in the heading of the CSF file and
-- loads the plug-in indicated in the resource file.
-- This plug-in instantiates the actual driver for
-- transient-persistent conversion.
-- Your application can bring this process into play
-- by defining a class which inherits
-- CDF_Application and redefines the function
-- which returns the appropriate resources file. At
-- this point, the function Retrieve and the class
-- CDF_Store can be called. This allows you to
-- deal with storage and retrieval of - as well as
-- copying and pasting - documents.
-- To implement a class like this, several virtual
-- functions should be redefined. In particular, you
-- must redefine the abstract function Resources
-- inherited from the superclass CDM_Application.
returns CString from Standard
is deferred;
NbDocuments (me)
---Purpose: returns the number of documents handled by the current applicative session.
returns Integer from Standard;
GetDocument (me; index : Integer from Standard; aDoc : in out Document from TDocStd);
---Purpose: Constructs the new document aDoc.
-- aDoc is identified by the index index which is
-- any integer between 1 and n where n is the
-- number of documents returned by NbDocument.
-- Example
-- Handle(TDocStd_Application)
-- anApp;
-- if (!CafTest::Find(A)) return 1;
-- Handle(TDocStd) aDoc;
-- Standard_Integer nbdoc = anApp->NbDocuments();
-- for (Standard_Integer i = 1; i <= nbdoc; i++) {
-- aApp->GetDocument(i,aDoc);
Formats(me: mutable; Formats: out SequenceOfExtendedString from TColStd)
---Purpose:
-- Returns the format name Formats
-- representing the format supported for
-- application documents.
-- This virtual function is to be redefined for each
-- specific application.
is redefined deferred;
NewDocument (me : mutable; format : ExtendedString from TCollection; aDoc : out Document from TDocStd)
---Purpose: Constructs the empty new document aDoc.
-- This document will have the format format.
-- If InitDocument is redefined for a specific
-- application, the new document is handled by the
-- applicative session.
is virtual;
InitDocument (me; aDoc : Document from TDocStd)
---Purpose: Initialize the document aDoc for the applicative session.
-- This virtual function is called by NewDocument
-- and is to be redefined for each specific application.
is virtual;
---Purpose: Modified flag (different of disk version)
-- =============
--Modify(me: mutable); (see CDM_Document)
--IsModified(me) returns Boolean from Standard; (see CDM_Document)
---Purpose: to open/save a document
-- =======================
Close (me : mutable; aDoc : Document from TDocStd);
---Purpose: Close the given document. the document is not any more
-- handled by the applicative session.
IsInSession (me; path : ExtendedString from TCollection)
---Purpose: Returns an index for the document found in the
-- path path in this applicative session.
-- If the returned value is 0, the document is not
-- present in the applicative session.
-- This method can be used for the interactive part
-- of an application. For instance, on a call to
-- Open, the document to be opened may already
-- be in memory. IsInSession checks to see if this
-- is the case. Open can be made to depend on
-- the value of the index returned: if IsInSession
-- returns 0, the document is opened; if it returns
-- another value, a message is displayed asking the
-- user if he wants to override the version of the
-- document in memory.
-- Example:
-- Standard_Integer insession = A->IsInSession(aDoc);
-- if (insession > 0) {
-- cout << "document " << insession << " is already in session" << endl;
-- return 0;
-- }
returns Integer from Standard;
Open (me : mutable; path : ExtendedString from TCollection;
aDoc : out Document from TDocStd)
---Purpose: Retrieves the document aDoc stored under the
-- name aName in the directory directory.
-- In order not to override a version of aDoc which
-- is already in memory, this method can be made
-- to depend on the value returned by IsInSession.
returns RetrievableStatus from CDF;
SaveAs (me : mutable; aDoc : Document from TDocStd;
path : ExtendedString from TCollection)
---Purpose: Save the active document in the file <name> in the
-- path <path> ; o verwrites the file if it already exists.
returns StoreStatus from CDF;
Save (me : mutable; aDoc : Document from TDocStd)
---Purpose: Save aDoc active document.
-- Exceptions:
-- Standard_NotImplemented if the document
-- was not retrieved in the applicative session by using Open.
returns StoreStatus from CDF;
SaveAs (me : mutable; aDoc : Document from TDocStd;
path : ExtendedString from TCollection;
theStatusMessage: out ExtendedString from TCollection)
---Purpose: Save the active document in the file <name> in the
-- path <path> . overwrite the file if it
-- already exist.
returns StoreStatus from CDF;
Save (me : mutable; aDoc : Document from TDocStd;
theStatusMessage: out ExtendedString from TCollection)
---Purpose: Save the document overwriting the previous file
returns StoreStatus from CDF;
--Exit (me)
-- to quit the application. the applicative documents must be closed before.
OnOpenTransaction (me:mutable; theDoc: Document from TDocStd)
is virtual protected;
---Purpose: Notification that is fired at each OpenTransaction event.
OnCommitTransaction (me:mutable; theDoc: Document from TDocStd)
is virtual protected;
---Purpose: Notification that is fired at each CommitTransaction event.
OnAbortTransaction (me:mutable; theDoc: Document from TDocStd)
is virtual protected;
---Purpose: Notification that is fired at each AbortTransaction event.
fields
myResources : Manager from Resource;
myIsDriverLoaded : Boolean from Standard;
friends
class Document from TDocStd
end Application;

View File

@@ -0,0 +1,434 @@
// File: TDocStd_Application.cxx
// Created: Wed Jun 30 12:40:45 1999
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDocStd_Application.ixx>
#include <CDF_Session.hxx>
#include <CDF_DirectoryIterator.hxx>
#include <CDF_Directory.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_DomainError.hxx>
#include <Plugin_Failure.hxx>
#include <TDF_Label.hxx>
#include <CDF_Store.hxx>
#include <TDocStd_PathParser.hxx>
#include <CDM_MessageDriver.hxx>
// The improvement concerns returning value of the methods Open(), Save() and SaveAs():
#define BUC60867
// TDocStd_Owner attribute have pointer of closed TDocStd_Document
#define OCC159
#ifdef OCC159
#include <TDocStd_Owner.hxx>
#endif
//=======================================================================
//function : TDocStd_Application
//purpose :
//=======================================================================
TDocStd_Application::TDocStd_Application()
: myIsDriverLoaded (Standard_True)
{
Handle(CDF_Session) S;
if (!CDF_Session::Exists()) S = new CDF_Session();
else S = CDF_Session::CurrentSession();
S->SetCurrentApplication(this);
try
{
OCC_CATCH_SIGNALS
S->LoadDriver();
}
catch (Plugin_Failure)
{
myIsDriverLoaded = Standard_False;
}
}
//=======================================================================
//function : IsDriverLoaded
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Application::IsDriverLoaded() const
{
return myIsDriverLoaded;
}
//=======================================================================
//function : Resources
//purpose :
//=======================================================================
Handle(Resource_Manager) TDocStd_Application::Resources() {
if (myResources.IsNull()) {
myResources = new Resource_Manager(ResourcesName());
}
return myResources;
}
//=======================================================================
//function : NbDocuments
//purpose :
//=======================================================================
Standard_Integer TDocStd_Application::NbDocuments() const
{
if (!CDF_Session::Exists())
Standard_DomainError::Raise("TDocStd_Application::NbDocuments");
Handle(CDF_Session) S = CDF_Session::CurrentSession();
return S->Directory()->Length();
}
//=======================================================================
//function : GetDocument
//purpose :
//=======================================================================
void TDocStd_Application::GetDocument(const Standard_Integer index,Handle(TDocStd_Document)& aDoc) const
{
if (!CDF_Session::Exists())
Standard_DomainError::Raise("TDocStd_Application::NbDocuments");
Handle(CDF_Session) S = CDF_Session::CurrentSession();
CDF_DirectoryIterator it (S->Directory());
Standard_Integer current = 0;
for (;it.MoreDocument();it.NextDocument()) {
current++;
if (index == current) {
Handle(TDocStd_Document) D =
Handle(TDocStd_Document)::DownCast(it.Document());
aDoc = D;
return;
}
}
}
//=======================================================================
//function : NewDocument
//purpose :
//=======================================================================
void TDocStd_Application::NewDocument(const TCollection_ExtendedString& format,Handle(TDocStd_Document)& aDoc)
{
Handle(TDocStd_Document) D = new TDocStd_Document(format);
InitDocument (D);
CDF_Application::Open(D); // add the document in the session
aDoc = D;
}
//=======================================================================
//function : InitDocument
//purpose : do nothing
//=======================================================================
void TDocStd_Application::InitDocument(const Handle(TDocStd_Document)& /*aDoc*/) const
{
}
#ifdef OCC159
//=======================================================================
//function : Close
//purpose :
//=======================================================================
void TDocStd_Application::Close(const Handle(TDocStd_Document)& aDoc)
{
Handle(TDocStd_Owner) Owner;
if (aDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) {
Handle(TDocStd_Document) emptyDoc;
Owner->SetDocument(emptyDoc);
}
CDF_Application::Close(aDoc);
}
#endif
//=======================================================================
//function : IsInSession
//purpose :
//=======================================================================
Standard_Integer TDocStd_Application::IsInSession (const TCollection_ExtendedString& path) const
{
Standard_Integer nbdoc = NbDocuments();
Handle(TDocStd_Document) D;
for (Standard_Integer i = 1; i <= nbdoc; i++) {
GetDocument(i,D);
if (D->IsSaved()) {
if (path == D->GetPath()) return i;
}
}
return 0;
}
//=======================================================================
//function : Open
//purpose :
//=======================================================================
CDF_RetrievableStatus TDocStd_Application::Open(const TCollection_ExtendedString& path,Handle(TDocStd_Document)& aDoc) {
CDF_RetrievableStatus status = CDF_RS_DriverFailure;
TDocStd_PathParser tool (path);
TCollection_ExtendedString directory = tool.Trek();
TCollection_ExtendedString file = tool.Name();
file+=".";
file+=tool.Extension();
#ifdef BUC60867
status = CanRetrieve(directory,file);
if (status != CDF_RS_OK) return status;
#endif
try {
OCC_CATCH_SIGNALS
Handle(TDocStd_Document) D =
Handle(TDocStd_Document)::DownCast(Retrieve(directory,file));
CDF_Application::Open(D);
aDoc = D;
}
catch (Standard_Failure) {
// status = GetRetrieveStatus();
Handle(Standard_Failure) F = Standard_Failure::Caught();
if (!F.IsNull() && !MessageDriver().IsNull()) {
// Standard_SStream aMsg;
// aMsg << Standard_Failure::Caught() << endl;
// cout << "TDocStd_Application::Open(): " << aMsg.rdbuf()->str() << endl;
TCollection_ExtendedString aString (F->GetMessageString());
MessageDriver()->Write(aString.ToExtString());
}
}
status = GetRetrieveStatus();
#ifdef DEB
cout<<"TDocStd_Application::Open(): The status = "<<status<<endl;
#endif
return status;
}
//=======================================================================
//function : SaveAs
//purpose :
//=======================================================================
CDF_StoreStatus TDocStd_Application::SaveAs(const Handle(TDocStd_Document)& D,const TCollection_ExtendedString& path) {
TDocStd_PathParser tool (path);
TCollection_ExtendedString directory = tool.Trek();
TCollection_ExtendedString file = tool.Name();
file+=".";
file+=tool.Extension();
D->Open(this);
CDF_Store storer (D);
#ifdef BUC60867
if (!storer.SetFolder(directory))
{
TCollection_ExtendedString aMsg ("TDocStd_Application::SaveAs() - folder ");
aMsg += directory;
aMsg += " does not exist";
if(!MessageDriver().IsNull())
MessageDriver()->Write(aMsg.ToExtString());
return storer.StoreStatus(); //CDF_SS_Failure;
}
#endif
storer.SetName (file);
try {
OCC_CATCH_SIGNALS
storer.Realize();
}
catch (Standard_Failure) {
Handle(Standard_Failure) F = Standard_Failure::Caught();
if (!F.IsNull() && !MessageDriver().IsNull()) {
TCollection_ExtendedString aString (F->GetMessageString());
MessageDriver()->Write(aString.ToExtString());
}
}
if(storer.StoreStatus() == CDF_SS_OK)
D->SetSaved();
#ifdef BUC60867
#ifdef DEB
cout<<"TDocStd_Application::SaveAs(): The status = "<<storer.StoreStatus()<<endl;
#endif
return storer.StoreStatus();
#endif
}
//=======================================================================
//function : Save
//purpose :
//=======================================================================
CDF_StoreStatus TDocStd_Application::Save (const Handle(TDocStd_Document)& D) {
#ifdef BUC60867
CDF_StoreStatus status = CDF_SS_OK;
#endif
if (D->IsSaved()) {
CDF_Store storer (D);
try{
OCC_CATCH_SIGNALS
storer.Realize();
}
catch (Standard_Failure) {
Handle(Standard_Failure) F = Standard_Failure::Caught();
if (!F.IsNull() && !MessageDriver().IsNull()) {
TCollection_ExtendedString aString (F->GetMessageString());
MessageDriver()->Write(aString.ToExtString());
}
}
if(storer.StoreStatus() == CDF_SS_OK)
D->SetSaved();
#ifdef BUC60867
status = storer.StoreStatus();
#endif
} else {
// Standard_DomainError::Raise ("TDocStd_Application::Save document is not already saved");
if(!MessageDriver().IsNull()) {
TCollection_ExtendedString aMsg("Document is already saved");
MessageDriver()->Write(aMsg.ToExtString());
}
status = CDF_SS_Failure;
}
#ifdef BUC60867
#ifdef DEB
cout<<"TDocStd_Application::Save(): The status = "<<status<<endl;
#endif
return status;
#endif
}
//=======================================================================
//function : SetViewer
//purpose :
//=======================================================================
// void TDocStd_Application::SetViewer(const Handle(TDocStd_Document)& D,
// const Handle(V3d_Viewer)& viewer)
// {
// TPrsStd_AISViewer::New (D->Main(),viewer);
// InitViewer(D);
// }
//=======================================================================
//function : SetViewer
//purpose :
//=======================================================================
// void TDocStd_Application::SetViewer(const Handle(TDocStd_Document)& D,
// const Handle(AIS_InteractiveContext)& IC)
// {
// TPrsStd_AISViewer::New (D->Main(),IC);
// InitViewer(D);
// }
//=======================================================================
//function : SaveAs
//purpose :
//=======================================================================
CDF_StoreStatus TDocStd_Application::SaveAs(const Handle(TDocStd_Document)& D,
const TCollection_ExtendedString& path,
TCollection_ExtendedString& theStatusMessage)
{
TDocStd_PathParser tool (path);
CDF_StoreStatus aStatus = CDF_SS_Failure;
TCollection_ExtendedString directory = tool.Trek();
TCollection_ExtendedString file = tool.Name();
file+=".";
file+=tool.Extension();
D->Open(this);
CDF_Store storer (D);
if (storer.SetFolder(directory)) {
storer.SetName (file);
try {
OCC_CATCH_SIGNALS
storer.Realize();
}
catch (Standard_Failure) {
Handle(Standard_Failure) F = Standard_Failure::Caught();
if (!F.IsNull() && !MessageDriver().IsNull()) {
TCollection_ExtendedString aString (F->GetMessageString());
MessageDriver()->Write(aString.ToExtString());
}
}
if(storer.StoreStatus() == CDF_SS_OK)
D->SetSaved();
theStatusMessage = storer.AssociatedStatusText();
aStatus = storer.StoreStatus();
} else {
theStatusMessage =
TCollection_ExtendedString("TDocStd_Application::SaveAs"
": No such directory ") + directory;
aStatus = CDF_SS_Failure;
}
return aStatus;
}
//=======================================================================
//function : Save
//purpose :
//=======================================================================
CDF_StoreStatus TDocStd_Application::Save (const Handle(TDocStd_Document)& D,
TCollection_ExtendedString& theStatusMessage)
{
CDF_StoreStatus status = CDF_SS_OK;
if (D->IsSaved()) {
CDF_Store storer (D);
try {
OCC_CATCH_SIGNALS
storer.Realize();
}
catch (Standard_Failure) {
Handle(Standard_Failure) F = Standard_Failure::Caught();
if (!F.IsNull() && !MessageDriver().IsNull()) {
TCollection_ExtendedString aString (F->GetMessageString());
MessageDriver()->Write(aString.ToExtString());
}
}
if(storer.StoreStatus() == CDF_SS_OK)
D->SetSaved();
status = storer.StoreStatus();
theStatusMessage = storer.AssociatedStatusText();
} else {
Standard_DomainError::Raise ("TDocStd_Application::Save"
" document is not already saved");
theStatusMessage = "TDocStd_Application::the document is not already saved";
}
return status;
}
//=======================================================================
//function : OnOpenTransaction
//purpose :
//=======================================================================
void TDocStd_Application::OnOpenTransaction (const Handle(TDocStd_Document)&)
{
// nothing to do on this level
}
//=======================================================================
//function : OnAbortTransaction
//purpose :
//=======================================================================
void TDocStd_Application::OnAbortTransaction (const Handle(TDocStd_Document)&)
{
// nothing to do on this level
}
//=======================================================================
//function : OnCommitTransaction
//purpose :
//=======================================================================
void TDocStd_Application::OnCommitTransaction (const Handle(TDocStd_Document)&)
{
// nothing to do on this level
}

View File

@@ -0,0 +1,41 @@
-- File: TDocStd_ApplicationDelta.cdl<2>
-- Created: Tue Nov 19 16:16:47 2002
-- Author: Vladimir ANIKIN
-- <van@matrox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2002
class ApplicationDelta from TDocStd inherits TShared from MMgt
uses
SequenceOfDocument from TDocStd,
ExtendedString from TCollection,
OStream from Standard
is
Create returns ApplicationDelta from TDocStd;
GetDocuments(me : mutable)
returns SequenceOfDocument from TDocStd;
---C++: return &
---C++: inline
GetName(me)
returns ExtendedString from TCollection;
---C++: return const &
---C++: inline
SetName(me : mutable;
theName : ExtendedString from TCollection);
---C++: inline
Dump(me;
anOS : in out OStream from Standard);
fields
myDocuments : SequenceOfDocument from TDocStd;
myName : ExtendedString from TCollection;
end ApplicationDelta;

View File

@@ -0,0 +1,34 @@
// File: TDocStd_ApplicationDelta.cxx
// Created: 19.11.02 16:17:37
// Author: Vladimir ANIKIN
// Copyright: Open CASCADE 2002
#include <TDocStd_ApplicationDelta.ixx>
#include <TCollection_AsciiString.hxx>
#include <TDocStd_Document.hxx>
//=======================================================================
//function : TDocStd_ApplicationDelta
//purpose :
//=======================================================================
TDocStd_ApplicationDelta::TDocStd_ApplicationDelta() {}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void TDocStd_ApplicationDelta::Dump(Standard_OStream& anOS) const {
anOS<<"\t";
myName.Print(anOS);
anOS<<" - " << myDocuments.Length() << " documents ";
anOS<<" ( ";
Standard_Integer i;
for (i = 1; i <= myDocuments.Length(); i++) {
Handle(TDocStd_Document) aDocAddr= myDocuments.Value(i);
anOS << "\"" << ((Standard_Transient*)aDocAddr);
anOS << "\" ";
}
anOS << ") ";
}

View File

@@ -0,0 +1,35 @@
// File: TDocStd_ApplicationDelta.lxx
// Created: 21.11.02 14:40:25
// Author: Vladimir ANIKIN
// Copyright: Open CASCADE 2002
//=======================================================================
//function : GetDocuments
//purpose :
//=======================================================================
inline TDocStd_SequenceOfDocument& TDocStd_ApplicationDelta::GetDocuments()
{
return myDocuments;
}
//=======================================================================
//function : GetName
//purpose :
//=======================================================================
inline const TCollection_ExtendedString& TDocStd_ApplicationDelta::GetName() const
{
return myName;
}
//=======================================================================
//function : SetName
//purpose :
//=======================================================================
inline void TDocStd_ApplicationDelta::SetName(const TCollection_ExtendedString& theName)
{
myName = theName;
}

View File

@@ -0,0 +1,34 @@
-- File: TDocStd_CompoundDelta.cdl
-- Author: Sergey RUIN
---Copyright: MATRA DATAVISION 2001
class CompoundDelta from TDocStd inherits Delta from TDF
---Purpose: A delta set is available at <aSourceTime>. If
-- applied, it restores the TDF_Data in the state it
-- was at <aTargetTime>.
uses
OStream from Standard
is
Create;
---Purpose: Creates a compound delta.
-- SetValidTime(me : mutable; aBeginTime, anEndTime : Integer from Standard) is private;
---Purpose: Validates <me> at <aBeginTime>. If applied, it
-- restores the TDF_Data in the state it was at
-- <anEndTime>. Reserved to TDF_Data.
-- AppendAttributeDelta(me : mutable; anAttributeDelta : AttributeDelta from TDF) is private;
friends
class Document from TDocStd
end Delta;

View File

@@ -0,0 +1,17 @@
// File: TDF_Delta.cxx
// -------------
// Author: Sergey RUIN
// Copyright: Matra Datavision 2001
#include <TDocStd_CompoundDelta.ixx>
//=======================================================================
//function : TDocStd_CompoundDelta
//purpose :
//=======================================================================
TDocStd_CompoundDelta::TDocStd_CompoundDelta() {}

23
src/TDocStd/TDocStd_Context.cdl Executable file
View File

@@ -0,0 +1,23 @@
-- File: TDocStd_Context.cdl
-- Created: Mon Jun 8 14:54:03 1998
-- Author: Isabelle GRIGNON
-- <isg@bigbox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1998
class Context from TDocStd
---Purpose:
is
Create returns Context from TDocStd;
SetModifiedReferences(me :in out ; Mod : Boolean from Standard);
ModifiedReferences(me) returns Boolean from Standard;
fields
modifiedRef : Boolean from Standard;
end Context;

27
src/TDocStd/TDocStd_Context.cxx Executable file
View File

@@ -0,0 +1,27 @@
// File: TDocStd_Context.cxx
// Created: Mon Jun 8 15:25:21 1998
// Author: Isabelle GRIGNON
// <isg@bigbox.paris1.matra-dtv.fr>
#include <TDocStd_Context.ixx>
//=======================================================================
//function : TDocStd_Context
//purpose :
//=======================================================================
TDocStd_Context::TDocStd_Context():modifiedRef(Standard_False){}
//=======================================================================
//function : SetModifiedReferences
//purpose :
//=======================================================================
void TDocStd_Context::SetModifiedReferences(const Standard_Boolean Mod) {
modifiedRef = Mod;
}
Standard_Boolean TDocStd_Context::ModifiedReferences() const {
return modifiedRef;
}

336
src/TDocStd/TDocStd_Document.cdl Executable file
View File

@@ -0,0 +1,336 @@
-- File: TDocStd_Document.cdl
-- Created: Wed Apr 7 11:01:48 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class Document from TDocStd inherits Document from CDM
---Purpose: The contents of a TDocStd_Application, a
-- document is a container for a data framework
-- composed of labels and attributes. As such,
-- TDocStd_Document is the entry point into the data framework.
-- To gain access to the data, you create a document as follows:
-- Handle(TDocStd_Document) MyDF = new TDocStd_Document
-- The document also allows you to manage:
-- - modifications, providing Undo and Redo functions.
-- - command transactions.
-- Warning: The only data saved is the framework (TDF_Data)
---Purpose:
uses Data from TDF,
Label from TDF,
LabelMap from TDF,
ExtendedString from TCollection,
AsciiString from TCollection,
Context from TDocStd,
Delta from TDF,
DeltaList from TDF,
Transaction from TDF,
CompoundDelta from TDocStd
is
--Destroy (me : mutable);
---Purpose: Will Abort any execution, and commit the Undo transaction
-----C++: alias ~
Get (myclass; L : Label from TDF)
---Purpose: returns the document which contains <L>. raises an
-- exception if the document is not found.
returns Document from TDocStd;
Create (astorageformat : ExtendedString from TCollection)
returns mutable Document from TDocStd;
---Purpose: Constructs a document object defined by the
-- string astorageformat.
IsSaved (me)
---Purpose: the document is saved in a file.
returns Boolean from Standard;
IsChanged (me)
returns Boolean from Standard;
---Purpose: returns True if document differs from the state of last saving.
-- this method have to be called only wroking in the transaction mode
---C++: inline
SetSaved (me : mutable);
---Purpose: This method have to be called to show document that it has been saved
---C++: inline
SetSavedTime (me : mutable; theTime : Integer from Standard);
---Purpose: Say to document what it is not saved.
-- Use value, returned earlier by GetSavedTime().
---C++: inline
GetSavedTime (me)
---Purpose: Returns value of <mySavedTime> to be used later in SetSavedTime()
---C++: inline
returns Integer from Standard;
GetName (me)
---Purpose: raise if <me> is not saved.
returns ExtendedString from TCollection;
GetPath (me)
---Purpose: returns the OS path of the file, in wich one <me> is
-- saved. Raise an exception if <me> is not saved.
returns ExtendedString from TCollection;
---Category: Data Framework
-- ==============
SetData (me : mutable ; data : Data from TDF);
GetData (me)
returns Data from TDF;
Main (me)
---Purpose: Returns the main label in this data framework.
-- By definition, this is the label with the entry 0:1.
returns Label from TDF;
IsEmpty(me)
---Purpose: Returns True if the main label has no attributes
returns Boolean from Standard;
---Category: Durty Flag and Modified labels
-- ==============================
IsValid(me) returns Boolean;
---Purpose: Returns False if the document has been modified
-- but not recomputed.
SetModified (me : mutable; L : Label from TDF);
---Purpose: Notify the label as modified, the Document becomes UnValid.
--IsModified (me; L : Label from TDF)
--returns Boolean from Standard;
---Purpose: returns True if <L> has been notified as modified.
PurgeModified (me : mutable);
---Purpose: Remove all modifications. After this call The document
-- becomesagain Valid.
GetModified (me)
---Purpose: Returns the labels which have been modified in
-- this document.
---C++: return const&
returns LabelMap from TDF;
---Category: COMMAND Transaction and UNDO/REDO
-- =================================
NewCommand (me : mutable);
---Purpose: Launches a new command. This command may be undone.
HasOpenCommand (me)
---Purpose: returns True if a Command transaction is open in the curret .
returns Boolean from Standard;
OpenCommand (me : mutable);
---Purpose: Opens a new command transaction in this document.
-- You can use HasOpenCommand to see whether a command is already open.
-- Exceptions
-- Standard_DomainError if a command is already open in this document.
CommitCommand (me : mutable) returns Boolean;
---Purpose: Commits documents transactions and fills the
-- transaction manager with documents that have
-- been changed during the transaction.
-- If no command transaction is open, nothing is done.
-- Returns True if a new delta has been added to myUndos.
AbortCommand (me : mutable);
---Purpose: Abort the Command transaction. Does nothing If there is
-- no Command transaction open.
GetUndoLimit(me) returns Integer;
---Purpose: The current limit on the number of undos
SetUndoLimit(me : mutable; L : Integer);
---Purpose: Set the limit on the number of Undo Delta stored 0
-- will disable Undo on the document A negative value
-- means no limit. Note that by default Undo is disabled.
-- Enabling it will take effect with the next call to
-- NewCommand. Of course this limit is the same for Redo
ClearUndos(me : mutable);
---Purpose: Remove all stored Undos and Redos
ClearRedos(me : mutable);
---Purpose: Remove all stored Redos
GetAvailableUndos (me) returns Integer;
---Purpose: Returns the number of undos stored in this
-- document. If this figure is greater than 0, the method Undo
-- can be used.
Undo (me:mutable) returns Boolean;
---Purpose: Will UNDO one step, returns False if no undo was
-- done (Undos == 0).
-- Otherwise, true is returned and one step in the
-- list of undoes is undone.
GetAvailableRedos (me) returns Integer;
---Purpose: Returns the number of redos stored in this
-- document. If this figure is greater than 0, the method Redo
-- can be used.
Redo (me : mutable) returns Boolean;
---Purpose: Will REDO one step, returns False if no redo was
-- done (Redos == 0).
-- Otherwise, true is returned, and one step in the list of redoes is done again.
GetUndos (me)
---C++: return const &
returns DeltaList from TDF;
GetRedos (me)
---C++: return const &
returns DeltaList from TDF;
RemoveFirstUndo (me : mutable);
---Purpose: Removes the first undo in the list of document undos.
-- It is used in the application when the undo limit is exceed.
InitDeltaCompaction(me : mutable)
---Purpose: Initializes the procedure of delta compaction
-- Returns false if there is no delta to compact
-- Marks the last delta as a "from" delta
returns Boolean from Standard;
PerformDeltaCompaction(me : mutable)
---Purpose: Performs the procedure of delta compaction
-- Makes all deltas starting from "from" delta
-- till the last one to be one delta.
returns Boolean from Standard;
---Category: External references
-- ===================
UpdateReferences (me : mutable; aDocEntry : AsciiString from TCollection);
---Purpose: Set modifications on labels impacted by external
-- references to the entry. The document becomes invalid
-- and must be recomputed.
Recompute (me : mutable);
---Purpose: Recompute if the document was not valid and propagate
-- the reccorded modification.
---Category: deferred methods CDM_Document
-- =============================
Update (me: mutable; aToDocument : Document from CDM;
aReferenceIdentifier : Integer from Standard;
aModifContext : Address from Standard)
is redefined;
--Update(me:mutable; ErrorString: out ExtendedString from TCollection)
--returns Boolean from Standard
---Purpose: This method Update will be called
-- to signal the end of the modified references list.
-- The document should be recomputed and
-- UpdateFromDocuments should be called. Update should
-- returns True in case of success, false otherwise. In
-- case of Failure, additional information can be given in
-- ErrorString.
--is redefined;
--Update (me: mutable)
--is redefined;
---Purpose: Update the document by propagation
-- ==================================
--Propagate (me: mutable);
---Purpose: Update the document from internal stored
-- modifications. If you want to undoing this
-- operation, please call NewCommand before.
---Purpose: to change format (advanced programming)
-- ================
StorageFormat(me)
returns ExtendedString from TCollection
is virtual;
ChangeStorageFormat(me : mutable; newStorageFormat : ExtendedString from TCollection)
is virtual;
---Purpose: methods for the nested transaction mode
SetNestedTransactionMode(me : mutable; isAllowed : Boolean = Standard_True);
---Purpose: Sets nested transaction mode if isAllowed == Standard_True
IsNestedTransactionMode (me)
returns Boolean from Standard;
---Purpose: Returns Standard_True if mode is set
---C++: inline
AppendDeltaToTheFirst (myclass;
theDelta1 : CompoundDelta from TDocStd;
theDelta2 : Delta from TDF) is private;
---Purpose: Appends delta to the first delta in the myUndoFILO
---Purpose: private methods
-- ===============
CommitTransaction (me : mutable) returns Boolean
is virtual protected;
---Purpose: Returns Standard_True done
AbortTransaction (me : mutable)
is virtual protected;
OpenTransaction (me : mutable)
is virtual protected;
---Purpose: methods for protection of changes outside transactions
SetModificationMode (me : mutable; theTransactionOnly : Boolean from Standard);
---Purpose: if theTransactionOnly is True changes is denied outside transactions
---C++: inline
ModificationMode (me) returns Boolean from Standard;
---Purpose: returns True if changes allowed only inside transactions
---C++: inline
fields
---Purpose: storage format
myStorageFormat : ExtendedString from TCollection is protected;
---Purpose: data framework
myData : Data from TDF;
myUndoLimit : Integer from Standard;
myUndoTransaction : Transaction from TDF;
myUndos : DeltaList from TDF;
myRedos : DeltaList from TDF;
myFromUndo : Delta from TDF;
myFromRedo : Delta from TDF;
mySaveTime : Integer from Standard;
---Purpose: data for the nested transactions
myIsNestedTransactionMode : Boolean from Standard;
myUndoFILO : DeltaList from TDF;
---Purpose: data for protection of changes outside transactions
myOnlyTransactionModification : Boolean from Standard;
end Document;

891
src/TDocStd/TDocStd_Document.cxx Executable file
View File

@@ -0,0 +1,891 @@
// File: TDocStd_Document.cxx
// Copyright: Open Cascade 2006
#include <TDocStd_Document.ixx>
#include <TDocStd.hxx>
#include <TDocStd_XLink.hxx>
#include <TDocStd_XLinkIterator.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Context.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ListIteratorOfDeltaList.hxx>
#include <TDF_AttributeList.hxx>
#include <TDF_ListIteratorOfAttributeList.hxx>
#include <TDF_AttributeDelta.hxx>
#include <TDF_AttributeDeltaList.hxx>
#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
#include <TDF_Label.hxx>
#include <TDF_Delta.hxx>
#include <TDocStd_CompoundDelta.hxx>
#include <TDocStd_Owner.hxx>
#include <TDocStd_Modified.hxx>
#include <TDF_IDMap.hxx>
#include <TDocStd_LabelIDMapDataMap.hxx>
#include <CDM_MetaData.hxx>
// List should have a RemoveLast...
#define TDocStd_List_RemoveLast(theList) \
TDF_ListIteratorOfDeltaList it(theList); \
Standard_Integer i,n = theList.Extent(); \
for (i = 1; i < n; i++) it.Next(); \
theList.Remove(it);
#undef DEB_TRANS
#undef DEB_DELTA
#define BUC60836
#define SRN_DELTA_COMPACT
//=======================================================================
//function : Get
//purpose :
//=======================================================================
Handle(TDocStd_Document) TDocStd_Document::Get (const TDF_Label& acces)
{
return TDocStd_Owner::GetDocument(acces.Data());
}
//=======================================================================
//function : Destroy
//purpose :
//=======================================================================
// void TDocStd_Document::Destroy()
// {
// myUndoTransaction.Commit(); // no needs to store the Undo
// }
//=======================================================================
//function : TDocStd_Document
//purpose :
//=======================================================================
TDocStd_Document::TDocStd_Document(const TCollection_ExtendedString& aStorageFormat) :
myStorageFormat(aStorageFormat),
myData (new TDF_Data()),
myUndoLimit(0),
mySaveTime(0),
myIsNestedTransactionMode(0)
{
TDF_Transaction* pTr = new TDF_Transaction (myData,"UNDO");
myUndoTransaction = *pTr; delete pTr;
TDocStd_Owner::SetDocument(myData,this);
#ifdef SRN_DELTA_COMPACT
myFromUndo.Nullify();
myFromRedo.Nullify();
#endif
}
//=======================================================================
//function : IsSaved
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::IsSaved() const
{
return CDM_Document::IsStored();
}
//=======================================================================
//function : GetName
//purpose :
//=======================================================================
TCollection_ExtendedString TDocStd_Document::GetName () const
{
return CDM_Document::MetaData()->Name();
}
//=======================================================================
//function : GetPath
//purpose :
//=======================================================================
TCollection_ExtendedString TDocStd_Document::GetPath () const
{
return CDM_Document::MetaData()->Path();
}
//=======================================================================
//function : SetData
//purpose :
//=======================================================================
void TDocStd_Document::SetData (const Handle(TDF_Data)& D)
{
myData = D;
TDF_Transaction* pTr = new TDF_Transaction(myData,"UNDO");
myUndoTransaction = *pTr; delete pTr;
}
//=======================================================================
//function : GetData
//purpose :
//=======================================================================
Handle(TDF_Data) TDocStd_Document::GetData () const
{
return myData;
}
//=======================================================================
//function : Main
//purpose :
//=======================================================================
TDF_Label TDocStd_Document::Main () const
{
return myData->Root().FindChild(1,Standard_True);
}
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::IsEmpty() const
{
TDF_AttributeIterator It (Main());
return !It.More();
}
//=======================================================================
//function : IsValid
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::IsValid() const
{
return TDocStd_Modified::IsEmpty(Main());
}
//=======================================================================
//function : SetModified
//purpose :
//=======================================================================
void TDocStd_Document::SetModified (const TDF_Label& L)
{
TDocStd_Modified::Add(L);
}
//=======================================================================
//function : IsModified
//purpose :
//=======================================================================
//Standard_Boolean TDocStd_Document::IsModified (const TDF_Label& L) const
//{
// return TDocStd_Modified::Contains(L);
//}
//=======================================================================
//function : PurgeModified
//purpose :
//=======================================================================
void TDocStd_Document::PurgeModified()
{
TDocStd_Modified::Clear(Main());
}
//=======================================================================
//function : GetModified
//purpose :
//=======================================================================
const TDF_LabelMap& TDocStd_Document::GetModified() const
{
return TDocStd_Modified::Get(Main());
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
void TDocStd_Document::Update(const Handle(CDM_Document)& /*aToDocument*/,
const Standard_Integer aReferenceIdentifier,
const Standard_Address aModifContext)
{
const TDocStd_Context CC = *((TDocStd_Context *)&aModifContext);
if (CC.ModifiedReferences() || !IsUpToDate(aReferenceIdentifier)) {
TCollection_AsciiString aDocEntry(aReferenceIdentifier);
UpdateReferences(aDocEntry);
SetIsUpToDate(aReferenceIdentifier);
}
}
//=======================================================================
//function : NewCommand
//purpose :
//=======================================================================
void TDocStd_Document::NewCommand()
{
#ifdef DEB_TRANS
if (myUndoTransaction.IsOpen() && myData->Transaction() > 1) {
Standard_DomainError::Raise ("NewCommand : many open transactions");
}
#endif
CommitTransaction();
OpenTransaction();
#ifdef DEB_TRANS
cout<<"End NewCommand"<<endl;
#endif
}
//=======================================================================
//function : HasOpenCommand
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::HasOpenCommand() const
{
return myUndoTransaction.IsOpen();
}
//=======================================================================
//function : OpenCommand
//purpose :
//=======================================================================
void TDocStd_Document::OpenCommand ()
{
if (!myIsNestedTransactionMode && myUndoTransaction.IsOpen()) {
Standard_DomainError::Raise("TDocStd_Document::OpenCommand : already open");
}
OpenTransaction();
// if (myUndoLimit != 0) myUndoTransaction.Open();
}
//=======================================================================
//function : CommitCommand
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::CommitCommand ()
{
return CommitTransaction();
}
//=======================================================================
//function : AbortCommand
//purpose :
//=======================================================================
void TDocStd_Document::AbortCommand ()
{
AbortTransaction();
}
//=======================================================================
//function : CommitTransaction
//purpose : Private method.
//=======================================================================
Standard_Boolean TDocStd_Document::CommitTransaction()
{
myData->AllowModification(Standard_True);
Standard_Boolean isDone = Standard_False;
// nested transaction mode
if (myIsNestedTransactionMode && myUndoTransaction.IsOpen()) {
Handle(TDF_Delta) D = myUndoTransaction.Commit(Standard_True);
Handle(TDocStd_CompoundDelta) aCompDelta =
Handle(TDocStd_CompoundDelta)::DownCast(myUndoFILO.First());
AppendDeltaToTheFirst(aCompDelta, D);
D = aCompDelta;
myUndoFILO.RemoveFirst();
if(myUndoFILO.Extent()) {
aCompDelta = Handle(TDocStd_CompoundDelta)::DownCast(myUndoFILO.First());
AppendDeltaToTheFirst(aCompDelta, D);
myUndoTransaction.Open();
}
else {
if(!D->IsEmpty()) {
myUndos.Append(D);
myRedos.Clear(); // if we push an Undo we clear the redos
isDone = Standard_True;
}
}
// deny modifications if the transaction is not opened
if(myOnlyTransactionModification) {
myData->AllowModification(myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
} else {
// are we undoing...
if (myUndoLimit != 0 && myUndoTransaction.IsOpen()) {
Handle(TDF_Delta) D = myUndoTransaction.Commit(Standard_True);
if (!(D.IsNull() || D->IsEmpty())) {
isDone = Standard_True;
myRedos.Clear(); // if we push an Undo we clear the redos
myUndos.Append(D); // New undos are at the end of the list
// Check the limit to remove the oldest one
if (myUndos.Extent() > myUndoLimit) {
#ifdef SRN_DELTA_COMPACT
Handle(TDF_Delta) aDelta = myUndos.First();
#endif
myUndos.RemoveFirst();
#ifdef SRN_DELTA_COMPACT
if(myFromUndo == aDelta) {
//The oldest Undo delta coincides with `from` delta
if(myUndos.Extent() == 1) { //There is the only Undo
myFromUndo.Nullify();
myFromRedo.Nullify();
}
else
myFromUndo = myUndos.First();
}
#endif
}
}
}
// deny or allow modifications acording to transaction state
if(myOnlyTransactionModification) {
myData->AllowModification (myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
}
// Notify CDM_Application of the successful commit
if (isDone && IsOpened()) {
const Handle(TDocStd_Application) anAppli =
Handle(TDocStd_Application)::DownCast(Application());
if (!anAppli.IsNull())
anAppli -> OnCommitTransaction (this);
}
return isDone;
}
//=======================================================================
//function : AbortTransaction
//purpose : Private method.
//=======================================================================
void TDocStd_Document::AbortTransaction()
{
myData->AllowModification(Standard_True);
if (myUndoTransaction.IsOpen())
if (myUndoLimit != 0)
myUndoTransaction.Abort();
if (myIsNestedTransactionMode && myUndoFILO.Extent()) {
if (!myUndoFILO.First()->IsEmpty())
myData->Undo(myUndoFILO.First(),Standard_True);
myUndoFILO.RemoveFirst();
if (myUndoFILO.Extent())
myUndoTransaction.Open();
}
// deny or allow modifications acording to transaction state
if (myOnlyTransactionModification) {
myData->AllowModification (myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
// Notify CDM_Application of the event
if (IsOpened()) {
const Handle(TDocStd_Application) anAppli =
Handle(TDocStd_Application)::DownCast(Application());
if (!anAppli.IsNull())
anAppli -> OnAbortTransaction (this);
}
}
//=======================================================================
//function :OpenTransaction
//purpose : Private method.
//=======================================================================
void TDocStd_Document::OpenTransaction()
{
myData->AllowModification(Standard_True);
// nested transaction mode
if (myIsNestedTransactionMode) {
if (myUndoTransaction.IsOpen()) {
Handle(TDF_Delta) D = myUndoTransaction.Commit(Standard_True);
Handle(TDocStd_CompoundDelta) aCompDelta =
Handle(TDocStd_CompoundDelta)::DownCast(myUndoFILO.First());
AppendDeltaToTheFirst(aCompDelta, D);
}
Standard_Integer aLastTime = myData->Time();
if (myUndoFILO.Extent())
aLastTime = myUndoFILO.First()->EndTime();
Handle(TDocStd_CompoundDelta) aCompoundDelta =
new TDocStd_CompoundDelta;
aCompoundDelta->Validity(aLastTime, aLastTime);
myUndoFILO.Prepend(aCompoundDelta);
}
if (myUndoLimit != 0) myUndoTransaction.Open();
// deny or allow modifications acording to transaction state
if (myOnlyTransactionModification) {
myData->AllowModification (myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
// Notify CDM_Application of the event
if (IsOpened()) {
const Handle(TDocStd_Application) anAppli =
Handle(TDocStd_Application)::DownCast(Application());
if (!anAppli.IsNull())
anAppli -> OnOpenTransaction (this);
}
}
//=======================================================================
//function : SetUndoLimit
//purpose :
//=======================================================================
void TDocStd_Document::SetUndoLimit(const Standard_Integer L)
{
#ifdef SRN_DELTA_COMPACT
myFromUndo.Nullify(); //Compaction has to aborted
myFromRedo.Nullify();
#endif
CommitTransaction ();
myUndoLimit = (L > 0) ? L : 0;
Standard_Integer n = myUndos.Extent() - myUndoLimit;
while (n > 0) {
myUndos.RemoveFirst();
--n;
}
// deny or allow modifications acording to transaction state
if(myOnlyTransactionModification) {
myData->AllowModification(myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
//OpenTransaction(); dp 15/10/99
}
//=======================================================================
//function : GetUndoLimit
//purpose :
//=======================================================================
Standard_Integer TDocStd_Document::GetUndoLimit() const
{
return myUndoLimit;
}
//=======================================================================
//function : Undos
//purpose :
//=======================================================================
Standard_Integer TDocStd_Document::GetAvailableUndos() const
{
return myUndos.Extent();
}
//=======================================================================
//function : ClearUndos
//purpose :
//=======================================================================
void TDocStd_Document::ClearUndos()
{
myUndos.Clear();
myRedos.Clear();
#ifdef SRN_DELTA_COMPACT
myFromRedo.Nullify();
myFromUndo.Nullify();
#endif
}
//=======================================================================
//function : ClearRedos
//purpose :
//=======================================================================
void TDocStd_Document::ClearRedos()
{
myRedos.Clear();
#ifdef SRN_DELTA_COMPACT
myFromRedo.Nullify();
#endif
}
//=======================================================================
//function : Undo
//purpose :
// Some importante notice:
// 1) The most recent undo delta is at the end of the list.
// 2) Removing the LAST item of a list is tedious, but it is done only on
// Undo. Remove first is done at each command if the limit is reached!
// 3) To make fun, the redos are not like the undos: the most recent delta
// is at the beginning! Like this, it is easier to remove it after use.
//=======================================================================
Standard_Boolean TDocStd_Document::Undo()
{
// Don't call NewCommand(), because it may commit Interactive Attributes
// and generate a undesirable Delta!
Standard_Boolean isOpened = myUndoTransaction.IsOpen();
Standard_Boolean undoDone = Standard_False;
//TDF_Label currentObjectLabel = CurrentLabel (); //Sauve pour usage ulterieur.
if (!myUndos.IsEmpty()) {
// Reset the transaction
AbortTransaction();
// only for nested transaction mode
while(myIsNestedTransactionMode && myUndoFILO.Extent())
AbortTransaction();
// allow modifications
myData->AllowModification(Standard_True);
// Apply the Undo
// should test the applicability before.
#ifdef DEB_DELTA
cout<<"DF before Undo =================================="<<endl; TDF_Tool::DeepDump(cout,myData);
#endif
Handle(TDF_Delta) D = myData->Undo(myUndos.Last(),Standard_True);
#ifdef BUC60836
D->SetName(myUndos.Last()->Name());
#endif
#ifdef DEB_DELTA
cout<<"DF after Undo =================================="<<endl; TDF_Tool::DeepDump(cout,myData);
#endif
// Push the redo
myRedos.Prepend(D);
// Remove the last Undo
TDocStd_List_RemoveLast(myUndos);
undoDone = Standard_True;
}
if (isOpened && undoDone) OpenTransaction();
// deny or allow modifications acording to transaction state
if(myOnlyTransactionModification) {
myData->AllowModification(myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
return undoDone;
}
//=======================================================================
//function : GetAvailableRedos
//purpose :
//=======================================================================
Standard_Integer TDocStd_Document:: GetAvailableRedos() const
{
// should test the applicability before.
return myRedos.Extent();
}
//=======================================================================
//function : Redo
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::Redo()
{
Standard_Boolean isOpened = myUndoTransaction.IsOpen();
Standard_Boolean undoDone = Standard_False;
// TDF_Label currentObjectLabel = CurrentLabel();//Sauve pour usage ulterieur.
if (!myRedos.IsEmpty()) {
// should test the applicability before.
// Reset the transaction
AbortTransaction();
// only for nested transaction mode
while(myIsNestedTransactionMode && myUndoFILO.Extent())
AbortTransaction();
// allow modifications
myData->AllowModification(Standard_True);
// Apply the Redo
#ifdef DEB_DELTA
cout<<"DF before Redo =================================="<<endl; TDF_Tool::DeepDump(cout,myData);
#endif
Handle(TDF_Delta) D = myData->Undo(myRedos.First(),Standard_True);
#ifdef BUC60836
D->SetName(myRedos.First()->Name());
#endif
#ifdef DEB_DELTA
cout<<"DF after Redo =================================="<<endl; TDF_Tool::DeepDump(cout,myData);
#endif
// Push the redo of the redo as an undo (got it !)
myUndos.Append(D);
// remove the Redo from the head
myRedos.RemoveFirst();
undoDone = Standard_True;
}
if (isOpened && undoDone) OpenTransaction();
// deny or allow modifications acording to transaction state
if(myOnlyTransactionModification) {
myData->AllowModification(myUndoTransaction.IsOpen() && myUndoLimit
? Standard_True :Standard_False);
}
return undoDone;
}
//=======================================================================
//function : UpdateReferences
//purpose :
//=======================================================================
void TDocStd_Document::UpdateReferences(const TCollection_AsciiString& aDocEntry)
{
TDF_AttributeList aRefList;
TDocStd_XLink* xRefPtr;
for (TDocStd_XLinkIterator xItr (this); xItr.More(); xItr.Next()) {
xRefPtr = xItr.Value();
if (xRefPtr->DocumentEntry() == aDocEntry) {
aRefList.Append(xRefPtr->Update());
}
}
TDF_ListIteratorOfAttributeList It(aRefList);
for (;It.More();It.Next()) {
// // mise a jour import
SetModified(It.Value()->Label());
}
}
//=======================================================================
//function : GetUndos
//purpose :
//=======================================================================
const TDF_DeltaList& TDocStd_Document::GetUndos() const
{
return myUndos;
}
//=======================================================================
//function : GetRedos
//purpose :
//=======================================================================
const TDF_DeltaList& TDocStd_Document::GetRedos() const
{
return myRedos;
}
//=======================================================================
//function : InitDeltaCompaction
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::InitDeltaCompaction()
{
#ifdef SRN_DELTA_COMPACT
if (myUndoLimit == 0 || myUndos.Extent() == 0) {
myFromRedo.Nullify();
myFromUndo.Nullify();
return Standard_False; //No Undos to compact
}
myFromRedo.Nullify();
myFromUndo = myUndos.Last();
if(myRedos.Extent() > 0) myFromRedo = myRedos.First();
#endif
return Standard_True;
}
//=======================================================================
//function : PerformDeltaCompaction
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Document::PerformDeltaCompaction()
{
#ifdef SRN_DELTA_COMPACT
if(myFromUndo.IsNull()) return Standard_False; //Redo can be Null for this operation
TDF_DeltaList aList;
Handle(TDocStd_CompoundDelta) aCompoundDelta = new TDocStd_CompoundDelta;
TDF_ListIteratorOfDeltaList anIterator(myUndos);
TDF_ListIteratorOfAttributeDeltaList aDeltasIterator;
TDocStd_LabelIDMapDataMap aMap;
Standard_Boolean isFound = Standard_False, isTimeSet = Standard_False;
//Process Undos
for(; anIterator.More(); anIterator.Next()) {
if(!isFound) {
if(myFromUndo == anIterator.Value()) isFound = Standard_True;
aList.Append(anIterator.Value()); //Fill the list of deltas that precede compound delta
continue;
}
if(!isTimeSet) { //Set begin and end time when the compound delta is valid
aCompoundDelta->Validity(anIterator.Value()->BeginTime(), myUndos.Last()->EndTime());
isTimeSet = Standard_True;
}
aDeltasIterator.Initialize(anIterator.Value()->AttributeDeltas());
for(; aDeltasIterator.More(); aDeltasIterator.Next()) {
if(!aMap.IsBound(aDeltasIterator.Value()->Label())) {
TDF_IDMap* pIDMap = new TDF_IDMap();
aMap.Bind(aDeltasIterator.Value()->Label(), *pIDMap);
delete pIDMap;
}
if(aMap(aDeltasIterator.Value()->Label()).Add(aDeltasIterator.Value()->ID())) //The attribute is not
aCompoundDelta->AddAttributeDelta(aDeltasIterator.Value()); //already in the delta
}
}
myUndos.Clear();
myUndos.Assign(aList);
myUndos.Append(aCompoundDelta);
//Process Redos
if(myFromRedo.IsNull()) {
myRedos.Clear();
return Standard_True;
}
aList.Clear();
for(anIterator.Initialize(myRedos); anIterator.More(); anIterator.Next()) {
aList.Append(anIterator.Value());
if(anIterator.Value() == myFromRedo) break;
}
myRedos.Clear();
myRedos.Assign(aList);
#endif
return Standard_True;
}
//=======================================================================
//function : StorageFormat
//purpose :
//=======================================================================
TCollection_ExtendedString TDocStd_Document::StorageFormat() const
{
return myStorageFormat;
}
//=======================================================================
//function : ChangeStorageFormat
//purpose :
//=======================================================================
void TDocStd_Document::ChangeStorageFormat (const TCollection_ExtendedString& newStorageFormat)
{
if (newStorageFormat != myStorageFormat) {
myStorageFormat = newStorageFormat;
myResourcesAreLoaded = Standard_False;
CDM_Document::LoadResources ();
}
}
//=======================================================================
//function : Recompute
//purpose :
//=======================================================================
void TDocStd_Document::Recompute ()
{
if (IsValid()) return;
// find the top function and execute it
// Handle(TDesign_Function) F;
// if (Main().FindAttribute(TDesign_Function::GetID(),F)) {
// TFunction_Solver slv;
// slv.SetTouched(GetModified());
// slv.ExecuteFrom(F);
PurgeModified();
}
//=======================================================================
//function : AppendDeltaToTheFirst
//purpose : Appends delta to the first delta in the myUndoFILO
//=======================================================================
void TDocStd_Document::AppendDeltaToTheFirst
(const Handle(TDocStd_CompoundDelta)& theDelta1,
const Handle(TDF_Delta)& theDelta2)
{
if(theDelta2->IsEmpty()) return;
TDocStd_LabelIDMapDataMap aMap;
TDF_ListIteratorOfAttributeDeltaList aDeltasIterator1
(theDelta1->AttributeDeltas());
for(; aDeltasIterator1.More(); aDeltasIterator1.Next()) {
TDF_Label aLabel = aDeltasIterator1.Value()->Label();
if(!aMap.IsBound(aLabel)) {
TDF_IDMap aTmpIDMap;
aMap.Bind(aLabel, aTmpIDMap);
}
Standard_GUID anID = aDeltasIterator1.Value()->ID();
TDF_IDMap& anIDMap = aMap.ChangeFind(aLabel);
anIDMap.Add(anID);
}
theDelta1->Validity(theDelta1->BeginTime(), theDelta2->EndTime());
TDF_ListIteratorOfAttributeDeltaList aDeltasIterator2
(theDelta2->AttributeDeltas());
for(; aDeltasIterator2.More(); aDeltasIterator2.Next()) {
TDF_Label aLabel = aDeltasIterator2.Value()->Label();
Standard_GUID anID = aDeltasIterator2.Value()->ID();
if(aMap.IsBound(aLabel)) {
const TDF_IDMap& anIDMap = aMap.Find(aLabel);
if(anIDMap.Contains(anID)) continue;
}
theDelta1->AddAttributeDelta(aDeltasIterator2.Value());
}
}
//=======================================================================
//function : RemoveFirstUndo
//purpose :
//=======================================================================
void TDocStd_Document::RemoveFirstUndo() {
if (myUndos.IsEmpty()) return;
myUndos.RemoveFirst();
}

View File

@@ -0,0 +1,98 @@
// File: TDocStd_Document.lxx
// Created: 19.11.02 10:19:39
// Author: Vladimir ANIKIN
// Copyright: Open CASCADE 2002
#include <TDF_Data.hxx>
//=======================================================================
//function : SetNestedTransactionMode
//purpose : Sets nested transaction mode if isAllowed == Standard_True
//=======================================================================
inline void
TDocStd_Document::SetNestedTransactionMode (const Standard_Boolean isAllowed)
{
myIsNestedTransactionMode = isAllowed;
}
//=======================================================================
//function : SetNestedTransactionMode
//purpose : Sets nested transaction mode if isAllowed == Standard_True
//=======================================================================
inline Standard_Boolean
TDocStd_Document::IsNestedTransactionMode () const
{
return myIsNestedTransactionMode;
}
//=======================================================================
//function : IsModified
//purpose : returns True if document differs from the state of last saving.
// this method have to be called only wroking in the transaction mode
//=======================================================================
inline Standard_Boolean
TDocStd_Document::IsChanged () const
{
return myData->Time() != mySaveTime;
}
//=======================================================================
//function : SetSaved
//purpose : This method have to be called to show document that it has been saved
//=======================================================================
inline void
TDocStd_Document::SetSaved ()
{
mySaveTime = myData->Time();
}
//=======================================================================
//function : SetModificationMode
//purpose : if theTransactionOnly is True changes is denied outside transactions
//=======================================================================
inline void TDocStd_Document::SetModificationMode
(const Standard_Boolean theTransactionOnly)
{
myOnlyTransactionModification = theTransactionOnly;
// deny or allow modifications acording to transaction state
if(myOnlyTransactionModification) {
myData->AllowModification(myUndoTransaction.IsOpen());
}
else {
myData->AllowModification(Standard_True);
}
}
//=======================================================================
//function : ModificationMode
//purpose : returns True if changes allowed only inside transactions
//=======================================================================
inline Standard_Boolean TDocStd_Document::ModificationMode() const
{
return myOnlyTransactionModification;
}
//=======================================================================
//function : SetSavedTime
//purpose : Say to document what it is not saved. Use value, returned earlier by GetSavedTime().
//=======================================================================
inline void TDocStd_Document::SetSavedTime (const Standard_Integer theTime)
{
mySaveTime = theTime;
}
//=======================================================================
//function : GetSavedTime
//purpose : Returns value of <mySavedTime> to be used later in SetSavedTime()
//=======================================================================
inline Standard_Integer TDocStd_Document::GetSavedTime () const
{
return mySaveTime;
}

View File

@@ -0,0 +1,97 @@
-- File: TDocStd_Modified.cdl
-- Created: Mon Jul 12 11:21:21 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
private class Modified from TDocStd inherits Attribute from TDF
---Purpose: Transient attribute wich register modified
-- labels. This attribute is attached to root label.
uses Label from TDF,
Attribute from TDF,
LabelMap from TDF,
RelocationTable from TDF
is
---Purpose: API class methods
-- =================
IsEmpty (myclass; access : Label from TDF)
returns Boolean;
Add (myclass; alabel : Label from TDF)
returns Boolean;
Remove (myclass; alabel : Label from TDF)
returns Boolean;
Contains (myclass; alabel : Label from TDF)
returns Boolean;
Get (myclass; access : Label from TDF)
---Purpose: if <IsEmpty> raise an exception.
---C++: return const &
returns LabelMap from TDF;
Clear (myclass; access : Label from TDF);
---Purpose: remove all modified labels. becomes empty
GetID (myclass)
---C++: return const &
returns GUID from Standard;
---Purpose: Modified methods
-- ================
Create
returns mutable Modified from TDocStd;
IsEmpty (me)
returns Boolean from Standard;
Clear (me : mutable);
AddLabel (me : mutable; L : Label from TDF)
---Purpose: add <L> as modified
returns Boolean from Standard;
RemoveLabel (me : mutable; L : Label from TDF)
---Purpose: remove <L> as modified
returns Boolean from Standard;
Get (me)
---Purpose: returns modified label map
---C++: return const &
returns LabelMap from TDF;
---Category: methodes de TDF_Attribute
-- =========================
ID (me)
---C++: return const &
returns GUID from Standard;
Restore (me: mutable; With : Attribute from TDF);
NewEmpty (me)
returns mutable Attribute from TDF;
Paste (me; Into : mutable Attribute from TDF;
RT : mutable RelocationTable from TDF);
Dump (me; anOS : in out OStream from Standard)
returns OStream from Standard
is redefined;
---C++: return &
fields
myModified : LabelMap from TDF;
end Modified;

223
src/TDocStd/TDocStd_Modified.cxx Executable file
View File

@@ -0,0 +1,223 @@
// File: TDocStd_Modified.cxx
// Created: Mon Jul 12 11:29:07 1999
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDocStd_Modified.ixx>
#include <Standard_DomainError.hxx>
#include <TDF_Data.hxx>
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::IsEmpty(const TDF_Label& access)
{
Handle(TDocStd_Modified) MDF;
if (!access.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
return Standard_True;
}
else return MDF->IsEmpty();
}
//=======================================================================
//function : Add
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::Add(const TDF_Label& alabel)
{
Handle(TDocStd_Modified) MDF;
if (!alabel.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
MDF = new TDocStd_Modified();
alabel.Root().AddAttribute(MDF);
}
return MDF->AddLabel (alabel);
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::Remove(const TDF_Label& alabel)
{
Handle(TDocStd_Modified) MDF;
if (!alabel.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
return Standard_True;
}
else return MDF->RemoveLabel (alabel);
}
//=======================================================================
//function : Contains
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::Contains (const TDF_Label& alabel)
{
Handle(TDocStd_Modified) MDF;
if (!alabel.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
return Standard_False;
}
return (MDF->Get().Contains(alabel));
}
//=======================================================================
//function : Get
//purpose :
//=======================================================================
const TDF_LabelMap& TDocStd_Modified::Get (const TDF_Label& access)
{
Handle(TDocStd_Modified) MDF;
if (!access.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
Standard_DomainError::Raise("TDocStd_Modified::Get : IsEmpty");
}
return MDF->Get();
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void TDocStd_Modified::Clear (const TDF_Label& access)
{
Handle(TDocStd_Modified) MDF;
if (!access.Root().FindAttribute (TDocStd_Modified::GetID(), MDF)) {
return;
}
else MDF->Clear();
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_Modified::GetID()
{
static Standard_GUID TDocStd_ModifiedID ("2a96b622-ec8b-11d0-bee7-080009dc3333");
return TDocStd_ModifiedID;
}
//=======================================================================
//function : TDocStd_Modified
//purpose :
//=======================================================================
TDocStd_Modified::TDocStd_Modified () { }
//=======================================================================
//function : AddLabel
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::AddLabel (const TDF_Label& L)
{
Backup ();
return myModified.Add(L);
}
//=======================================================================
//function : RemoveLabel
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::RemoveLabel (const TDF_Label& L)
{
Backup ();
return myModified.Remove(L);
}
//=======================================================================
//function : IsEmpty
//purpose :
//=======================================================================
Standard_Boolean TDocStd_Modified::IsEmpty () const
{
return myModified.IsEmpty();
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void TDocStd_Modified::Clear ()
{
Backup ();
myModified.Clear();
}
//=======================================================================
//function : Get
//purpose :
//=======================================================================
const TDF_LabelMap& TDocStd_Modified::Get () const
{
return myModified;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_Modified::ID () const { return GetID(); }
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_Modified::NewEmpty () const
{
return new TDocStd_Modified ();
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDocStd_Modified::Restore(const Handle(TDF_Attribute)& With) {
Handle(TDocStd_Modified) MDF = Handle(TDocStd_Modified)::DownCast(With);
myModified = MDF->myModified;
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDocStd_Modified::Paste (const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& RT) const
{
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDocStd_Modified::Dump (Standard_OStream& anOS) const
{
anOS << "Modified";
return anOS;
}

View File

@@ -0,0 +1,159 @@
-- File: TDocStd_MultiTransactionManager.cdl
-- Created: Mon Nov 18 17:52:55 2002
-- Author: Vladimir ANIKIN
-- <van@matrox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2002
class MultiTransactionManager from TDocStd inherits TShared from MMgt
---Purpose: Class for synchronization of transactions within multiple documents.
-- Each transaction of this class involvess one transaction in each modified document.
--
-- The documents to be synchronized should be added explicitly to
-- the manager; then its interface is uesd to ensure that all transactions
-- (Open/Commit, Undo/Redo) are performed synchronously in all managed documents.
--
-- The current implementation does not support nested transactions
-- on multitransaction manager level. It only sets the flag enabling
-- or disabling nested transactions in all its documents, so that
-- a nested transaction can be opened for each particular document
-- with TDocStd_Document class interface.
--
-- NOTE: When you invoke CommitTransaction of multi transaction
-- manager, all nested transaction of its documents will be closed (commited).
uses SequenceOfApplicationDelta from TDocStd,
ExtendedString from TCollection,
Document from TDocStd,
SequenceOfDocument from TDocStd
is
Create returns MultiTransactionManager from TDocStd;
---Purpose: Constructor
SetUndoLimit (me : mutable;
theLimit : Integer from Standard);
---Purpose: Sets undo limit for the manager and all documents.
GetUndoLimit (me)
returns Integer from Standard;
---Purpose: Returns undo limit for the manager.
---C++: inline
Undo (me : mutable);
---Purpose: Undoes the current transaction of the manager.
-- It calls the Undo () method of the document being
-- on top of the manager list of undos (list.First())
-- and moves the list item to the top of the list of manager
-- redos (list.Prepend(item)).
Redo (me : mutable);
---Purpose: Redoes the current transaction of the application. It calls
-- the Redo () method of the document being on top of the
-- manager list of redos (list.First()) and moves the list
-- item to the top of the list of manager undos (list.Prepend(item)).
GetAvailableUndos (me)
returns SequenceOfApplicationDelta from TDocStd;
---Purpose: Returns available manager undos.
---C++: inline
---C++: return const &
GetAvailableRedos (me)
returns SequenceOfApplicationDelta from TDocStd;
---Purpose: Returns available manager redos.
---C++: inline
---C++: return const &
OpenCommand (me : mutable);
---Purpose: Opens transaction in each document and sets the flag that
-- transaction is opened. If there are already opened transactions in the documents,
-- these transactions will be aborted before openning new ones.
AbortCommand (me : mutable);
---Purpose: Unsets the flag of started manager transaction and aborts
-- transaction in each document.
CommitCommand (me : mutable) returns Boolean;
---Purpose: Commits transaction in all documents and fills the transaction manager
-- with the documents that have been changed during the transaction.
-- Returns True if new data has been added to myUndos.
-- NOTE: All nested transactions in the documents will be commited.
CommitCommand (me : mutable;
theName : ExtendedString from TCollection) returns Boolean;
---Purpose: Makes the same steps as the previous function but defines the name for transaction.
-- Returns True if new data has been added to myUndos.
HasOpenCommand (me)
returns Boolean from Standard;
---Purpose: Returns true if a transaction is opened.
---C++: inline
RemoveLastUndo (me : mutable);
---Purpose: Removes undo information from the list of undos of the manager and
-- all documents which have been modified during the transaction.
DumpTransaction(me; theOS : in out OStream from Standard);
---Purpose: Dumps transactions in undos and redos
AddDocument(me : mutable; theDoc : Document from TDocStd);
---Purpose: Adds the document to the transaction manager and
-- checks if it has been already added
RemoveDocument(me : mutable; theDoc : Document from TDocStd);
---Purpose: Removes the document from the transaction manager.
Documents(me) returns SequenceOfDocument from TDocStd;
---Purpose: Returns the added documents to the transaction manager.
---C++: inline
---C++: return const &
SetNestedTransactionMode(me : mutable; isAllowed : Boolean = Standard_True);
---Purpose: Sets nested transaction mode if isAllowed == Standard_True
-- NOTE: field myIsNestedTransactionMode exists only for synchronization
-- between several documents and has no effect on transactions
-- of multitransaction manager.
IsNestedTransactionMode (me)
returns Boolean from Standard;
---Purpose: Returns Standard_True if NestedTransaction mode is set.
---C++: inline
---Purpose: Methods for protection of changes outside transactions
SetModificationMode (me : mutable; theTransactionOnly : Boolean from Standard);
---Purpose: If theTransactionOnly is True, denies all changes outside transactions.
ModificationMode (me) returns Boolean from Standard;
---Purpose: Returns True if changes are allowed only inside transactions.
---C++: inline
ClearUndos (me : mutable);
---Purpose: Clears undos in the manager and in documents.
ClearRedos (me : mutable);
---Purpose: Clears redos in the manager and in documents.
fields
---Purpose: Data framework
myDocuments : SequenceOfDocument from TDocStd;
myUndos : SequenceOfApplicationDelta from TDocStd;
myRedos : SequenceOfApplicationDelta from TDocStd;
myUndoLimit : Integer from Standard;
myOpenTransaction : Boolean from Standard;
---Purpose: A flag for nested transaction mode.
myIsNestedTransactionMode : Boolean from Standard;
---Purpose: Data for protection of changes outside transactions.
myOnlyTransactionModification : Boolean from Standard;
end MultiTransactionManager;

View File

@@ -0,0 +1,368 @@
// File: TDocStd_MultiTransactionManager.cxx
// Created: 19.11.02 16:41:50
// Author: Vladimir ANIKIN
// Copyright: Open CASCADE 2002
#include <TDocStd_MultiTransactionManager.ixx>
#include <TDocStd_Document.hxx>
#include <TDocStd_ApplicationDelta.hxx>
//=======================================================================
//function : TDocStd_MultiTransactionManager
//purpose : Constructor
//=======================================================================
TDocStd_MultiTransactionManager::TDocStd_MultiTransactionManager ()
{
myUndoLimit = 0;
myOpenTransaction = Standard_False;
myIsNestedTransactionMode = Standard_False;
myOnlyTransactionModification = Standard_False;
}
//=======================================================================
//function : SetUndoLimit
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::SetUndoLimit(const Standard_Integer theLimit)
{
myUndoLimit = theLimit;
CommitCommand ();
Standard_Integer n = myUndos.Length() - myUndoLimit;
while (n > 0) {
RemoveLastUndo();
--n;
}
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--)
myDocuments.Value(i)->SetUndoLimit(myUndoLimit);
}
//=======================================================================
//function : Undo
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::Undo()
{
if (myUndos.IsEmpty()) return;
const TDocStd_SequenceOfDocument& docs = myUndos.First()->GetDocuments();
Standard_Integer i;
for (i = docs.Length(); i > 0; i--) {
Handle(TDocStd_Document) doc = docs.Value(i);
if (doc.IsNull() || doc->GetAvailableUndos() == 0) continue;
doc->Undo();
}
myRedos.Prepend(myUndos.First());
myUndos.Remove(1);
myOpenTransaction = Standard_False;
}
//=======================================================================
//function : Redo
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::Redo() {
if (myRedos.IsEmpty()) return;
const TDocStd_SequenceOfDocument& docs = myRedos.First()->GetDocuments();
Standard_Integer i;
for (i = docs.Length(); i > 0; i--) {
Handle(TDocStd_Document) doc = docs.Value(i);
if (doc.IsNull() || doc->GetAvailableRedos() == 0) continue;
doc->Redo();
}
myUndos.Prepend(myRedos.First());
myRedos.Remove(1);
myOpenTransaction = Standard_False;
}
//=======================================================================
//function : OpenCommand
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::OpenCommand() {
if (myOpenTransaction) {
#ifdef DEB
cout << "TDocStd_MultiTransactionManager::OpenCommand(): "
"Can't start new application transaction while a "
"previous one is not commited or aborted" << endl;
#endif
Standard_Failure::Raise("Can't start new application transaction"
"while a previous one is not commited or aborted");
}
myOpenTransaction = Standard_True;
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
while(myDocuments.Value(i)->HasOpenCommand())
myDocuments.Value(i)->AbortCommand();
myDocuments.Value(i)->OpenCommand();
}
}
//=======================================================================
//function : AbortCommand
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::AbortCommand() {
myOpenTransaction = Standard_False;
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
while(myDocuments.Value(i)->HasOpenCommand())
myDocuments.Value(i)->AbortCommand();
}
}
//=======================================================================
//function : CommitCommand
//purpose :
//=======================================================================
Standard_Boolean TDocStd_MultiTransactionManager::CommitCommand()
{
Handle(TDocStd_ApplicationDelta) aDelta = new TDocStd_ApplicationDelta;
Standard_Boolean isCommited = Standard_False;
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
isCommited = Standard_False;
while(myDocuments.Value(i)->HasOpenCommand())
if (myDocuments.Value(i)->CommitCommand())
isCommited = Standard_True;
if(isCommited) {
aDelta->GetDocuments().Append(myDocuments.Value(i));
}
}
if (aDelta->GetDocuments().Length()) {
myUndos.Prepend(aDelta);
if (myUndos.Length() > myUndoLimit) {
RemoveLastUndo();
}
myRedos.Clear();
isCommited = Standard_True;
}
myOpenTransaction = Standard_False;
return isCommited;
}
//=======================================================================
//function : CommitCommand
//purpose :
//=======================================================================
Standard_Boolean TDocStd_MultiTransactionManager::CommitCommand
(const TCollection_ExtendedString& theName)
{
Standard_Boolean isCommited = CommitCommand();
if (isCommited && myUndos.Length())
myUndos.First()->SetName(theName);
return isCommited;
}
//=======================================================================
//function : DumpTransaction
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::DumpTransaction(Standard_OStream& anOS) const
{
Standard_Integer i;
if(myDocuments.Length() == 0)
anOS << "Manager is empty" << endl;
else {
if(myDocuments.Length() == 1)
anOS << "There is one document ( ";
else
anOS << "There are " << myDocuments.Length() << " documents ( ";
for(i = 1; i <= myDocuments.Length(); i++) {
Handle(Standard_Transient) aDoc = myDocuments.Value(i);
anOS << "\"" << (Standard_Transient*)aDoc;
anOS << "\" ";
}
anOS << ") in the manager " << endl;
if(myIsNestedTransactionMode)
anOS << "Nested transaction mode is on" << endl;
else
anOS << "Nested transaction mode is off" << endl;
anOS << " " << endl;
}
for (i = myUndos.Length(); i > 0; i--) {
Handle(TDocStd_ApplicationDelta) delta = myUndos.Value(i);
anOS<<" Undo: ";
delta->Dump(anOS);
if (i == 1) {
anOS<<" < Last action"<<endl;
} else {
anOS<<endl;
}
}
for (i = 1; i <= myRedos.Length(); i++) {
Handle(TDocStd_ApplicationDelta) delta = myRedos.Value(i);
anOS<<" Redo: ";
delta->Dump(anOS);
anOS<<endl;
}
}
//=======================================================================
//function : RemoveLastUndo
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::RemoveLastUndo()
{
if(myUndos.Length() == 0) return;
const TDocStd_SequenceOfDocument& docs = myUndos.Last()->GetDocuments();
Standard_Integer i;
for (i = 1; i <= docs.Length(); i++) {
docs.Value(i)->RemoveFirstUndo();
}
myUndos.Remove(myUndos.Length());
}
//=======================================================================
//function : AddDocument
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::AddDocument
(const Handle(TDocStd_Document)& theDoc)
{
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--)
if(myDocuments.Value(i) == theDoc)
return; // the document is already added to the list
if(theDoc->IsNestedTransactionMode() !=
myIsNestedTransactionMode)
theDoc->SetNestedTransactionMode(myIsNestedTransactionMode);
theDoc->SetModificationMode(myOnlyTransactionModification);
myDocuments.Append(theDoc);
theDoc->SetUndoLimit(myUndoLimit);
if(myOpenTransaction) {
if(!theDoc->HasOpenCommand())
theDoc->OpenCommand();
}
else {
if(theDoc->HasOpenCommand())
theDoc->CommitCommand();
}
theDoc->ClearUndos();
theDoc->ClearRedos();
}
//=======================================================================
//function : RemoveDocument
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::RemoveDocument
(const Handle(TDocStd_Document)& theDoc)
{
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
if(myDocuments.Value(i) == theDoc)
myDocuments.Remove(i);
}
for (i = myUndos.Length(); i > 0; i--) {
Handle(TDocStd_ApplicationDelta) delta = myUndos.Value(i);
TDocStd_SequenceOfDocument& docs = delta->GetDocuments();
for(Standard_Integer j = docs.Length(); j > 0; j--) {
if(docs.Value(j) == theDoc) {
docs.Remove(j);
if(docs.Length() == 0)
myUndos.Remove(i);
}
}
}
for (i = myRedos.Length(); i > 0; i--) {
Handle(TDocStd_ApplicationDelta) delta = myRedos.Value(i);
TDocStd_SequenceOfDocument& docs = delta->GetDocuments();
for(Standard_Integer j = docs.Length(); j > 0; j--) {
if(docs.Value(j) == theDoc) {
docs.Remove(j);
if(docs.Length() == 0)
myRedos.Remove(i);
}
}
}
}
//=======================================================================
//function : SetNestedTransactionMode
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::SetNestedTransactionMode
(const Standard_Boolean isAllowed)
{
myIsNestedTransactionMode = isAllowed;
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
if(myDocuments.Value(i)->IsNestedTransactionMode() != myIsNestedTransactionMode)
myDocuments.Value(i)->SetNestedTransactionMode(myIsNestedTransactionMode);
}
}
//=======================================================================
//function : SetModificationMode
//purpose : if theTransactionOnly is True changes is denied outside transactions
//=======================================================================
void TDocStd_MultiTransactionManager::SetModificationMode
(const Standard_Boolean theTransactionOnly)
{
myOnlyTransactionModification = theTransactionOnly;
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
myDocuments.Value(i)->SetModificationMode(myOnlyTransactionModification);
}
}
//=======================================================================
//function : ClearUndos
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::ClearUndos()
{
AbortCommand();
myUndos.Clear();
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
myDocuments.Value(i)->ClearUndos();
}
}
//=======================================================================
//function : ClearRedos
//purpose :
//=======================================================================
void TDocStd_MultiTransactionManager::ClearRedos()
{
AbortCommand();
myRedos.Clear();
Standard_Integer i;
for(i = myDocuments.Length(); i > 0; i--) {
myDocuments.Value(i)->ClearRedos();
}
}

View File

@@ -0,0 +1,80 @@
// File: TDocStd_MultiTransactionManager.lxx
// Created: 20.11.02 10:05:12
// Author: Vladimir ANIKIN
// Copyright: Open CASCADE 2002
//=======================================================================
//function : GetUndoLimit
//purpose :
//=======================================================================
inline Standard_Integer
TDocStd_MultiTransactionManager::GetUndoLimit() const
{
return myUndoLimit;
}
//=======================================================================
//function : GetAvailableUndos
//purpose :
//=======================================================================
inline const TDocStd_SequenceOfApplicationDelta&
TDocStd_MultiTransactionManager::GetAvailableUndos() const
{
return myUndos;
}
//=======================================================================
//function : GetAvailableRedos
//purpose :
//=======================================================================
inline const TDocStd_SequenceOfApplicationDelta&
TDocStd_MultiTransactionManager::GetAvailableRedos() const
{
return myRedos;
}
//=======================================================================
//function : Documents
//purpose :
//=======================================================================
inline const TDocStd_SequenceOfDocument&
TDocStd_MultiTransactionManager::Documents() const
{
return myDocuments;
}
//=======================================================================
//function : IsNestedTransactionMode
//purpose :
//=======================================================================
inline Standard_Boolean
TDocStd_MultiTransactionManager::IsNestedTransactionMode () const
{
return myIsNestedTransactionMode;
}
//=======================================================================
//function : HasOpenCommand
//purpose :
//=======================================================================
inline Standard_Boolean
TDocStd_MultiTransactionManager::HasOpenCommand () const
{
return myOpenTransaction;
}
//=======================================================================
//function : ModificationMode
//purpose : returns True if changes allowed only inside transactions
//=======================================================================
inline Standard_Boolean TDocStd_MultiTransactionManager::ModificationMode() const
{
return myOnlyTransactionModification;
}

69
src/TDocStd/TDocStd_Owner.cdl Executable file
View File

@@ -0,0 +1,69 @@
-- File: TDocStd_Owner.cdl
-- Created: Mon Jul 12 08:39:13 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
private class Owner from TDocStd inherits Attribute from TDF
---Purpose:
uses Attribute from TDF,
GUID from Standard,
RelocationTable from TDF,
Data from TDF,
Label from TDF,
Document from TDocStd
is
---Purpose: class methods
-- =============
GetID (myclass)
---C++: return const &
returns GUID from Standard;
SetDocument (myclass; indata : Data from TDF; doc : Document from TDocStd);
GetDocument (myclass; ofdata : Data from TDF)
returns Document from TDocStd;
---Purpose: Owner methods
-- ===============
Create
returns mutable Owner from TDocStd;
SetDocument (me : mutable; document : Document from TDocStd);
GetDocument (me)
returns Document from TDocStd;
---Category: methodes de TDF_Attribute
-- =========================
ID (me)
---C++: return const &
returns GUID from Standard;
Restore (me: mutable; With : Attribute from TDF);
NewEmpty (me)
returns mutable Attribute from TDF;
Paste (me; Into : mutable Attribute from TDF;
RT : mutable RelocationTable from TDF);
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard
is redefined;
---C++: return &
fields
myDocument : Document from TDocStd;
end Owner;

131
src/TDocStd/TDocStd_Owner.cxx Executable file
View File

@@ -0,0 +1,131 @@
// File: TDocStd_Owner.cxx
// Created: Mon Jul 12 08:40:14 1999
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDocStd_Owner.ixx>
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_Owner::GetID()
{
static Standard_GUID TDocStd_OwnerID ("2a96b617-ec8b-11d0-bee7-080009dc3333");
return TDocStd_OwnerID;
}
//=======================================================================
//function : SetDocument
//purpose :
//=======================================================================
void TDocStd_Owner::SetDocument (const Handle(TDF_Data)& indata,
const Handle(TDocStd_Document)& D)
{
Handle(TDocStd_Owner) A;
if (!indata->Root().FindAttribute (TDocStd_Owner::GetID(), A)) {
A = new TDocStd_Owner ();
A->SetDocument(D);
indata->Root().AddAttribute(A);
}
else {
Standard_DomainError::Raise("TDocStd_Owner::SetDocument : already called");
}
}
//=======================================================================
//function : GetDocument
//purpose :
//=======================================================================
Handle(TDocStd_Document) TDocStd_Owner::GetDocument (const Handle(TDF_Data)& ofdata)
{
Handle(TDocStd_Owner) A;
if (!ofdata->Root().FindAttribute (TDocStd_Owner::GetID(), A)) {
Standard_DomainError::Raise("TDocStd_Owner::GetDocument : document not found");
}
return A->GetDocument();
}
//=======================================================================
//function : TDocStd_Owner
//purpose :
//=======================================================================
TDocStd_Owner::TDocStd_Owner () { }
//=======================================================================
//function : SetDocument
//purpose :
//=======================================================================
void TDocStd_Owner::SetDocument(const Handle( TDocStd_Document)& D)
{
myDocument = D;
}
//=======================================================================
//function : Get
//purpose :
//=======================================================================
Handle(TDocStd_Document) TDocStd_Owner::GetDocument () const
{ return myDocument;
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_Owner::ID () const { return GetID(); }
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_Owner::NewEmpty () const
{
Handle(TDF_Attribute) dummy;
return dummy;
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDocStd_Owner::Restore(const Handle(TDF_Attribute)& With)
{
}
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDocStd_Owner::Paste (const Handle(TDF_Attribute)& Into,
const Handle(TDF_RelocationTable)& RT) const
{
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDocStd_Owner::Dump (Standard_OStream& anOS) const
{
anOS << "Owner";
return anOS;
}

View File

@@ -0,0 +1,27 @@
-- File: TDocStd_PathParser.cdl
-- Created: Fri Sep 17 17:46:17 1999
-- Author: Denis PASCAL
-- <dp@dingox.paris1.matra-dtv.fr>
---Copyright: Matra Datavision 1999
class PathParser from TDocStd
---Purpose: parse an OS path
uses ExtendedString from TCollection
is
Create (path : ExtendedString from TCollection) returns PathParser from TDocStd;
Parse (me : in out);
Trek(me) returns ExtendedString from TCollection;
Name(me) returns ExtendedString from TCollection;
Extension(me) returns ExtendedString from TCollection;
Path(me) returns ExtendedString from TCollection;
Length (me) returns Integer from Standard;
fields
myPath : ExtendedString from TCollection;
myExtension : ExtendedString from TCollection;
myTrek : ExtendedString from TCollection;
myName : ExtendedString from TCollection;
end;

View File

@@ -0,0 +1,87 @@
// File: TDocStd_PathParser.cxx
// Created: Fri Sep 17 17:51:42 1999
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDocStd_PathParser.ixx>
TDocStd_PathParser::TDocStd_PathParser(const TCollection_ExtendedString& path)
{
myPath = path;
Parse();
}
void TDocStd_PathParser::Parse()
{
TCollection_ExtendedString temp = myPath;
Standard_Integer PointPosition = myPath.SearchFromEnd(TCollection_ExtendedString("."));
if (PointPosition>0)
myExtension = temp.Split(PointPosition);
else
return;
temp.Trunc(PointPosition-1);
Standard_Boolean isFileName = (temp.Length()) ? Standard_True : Standard_False;
Standard_Boolean isTrek = Standard_True;
#ifdef WNT
PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("\\"));
if (!(PointPosition>0))
PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("/"));
if (PointPosition >0)
myName = temp.Split(PointPosition);
else {
if(isFileName) {
myName = temp;
isTrek = Standard_False;}
else
return;
}
#else
PointPosition = temp.SearchFromEnd(TCollection_ExtendedString("/"));
if (PointPosition >0)
myName = temp.Split(PointPosition);
else {
if(isFileName) {
myName = temp;
isTrek = Standard_False;}
else
return;
}
#endif //WNT
if(isTrek) {
temp.Trunc(PointPosition-1);
myTrek = temp;
} else
#ifdef WNT
myTrek = ".\\";
#else
myTrek = "./";
#endif
}
TCollection_ExtendedString TDocStd_PathParser::Extension() const
{
return myExtension;
}
TCollection_ExtendedString TDocStd_PathParser::Name() const
{
return myName;
}
TCollection_ExtendedString TDocStd_PathParser::Trek() const
{
return myTrek;
}
TCollection_ExtendedString TDocStd_PathParser::Path() const
{
return myPath;
}
Standard_Integer TDocStd_PathParser::Length() const
{
return myPath.Length();
}

178
src/TDocStd/TDocStd_XLink.cdl Executable file
View File

@@ -0,0 +1,178 @@
-- File: TDocStd_XLink.cdl
-- --------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Sep 15 1997 Creation
class XLink from TDocStd inherits Attribute from TDF
---Purpose: An attribute to store the path and the entry of
-- external links.
-- These refer from one data structure to a data
-- structure in another document.
uses
GUID from Standard,
AsciiString from TCollection,
Label from TDF,
RelocationTable from TDF,
AttributeDelta from TDF,
Reference from TDF,
XLinkPtr from TDocStd
-- raises
is
-- Class methods ---------------------------------------------------------
Set (myclass; atLabel : Label from TDF)
returns mutable XLink from TDocStd;
---Purpose: Sets an empty external reference, at the label aLabel.
-- -----------------------------------------------------------------------
Create
returns mutable XLink from TDocStd;
---Purpose: Initializes fields.
Update (me : mutable)
returns Reference from TDF;
---Purpose: Updates the data referenced in this external link attribute.
ID(me) returns GUID from Standard
is redefined static;
---Purpose: Returns the ID of the attribute.
--
---C++: return const &
GetID(myclass) returns GUID from Standard;
---Purpose: Returns the GUID for external links.
--
---C++: return const &
DocumentEntry(me : mutable; aDocEntry : AsciiString from TCollection);
---Purpose: Sets the name aDocEntry for the external
-- document in this external link attribute.
DocumentEntry(me)
returns AsciiString from TCollection;
---Purpose: Returns the contents of the document identified by aDocEntry.
-- aDocEntry provides external data to this external link attribute.
---C++ : return const &
LabelEntry(me : mutable; aLabel : Label from TDF);
---Purpose: Sets the label entry for this external link attribute with the label aLabel.
-- aLabel pilots the importation of data from the document entry.
LabelEntry(me : mutable; aLabEntry : AsciiString from TCollection);
---Purpose: Sets the label entry for this external link attribute
-- as a document identified by aLabEntry.
LabelEntry(me)
returns AsciiString from TCollection;
---Purpose: Returns the contents of the field <myLabelEntry>.
--
---C++ : return const &
Next (me : mutable; anXLinkPtr : XLinkPtr from TDocStd)
is private;
---Purpose: Sets the field <myNext> with <anXLinkPtr>.
--
---C++: inline
Next (me)
returns XLinkPtr from TDocStd
is private;
---Purpose: Returns the contents of the field <myNext>.
--
---C++: inline
-- Call back methods.
-- ------------------
AfterAddition(me: mutable)
is redefined static;
---Purpose: Updates the XLinkRoot attribute by adding <me>
-- to its list.
BeforeRemoval(me: mutable)
is redefined static;
---Purpose: Updates the XLinkRoot attribute by removing <me>
-- from its list.
BeforeUndo(me: mutable;
anAttDelta : AttributeDelta from TDF;
forceIt : Boolean from Standard = Standard_False)
returns Boolean from Standard
is redefined;
---Purpose: Something to do before applying <anAttDelta>.
AfterUndo(me: mutable;
anAttDelta : AttributeDelta from TDF;
forceIt : Boolean from Standard = Standard_False)
returns Boolean from Standard
is redefined;
---Purpose: Something to do after applying <anAttDelta>.
-- Modification & Transaction use methods.
-- --------------------------------------
BackupCopy(me) returns mutable Attribute from TDF
is redefined static;
---Purpose: Returns a null handle. Raise allways for ,it is
-- nonsense to use this method.
Restore(me: mutable;
anAttribute : Attribute from TDF)
is redefined static;
---Purpose: Does nothing.
-- Copy use methods
-- ----------------
NewEmpty(me)
returns mutable Attribute from TDF
is redefined static;
---Purpose: Returns a null handle.
Paste(me;
intoAttribute : mutable Attribute from TDF;
aRelocationTable : mutable RelocationTable from TDF)
is redefined static;
---Purpose: Does nothing.
-- Miscelleaneous
-- --------------
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard
is redefined static;
---Purpose: Dumps the attribute on <aStream>.
---C++ : return &
fields
myDocEntry : AsciiString from TCollection;
myLabelEntry : AsciiString from TCollection;
myNext : XLinkPtr from TDocStd;
friends
class XLinkRoot from TDocStd,
class XLinkIterator from TDocStd
end XLink from TDocStd;

264
src/TDocStd/TDocStd_XLink.cxx Executable file
View File

@@ -0,0 +1,264 @@
// File: TDocStd_XLink.cxx
// --------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 15 1997 Creation
#include <TDocStd_XLink.ixx>
#include <Standard_NotImplemented.hxx>
#include <TDF_DeltaOnAddition.hxx>
#include <TDF_DeltaOnRemoval.hxx>
#include <TDF_Tool.hxx>
#include <TDF_Reference.hxx>
#include <TDocStd.hxx>
#include <TDocStd_Document.hxx>
#include <TDocStd_XLinkRoot.hxx>
//=======================================================================
//function : TDocStd_XLink
//purpose :
//=======================================================================
TDocStd_XLink::TDocStd_XLink()
: myNext(NULL)
{}
//=======================================================================
//function : Set
//purpose : Class method.
//=======================================================================
Handle(TDocStd_XLink) TDocStd_XLink::Set (const TDF_Label& atLabel)
{
Handle(TDocStd_XLink) xRef;
if (!atLabel.FindAttribute(TDocStd_XLink::GetID(),xRef)) {
xRef = new TDocStd_XLink;
atLabel.AddAttribute(xRef);
}
return xRef;
}
//=======================================================================
//function : Update
//purpose :
//=======================================================================
Handle(TDF_Reference) TDocStd_XLink::Update ()
{
TDF_Label reflabel;
Handle(TDocStd_Document) refdoc;
Standard_Integer IEntry = myDocEntry.IntegerValue();
Handle(TDocStd_Document) mydoc = TDocStd_Document::Get(Label()); //mon document
refdoc = Handle(TDocStd_Document)::DownCast(mydoc->Document(IEntry));
TDF_Tool::Label(refdoc->GetData(),myLabelEntry,reflabel);
// return TXLink::Import(reflabel,Label());
return TDF_Reference::Set(Label(),reflabel);
}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_XLink::ID() const
{ return GetID(); }
//=======================================================================
//function : GetID
//purpose :
//======================================================================
const Standard_GUID& TDocStd_XLink::GetID()
{
static Standard_GUID myID("5d587400-5690-11d1-8940-080009dc3333");
return myID;
}
//=======================================================================
//function : DocumentEntry
//purpose :
//=======================================================================
void TDocStd_XLink::DocumentEntry
(const TCollection_AsciiString& aDocEntry)
{ Backup(); myDocEntry = aDocEntry; }
//=======================================================================
//function : DocumentEntry
//purpose :
//=======================================================================
const TCollection_AsciiString& TDocStd_XLink::DocumentEntry() const
{ return myDocEntry; }
//=======================================================================
//function : LabelEntry
//purpose :
//=======================================================================
void TDocStd_XLink::LabelEntry
(const TDF_Label& aLabel)
{
Backup();
TDF_Tool::Entry(aLabel,myLabelEntry);
}
//=======================================================================
//function : LabelEntry
//purpose :
//=======================================================================
void TDocStd_XLink::LabelEntry
(const TCollection_AsciiString& aLabEntry)
{ Backup(); myLabelEntry = aLabEntry; }
//=======================================================================
//function : LabelEntry
//purpose :
//=======================================================================
const TCollection_AsciiString& TDocStd_XLink::LabelEntry() const
{ return myLabelEntry; }
//=======================================================================
//function : AfterAddition
//purpose :
//=======================================================================
void TDocStd_XLink::AfterAddition()
{
TDocStd_XLinkRoot::Insert(this);
Label().Imported(Standard_True);
}
//=======================================================================
//function : BeforeRemoval
//purpose :
//=======================================================================
void TDocStd_XLink::BeforeRemoval()
{
if (!IsBackuped()) {
TDocStd_XLinkRoot::Remove(this);
Label().Imported(Standard_False);
}
}
//=======================================================================
//function : BeforeUndo
//purpose : Before application of a TDF_Delta.
//=======================================================================
Standard_Boolean TDocStd_XLink::BeforeUndo
(const Handle(TDF_AttributeDelta)& anAttDelta,
const Standard_Boolean forceIt)
{
if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
anAttDelta->Attribute()->BeforeRemoval();
}
return Standard_True;
}
//=======================================================================
//function : AfterUndo
//purpose : After application of a TDF_Delta.
//=======================================================================
Standard_Boolean TDocStd_XLink::AfterUndo
(const Handle(TDF_AttributeDelta)& anAttDelta,
const Standard_Boolean forceIt)
{
if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval))) {
anAttDelta->Attribute()->AfterAddition();
}
return Standard_True;
}
//=======================================================================
//function : BackupCopy
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_XLink::BackupCopy() const
{
Handle(TDocStd_XLink) xRef = new TDocStd_XLink();
xRef->DocumentEntry(myDocEntry);
xRef->LabelEntry(myLabelEntry);
return xRef;
}
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDocStd_XLink::Restore(const Handle(TDF_Attribute)& anAttribute)
{
const Handle(TDocStd_XLink)& xRef =
Handle(TDocStd_XLink)::DownCast(anAttribute);
if (!xRef.IsNull()) {
myDocEntry = xRef->DocumentEntry();
myLabelEntry = xRef->LabelEntry();
}
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_XLink::NewEmpty() const
{ return new TDocStd_XLink(); }
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDocStd_XLink::Paste
(const Handle(TDF_Attribute)& intoAttribute,
const Handle(TDF_RelocationTable)& aRelocationTable) const
{
const Handle(TDocStd_XLink)& xRef =
Handle(TDocStd_XLink)::DownCast(intoAttribute);
if (!xRef.IsNull()) {
xRef->DocumentEntry(myDocEntry);
xRef->LabelEntry(myLabelEntry);
}
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDocStd_XLink::Dump(Standard_OStream& anOS) const
{
return anOS;
}

17
src/TDocStd/TDocStd_XLink.lxx Executable file
View File

@@ -0,0 +1,17 @@
// File: TDocStd_XLink.lxx
// --------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 16 1997 Creation
inline void TDocStd_XLink::Next(const TDocStd_XLinkPtr& anXLinkPtr)
{ myNext = anXLinkPtr; }
inline TDocStd_XLinkPtr TDocStd_XLink::Next() const
{ return myNext; }

View File

@@ -0,0 +1,59 @@
-- File: TDocStd_XLinkIterator.cdl
-- ----------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Aug 27 1997 Creation
class XLinkIterator from TDocStd
---Purpose: Iterates on Reference attributes.
uses Document from TDocStd,
XLink from TDocStd,
XLinkPtr from TDocStd
raises
NoMoreObject from Standard
is
Create
returns XLinkIterator from TDocStd;
---Purpose: Returns an empty iterator;
Create (D : Document from TDocStd)
returns XLinkIterator from TDocStd;
---Purpose: Creates an iterator on Reference of <D>.
Initialize (me : in out; D : Document from TDocStd);
---Purpose: Restarts an iteration with <D>.
More (me) returns Boolean;
---Purpose: Returns True if there is a current Item in the
-- iteration.
--
---C++: inline
Next (me : in out)
raises NoMoreObject from Standard;
---Purpose: Move to the next item; raises if there is no more item.
Value (me) returns XLinkPtr from TDocStd;
---Purpose: Returns the current item; a null handle if there is none.
--
---C++: inline
Init (me : in out; D : Document from TDocStd) is private;
fields
myValue : XLinkPtr from TDocStd;
end XLinkIterator;

View File

@@ -0,0 +1,71 @@
// File: TDocStd_XLinkIterator.cxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 15 1997 Creation
#include <TDocStd_XLinkIterator.ixx>
#include <TDF_Data.hxx>
#include <TDocStd_XLink.hxx>
#include <TDocStd_XLinkRoot.hxx>
//=======================================================================
//function : TDocStd_XLinkIterator
//purpose :
//=======================================================================
TDocStd_XLinkIterator::TDocStd_XLinkIterator()
: myValue(NULL)
{}
//=======================================================================
//function : TDocStd_XLinkIterator
//purpose :
//=======================================================================
TDocStd_XLinkIterator::TDocStd_XLinkIterator
(const Handle(TDocStd_Document)& DOC)
: myValue(NULL)
{ Init(DOC); }
//=======================================================================
//function : Initialize
//purpose :
//=======================================================================
void TDocStd_XLinkIterator::Initialize(const Handle(TDocStd_Document)& DOC)
{ myValue = NULL; Init(DOC); }
//=======================================================================
//function : Next
//purpose :
//=======================================================================
void TDocStd_XLinkIterator::Next()
{
if (myValue == NULL) Standard_NoMoreObject::Raise("");
else myValue = myValue->Next();
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void TDocStd_XLinkIterator::Init(const Handle(TDocStd_Document)& DOC)
{
Handle(TDocStd_XLinkRoot) xRefRoot;
if (DOC->GetData()->Root().FindAttribute(TDocStd_XLinkRoot::GetID(),xRefRoot))
myValue = xRefRoot->First();
}

View File

@@ -0,0 +1,15 @@
// File: TDocStd_XLinkIterator.lxx
// ----------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 15 1997 Creation
inline Standard_Boolean TDocStd_XLinkIterator::More() const
{ return (myValue != NULL); }
inline TDocStd_XLink* TDocStd_XLinkIterator::Value() const
{ return myValue; }

126
src/TDocStd/TDocStd_XLinkRoot.cdl Executable file
View File

@@ -0,0 +1,126 @@
-- File: TDocStd_XLinkRoot.cdl
-- ------------------------
-- Author: DAUTRY Philippe
-- <fid@fox.paris1.matra-dtv.fr>
---Copyright: MATRA DATAVISION 1997
---Version: 0.0
---History: Version Date Purpose
-- 0.0 Aug 27 1997 Creation
private class XLinkRoot from TDocStd inherits Attribute from TDF
---Purpose: This attribute is the root of all external
-- references contained in a Data from TDF. Only one
-- instance of this class is added to the TDF_Data
-- root label. Starting from this attribute all the
-- Reference are linked together, to be found
-- easely.
uses
GUID from Standard,
Data from TDF,
RelocationTable from TDF,
XLink from TDocStd,
XLinkPtr from TDocStd
-- raises
is
-- CLASS methods.
-- --------------
GetID(myclass) returns GUID from Standard;
---Purpose: Returns the ID: 2a96b61d-ec8b-11d0-bee7-080009dc3333
--
---C++: return const &
Set(myclass; aDF : Data from TDF)
returns XLinkRoot from TDocStd;
---Purpose: Sets an empty XLinkRoot to Root or gets the
-- existing one. Only one attribute per TDF_Data.
Insert(myclass; anXLinkPtr : XLinkPtr from TDocStd);
---Purpose: Inserts <anXLinkPtr> at the beginning of the XLink chain.
Remove(myclass; anXLinkPtr : XLinkPtr from TDocStd);
---Purpose: Removes <anXLinkPtr> from the XLink chain, if it exists.
-- Basic methods.
-- --------------
Create
returns mutable XLinkRoot from TDocStd
is private;
---Purpose: Initializes fields.
-- Information access.
-- -------------------
ID(me) returns GUID from Standard
is redefined static;
---Purpose: Returns the ID of the attribute.
--
---C++: return const &
BackupCopy(me) returns mutable Attribute from TDF
is redefined static;
---Purpose: Returns a null handle.
Restore(me: mutable;
anAttribute : Attribute from TDF)
is redefined static;
---Purpose: Does nothing.
First(me : mutable; anXLinkPtr : XLinkPtr from TDocStd)
is private;
---Purpose: Sets the field <myFirst> with <anXLinkPtr>.
--
---C++: inline
First(me)
returns XLinkPtr from TDocStd
is private;
---Purpose: Returns the contents of the field <myFirst>.
--
---C++: inline
-- Copy use methods
-- ----------------
NewEmpty(me)
returns mutable Attribute from TDF
is redefined static;
---Purpose: Returns a null handle.
Paste(me;
intoAttribute : mutable Attribute from TDF;
aRelocationTable : mutable RelocationTable from TDF)
is redefined static;
---Purpose: Does nothing.
-- Miscelleaneous
-- --------------
Dump(me; anOS : in out OStream from Standard)
returns OStream from Standard
is redefined static;
---Purpose: Dumps the attribute on <aStream>.
---C++ : return &
fields
myFirst : XLinkPtr from TDocStd;
friends
class XLinkIterator from TDocStd
end XLinkRoot;

161
src/TDocStd/TDocStd_XLinkRoot.cxx Executable file
View File

@@ -0,0 +1,161 @@
// File: TDocStd_XLinkRoot.cxx
// ------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 15 1997 Creation
#include <TDocStd_XLinkRoot.ixx>
#include <TDocStd_XLink.hxx>
//=======================================================================
// CLASS METHODS
//=======================================================================
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_XLinkRoot::GetID()
{
static Standard_GUID myID("5d587401-5690-11d1-8940-080009dc3333");
return myID;
}
//=======================================================================
//function : Set
//purpose : CLASS method.
//=======================================================================
Handle(TDocStd_XLinkRoot) TDocStd_XLinkRoot::Set
(const Handle(TDF_Data)& aDF)
{
Handle(TDocStd_XLinkRoot) xRefRoot;
if (!aDF->Root().FindAttribute (TDocStd_XLinkRoot::GetID(),xRefRoot)) {
xRefRoot = new TDocStd_XLinkRoot;
aDF->Root().AddAttribute(xRefRoot);
}
return xRefRoot;
}
//=======================================================================
//function : Insert
//purpose :
//=======================================================================
void TDocStd_XLinkRoot::Insert(const TDocStd_XLinkPtr& anXLinkPtr)
{
Handle(TDocStd_XLinkRoot) xRefRoot =
TDocStd_XLinkRoot::Set(anXLinkPtr->Label().Data());
// Insertion at beginning because the order is not significant.
anXLinkPtr->Next(xRefRoot->First());
xRefRoot->First(anXLinkPtr);
}
//=======================================================================
//function : Remove
//purpose :
//=======================================================================
void TDocStd_XLinkRoot::Remove(const TDocStd_XLinkPtr& anXLinkPtr)
{
Handle(TDocStd_XLinkRoot) xRefRoot;
if (anXLinkPtr->Label().Root().FindAttribute(TDocStd_XLinkRoot::GetID(),
xRefRoot)) {
TDocStd_XLink* previous = xRefRoot->First();
if (previous == anXLinkPtr) {
xRefRoot->First(anXLinkPtr->Next());
previous = NULL; anXLinkPtr->Next(previous);
}
else {
while (previous != NULL && previous->Next() != anXLinkPtr)
previous = previous->Next();
if (previous != NULL) {
previous->Next(anXLinkPtr->Next());
previous = NULL; anXLinkPtr->Next(previous);
}
}
}
}
//=======================================================================
// INSTANCE METHODS
//=======================================================================
//=======================================================================
//function : TDocStd_XLinkRoot
//purpose :
//=======================================================================
TDocStd_XLinkRoot::TDocStd_XLinkRoot()
: myFirst(NULL)
{}
//=======================================================================
//function : ID
//purpose :
//=======================================================================
const Standard_GUID& TDocStd_XLinkRoot::ID() const
{ return GetID(); }
//=======================================================================
//function : BackupCopy
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_XLinkRoot::BackupCopy() const
{ return new TDocStd_XLinkRoot; } // Does nothing.
//=======================================================================
//function : Restore
//purpose :
//=======================================================================
void TDocStd_XLinkRoot::Restore(const Handle(TDF_Attribute)& anAttribute)
{} // Does nothing.
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) TDocStd_XLinkRoot::NewEmpty() const
{ return new TDocStd_XLinkRoot; }
//=======================================================================
//function : Paste
//purpose :
//=======================================================================
void TDocStd_XLinkRoot::Paste
(const Handle(TDF_Attribute)& intoAttribute,
const Handle(TDF_RelocationTable)& aRelocationTable) const
{} // Does nothing.
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
Standard_OStream& TDocStd_XLinkRoot::Dump(Standard_OStream& anOS) const
{ return anOS; }

View File

@@ -0,0 +1,16 @@
// File: TDocStd_XLinkRoot.lxx
// ------------------
// Author: DAUTRY Philippe
// <fid@fox.paris1.matra-dtv.fr>
// Copyright: Matra Datavision 1997
// Version: 0.0
// History: Version Date Purpose
// 0.0 Sep 16 1997 Creation
inline void TDocStd_XLinkRoot::First(const TDocStd_XLinkPtr& anXLinkPtr)
{ myFirst = anXLinkPtr; }
inline TDocStd_XLinkPtr TDocStd_XLinkRoot::First() const
{ return myFirst; }

View File

@@ -0,0 +1,93 @@
-- File: TDocStd_XLinkTool.cdl
-- Created: Tue May 12 10:05:06 1998
-- Author: Isabelle GRIGNON
-- <isg@bigbox.paris1.matra-dtv.fr>
---XLinkToolright: Matra Datavision 1998
class XLinkTool from TDocStd
---Purpose: This tool class is used to copy the content of
-- source label under target label. Only child
-- labels and attributes of source are copied.
-- attributes located out of source scope are not
-- copied by this algorithm.
-- Depending of the called method an external
-- reference is set in the the target document to
-- registred the externallink.
-- Warning1: Nothing is provided in this class about the
-- opportunity to copy, set a link or update it.
-- Such decisions must be under application control.
-- Warning2: If the document manages shapes, use after copy
-- TNaming::ChangeShapes(target,M) to make copy of
-- shapes.
uses Label from TDF,
LabelMap from TDF,
IDFilter from TDF,
RelocationTable from TDF,
DataSet from TDF
is
Create
returns XLinkTool from TDocStd;
CopyWithLink (me : in out; intarget : Label from TDF;
fromsource : Label from TDF);
---Purpose: Copies the content of the label <fromsource> to the label <intarget>.
-- The link is registred with an XLink attribute by <intarget>
-- label. if the content of <fromsource> is not
-- self-contained, and/or <intarget> has already an XLink
-- attribute, an exception is raised.
UpdateLink (me : in out; L : Label);
---Purpose: Update the external reference set at <L>.
-- Example
-- Handle(TDocStd_Document) aDoc;
-- if
-- (!OCAFTest::GetDocument(1,aDoc)) return 1;
-- Handle(TDataStd_Reference) aRef;
-- TDocStd_XLinkTool xlinktool;
-- if
-- (!OCAFTest::Find(aDoc,2),TDataStd_Reference::GetID(),aRef) return 1;
-- xlinktool.UpdateLink(aRef->Label());
-- Exceptions
-- Standard_DomainError if <L> has no XLink attribute.
Copy (me : in out; intarget : Label from TDF;
fromsource : Label from TDF) is virtual;
---Purpose: Copy the content of <fromsource> under
-- <intarget>. Noone link is registred. noone check is done.
-- Example
-- Handle(TDocStd_Document) DOC, XDOC;
-- TDF_Label L, XL;
-- TDocStd_XLinkTool xlinktool;
-- xlinktool.Copy(L,XL);
-- Exceptions:
-- Standard_DomainError if the contents of
-- fromsource are not entirely in the scope of this
-- label, in other words, are not self-contained.
-- !!! ==> Warning:
-- If the document manages shapes use the next way:
-- TDocStd_XLinkTool xlinktool;
-- xlinktool.Copy(L,XL);
-- TopTools_DataMapOfShapeShape M;
-- TNaming::ChangeShapes(target,M);
IsDone (me)
returns Boolean from Standard;
DataSet (me)
returns DataSet from TDF;
RelocationTable (me)
returns RelocationTable from TDF;
fields
isDone : Boolean from Standard is protected;
myDS : DataSet from TDF;
myRT : RelocationTable from TDF;
end XLinkTool;

188
src/TDocStd/TDocStd_XLinkTool.cxx Executable file
View File

@@ -0,0 +1,188 @@
// File: TDocStd_XLinkTool.cxx
// Created: Fri May 21 17:25:10 1999
// Author: Denis PASCAL
// <dp@dingox.paris1.matra-dtv.fr>
#include <TDocStd_XLinkTool.ixx>
// standard copy
#include <TDocStd_Document.hxx>
#include <TDF_Label.hxx>
#include <Standard_GUID.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_LabelList.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_Tool.hxx>
#include <TDF_IDList.hxx>
#include <TDF_IDFilter.hxx>
#include <TDF_ClosureMode.hxx>
#include <TDF_ClosureTool.hxx>
#include <TDF_CopyTool.hxx>
#include <TDF_ComparisonTool.hxx>
#include <TDF_Reference.hxx>
#include <TDocStd_XLink.hxx>
#include <TDataStd_TreeNode.hxx>
#include <Standard_DomainError.hxx>
//=======================================================================
//function : TDocStd_XLinkTool
//purpose :
//=======================================================================
TDocStd_XLinkTool::TDocStd_XLinkTool () {
isDone = Standard_False;
myRT = new TDF_RelocationTable();
}
//=======================================================================
//function : Copy
//purpose :
//=======================================================================
void TDocStd_XLinkTool::Copy (const TDF_Label& target,
const TDF_Label& source)
{
Handle(TDocStd_Document) TARGET,SOURCE;
TARGET = TDocStd_Document::Get(target);
SOURCE = TDocStd_Document::Get(source);
if (TARGET != SOURCE) {
if (!TDF_Tool::IsSelfContained(source)) {
Standard_DomainError::Raise("TDocStd_XLinkTool::Copy : not self-contained");
}
}
// Remove TreeNode, then resotre, if present
Handle(TDataStd_TreeNode) aFather, aPrev, aNext;
Handle(TDataStd_TreeNode) anOldFather, anOldPrev, anOldNext;
Handle(TDataStd_TreeNode) aNode, anOldNode;
if(TDataStd_TreeNode::Find(source, aNode)) {
aFather = aNode->Father();
aPrev = aNode->Previous();
aNext = aNode->Next();
aNode->Remove();
}
if(TDataStd_TreeNode::Find(target, anOldNode)) {
anOldFather = anOldNode->Father();
anOldPrev = anOldNode->Previous();
anOldNext = anOldNode->Next();
anOldNode->Remove();
}
myRT = new TDF_RelocationTable(Standard_True);
myDS = new TDF_DataSet;
Handle(TDF_DataSet) DS = new TDF_DataSet();
TDF_ClosureMode mode(Standard_True); // descendant plus reference
myDS->AddLabel(source);
myRT->SetRelocation(source,target);
TDF_IDFilter filter (Standard_False); // on prend tout
TDF_ClosureTool::Closure(myDS,filter,mode);
TDF_CopyTool::Copy(myDS,myRT);
//TopTools_DataMapOfShapeShape M; // removed to avoid dependence with TNaming
//TNaming::ChangeShapes(target,M);// should be used as postfix after Copy
if(!aNode.IsNull()) {
if(!aPrev.IsNull())
aPrev->InsertAfter(aNode);
else if(!aNext.IsNull()) {
aNext->InsertBefore(aNode);
} else if (!aFather.IsNull())
aNode->SetFather(aFather);
}
if(!anOldNode.IsNull()) {
if(TDataStd_TreeNode::Find(target, anOldNode)) {
if(!anOldPrev.IsNull())
anOldPrev->InsertAfter(anOldNode);
else if(!anOldNext.IsNull()) {
anOldNext->InsertBefore(anOldNode);
} else if (!anOldFather.IsNull())
anOldNode->SetFather(anOldFather);
}
}
isDone = Standard_True;
}
//=======================================================================
//function : CopyWithLink
//purpose :
//=======================================================================
void TDocStd_XLinkTool::CopyWithLink (const TDF_Label& target,
const TDF_Label& source)
{
Handle(TDF_Reference) REF;
if (target.FindAttribute(TDF_Reference::GetID(),REF)) {
Standard_DomainError::Raise(" TDocStd_CopyWithLink : already a ref");
}
Copy(target,source);
if (isDone) {
TCollection_AsciiString xlabelentry, xdocentry;
TDF_Tool::Entry(source,xlabelentry);
Handle(TDocStd_Document) aSourceD = TDocStd_Document::Get(source);
Handle(TDocStd_Document) aTargetD = TDocStd_Document::Get(target);
Standard_Integer aDocEntry = 0;
if(aSourceD != aTargetD)
aDocEntry = aTargetD->CreateReference(aSourceD);
xdocentry = aDocEntry;
Handle(TDocStd_XLink) X = TDocStd_XLink::Set(target);
X->LabelEntry(xlabelentry);
X->DocumentEntry(xdocentry);
TDF_Reference::Set(target,source);
isDone = Standard_True;
}
}
//=======================================================================
//function : UpdateLink
//purpose :
//=======================================================================
void TDocStd_XLinkTool::UpdateLink (const TDF_Label& label)
{
Handle(TDF_Reference) REF;
if (!label.FindAttribute(TDF_Reference::GetID(),REF)) {
Standard_DomainError::Raise(" TDocStd_XLinkTool::UpdateLink : not ref registred");
}
TDocStd_XLinkTool XLinkTool;
Copy (label,REF->Get());
}
//=======================================================================
//function : IsDone
//purpose :
//=======================================================================
Standard_Boolean TDocStd_XLinkTool::IsDone () const
{
return isDone;
}
//=======================================================================
//function : RelocationTable
//purpose :
//=======================================================================
Handle(TDF_RelocationTable) TDocStd_XLinkTool::RelocationTable () const
{
return myRT;
}
//=======================================================================
//function : DataSet
//purpose :
//=======================================================================
Handle(TDF_DataSet) TDocStd_XLinkTool::DataSet () const
{
return myDS;
}