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:
49
src/TObj/FILES
Executable file
49
src/TObj/FILES
Executable file
@@ -0,0 +1,49 @@
|
||||
Handle_TObj_Model.hxx
|
||||
Handle_TObj_Object.hxx
|
||||
TObj_Application.cxx
|
||||
TObj_Application.hxx
|
||||
TObj_Assistant.cxx
|
||||
TObj_Assistant.hxx
|
||||
TObj_CheckModel.cxx
|
||||
TObj_CheckModel.hxx
|
||||
TObj_Common.hxx
|
||||
TObj_Container.hxx
|
||||
TObj_DeletingMode.hxx
|
||||
TObj_HiddenPartition.cxx
|
||||
TObj_HiddenPartition.hxx
|
||||
TObj_LabelIterator.cxx
|
||||
TObj_LabelIterator.hxx
|
||||
TObj_Model.cxx
|
||||
TObj_Model.hxx
|
||||
TObj_ModelIterator.cxx
|
||||
TObj_ModelIterator.hxx
|
||||
TObj_Object.cxx
|
||||
TObj_Object.hxx
|
||||
TObj_ObjectIterator.cxx
|
||||
TObj_ObjectIterator.hxx
|
||||
TObj_OcafObjectIterator.cxx
|
||||
TObj_OcafObjectIterator.hxx
|
||||
TObj_Partition.cxx
|
||||
TObj_Partition.hxx
|
||||
TObj_Persistence.cxx
|
||||
TObj_Persistence.hxx
|
||||
TObj_ReferenceIterator.cxx
|
||||
TObj_ReferenceIterator.hxx
|
||||
TObj_SequenceIterator.cxx
|
||||
TObj_SequenceIterator.hxx
|
||||
TObj_SequenceOfIterator.hxx
|
||||
TObj_SequenceOfObject.cxx
|
||||
TObj_SequenceOfObject.hxx
|
||||
TObj_TIntSparseArray.cxx
|
||||
TObj_TIntSparseArray.hxx
|
||||
TObj_TModel.cxx
|
||||
TObj_TModel.hxx
|
||||
TObj_TNameContainer.cxx
|
||||
TObj_TNameContainer.hxx
|
||||
TObj_TObject.cxx
|
||||
TObj_TObject.hxx
|
||||
TObj_TReference.cxx
|
||||
TObj_TReference.hxx
|
||||
TObj_TXYZ.cxx
|
||||
TObj_TXYZ.hxx
|
||||
TObj.msg
|
26
src/TObj/Handle_TObj_Model.hxx
Executable file
26
src/TObj/Handle_TObj_Model.hxx
Executable file
@@ -0,0 +1,26 @@
|
||||
// File: Handle_TObj_Model.hxx
|
||||
// Created: Mon Nov 22 09:24:32 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef Handle_TObj_Model_HeaderFile
|
||||
#define Handle_TObj_Model_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
//!
|
||||
//! Definition of the handle of TObj_Model
|
||||
//! to decrease dependances
|
||||
//!
|
||||
|
||||
class TObj_Model;
|
||||
|
||||
//! Define handle class for TObj_Model
|
||||
DEFINE_STANDARD_HANDLE(TObj_Model,MMgt_TShared)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
26
src/TObj/Handle_TObj_Object.hxx
Executable file
26
src/TObj/Handle_TObj_Object.hxx
Executable file
@@ -0,0 +1,26 @@
|
||||
// File: Handle_TObj_Object.hxx
|
||||
// Created: Mon Nov 22 09:24:32 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef Handle_TObj_Object_HeaderFile
|
||||
#define Handle_TObj_Object_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
//!
|
||||
//! Definition of the handle of TObj_Object
|
||||
//! to decrease dependances
|
||||
//!
|
||||
|
||||
class TObj_Object;
|
||||
|
||||
//! Define handle class for TObj_Object
|
||||
DEFINE_STANDARD_HANDLE(TObj_Object,MMgt_TShared)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
182
src/TObj/TObj.msg
Executable file
182
src/TObj/TObj.msg
Executable file
@@ -0,0 +1,182 @@
|
||||
!!!!!!!!!! ----- Messages file for TObj packages --------- !!!!!!!!!
|
||||
! Syntax for keywords: NameOfPackage_NameOfClass_NameOfMessage
|
||||
! where NameOfClass is optional or abbreviated
|
||||
!!!!!!!!!! --------------------------------------------------- !!!!!!!!!
|
||||
|
||||
.TObj_DL_VoidItemId
|
||||
Void ID attribute in XML file when loading the library %s
|
||||
|
||||
.TObj_DL_ZeroId
|
||||
Non-positive or irrelevant (%d) ID attribute in XML file when loading the library %s
|
||||
|
||||
.TObj_DL_MissItemData
|
||||
Missing LibraryData element with ID %d in XML file when loading the library %s
|
||||
|
||||
.TObj_DL_NoLibName
|
||||
Cannot find the library "%s" with the type "%s"
|
||||
|
||||
.TObj_DL_TraceReadLib
|
||||
Loading the library %s / %s, version %s, date %s
|
||||
|
||||
.TObj_DL_NoDocument
|
||||
The document %s does not contain data libraries
|
||||
|
||||
.TObj_DL_AlrReadLib
|
||||
The library "%s" for data type "%s" has already been loaded
|
||||
|
||||
.TObj_DL_AlrAddedReader
|
||||
TObj_DataLibrary::AddReader: Warning: this Reader already added to a different DataLibrary
|
||||
|
||||
.TObj_DL_InvalidLibHeader
|
||||
Invalid library header encountered in file %s
|
||||
|
||||
.TObj_DL_NotSupported
|
||||
The data type "%s" not supported
|
||||
|
||||
.TObj_DL_EmptyDL
|
||||
DataLibrary is empty, the file is not created
|
||||
|
||||
.TObj_DL_CannotCreateFile
|
||||
Can't create the file for data library
|
||||
|
||||
.TObj_DL_ErrorClosingFile
|
||||
Error closing the file for data library
|
||||
|
||||
.TObj_DL_DoubledTag
|
||||
Duplicate tag %d found for element "%s" in library "%s", type "%s"
|
||||
|
||||
!!! ---------------- TObj_Application ----------------
|
||||
|
||||
.TObj_Appl_SDriverFailure
|
||||
Error saving document %s : driver failure. Check presence of resource files.
|
||||
|
||||
.TObj_Appl_SWriteFailure
|
||||
Error saving document %s : write failure
|
||||
|
||||
.TObj_Appl_SUnknownFailure
|
||||
Error saving document %s : unknown failure
|
||||
|
||||
.TObj_Appl_RUnknownDocument
|
||||
Error loading document %s : unknown document
|
||||
|
||||
.TObj_Appl_RAlreadyRetrieved
|
||||
Error loading document %s : already retrieved
|
||||
|
||||
.TObj_Appl_RAlreadyRetrievedAndModified
|
||||
Error loading document %s : already retrieved and modified
|
||||
|
||||
.TObj_Appl_RNoDriver
|
||||
Error loading document %s : no appropriate driver was found
|
||||
|
||||
.TObj_Appl_ROpenError
|
||||
Error loading document %s : cannot open file
|
||||
|
||||
.TObj_Appl_RNoVersion
|
||||
Error loading document %s : no version
|
||||
|
||||
.TObj_Appl_RNoModel
|
||||
Error loading document %s : no model
|
||||
|
||||
.TObj_Appl_RNoDocument
|
||||
Error loading document %s : no document
|
||||
|
||||
.TObj_Appl_RFormatFailure
|
||||
Error loading document %s : format failure
|
||||
|
||||
.TObj_Appl_RTypeNotFound
|
||||
Error loading document %s : type not found in schema
|
||||
|
||||
.TObj_Appl_RBadFileFormat
|
||||
Error loading document %s : unrecognized file format
|
||||
|
||||
.TObj_Appl_RMakeFailure
|
||||
Error loading document %s : failure making document
|
||||
|
||||
.TObj_Appl_RPermissionDenied
|
||||
Error loading document %s : permission denied
|
||||
|
||||
.TObj_Appl_RDriverFailure
|
||||
Error loading document %s : driver failure
|
||||
|
||||
.TObj_Appl_RUnknownFail
|
||||
Error loading document %s : unknown failure
|
||||
|
||||
.TObj_Appl_RException
|
||||
Error loading document %s : the file is probably corrupted
|
||||
|
||||
.TObj_Appl_Exception
|
||||
An exception was caught: %s
|
||||
|
||||
!!! ---------------- TObj_Checker ----------------
|
||||
|
||||
.TObj_Ch_RefToNullObj
|
||||
Referencing to NULL object: %s
|
||||
|
||||
.TObj_Ch_BackRefToNullObj
|
||||
Back Referencing to NULL object: %s
|
||||
|
||||
.TObj_Ch_BackRefToDelObj
|
||||
Back Referencing to deleted object: %s
|
||||
|
||||
.TObj_Ch_BackRefError
|
||||
Back Reference Error: %s
|
||||
|
||||
.TObj_Ch_RefWithoutBack
|
||||
Reference without back one: %s
|
||||
|
||||
.TObj_Ch_BackRefWithoutDirect
|
||||
Back Reference without direct one: %s from: %s
|
||||
|
||||
.TObj_Ch_NoAttr
|
||||
Has no attribute %s at label
|
||||
|
||||
.TObj_Ch_NotOcafObj
|
||||
Object is not OCAF Object: %s
|
||||
|
||||
.TObj_Ch_ObjWithoutName
|
||||
Object without name: %s entry %s
|
||||
|
||||
.TObj_Ch_NameNotUnique
|
||||
Name: %s is not unique in the model %s
|
||||
|
||||
.TObj_Ch_NameNotRegistered
|
||||
Name: %s is not registered in names map %s
|
||||
|
||||
.TObj_Ch_RegistrationError
|
||||
Registration Error: name %s, target entry %s, entry %s
|
||||
|
||||
.TObj_Ch_ExtraName
|
||||
Map of model contains the extra name : %s
|
||||
|
||||
.TObj_M_LoadDocument
|
||||
+++++ Load document %s
|
||||
|
||||
.TObj_M_SaveDocument
|
||||
+++++ Save document %s
|
||||
|
||||
.TObj_M_TimeLoading
|
||||
+++++ Fin loading :
|
||||
|
||||
.TObj_M_TimeInit
|
||||
+++++ Fin initializing new model :
|
||||
|
||||
.TObj_M_TimeSaving
|
||||
+++++ Fin saving :
|
||||
|
||||
.TObj_M_WrongFile
|
||||
File %s has wrong content
|
||||
|
||||
.TObj_M_NoWriteAccess
|
||||
Cannot write the file %s, check permissions
|
||||
|
||||
.TObj_Any_FailCreateDir
|
||||
Error creating the directory %s
|
||||
|
||||
.TObj_Any_NoFormatVersion
|
||||
File %s has no format version, probably it is obsolete
|
||||
|
||||
.TObj_Any_WrongFormatVersion
|
||||
File %s has unsupported format version; model is discarded
|
||||
|
||||
.TObj_Any_OldFormatVersion
|
||||
Warning: Model version is updated; it will not be readable by previous versions of application
|
217
src/TObj/TObj_Application.cxx
Executable file
217
src/TObj/TObj_Application.cxx
Executable file
@@ -0,0 +1,217 @@
|
||||
// File: TObj_Application.cxx
|
||||
// Created: Tue Nov 23 11:08:43 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Application.hxx>
|
||||
|
||||
#include <Standard_SStream.hxx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TColStd_SequenceOfExtendedString.hxx>
|
||||
#include <CDM_COutMessageDriver.hxx>
|
||||
#include <Message_Msg.hxx>
|
||||
#include <stdio.h>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
|
||||
|
||||
//=======================================================================
|
||||
//function : GetInstance
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Application) TObj_Application::GetInstance()
|
||||
{
|
||||
static Handle(TObj_Application) anInstance = new TObj_Application;
|
||||
return anInstance;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_Application
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_Application::TObj_Application ()
|
||||
{
|
||||
myMessenger = new Message_Messenger;
|
||||
myMessageDriver = new CDM_COutMessageDriver;
|
||||
myIsVerbose = Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Formats
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
|
||||
{
|
||||
theFormats.Append(TCollection_ExtendedString ("TObjXml"));
|
||||
theFormats.Append(TCollection_ExtendedString ("TObjBin"));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ResourcesName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_CString TObj_Application::ResourcesName()
|
||||
{
|
||||
return Standard_CString("TObj");
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SaveDocument
|
||||
//purpose : Saving the OCAF document
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Application::SaveDocument
|
||||
(const Handle(TDocStd_Document)& theSourceDoc,
|
||||
const char* theTargetFile)
|
||||
{
|
||||
myIsError = Standard_False;
|
||||
TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile);
|
||||
|
||||
CDF_StoreStatus aStatus = SaveAs (theSourceDoc, aPath);
|
||||
myIsError = aStatus != CDF_SS_OK;
|
||||
if (myIsError)
|
||||
{
|
||||
switch (aStatus)
|
||||
{
|
||||
case CDF_SS_DriverFailure:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath);
|
||||
break;
|
||||
case CDF_SS_WriteFailure:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath);
|
||||
break;
|
||||
case CDF_SS_Failure:
|
||||
default:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Release free memory
|
||||
Standard::Purge();
|
||||
return myIsError ? Standard_False : Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LoadDocument
|
||||
//purpose : Loading the OCAF document
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Application::LoadDocument
|
||||
(const char* theSourceFile,
|
||||
Handle(TDocStd_Document)& theTargetDoc)
|
||||
{
|
||||
myIsError = Standard_False;
|
||||
TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile);
|
||||
|
||||
CDF_RetrievableStatus aStatus = (CDF_RetrievableStatus) -1;
|
||||
{
|
||||
try
|
||||
{
|
||||
aStatus = Open (aPath, theTargetDoc);
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
#if defined(_DEBUG) || defined(DEB)
|
||||
ErrorMessage (Message_Msg("TObj_Appl_Exception") <<
|
||||
Standard_Failure::Caught()->GetMessageString());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
myIsError = aStatus != CDF_RS_OK;
|
||||
if (myIsError)
|
||||
{
|
||||
switch (aStatus)
|
||||
{
|
||||
case CDF_RS_UnknownDocument:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath);
|
||||
break;
|
||||
case CDF_RS_AlreadyRetrieved:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath);
|
||||
break;
|
||||
case CDF_RS_AlreadyRetrievedAndModified:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath);
|
||||
break;
|
||||
case CDF_RS_NoDriver:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
|
||||
break;
|
||||
case CDF_RS_UnknownFileDriver:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath);
|
||||
break;
|
||||
case CDF_RS_OpenError:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath);
|
||||
break;
|
||||
case CDF_RS_NoVersion:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath);
|
||||
break;
|
||||
case CDF_RS_NoModel:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath);
|
||||
break;
|
||||
case CDF_RS_NoDocument:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath);
|
||||
break;
|
||||
case CDF_RS_FormatFailure:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath);
|
||||
break;
|
||||
case CDF_RS_TypeNotFoundInSchema:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath);
|
||||
break;
|
||||
case CDF_RS_UnrecognizedFileFormat:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath);
|
||||
break;
|
||||
case CDF_RS_MakeFailure:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath);
|
||||
break;
|
||||
case CDF_RS_PermissionDenied:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath);
|
||||
break;
|
||||
case CDF_RS_DriverFailure:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath);
|
||||
break;
|
||||
case -1:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath);
|
||||
break;
|
||||
default:
|
||||
ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Release free memory
|
||||
Standard::Purge();
|
||||
return myIsError ? Standard_False : Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateNewDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Application::CreateNewDocument
|
||||
(Handle(TDocStd_Document)& theDoc,
|
||||
const TCollection_ExtendedString& theFormat)
|
||||
{
|
||||
myIsError = Standard_False;
|
||||
|
||||
// Create the Document
|
||||
NewDocument (theFormat, theDoc);
|
||||
|
||||
return myIsError ? Standard_False : Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ErrorMessage
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Application::ErrorMessage (const TCollection_ExtendedString &theMsg,
|
||||
const Message_Gravity theLevel)
|
||||
{
|
||||
myMessenger->Send ( theMsg, theLevel );
|
||||
}
|
||||
|
121
src/TObj/TObj_Application.hxx
Executable file
121
src/TObj/TObj_Application.hxx
Executable file
@@ -0,0 +1,121 @@
|
||||
// File: TObj_Application.hxx
|
||||
// Created: Tue Nov 23 11:01:33 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Application_HeaderFile
|
||||
#define TObj_Application_HeaderFile
|
||||
|
||||
#include <TDocStd_Application.hxx>
|
||||
#include <TObj_Common.hxx>
|
||||
#include <Message_Gravity.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
|
||||
class Handle(TObj_Application);
|
||||
class TColStd_SequenceOfExtendedString;
|
||||
|
||||
//!
|
||||
//! This is a base class for OCAF based TObj models
|
||||
//! with declared virtual methods
|
||||
//!
|
||||
|
||||
class TObj_Application : public TDocStd_Application
|
||||
{
|
||||
public:
|
||||
//! Returns static instance of the application
|
||||
Standard_EXPORT static Handle(TObj_Application) GetInstance();
|
||||
|
||||
//! Returns reference to associated messenger handle
|
||||
Standard_EXPORT Handle(Message_Messenger) &Messenger() { return myMessenger; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Load/Save support
|
||||
*/
|
||||
|
||||
//! Saving the OCAF document to a file
|
||||
virtual Standard_EXPORT Standard_Boolean SaveDocument
|
||||
(const Handle(TDocStd_Document)& theSourceDoc,
|
||||
const char* theTargetFile);
|
||||
|
||||
//! Loading the OCAF document from a file
|
||||
virtual Standard_EXPORT Standard_Boolean LoadDocument
|
||||
(const char* theSourceFile,
|
||||
Handle(TDocStd_Document)& theTargetDoc);
|
||||
|
||||
//! Create the OCAF document from scratch
|
||||
virtual Standard_EXPORT Standard_Boolean CreateNewDocument
|
||||
(Handle(TDocStd_Document)& theDoc,
|
||||
const TCollection_ExtendedString& theFormat);
|
||||
|
||||
//! Signal error during Load or Save
|
||||
//! Default imiplementation is empty
|
||||
virtual Standard_EXPORT void ErrorMessage
|
||||
(const TCollection_ExtendedString &theMsg,
|
||||
const Message_Gravity theLevel);
|
||||
|
||||
//! Signal error during Load or Save
|
||||
//! Default imiplementation invoke previous declaration with 0
|
||||
virtual Standard_EXPORT void ErrorMessage
|
||||
(const TCollection_ExtendedString &theMsg)
|
||||
{ ErrorMessage( theMsg, Message_Alarm ); }
|
||||
|
||||
|
||||
//! Sets the verbose flag, meaning that load/save models should show
|
||||
//! CPU and elapsed times
|
||||
void SetVerbose (const Standard_Boolean isVerbose)
|
||||
{ myIsVerbose = isVerbose; }
|
||||
|
||||
//! Returns the verbose flag
|
||||
Standard_Boolean IsVerbose () const
|
||||
{ return myIsVerbose; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Redefined OCAF methods
|
||||
*/
|
||||
|
||||
//! Return name of resource (i.e. "TObj")
|
||||
virtual Standard_EXPORT Standard_CString ResourcesName();
|
||||
|
||||
//! Return format (i.e "TObj")
|
||||
virtual Standard_EXPORT void Formats(TColStd_SequenceOfExtendedString& theFormats);
|
||||
|
||||
//! Defines message driver for CDM layer
|
||||
virtual Standard_EXPORT Handle(CDM_MessageDriver) MessageDriver()
|
||||
{ return myMessageDriver; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Constructor is protected. Use method GetInstance() method to obtain
|
||||
//! the static instance of the object (or derive your own application)
|
||||
Standard_EXPORT TObj_Application();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
|
||||
Standard_Boolean myIsError; //!< error flag
|
||||
Standard_Boolean myIsVerbose; //!< verbose flag
|
||||
Handle(Message_Messenger) myMessenger; //!< messenger
|
||||
Handle(CDM_MessageDriver) myMessageDriver; //!< message driver
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_Application)
|
||||
};
|
||||
|
||||
|
||||
//! Define handle class
|
||||
DEFINE_STANDARD_HANDLE(TObj_Application,TDocStd_Application)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
226
src/TObj/TObj_Assistant.cxx
Executable file
226
src/TObj/TObj_Assistant.cxx
Executable file
@@ -0,0 +1,226 @@
|
||||
// File: TObj_Assistant.cxx
|
||||
// Created: Mon Nov 22 16:55:54 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Assistant.hxx>
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_Model.hxx>
|
||||
#include <TColStd_SequenceOfTransient.hxx>
|
||||
#include <TColStd_SequenceOfAsciiString.hxx>
|
||||
#include <TColStd_IndexedMapOfTransient.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : getModels
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TColStd_SequenceOfTransient& TObj_Assistant::getModels()
|
||||
{
|
||||
static TColStd_SequenceOfTransient sModels;
|
||||
return sModels;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getTypes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TColStd_IndexedMapOfTransient& TObj_Assistant::getTypes()
|
||||
{
|
||||
static TColStd_IndexedMapOfTransient sTypes;
|
||||
return sTypes;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getTypes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Model)& TObj_Assistant::getCurrentModel()
|
||||
{
|
||||
static Handle(TObj_Model) sCurrentModel;
|
||||
return sCurrentModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer& TObj_Assistant::getVersion()
|
||||
{
|
||||
static Standard_Integer sVersion = 0;
|
||||
return sVersion;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FindModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Model) TObj_Assistant::FindModel
|
||||
(const Standard_CString theName)
|
||||
{
|
||||
TCollection_ExtendedString aName( theName );
|
||||
Standard_Integer i = getModels().Length();
|
||||
Handle(TObj_Model) aModel;
|
||||
for(; i > 0; i --)
|
||||
{
|
||||
aModel = Handle(TObj_Model)::DownCast(getModels().Value( i ));
|
||||
if ( aName == aModel->GetModelName()->String() )
|
||||
break;
|
||||
}
|
||||
if (i == 0)
|
||||
aModel.Nullify();
|
||||
|
||||
return aModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BindModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Assistant::BindModel (const Handle(TObj_Model) theModel)
|
||||
{
|
||||
getModels().Append(theModel);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Clear
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Assistant::ClearModelMap ()
|
||||
{
|
||||
getModels().Clear();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FindType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Standard_Type) TObj_Assistant::FindType
|
||||
(const Standard_Integer theTypeIndex)
|
||||
{
|
||||
if(theTypeIndex > 0 && theTypeIndex <= getTypes().Extent())
|
||||
return Handle(Standard_Type)::DownCast(getTypes().FindKey(theTypeIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FindTypeIndex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_Assistant::FindTypeIndex
|
||||
(const Handle(Standard_Type)& theType)
|
||||
{
|
||||
if(!getTypes().Contains(theType))
|
||||
return 0;
|
||||
|
||||
return getTypes().FindIndex(theType);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//class : TObj_Assistant_UnknownType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
class TObj_Assistant_UnknownType : public MMgt_TShared
|
||||
{
|
||||
public:
|
||||
|
||||
TObj_Assistant_UnknownType() {}
|
||||
// Empty constructor
|
||||
|
||||
// CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_Assistant_UnknownType)
|
||||
};
|
||||
|
||||
// Define handle class for TObj_Assistant_UnknownType
|
||||
DEFINE_STANDARD_HANDLE(TObj_Assistant_UnknownType,MMgt_TShared)
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_Assistant_UnknownType,MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_Assistant_UnknownType,MMgt_TShared)
|
||||
|
||||
//=======================================================================
|
||||
//function : BindType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_Assistant::BindType
|
||||
(const Handle(Standard_Type)& theType)
|
||||
{
|
||||
if(theType.IsNull())
|
||||
{
|
||||
Handle(Standard_Transient) anUnknownType;
|
||||
anUnknownType = new TObj_Assistant_UnknownType;
|
||||
return getTypes().Add(anUnknownType);
|
||||
}
|
||||
|
||||
return getTypes().Add(theType);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ClearTypeMap
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Assistant::ClearTypeMap ()
|
||||
{
|
||||
getTypes().Clear();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetCurrentModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Assistant::SetCurrentModel (const Handle(TObj_Model)& theModel)
|
||||
{
|
||||
getCurrentModel() = theModel;
|
||||
getVersion() = -1;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetCurrentModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Model) TObj_Assistant::GetCurrentModel ()
|
||||
{
|
||||
return getCurrentModel();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UnSetCurrentModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Assistant::UnSetCurrentModel ()
|
||||
{
|
||||
getCurrentModel().Nullify();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetAppVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_Assistant::GetAppVersion()
|
||||
{
|
||||
Standard_Integer& aVersion = getVersion();
|
||||
if (aVersion < 0)
|
||||
{
|
||||
Handle(TObj_Model)& aModel = getCurrentModel();
|
||||
if (!aModel.IsNull())
|
||||
aVersion = aModel->GetFormatVersion();
|
||||
}
|
||||
return aVersion;
|
||||
}
|
110
src/TObj/TObj_Assistant.hxx
Executable file
110
src/TObj/TObj_Assistant.hxx
Executable file
@@ -0,0 +1,110 @@
|
||||
// File: TObj_Assistant.hxx
|
||||
// Created: Mon Nov 22 16:57:12 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Assistant_HeaderFile
|
||||
#define TObj_Assistant_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
class Handle(TObj_Model);
|
||||
class TColStd_SequenceOfTransient;
|
||||
class TColStd_SequenceOfAsciiString;
|
||||
class TColStd_IndexedMapOfTransient;
|
||||
|
||||
//! This class provides interface to the static data
|
||||
//! to be used during save or load models.
|
||||
//!
|
||||
//! Static data:
|
||||
//! 1. DataMap of Modeller name - handle to model to be used in loading of references
|
||||
//! 2. Indexed map of Standard_Type to be used during save or load of object type
|
||||
//! 3. Handle to the current model - model that is loaded at the current moment
|
||||
|
||||
class TObj_Assistant
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Interface for DataMap of Modeller name
|
||||
*/
|
||||
|
||||
//! Finds model by name
|
||||
static Standard_EXPORT Handle(TObj_Model)
|
||||
FindModel (const Standard_CString theName);
|
||||
|
||||
//! Binds model to the map
|
||||
static Standard_EXPORT void
|
||||
BindModel (const Handle(TObj_Model) theModel);
|
||||
|
||||
//! Clears all records from the model map
|
||||
static Standard_EXPORT void
|
||||
ClearModelMap ();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Interface for Map of Standard Types
|
||||
*/
|
||||
|
||||
//! Finds Standard_Type by index;
|
||||
//! returns NULL handle if not found
|
||||
static Standard_EXPORT Handle(Standard_Type)
|
||||
FindType (const Standard_Integer theTypeIndex);
|
||||
|
||||
//! Rinds index by Standard_Type;
|
||||
//! returns 0 if not found
|
||||
static Standard_EXPORT Standard_Integer
|
||||
FindTypeIndex (const Handle(Standard_Type)& theType);
|
||||
|
||||
//! Binds Standard_Type to the map;
|
||||
//! returns index of bound type
|
||||
static Standard_EXPORT Standard_Integer
|
||||
BindType (const Handle(Standard_Type)& theType);
|
||||
|
||||
//! Clears map of types
|
||||
static Standard_EXPORT void
|
||||
ClearTypeMap ();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Interface to the current model
|
||||
*/
|
||||
|
||||
//! Sets current model
|
||||
static Standard_EXPORT void
|
||||
SetCurrentModel (const Handle(TObj_Model)& theModel);
|
||||
|
||||
//! Returns current model
|
||||
static Standard_EXPORT Handle(TObj_Model)
|
||||
GetCurrentModel();
|
||||
|
||||
//! Unsets current model
|
||||
static Standard_EXPORT void
|
||||
UnSetCurrentModel ();
|
||||
|
||||
public:
|
||||
|
||||
//! Returns the version of application which wrote the currently read document.
|
||||
//! Returns 0 if it has not been set yet for the current document.
|
||||
static Standard_EXPORT Standard_Integer GetAppVersion();
|
||||
|
||||
private:
|
||||
|
||||
//! Method for taking fields for map of models
|
||||
static Standard_EXPORT TColStd_SequenceOfTransient& getModels();
|
||||
|
||||
//! Method for taking fields for map types
|
||||
static Standard_EXPORT TColStd_IndexedMapOfTransient& getTypes();
|
||||
|
||||
//! Method for taking fields for the Current model
|
||||
static Standard_EXPORT Handle(TObj_Model)& getCurrentModel();
|
||||
|
||||
//! Returns application version
|
||||
static Standard_EXPORT Standard_Integer& getVersion();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
116
src/TObj/TObj_CheckModel.cxx
Executable file
116
src/TObj/TObj_CheckModel.cxx
Executable file
@@ -0,0 +1,116 @@
|
||||
// File: TObj_CheckModel.cxx
|
||||
// Created: 17.04.2007
|
||||
// Author: Michael Sazonov
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_CheckModel.hxx>
|
||||
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
#include <Message_Msg.hxx>
|
||||
#include <Message_Status.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_CheckModel,Message_Algorithm)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_CheckModel,Message_Algorithm)
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_CheckModel::Perform()
|
||||
{
|
||||
ClearStatus();
|
||||
if (myModel.IsNull() || myModel->GetLabel().IsNull())
|
||||
{
|
||||
SetStatus (Message_Fail1);
|
||||
return Standard_False;
|
||||
}
|
||||
return checkReferences();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : checkReferences
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_CheckModel::checkReferences()
|
||||
{
|
||||
// iterate by all objects in the model
|
||||
Handle(TObj_ObjectIterator) anIt;
|
||||
for(anIt = myModel->GetObjects(); anIt->More(); anIt->Next())
|
||||
{
|
||||
Handle(TObj_Object) anObj = anIt->Value();
|
||||
if (anObj.IsNull())
|
||||
{
|
||||
SetStatus (Message_Alarm1, anIt->DynamicType()->Name());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check references
|
||||
Handle(TObj_ObjectIterator) aRefIter;
|
||||
for ( aRefIter = anObj->GetReferences(); aRefIter->More(); aRefIter->Next())
|
||||
{
|
||||
Handle(TObj_Object) aReferred = aRefIter->Value();
|
||||
if (aReferred.IsNull() || ! aReferred->IsAlive())
|
||||
{
|
||||
SetStatus (Message_Alarm2, anObj->GetName());
|
||||
continue;
|
||||
}
|
||||
|
||||
// check availability of corresponding back reference
|
||||
Handle(TObj_ObjectIterator) aBackIter = aReferred->GetBackReferences();
|
||||
if ( aBackIter.IsNull() )
|
||||
continue; // object does not support back references
|
||||
|
||||
for ( ; aBackIter->More(); aBackIter->Next() )
|
||||
if ( aBackIter->Value() == anObj ) break;
|
||||
if ( aBackIter->More() )
|
||||
continue; // ok, back reference found
|
||||
|
||||
if ( IsToFix() )
|
||||
{
|
||||
SetStatus (Message_Warn1, anObj->GetName());
|
||||
aReferred->AddBackReference (anObj);
|
||||
}
|
||||
else
|
||||
SetStatus (Message_Alarm4, anObj->GetName());
|
||||
}
|
||||
|
||||
// Checking back references
|
||||
aRefIter = anObj->GetBackReferences();
|
||||
if ( aRefIter.IsNull() )
|
||||
continue; // object does not support back references
|
||||
TObj_SequenceOfObject aBadBackRefs;
|
||||
for ( ; aRefIter->More(); aRefIter->Next())
|
||||
{
|
||||
Handle(TObj_Object) aReferring = aRefIter->Value();
|
||||
if (aReferring.IsNull() || ! aReferring->IsAlive())
|
||||
{
|
||||
SetStatus (Message_Alarm3, anObj->GetName());
|
||||
continue;
|
||||
}
|
||||
|
||||
Handle(TObj_ObjectIterator) aForwIter = aReferring->GetReferences();
|
||||
for ( ; aForwIter->More(); aForwIter->Next())
|
||||
if ( aForwIter->Value() == anObj ) break;
|
||||
if ( aForwIter->More() )
|
||||
continue; // ok, reference found
|
||||
|
||||
if ( IsToFix() )
|
||||
{
|
||||
SetStatus (Message_Warn2, anObj->GetName());
|
||||
aBadBackRefs.Append (aReferring);
|
||||
}
|
||||
else
|
||||
SetStatus (Message_Alarm5, anObj->GetName());
|
||||
}
|
||||
|
||||
// remove back references to objects that are not referenced actually
|
||||
for ( int i=1; i <= aBadBackRefs.Length(); i++ )
|
||||
anObj->RemoveBackReference (aBadBackRefs(i));
|
||||
}
|
||||
|
||||
return ! GetStatus().IsAlarm() && ! GetStatus().IsFail();
|
||||
}
|
76
src/TObj/TObj_CheckModel.hxx
Executable file
76
src/TObj/TObj_CheckModel.hxx
Executable file
@@ -0,0 +1,76 @@
|
||||
// File: TObj_CheckModel.hxx
|
||||
// Created: 17.04.2007
|
||||
// Author: Michael Sazonov
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_CheckModel_HeaderFile
|
||||
#define TObj_CheckModel_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_Model.hxx>
|
||||
#include <Message_Algorithm.hxx>
|
||||
|
||||
/**
|
||||
* This class provides consistency check of the TObj model.
|
||||
* It collects all inconsistencies in the status bits and prepaires
|
||||
* messages to be sent using SendStatusMessages (SendMessages) method.
|
||||
* It supports also the fix mode, in which some inconsistencies are
|
||||
* corrected.
|
||||
*/
|
||||
|
||||
class TObj_CheckModel: public Message_Algorithm
|
||||
{
|
||||
public:
|
||||
//! Initialize checker by model
|
||||
TObj_CheckModel(const Handle(TObj_Model)& theModel)
|
||||
: myModel (theModel),
|
||||
myToFix (Standard_False)
|
||||
{}
|
||||
|
||||
//! Sets flag allowing fixing inconsistencies
|
||||
void SetToFix(const Standard_Boolean theToFix)
|
||||
{ myToFix = theToFix; }
|
||||
|
||||
//! Returns true if it is allowed to fix inconsistencies
|
||||
Standard_Boolean IsToFix() const
|
||||
{ return myToFix; }
|
||||
|
||||
//! Returns the checked model
|
||||
const Handle(TObj_Model)& GetModel() const
|
||||
{ return myModel; }
|
||||
|
||||
//! Empty virtual destructor
|
||||
virtual ~TObj_CheckModel () {}
|
||||
|
||||
//! Performs all checks. Descendants should call parent method before
|
||||
//! doing own checks.
|
||||
//! This implementation checks OCAF references and back references
|
||||
//! between objects of the model.
|
||||
//! Returns true if no inconsistencies found.
|
||||
virtual Standard_EXPORT Standard_Boolean Perform();
|
||||
|
||||
private:
|
||||
//! Check References (and back references in model).
|
||||
//! This method just tries to find object to that this reference is indicate and
|
||||
//! test if that object is not null or not deleted. Also it test if that object has back
|
||||
//! reference to correct object (object that has forward reference).
|
||||
Standard_EXPORT Standard_Boolean checkReferences();
|
||||
|
||||
private:
|
||||
Handle(TObj_Model) myModel;
|
||||
Standard_Boolean myToFix;
|
||||
|
||||
public:
|
||||
//! Declaration of CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI (TObj_CheckModel)
|
||||
};
|
||||
|
||||
//! Definition of HANDLE object using Standard_DefineHandle.hxx
|
||||
DEFINE_STANDARD_HANDLE (TObj_CheckModel,Message_Algorithm)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
50
src/TObj/TObj_Common.hxx
Executable file
50
src/TObj/TObj_Common.hxx
Executable file
@@ -0,0 +1,50 @@
|
||||
// File: TObj_Common.hxx
|
||||
// Created: Mon Nov 22 13:00:11 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
// Purpose: This header file collects basic definitions
|
||||
// to be included in most of sources
|
||||
|
||||
#ifndef TObj_Common_HeaderFile
|
||||
#define TObj_Common_HeaderFile
|
||||
|
||||
//! Basic CASCADE definitions
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <Standard_Type.hxx>
|
||||
#include <MMgt_TShared.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TCollection_HExtendedString.hxx>
|
||||
#include <Standard_Failure.hxx>
|
||||
|
||||
//! The function IsEqual explicitly defined for Handle(Standard_Transient)
|
||||
//! in order to avoid the problem with implicit using of IsEqual() defined
|
||||
//! for Standard_Address. The problem is that Handle(Standard_Transient)
|
||||
//! have only operator of type casting to (non-const) Standard_Transient*,
|
||||
//! hence this implicit way cannot be used for const Handle(Standard_Transient)
|
||||
inline Standard_Boolean IsEqual(const Handle(Standard_Transient)& One,
|
||||
const Handle(Standard_Transient)& Two)
|
||||
{
|
||||
return One == Two;
|
||||
}
|
||||
|
||||
//! Methods inline implimentation for HExtendedString
|
||||
|
||||
inline Standard_Integer HashCode (const Handle(TCollection_HExtendedString)& theStr,
|
||||
const Standard_Integer theBnd)
|
||||
{
|
||||
return TCollection_ExtendedString::HashCode(theStr->String(), theBnd);
|
||||
}
|
||||
|
||||
inline Standard_Boolean IsEqual (const Handle(TCollection_HExtendedString)& theStr1,
|
||||
const Handle(TCollection_HExtendedString)& theStr2)
|
||||
{
|
||||
return TCollection_ExtendedString::IsEqual(theStr1->String(),theStr2->String());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
38
src/TObj/TObj_Container.hxx
Executable file
38
src/TObj/TObj_Container.hxx
Executable file
@@ -0,0 +1,38 @@
|
||||
// File: TObj_Container.hxx
|
||||
// Created: 22.11.04 13:31:14
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Container_HeaderFile
|
||||
#define TObj_Container_HeaderFile
|
||||
|
||||
#include <NCollection_DefineBaseCollection.hxx>
|
||||
#include <NCollection_DefineDataMap.hxx>
|
||||
#include <NCollection_DefineSequence.hxx>
|
||||
#include <NCollection_DefineHSequence.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_HExtendedString.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_SequenceOfObject.hxx>
|
||||
|
||||
DEFINE_BASECOLLECTION (TObj_CollectionOfLabel, TDF_Label)
|
||||
|
||||
DEFINE_BASECOLLECTION(TObj_CollectionOfPointer, Standard_Address)
|
||||
|
||||
DEFINE_BASECOLLECTION (TObj_CollectionOfHSeqOfObject,
|
||||
Handle(TObj_HSequenceOfObject))
|
||||
|
||||
DEFINE_DATAMAP (TObj_DataMapOfNameLabel, TObj_CollectionOfLabel,
|
||||
Handle(TCollection_HExtendedString), TDF_Label)
|
||||
|
||||
|
||||
DEFINE_DATAMAP (TObj_DataMapOfObjectHSequenceOcafObjects,
|
||||
TObj_CollectionOfHSeqOfObject,
|
||||
Handle_TObj_Object,Handle_TObj_HSequenceOfObject)
|
||||
|
||||
DEFINE_DATAMAP(TObj_DataMapOfStringPointer,TObj_CollectionOfPointer,
|
||||
TCollection_AsciiString,Standard_Address)
|
||||
#endif
|
21
src/TObj/TObj_DeletingMode.hxx
Executable file
21
src/TObj/TObj_DeletingMode.hxx
Executable file
@@ -0,0 +1,21 @@
|
||||
// File: TObj_DeletingMode.hxx
|
||||
// Created: Mon Nov 22 13:00:11 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_DeletingMode_HeaderFile
|
||||
#define TObj_DeletingMode_HeaderFile
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TObj_FreeOnly = 0, //!< Delete objects only without dependence.
|
||||
TObj_KeepDepending, //!< Remove object if depending one will be correct elsewhere.
|
||||
TObj_Forced //!< Delete this object and all depenging object.
|
||||
} TObj_DeletingMode;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
32
src/TObj/TObj_HiddenPartition.cxx
Executable file
32
src/TObj/TObj_HiddenPartition.cxx
Executable file
@@ -0,0 +1,32 @@
|
||||
// File: TObj_HiddenPartition.cxx
|
||||
// Created: Tue Nov 23 11:39:12 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_HiddenPartition.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_HiddenPartition, TObj_Partition)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_HiddenPartition, TObj_Partition)
|
||||
IMPLEMENT_TOBJOCAF_PERSISTENCE(TObj_HiddenPartition)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_HiddenPartition
|
||||
//purpose : constructor
|
||||
//=======================================================================
|
||||
|
||||
Standard_EXPORT TObj_HiddenPartition::TObj_HiddenPartition
|
||||
(const TDF_Label& theLabel):
|
||||
TObj_Partition(theLabel)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetTypeFlags
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_HiddenPartition::GetTypeFlags() const
|
||||
{
|
||||
return TObj_Partition::GetTypeFlags() & (~Visible);
|
||||
}
|
41
src/TObj/TObj_HiddenPartition.hxx
Executable file
41
src/TObj/TObj_HiddenPartition.hxx
Executable file
@@ -0,0 +1,41 @@
|
||||
// File: TObj_HiddenPartition.hxx
|
||||
// Created: Tue Nov 23 11:38:32 2004
|
||||
// Autho: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_HiddenPartition_HeaderFile
|
||||
#define TObj_HiddenPartition_HeaderFile
|
||||
|
||||
#include <TObj_Partition.hxx>
|
||||
|
||||
/**
|
||||
* This class is partition is predefined hidden flag
|
||||
*/
|
||||
|
||||
class TObj_HiddenPartition : public TObj_Partition
|
||||
{
|
||||
public:
|
||||
//! constructor
|
||||
Standard_EXPORT TObj_HiddenPartition (const TDF_Label& theLabel);
|
||||
|
||||
//! Returns all flags of father except Visible
|
||||
virtual Standard_EXPORT Standard_Integer GetTypeFlags() const;
|
||||
|
||||
protected:
|
||||
//! Persistence of TObj object
|
||||
DECLARE_TOBJOCAF_PERSISTENCE(TObj_HiddenPartition,TObj_Partition)
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_HiddenPartition)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_HiddenPartition
|
||||
DEFINE_STANDARD_HANDLE(TObj_HiddenPartition,TObj_Partition)
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
42
src/TObj/TObj_LabelIterator.cxx
Executable file
42
src/TObj/TObj_LabelIterator.cxx
Executable file
@@ -0,0 +1,42 @@
|
||||
// File: TObj_LabelIterator.cxx
|
||||
// Created: Tue Nov 23 11:51:13 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_LabelIterator.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_LabelIterator,TObj_ObjectIterator)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_LabelIterator,TObj_ObjectIterator)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_LabelIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_LabelIterator::TObj_LabelIterator()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_LabelIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_LabelIterator::TObj_LabelIterator(const TDF_Label& theLabel,
|
||||
const Standard_Boolean isRecursive)
|
||||
{
|
||||
Init(theLabel,isRecursive);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_LabelIterator::Next()
|
||||
{
|
||||
myObject.Nullify();
|
||||
myNode.Nullify();
|
||||
MakeStep();
|
||||
}
|
101
src/TObj/TObj_LabelIterator.hxx
Executable file
101
src/TObj/TObj_LabelIterator.hxx
Executable file
@@ -0,0 +1,101 @@
|
||||
// File: TObj_LabelIterator.hxx
|
||||
// Created: Tue Nov 23 11:42:23 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_LabelIterator_HeaderFile
|
||||
#define TObj_LabelIterator_HeaderFile
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
|
||||
/**
|
||||
* This class is a basis for OCAF based iterators.
|
||||
*/
|
||||
|
||||
class TObj_LabelIterator : public TObj_ObjectIterator
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates an Empty Iterator
|
||||
Standard_EXPORT TObj_LabelIterator();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates an iterator an initialize it by theLabel and recursive flag.
|
||||
//! If isRecursive is Standard_True make recursive iterations
|
||||
Standard_EXPORT TObj_LabelIterator
|
||||
(const TDF_Label& theLabel,
|
||||
const Standard_Boolean isRecursive = Standard_False);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Redefined methods
|
||||
*/
|
||||
|
||||
//! Returns True if there is a current Item in the iteration.
|
||||
virtual Standard_EXPORT Standard_Boolean More () const
|
||||
{ return !myNode.IsNull(); }
|
||||
|
||||
//! Move to the next Item
|
||||
virtual Standard_EXPORT void Next ();
|
||||
|
||||
//! Returns the current item
|
||||
virtual Standard_EXPORT Handle(TObj_Object) Value () const
|
||||
{ return myObject; }
|
||||
|
||||
//! Returns the label of the current item
|
||||
inline const TDF_Label& LabelValue() const
|
||||
{ return myNode; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Iterating methods
|
||||
*/
|
||||
|
||||
//! Shifts iterator to the next object
|
||||
virtual Standard_EXPORT void MakeStep() = 0;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
|
||||
//! Initialize Iterator by the theLabel
|
||||
Standard_EXPORT void Init(const TDF_Label& theLabel,
|
||||
const Standard_Boolean isRecursive = Standard_False)
|
||||
{ myIterator.Initialize(theLabel,isRecursive); }
|
||||
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
TDF_Label myNode; //!< Current node
|
||||
TDF_ChildIterator myIterator; //!< OCAF Child iterator
|
||||
Handle(TObj_Object) myObject; //!< Current Object
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_LabelIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_LabelIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_LabelIterator,TObj_ObjectIterator)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
903
src/TObj/TObj_Model.cxx
Executable file
903
src/TObj/TObj_Model.cxx
Executable file
@@ -0,0 +1,903 @@
|
||||
// File: TObj_Model.cxx
|
||||
// Created: Tue Nov 23 09:38:21 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Model.hxx>
|
||||
|
||||
#include <OSD_File.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <Standard_ErrorHandler.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <TCollection_HAsciiString.hxx>
|
||||
#include <TDataStd_Integer.hxx>
|
||||
#include <TDataStd_Real.hxx>
|
||||
#include <TDF_Tool.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <TDocStd_Owner.hxx>
|
||||
|
||||
#include <TObj_Assistant.hxx>
|
||||
#include <TObj_Application.hxx>
|
||||
#include <TObj_CheckModel.hxx>
|
||||
#include <TObj_HiddenPartition.hxx>
|
||||
#include <TObj_LabelIterator.hxx>
|
||||
#include <TObj_ModelIterator.hxx>
|
||||
#include <TObj_Object.hxx>
|
||||
#include <TObj_Partition.hxx>
|
||||
#include <TObj_TObject.hxx>
|
||||
#include <TObj_TModel.hxx>
|
||||
#include <TObj_TNameContainer.hxx>
|
||||
#include <Message_Msg.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_Model,MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_Model,MMgt_TShared)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_Model
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_Model::TObj_Model ()
|
||||
{
|
||||
myMessenger = GetApplication()->Messenger();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetApplication
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Handle(TObj_Application) TObj_Model::GetApplication()
|
||||
{
|
||||
return TObj_Application::GetInstance();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Destructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_Model::~TObj_Model ()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CloseDocument
|
||||
//purpose : free OCAF document
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::CloseDocument (const Handle(TDocStd_Document)& theDoc)
|
||||
{
|
||||
// prevent Abort of the following modifs at document destruction if
|
||||
// a transaction is open: see theDoc->myUndoTransaction.~()
|
||||
if ( theDoc->HasOpenCommand() )
|
||||
theDoc->AbortCommand();
|
||||
|
||||
// Application
|
||||
const Handle(TObj_Application) anApplication = GetApplication();
|
||||
|
||||
// cleanup CAF data
|
||||
// PTV 21.11.2006:
|
||||
//WARNING: It could be better to remove all attributes in OCAF document structure
|
||||
// except TDocStd_Owner attribute.
|
||||
// After all other is dead set to empty document to it and remove it from label
|
||||
// ...
|
||||
// But we still have previous implementation:
|
||||
// - owner
|
||||
Handle(TDocStd_Owner) owner;
|
||||
if (theDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), owner))
|
||||
{
|
||||
Handle_TDocStd_Document empty;
|
||||
owner->SetDocument(empty);
|
||||
}
|
||||
|
||||
// just all other attributes
|
||||
theDoc->Main().Root().ForgetAllAttributes(Standard_True);
|
||||
anApplication->Close( theDoc );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Load
|
||||
//purpose : Loads the model from the file
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::Load (const char* theFile)
|
||||
{
|
||||
// Return status
|
||||
Standard_Boolean aStatus = Standard_True;
|
||||
|
||||
// Document
|
||||
Handle(TDocStd_Document) aDoc;
|
||||
|
||||
// Application
|
||||
const Handle(TObj_Application) anApplication = GetApplication();
|
||||
|
||||
// Current model
|
||||
const Handle(TObj_Model) me = this;
|
||||
TObj_Assistant::SetCurrentModel( me );
|
||||
TObj_Assistant::ClearTypeMap();
|
||||
|
||||
Standard_Boolean isFileEmpty = checkDocumentEmpty( theFile );
|
||||
if ( isFileEmpty )
|
||||
{
|
||||
// theFile is empty, create new TDocStd_Document for this model
|
||||
aStatus = anApplication->CreateNewDocument(aDoc, GetFormat());
|
||||
|
||||
if ( aStatus == Standard_True )
|
||||
{
|
||||
// Put model in a new attribute on root label
|
||||
TDF_Label aLabel = aDoc->Main();
|
||||
Handle(TObj_TModel) anAtr = new TObj_TModel;
|
||||
aLabel.AddAttribute(anAtr);
|
||||
anAtr->Set( me );
|
||||
// Record that label in the model object, and initialise the new model
|
||||
SetLabel(aLabel);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// retrieve TDocStd_Document from <theFile>
|
||||
Messenger()->Send(Message_Msg("TObj_M_LoadDocument") << (Standard_CString)theFile,
|
||||
Message_Info);
|
||||
aStatus = anApplication->LoadDocument(theFile,aDoc);
|
||||
|
||||
if ( aStatus == Standard_True )
|
||||
{
|
||||
// Check for validity of the model read:
|
||||
// if it had wrong type, it has not been not properly restored
|
||||
TDF_Label aLabel = GetLabel();
|
||||
Standard_Boolean isValid = !aLabel.IsNull() && !aDoc.IsNull();
|
||||
{
|
||||
try
|
||||
{
|
||||
isValid = isValid && aLabel.Data() == aDoc->GetData();
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
isValid = Standard_False;
|
||||
}
|
||||
}
|
||||
if (!isValid)
|
||||
{
|
||||
if (!aDoc.IsNull()) CloseDocument (aDoc);
|
||||
myLabel.Nullify();
|
||||
Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile,
|
||||
Message_Alarm);
|
||||
aStatus = Standard_False;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// release document from session
|
||||
// no message is needed as it has been put in anApplication->LoadDocument()
|
||||
if (!aDoc.IsNull()) CloseDocument (aDoc);
|
||||
myLabel.Nullify();
|
||||
}
|
||||
}
|
||||
// initialise the new model
|
||||
if ( aStatus == Standard_True )
|
||||
{
|
||||
Standard_Boolean isInitOk = Standard_False;
|
||||
{
|
||||
try
|
||||
{
|
||||
isInitOk = initNewModel(isFileEmpty);
|
||||
}
|
||||
catch (Standard_Failure)
|
||||
{
|
||||
#if defined(_DEBUG) || defined(DEB)
|
||||
Handle(Standard_Failure) anExc = Standard_Failure::Caught();
|
||||
TCollection_ExtendedString aString(anExc->DynamicType()->Name());
|
||||
aString = aString + ": " + anExc->GetMessageString();
|
||||
Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString);
|
||||
#endif
|
||||
Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile,
|
||||
Message_Alarm);
|
||||
}
|
||||
}
|
||||
if (!isInitOk )
|
||||
{
|
||||
if (!aDoc.IsNull()) CloseDocument (aDoc);
|
||||
myLabel.Nullify();
|
||||
aStatus = Standard_False;
|
||||
}
|
||||
}
|
||||
TObj_Assistant::UnSetCurrentModel();
|
||||
TObj_Assistant::ClearTypeMap();
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFile
|
||||
//purpose : Returns the full file name this model is to be saved to,
|
||||
// or null if the model was not saved yet
|
||||
//=======================================================================
|
||||
|
||||
Handle(TCollection_HAsciiString) TObj_Model::GetFile() const
|
||||
{
|
||||
Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel());
|
||||
if ( !aDoc.IsNull() ) {
|
||||
TCollection_AsciiString anOldPath( aDoc->GetPath() );
|
||||
if ( !anOldPath.IsEmpty() )
|
||||
return new TCollection_HAsciiString( anOldPath );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Save
|
||||
//purpose : Save the model to the same file
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::Save ()
|
||||
{
|
||||
Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel());
|
||||
if ( aDoc.IsNull() )
|
||||
return Standard_False;
|
||||
|
||||
TCollection_AsciiString anOldPath( aDoc->GetPath() );
|
||||
if ( !anOldPath.IsEmpty() )
|
||||
return SaveAs( anOldPath.ToCString() );
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SaveAs
|
||||
//purpose : Save the model to a file
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::SaveAs (const char* theFile)
|
||||
{
|
||||
TObj_Assistant::ClearTypeMap();
|
||||
// OCAF document
|
||||
Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel());
|
||||
if ( aDoc.IsNull() )
|
||||
return Standard_False;
|
||||
|
||||
// checking that file is present on disk
|
||||
/* do not check, because could try to save as new document to existent file
|
||||
if(!access(theFile, 0))
|
||||
{
|
||||
// checking that document has not been changed from last save
|
||||
if(!aDoc->IsChanged())
|
||||
return Standard_True;
|
||||
}
|
||||
*/
|
||||
// checking write access permission
|
||||
FILE *aF = fopen (theFile, "w");
|
||||
if (aF == NULL) {
|
||||
Messenger()->Send (Message_Msg("TObj_M_NoWriteAccess") << (Standard_CString)theFile,
|
||||
Message_Alarm);
|
||||
return Standard_False;
|
||||
}
|
||||
else
|
||||
fclose (aF);
|
||||
|
||||
// store transaction mode
|
||||
Standard_Boolean aTrMode = aDoc->ModificationMode();
|
||||
aDoc->SetModificationMode( Standard_False );
|
||||
// store all trancienmt fields of object in OCAF document if any
|
||||
Handle(TObj_ObjectIterator) anIterator;
|
||||
for(anIterator = GetObjects(); anIterator->More(); anIterator->Next())
|
||||
{
|
||||
Handle(TObj_Object) anOCAFObj = anIterator->Value();
|
||||
if (anOCAFObj.IsNull())
|
||||
continue;
|
||||
anOCAFObj->BeforeStoring();
|
||||
} // end of for(anIterator = ...)
|
||||
// set transaction mode back
|
||||
aDoc->SetModificationMode( aTrMode );
|
||||
|
||||
// Application
|
||||
const Handle(TObj_Application) anApplication = GetApplication();
|
||||
|
||||
// call Application->SaveAs()
|
||||
Standard_Boolean aStatus = anApplication->SaveDocument (aDoc, theFile);
|
||||
|
||||
TObj_Assistant::ClearTypeMap();
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Close
|
||||
//purpose : Close the model and free related OCAF document
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::Close()
|
||||
{
|
||||
// OCAF document
|
||||
TDF_Label aLabel = GetLabel();
|
||||
if ( aLabel.IsNull() )
|
||||
return Standard_False;
|
||||
Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(aLabel);
|
||||
if ( aDoc.IsNull() )
|
||||
return Standard_False;
|
||||
|
||||
CloseDocument (aDoc);
|
||||
|
||||
myLabel.Nullify();
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDocumentModel
|
||||
//purpose : returns model which contains a document with the label
|
||||
// returns NULL handle if label is NULL
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Model) TObj_Model::GetDocumentModel
|
||||
(const TDF_Label& theLabel)
|
||||
{
|
||||
Handle(TObj_Model) aModel;
|
||||
if(theLabel.IsNull())
|
||||
return aModel;
|
||||
|
||||
Handle(TDocStd_Document) aDoc;
|
||||
Handle(TDF_Data) aData = theLabel.Data();
|
||||
TDF_Label aRootL = aData->Root();
|
||||
if ( aRootL.IsNull())
|
||||
return aModel;
|
||||
Handle(TDocStd_Owner) aDocOwnerAtt;
|
||||
if (aRootL.FindAttribute (TDocStd_Owner::GetID(), aDocOwnerAtt))
|
||||
aDoc = aDocOwnerAtt->GetDocument();
|
||||
|
||||
if ( aDoc.IsNull() )
|
||||
return aModel;
|
||||
|
||||
TDF_Label aLabel = aDoc->Main();
|
||||
Handle(TObj_TModel) anAttr;
|
||||
if(aLabel.FindAttribute(TObj_TModel::GetID(), anAttr))
|
||||
aModel = anAttr->Model();
|
||||
|
||||
return aModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetObjects
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_ObjectIterator) TObj_Model::GetObjects() const
|
||||
{
|
||||
Handle(TObj_Model) me = this;
|
||||
return new TObj_ModelIterator(me);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetChildren
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_ObjectIterator) TObj_Model::GetChildren() const
|
||||
{
|
||||
Handle(TObj_Partition) aMainPartition = GetMainPartition();
|
||||
if(aMainPartition.IsNull())
|
||||
return 0;
|
||||
return aMainPartition->GetChildren();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : FindObject
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_Model::FindObject
|
||||
(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const
|
||||
{
|
||||
Handle(TObj_TNameContainer) aDictionary = theDictionary;
|
||||
if ( aDictionary.IsNull() )
|
||||
aDictionary = GetDictionary();
|
||||
Handle(TObj_Object) aResult;
|
||||
//Check is object with given name is present in model
|
||||
if( IsRegisteredName( theName, aDictionary ) )
|
||||
{
|
||||
TDF_Label aLabel = aDictionary->Get().Find( theName );
|
||||
TObj_Object::GetObj( aLabel, aResult );
|
||||
}
|
||||
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetRoot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_Model::GetRoot() const
|
||||
{
|
||||
return getPartition(GetLabel());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetMainPartition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Model::GetMainPartition() const
|
||||
{
|
||||
return getPartition( GetLabel() );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNewName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::SetNewName(const Handle(TObj_Object)& theObject)
|
||||
{
|
||||
Handle(TObj_Partition) aPartition = TObj_Partition::GetPartition(theObject);
|
||||
|
||||
//sets name if partition is found
|
||||
if(aPartition.IsNull()) return;
|
||||
|
||||
Handle(TCollection_HExtendedString) name = aPartition->GetNewName();
|
||||
if ( ! name.IsNull() ) theObject->SetName(name);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsRegisteredName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::IsRegisteredName(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const
|
||||
{
|
||||
Handle(TObj_TNameContainer) aDictionary = theDictionary;
|
||||
if ( aDictionary.IsNull() )
|
||||
aDictionary = GetDictionary();
|
||||
|
||||
if ( aDictionary.IsNull() )
|
||||
return Standard_False;
|
||||
return aDictionary->IsRegistered( theName );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RegisterName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::RegisterName(const Handle(TCollection_HExtendedString)& theName,
|
||||
const TDF_Label& theLabel,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const
|
||||
{
|
||||
Handle(TObj_TNameContainer) aDictionary = theDictionary;
|
||||
if ( aDictionary.IsNull() )
|
||||
aDictionary = GetDictionary();
|
||||
|
||||
if ( !aDictionary.IsNull() )
|
||||
aDictionary->RecordName( theName, theLabel );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UnRegisterName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::UnRegisterName(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const
|
||||
{
|
||||
Handle(TObj_TNameContainer) aDictionary = theDictionary;
|
||||
if ( aDictionary.IsNull() )
|
||||
aDictionary = GetDictionary();
|
||||
|
||||
if ( !aDictionary.IsNull() )
|
||||
aDictionary->RemoveName( theName );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDictionary
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TNameContainer) TObj_Model::GetDictionary() const
|
||||
{
|
||||
Handle(TObj_TNameContainer) A;
|
||||
TDF_Label aLabel = GetLabel();
|
||||
if (!aLabel.IsNull())
|
||||
aLabel.FindAttribute(TObj_TNameContainer::GetID(),A);
|
||||
return A;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getPartition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Model::getPartition
|
||||
(const TDF_Label& theLabel,
|
||||
const Standard_Boolean theHidden) const
|
||||
{
|
||||
Handle(TObj_Partition) aPartition;
|
||||
if(theLabel.IsNull()) return aPartition;
|
||||
Handle(TObj_TObject) A;
|
||||
|
||||
if (!theLabel.FindAttribute (TObj_TObject::GetID(), A))
|
||||
{
|
||||
if (theHidden)
|
||||
aPartition = new TObj_HiddenPartition(theLabel);
|
||||
else
|
||||
aPartition = TObj_Partition::Create(theLabel);
|
||||
}
|
||||
else
|
||||
aPartition = Handle(TObj_Partition)::DownCast(A->Get());
|
||||
|
||||
return aPartition;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getPartition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Model::getPartition
|
||||
(const TDF_Label& theLabel,
|
||||
const Standard_Integer theIndex,
|
||||
const TCollection_ExtendedString& theName,
|
||||
const Standard_Boolean theHidden) const
|
||||
{
|
||||
Handle(TObj_Partition) aPartition;
|
||||
if(theLabel.IsNull()) return aPartition;
|
||||
|
||||
TDF_Label aLabel = theLabel.FindChild(theIndex,Standard_False);
|
||||
Standard_Boolean isNew = Standard_False;
|
||||
// defining is partition new
|
||||
if ( aLabel.IsNull() )
|
||||
{
|
||||
aLabel = theLabel.FindChild(theIndex,Standard_True);
|
||||
isNew = Standard_True;
|
||||
}
|
||||
// obtaining the partition
|
||||
aPartition = getPartition( aLabel, theHidden );
|
||||
|
||||
//setting name to new partition
|
||||
if(isNew)
|
||||
aPartition->SetName(new TCollection_HExtendedString(theName));
|
||||
return aPartition;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : getPartition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Model::getPartition
|
||||
(const Standard_Integer theIndex,
|
||||
const TCollection_ExtendedString& theName,
|
||||
const Standard_Boolean theHidden) const
|
||||
{
|
||||
return getPartition (GetMainPartition()->GetChildLabel(),
|
||||
theIndex, theName, theHidden);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : initNewModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::initNewModel (const Standard_Boolean IsNew)
|
||||
{
|
||||
// set names map
|
||||
TObj_TNameContainer::Set(GetLabel());
|
||||
|
||||
// do something for loaded model.
|
||||
if (!IsNew)
|
||||
{
|
||||
// Register names of model in names map.
|
||||
Handle(TObj_ObjectIterator) anIterator;
|
||||
for(anIterator = GetObjects(); anIterator->More(); anIterator->Next())
|
||||
{
|
||||
Handle(TObj_Object) anOCAFObj = anIterator->Value();
|
||||
if (anOCAFObj.IsNull())
|
||||
continue;
|
||||
anOCAFObj->AfterRetrieval();
|
||||
} // end of for(anIterator = ...)
|
||||
// update back references for loaded model by references
|
||||
updateBackReferences( GetMainPartition() );
|
||||
|
||||
if ( isToCheck() )
|
||||
{
|
||||
// check model consistency
|
||||
Handle(TObj_CheckModel) aCheck = GetChecker();
|
||||
aCheck->Perform();
|
||||
aCheck->SendMessages();
|
||||
// tell that the model has been modified
|
||||
SetModified(Standard_True);
|
||||
}
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : updateBackReferences
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::updateBackReferences (const Handle(TObj_Object)& theObject)
|
||||
{
|
||||
// recursive update back references
|
||||
if ( theObject.IsNull() )
|
||||
return;
|
||||
Handle(TObj_ObjectIterator) aChildren = theObject->GetChildren();
|
||||
for(;aChildren->More() && aChildren->More(); aChildren->Next())
|
||||
{
|
||||
Handle(TObj_Object) aChild = aChildren->Value();
|
||||
updateBackReferences( aChild );
|
||||
}
|
||||
// update back references of reference objects
|
||||
Handle(TObj_LabelIterator) anIter =
|
||||
Handle(TObj_LabelIterator)::DownCast(theObject->GetReferences());
|
||||
|
||||
if(anIter.IsNull()) // to avoid exception
|
||||
return;
|
||||
|
||||
// LH3D15722. Remove all back references to make sure there will be no unnecessary
|
||||
// duplicates, since some back references may already exist after model upgrading.
|
||||
// (do not take care that object can be from other document, because
|
||||
// we do not modify document, all modifications are made in transient fields)
|
||||
for( ; anIter->More() ; anIter->Next())
|
||||
{
|
||||
Handle(TObj_Object) anObject = anIter->Value();
|
||||
if ( !anObject.IsNull() )
|
||||
anObject->RemoveBackReference( theObject, Standard_False );
|
||||
}
|
||||
// and at last create back references
|
||||
anIter = Handle(TObj_LabelIterator)::DownCast(theObject->GetReferences());
|
||||
if(!anIter.IsNull())
|
||||
for( ; anIter->More() ; anIter->Next())
|
||||
{
|
||||
Handle(TObj_Object) anObject = anIter->Value();
|
||||
if ( !anObject.IsNull() )
|
||||
anObject->AddBackReference( theObject );
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDocStd_Document) TObj_Model::GetDocument() const
|
||||
{
|
||||
Handle(TDocStd_Document) D;
|
||||
TDF_Label aLabel = GetLabel();
|
||||
if (!aLabel.IsNull())
|
||||
D = TDocStd_Document::Get(aLabel);
|
||||
return D;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HasOpenCommand
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::HasOpenCommand() const
|
||||
{
|
||||
return GetDocument()->HasOpenCommand();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : OpenCommand
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::OpenCommand() const
|
||||
{
|
||||
GetDocument()->OpenCommand();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CommitCommand
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::CommitCommand() const
|
||||
{
|
||||
GetDocument()->CommitCommand();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AbortCommand
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::AbortCommand() const
|
||||
{
|
||||
GetDocument()->AbortCommand();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsModified
|
||||
//purpose : Status of modification
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::IsModified () const
|
||||
{
|
||||
Handle(TDocStd_Document) aDoc = GetDocument();
|
||||
return aDoc.IsNull() ? Standard_False : aDoc->IsChanged();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetModified
|
||||
//purpose : Status of modification
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::SetModified (const Standard_Boolean theModified)
|
||||
{
|
||||
Handle(TDocStd_Document) aDoc = GetDocument();
|
||||
if (!aDoc.IsNull())
|
||||
{
|
||||
Standard_Integer aSavedTime = aDoc->GetData()->Time();
|
||||
if (theModified)
|
||||
--aSavedTime;
|
||||
aDoc->SetSavedTime (aSavedTime);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : checkDocumentEmpty
|
||||
//purpose : Check whether the document contains the Ocaf data
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::checkDocumentEmpty (const char* theFile)
|
||||
{
|
||||
if (!theFile)
|
||||
return Standard_True;
|
||||
|
||||
TCollection_AsciiString aFile ((Standard_CString) theFile);
|
||||
if (aFile.IsEmpty())
|
||||
return Standard_True;
|
||||
|
||||
OSD_Path aPath (aFile);
|
||||
OSD_File osdfile (aPath);
|
||||
if ( !osdfile.Exists() )
|
||||
return Standard_True;
|
||||
|
||||
FILE* f = fopen( theFile, "r" );
|
||||
if ( f )
|
||||
{
|
||||
Standard_Boolean isZeroLengh = Standard_False;
|
||||
fseek( f, 0, SEEK_END );
|
||||
if ( ftell( f ) == 0 )
|
||||
isZeroLengh = Standard_True;
|
||||
|
||||
fclose( f );
|
||||
return isZeroLengh;
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetGUID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_GUID TObj_Model::GetGUID() const
|
||||
{
|
||||
Standard_GUID aGUID("3bbefb49-e618-11d4-ba38-0060b0ee18ea");
|
||||
return aGUID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFormat
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TCollection_ExtendedString TObj_Model::GetFormat() const
|
||||
{
|
||||
return TCollection_ExtendedString ("TObjBin");
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFormatVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_Model::GetFormatVersion() const
|
||||
{
|
||||
TDF_Label aLabel = GetDataLabel().FindChild(DataTag_FormatVersion,Standard_False);
|
||||
if(aLabel.IsNull())
|
||||
return -1;
|
||||
|
||||
Handle(TDataStd_Integer) aNum;
|
||||
if(!aLabel.FindAttribute ( TDataStd_Integer::GetID(), aNum ))
|
||||
return -1;
|
||||
else
|
||||
return aNum->Get();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetFormatVersion
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::SetFormatVersion(const Standard_Integer theVersion)
|
||||
{
|
||||
TDF_Label aLabel = GetDataLabel().FindChild(DataTag_FormatVersion,Standard_True);
|
||||
TDataStd_Integer::Set(aLabel,theVersion);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : GetDataLabel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TDF_Label TObj_Model::GetDataLabel() const
|
||||
{
|
||||
return GetMainPartition()->GetDataLabel();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::Paste (Handle(TObj_Model) theModel,
|
||||
Handle(TDF_RelocationTable) theRelocTable)
|
||||
{
|
||||
if(theModel.IsNull()) return Standard_False;
|
||||
// clearing dictionary of objects names
|
||||
// theModel->GetDictionary()->NewEmpty()->Paste(theModel->GetDictionary(),
|
||||
// new TDF_RelocationTable);
|
||||
// theModel->GetLabel().ForgetAllAttributes(Standard_True);
|
||||
TObj_TNameContainer::Set(theModel->GetLabel());
|
||||
GetMainPartition()->Clone(theModel->GetLabel(), theRelocTable);
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CopyReferences
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Model::CopyReferences(const Handle(TObj_Model)& theTarget,
|
||||
const Handle(TDF_RelocationTable)& theRelocTable)
|
||||
{
|
||||
Handle(TObj_Object) aMyRoot = GetMainPartition();
|
||||
Handle(TObj_Object) aTargetRoot = theTarget->GetMainPartition();
|
||||
aMyRoot->CopyReferences(aTargetRoot, theRelocTable);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetModelName
|
||||
//purpose : Returns the name of the model
|
||||
// by default returns TObj
|
||||
//=======================================================================
|
||||
|
||||
Handle(TCollection_HExtendedString) TObj_Model::GetModelName() const
|
||||
{
|
||||
Handle(TCollection_HExtendedString) aName =
|
||||
new TCollection_HExtendedString("TObj");
|
||||
return aName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Update
|
||||
//purpose : default implementation is empty
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Model::Update ()
|
||||
{
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetChecker
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_CheckModel) TObj_Model::GetChecker() const
|
||||
{
|
||||
return new TObj_CheckModel (this);
|
||||
}
|
359
src/TObj/TObj_Model.hxx
Executable file
359
src/TObj/TObj_Model.hxx
Executable file
@@ -0,0 +1,359 @@
|
||||
// File: TObj_Model.hxx
|
||||
// Created: Tue Nov 23 9:31:17 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Model_HeaderFile
|
||||
#define TObj_Model_HeaderFile
|
||||
|
||||
#include <Handle_TObj_Model.hxx>
|
||||
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TObj_Partition.hxx>
|
||||
#include <NCollection_DefineBaseCollection.hxx>
|
||||
#include <NCollection_DefineDataMap.hxx>
|
||||
#include <Message_Messenger.hxx>
|
||||
|
||||
class Handle(TObj_Application);
|
||||
class Handle(TObj_TNameContainer);
|
||||
class Handle(TObj_Object);
|
||||
class Handle(TObj_Partition);
|
||||
class Handle(TObj_CheckModel);
|
||||
|
||||
class Handle(TCollection_HExtendedString);
|
||||
class Handle(TDocStd_Document);
|
||||
|
||||
/**
|
||||
* Base class for OCAF based models.
|
||||
* Defines common behaviour for all models based on TObject
|
||||
* classes, basic services to access model objects and common
|
||||
* operations with the model.
|
||||
* Provides default implementation for many methods.
|
||||
*/
|
||||
|
||||
class TObj_Model : public MMgt_TShared
|
||||
{
|
||||
protected:
|
||||
|
||||
//! Model may store some data on the data labels of its main partition
|
||||
//! See TObj_Object for
|
||||
enum DataTag
|
||||
{
|
||||
DataTag_FormatVersion = TObj_Partition::DataTag_Last,
|
||||
DataTag_Last
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructors and Persistence
|
||||
*/
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_Model ();
|
||||
|
||||
//! Destructor closes the model
|
||||
Standard_EXPORT ~TObj_Model ();
|
||||
|
||||
//! Check whether the document contains the OCAF data.
|
||||
//! This implementation checks theFile on NULL only.
|
||||
Standard_EXPORT virtual Standard_Boolean checkDocumentEmpty (const char* theFile);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Messages mechanism
|
||||
*/
|
||||
|
||||
//! Set messenger to use for messages output
|
||||
Standard_EXPORT void SetMessenger (const Handle(Message_Messenger) &theMsgr) { myMessenger = theMsgr; }
|
||||
|
||||
//! Get messenger used for messages output (by default, the messenger from
|
||||
//! application is used)
|
||||
Standard_EXPORT Handle(Message_Messenger) Messenger () const { return myMessenger; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Implementation of Load/Save for OCAF based models
|
||||
*/
|
||||
|
||||
//! Load the OCAF model from a file
|
||||
virtual Standard_EXPORT Standard_Boolean Load (const char* theFile);
|
||||
|
||||
//! Save the model to a file
|
||||
virtual Standard_EXPORT Standard_Boolean SaveAs (const char* theFile);
|
||||
|
||||
//! Save the model to the same file
|
||||
Standard_EXPORT Standard_Boolean Save ();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Work with document
|
||||
*/
|
||||
|
||||
//! Close the model
|
||||
virtual Standard_EXPORT Standard_Boolean Close();
|
||||
|
||||
//! Close Free OCAF document
|
||||
Standard_EXPORT void CloseDocument (const Handle(TDocStd_Document)& theDoc);
|
||||
|
||||
//! Returns model which contains a document with the label,
|
||||
//! or NULL handle if label is NULL
|
||||
static Standard_EXPORT Handle(TObj_Model) GetDocumentModel (const TDF_Label& theLabel);
|
||||
|
||||
//! Returns the full file name this model is to be saved to,
|
||||
//! or null if the model was not saved yet
|
||||
virtual Standard_EXPORT Handle(TCollection_HAsciiString) GetFile() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Access to the objects in the model
|
||||
*/
|
||||
|
||||
//! Returns an Iterator on all objects in the Model
|
||||
virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetObjects () const;
|
||||
|
||||
//! Returns an Iterator on objects in the main partition
|
||||
virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetChildren () const;
|
||||
|
||||
//! Returns an Object by given Name (or Null if not found).
|
||||
virtual Standard_EXPORT Handle(TObj_Object) FindObject
|
||||
(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const;
|
||||
|
||||
//! Returns the tool checking model consistency.
|
||||
//! Descendant may redefine it to return its own tool.
|
||||
virtual Standard_EXPORT Handle(TObj_CheckModel) GetChecker() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for iteration on the model
|
||||
*/
|
||||
|
||||
//! Returns root object of model
|
||||
virtual Standard_EXPORT Handle(TObj_Object) GetRoot() const;
|
||||
|
||||
//! Returns root object of model
|
||||
Standard_EXPORT Handle(TObj_Partition) GetMainPartition() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* OCAF methods
|
||||
*/
|
||||
|
||||
//! Returns OCAF label on which model data are stored.
|
||||
TDF_Label GetLabel() const { return myLabel; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for supporting unique naming of the objects in model
|
||||
*/
|
||||
|
||||
//! Returns the name of the model
|
||||
virtual Standard_EXPORT Handle(TCollection_HExtendedString) GetModelName() const;
|
||||
|
||||
//! Sets new unique name for the object
|
||||
static Standard_EXPORT void SetNewName
|
||||
(const Handle(TObj_Object)& theObject);
|
||||
|
||||
//! Returns True is name is registered in the names map
|
||||
//! The input argument may be NULL handle, then model check in own global container
|
||||
Standard_EXPORT Standard_Boolean IsRegisteredName
|
||||
(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const;
|
||||
|
||||
//! Register name in the map
|
||||
//! The input argument may be NULL handle, then model check in own global container
|
||||
Standard_EXPORT void RegisterName
|
||||
(const Handle(TCollection_HExtendedString)& theName,
|
||||
const TDF_Label& theLabel,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const;
|
||||
|
||||
//! Unregisters name from the map
|
||||
//! The input argument may be NULL handle, then model check in own global container
|
||||
Standard_EXPORT void UnRegisterName
|
||||
(const Handle(TCollection_HExtendedString)& theName,
|
||||
const Handle(TObj_TNameContainer)& theDictionary ) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* API for transaction mechanism
|
||||
*/
|
||||
|
||||
//! Returns True if a Command transaction is open
|
||||
//! Starting, finishing the transaction
|
||||
Standard_EXPORT Standard_Boolean HasOpenCommand() const;
|
||||
|
||||
//! Open a new command transaction.
|
||||
Standard_EXPORT void OpenCommand() const;
|
||||
|
||||
//! Commit the Command transaction. Do nothing If there is no Command
|
||||
//! transaction open.
|
||||
Standard_EXPORT void CommitCommand() const;
|
||||
|
||||
//! Abort the Command transaction. Do nothing If there is no Command
|
||||
//! transaction open.
|
||||
Standard_EXPORT void AbortCommand() const;
|
||||
|
||||
//! Modification status
|
||||
virtual Standard_EXPORT Standard_Boolean IsModified () const;
|
||||
|
||||
//! Sets modification status
|
||||
Standard_EXPORT void SetModified (const Standard_Boolean theModified);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for obtaining application
|
||||
*/
|
||||
|
||||
//! Returns handle to static instance of the relevant application class
|
||||
virtual Standard_EXPORT const Handle(TObj_Application) GetApplication();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for obtaining the version of Format
|
||||
*/
|
||||
|
||||
//! Returns the format for save/restore.
|
||||
//! This implementation returns "BinOcaf". The method should be redefined
|
||||
//! for those models that should use another format.
|
||||
virtual Standard_EXPORT TCollection_ExtendedString GetFormat() const;
|
||||
|
||||
//! Returns the version of format stored in TObj file
|
||||
Standard_EXPORT Standard_Integer GetFormatVersion() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Methods for handling the version of the Format
|
||||
*/
|
||||
|
||||
//! Sets the format version to save
|
||||
Standard_EXPORT void SetFormatVersion(const Standard_Integer theVersion);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for updating model
|
||||
*/
|
||||
|
||||
//! this method is called before activating this model
|
||||
virtual Standard_EXPORT Standard_Boolean Update ();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Definition of interface GUID
|
||||
*/
|
||||
|
||||
//! Defines interface GUID for TObj_Model
|
||||
virtual Standard_EXPORT Standard_GUID GetGUID () const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
|
||||
//! Returns the map of names of the objects
|
||||
Standard_EXPORT Handle(TObj_TNameContainer) GetDictionary() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
|
||||
//! Returns (or creates a new) partition on a given label
|
||||
Standard_EXPORT Handle(TObj_Partition) getPartition
|
||||
(const TDF_Label& theLabel,
|
||||
const Standard_Boolean theHidden=Standard_False) const;
|
||||
|
||||
//! Returns Partition specified by its index number on a given label
|
||||
//! If not exists, creates anew with specified name
|
||||
Standard_EXPORT Handle(TObj_Partition) getPartition
|
||||
(const TDF_Label& theLabel,
|
||||
const Standard_Integer theIndex,
|
||||
const TCollection_ExtendedString& theName,
|
||||
const Standard_Boolean theHidden=Standard_False) const;
|
||||
|
||||
//! Returns Partition specified by its index number
|
||||
//! If not exists, creates anew with specified name
|
||||
Standard_EXPORT Handle(TObj_Partition) getPartition
|
||||
(const Standard_Integer theIndex,
|
||||
const TCollection_ExtendedString& theName,
|
||||
const Standard_Boolean theHidden=Standard_False) const;
|
||||
|
||||
public:
|
||||
|
||||
//! Returns OCAF document of Model
|
||||
Standard_EXPORT Handle(TDocStd_Document) GetDocument() const;
|
||||
|
||||
protected:
|
||||
// all that labels is sublabels of main partition
|
||||
|
||||
//! Returns the labels under which the data is stored.
|
||||
//! the data stored from the third sublabel of this one.
|
||||
Standard_EXPORT TDF_Label GetDataLabel() const;
|
||||
|
||||
public:
|
||||
|
||||
//! Sets OCAF label on which model data are stored.
|
||||
//! Used by persistence mechanism.
|
||||
void Standard_EXPORT SetLabel(const TDF_Label& theLabel) { myLabel = theLabel; }
|
||||
|
||||
protected:
|
||||
|
||||
//! Do the necessary initialisations after creation of a new model.
|
||||
//! This function is called by LoadModel after creation of OCAF document
|
||||
//! and setting myModel on its main label.
|
||||
//! Default implementation does nothing.
|
||||
//! Returns True is model sucsesfully initialized
|
||||
virtual Standard_EXPORT Standard_Boolean initNewModel
|
||||
(const Standard_Boolean IsNew);
|
||||
|
||||
//! Updates back references of object
|
||||
//! Recursive method.
|
||||
virtual Standard_EXPORT void updateBackReferences
|
||||
(const Handle(TObj_Object)& theObject);
|
||||
|
||||
//! Returns boolean value is to check model in Init new model
|
||||
//! The check could be useful if version of model changed
|
||||
//! Default implementation returns FALSE (check turned OFF)
|
||||
virtual Standard_EXPORT Standard_Boolean isToCheck() const
|
||||
{ return Standard_True; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for clone model
|
||||
*/
|
||||
|
||||
//! Pastes me to the new model
|
||||
//! references will not be copied if theRelocTable is not 0
|
||||
//! if theRelocTable is not NULL theRelocTable is filled by objects
|
||||
virtual Standard_EXPORT Standard_Boolean Paste
|
||||
(Handle(TObj_Model) theModel,
|
||||
Handle(TDF_RelocationTable) theRelocTable = 0);
|
||||
|
||||
//! This function have to create a new model with type like me
|
||||
virtual Standard_EXPORT Handle(TObj_Model) NewEmpty() = 0;
|
||||
|
||||
//! Copy references from me to the other
|
||||
Standard_EXPORT void CopyReferences
|
||||
(const Handle(TObj_Model)& theTarget,
|
||||
const Handle(TDF_RelocationTable)& theRelocTable);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
|
||||
TDF_Label myLabel; //!< Root label of the model in OCAF document
|
||||
Handle(Message_Messenger) myMessenger; //!< Messenger object
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_Model)
|
||||
};
|
||||
|
||||
//! The Model Handle is defined in a separate header file
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
78
src/TObj/TObj_ModelIterator.cxx
Executable file
78
src/TObj/TObj_ModelIterator.cxx
Executable file
@@ -0,0 +1,78 @@
|
||||
// File: TObj_ModelIterator.cxx
|
||||
// Created: Tue Nov 23 11:58:14 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_ModelIterator.hxx>
|
||||
|
||||
#include <TObj_Model.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_ModelIterator,TObj_ObjectIterator)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_ModelIterator,TObj_ObjectIterator)
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_ModelIterator::TObj_ModelIterator(const Handle(TObj_Model)& theModel)
|
||||
{
|
||||
myObject = theModel->GetRoot();
|
||||
if ( ! myObject.IsNull() )
|
||||
addIterator(myObject);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : addIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_ModelIterator::addIterator(const Handle(TObj_Object)& theObj)
|
||||
{
|
||||
Handle(TObj_ObjectIterator) anIter = theObj->GetChildren();
|
||||
if (anIter.IsNull() )
|
||||
return; // object has no children.
|
||||
myIterSeq.Append(anIter);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_ModelIterator::More() const
|
||||
{
|
||||
return ! myObject.IsNull();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_ModelIterator::Value() const
|
||||
{
|
||||
return myObject;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_ModelIterator::Next()
|
||||
{
|
||||
myObject.Nullify();
|
||||
while ( myIterSeq.Length() >0 )
|
||||
{
|
||||
if ( myIterSeq.Last()->More() )
|
||||
{
|
||||
myObject = myIterSeq.Last()->Value();
|
||||
myIterSeq.Last()->Next();
|
||||
addIterator ( myObject );
|
||||
return;
|
||||
}
|
||||
else myIterSeq.Remove(myIterSeq.Length());
|
||||
}
|
||||
}
|
71
src/TObj/TObj_ModelIterator.hxx
Executable file
71
src/TObj/TObj_ModelIterator.hxx
Executable file
@@ -0,0 +1,71 @@
|
||||
// File: TObj_ModelIterator.hxx
|
||||
// Created: Wed Jan 31 12:03:38 2001
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_ModelIterator_HeaderFile
|
||||
#define TObj_ModelIterator_HeaderFile
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
#include <TObj_SequenceOfIterator.hxx>
|
||||
|
||||
class Handle(TObj_Model);
|
||||
|
||||
/**
|
||||
* This class provides an iterator by all objects in the model.
|
||||
*/
|
||||
|
||||
class TObj_ModelIterator : public TObj_ObjectIterator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
//! Creates Iterator and initialize it by Model`s label
|
||||
Standard_EXPORT TObj_ModelIterator(const Handle(TObj_Model)& theModel);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods to iterate on objects.
|
||||
*/
|
||||
|
||||
//! Returns True if iteration is not finished and method Value()
|
||||
//! will give the object
|
||||
virtual Standard_EXPORT Standard_Boolean More() const;
|
||||
|
||||
//! Iterates to the next object
|
||||
virtual Standard_EXPORT void Next ();
|
||||
|
||||
//! Returns current object (or MainObj of Model if iteration has finished)
|
||||
virtual Standard_EXPORT Handle(TObj_Object) Value () const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* private methods
|
||||
*/
|
||||
|
||||
//! Add iterator on children of indicated object recursively.
|
||||
virtual Standard_EXPORT void addIterator(const Handle(TObj_Object)& theObj);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
Handle(TObj_Object) myObject; //!< Current object
|
||||
TObj_SequenceOfIterator myIterSeq; //!< Sequence of iterators in model
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_ModelIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_ObjectIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_ModelIterator,TObj_ObjectIterator)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
1606
src/TObj/TObj_Object.cxx
Executable file
1606
src/TObj/TObj_Object.cxx
Executable file
File diff suppressed because it is too large
Load Diff
628
src/TObj/TObj_Object.hxx
Executable file
628
src/TObj/TObj_Object.hxx
Executable file
@@ -0,0 +1,628 @@
|
||||
// File: TObj_Object.hxx
|
||||
// Created: Mon Nov 22 13:39:27 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Object_HeaderFile
|
||||
#define TObj_Object_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_DeletingMode.hxx>
|
||||
#include <TObj_SequenceOfObject.hxx>
|
||||
#include <Handle_TObj_Model.hxx>
|
||||
#include <Handle_TObj_Object.hxx>
|
||||
|
||||
#include <TDF_Label.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
|
||||
class TObj_Persistence;
|
||||
class Handle(TObj_ObjectIterator);
|
||||
class Handle(TObj_TNameContainer);
|
||||
|
||||
class Handle(TCollection_HAsciiString);
|
||||
class Handle(TCollection_HExtendedString);
|
||||
class Handle(TColStd_HArray1OfReal);
|
||||
class Handle(TColStd_HArray1OfInteger);
|
||||
class Handle(TColStd_HArray1OfExtendedString);
|
||||
|
||||
//! Basis class for transient objects in OCAF-based models
|
||||
|
||||
class TObj_Object : public MMgt_TShared
|
||||
{
|
||||
public:
|
||||
enum TypeFlags //!< Flags that define type-specific behaviour of objects
|
||||
{
|
||||
Visible = 0x0001 //!< Is visible in DataViewer
|
||||
};
|
||||
|
||||
//! enumeration describing various object state bit flags (see Set/GetFlags())
|
||||
enum ObjectState
|
||||
{
|
||||
ObjectState_Hidden = 0x0001, //!< object is hidden in tree browser
|
||||
ObjectState_Saved = 0x0002, //!< object has (or should have)
|
||||
//!< corresponding saved file on disk
|
||||
ObjectState_Imported = 0x0004, //!< object's data are just imported from somewhere
|
||||
ObjectState_ImportedByFile = 0x0008, //!< a model imported by file may need a
|
||||
//!< sophisticated update of external references
|
||||
ObjectState_Ordered = 0x0010 //!< flag that partition contains ordered objects
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
//! enumeration for the ranks of label under Data section.
|
||||
enum DataTag
|
||||
{
|
||||
DataTag_First = 0,
|
||||
DataTag_Flags, //!< stores flags of object
|
||||
DataTag_Order, //!< stores order of object
|
||||
DataTag_Last = DataTag_First + 100 //!< Reserved for possible future use
|
||||
};
|
||||
|
||||
//! enumeration for the ranks of label under Child section.
|
||||
enum ChildTag
|
||||
{
|
||||
ChildTag_First = 0,
|
||||
ChildTag_Last = ChildTag_First //!< No children
|
||||
};
|
||||
|
||||
//! enumeration for the ranks of label under Reference section.
|
||||
enum RefTag
|
||||
{
|
||||
RefTag_First = 0,
|
||||
RefTag_Last = RefTag_First //!< No children
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
//! Constructor of a new object interface: requires label,
|
||||
//! which should be one of the labels in model's data structure.
|
||||
//! This creates a new object and attaches it to a given label.
|
||||
//! The initialisation of the object's data and their integrity is
|
||||
//! to be ensured by implementations and by persistence mechanism.
|
||||
//! If the flag theSetName is true (default) the object is assign the default name
|
||||
//! that is generated using the father partition object if any.
|
||||
Standard_EXPORT TObj_Object (const TDF_Label& theLabel,
|
||||
const Standard_Boolean theSetName = Standard_True);
|
||||
|
||||
//! The special constructor intended for implementation of persistence
|
||||
//! mechanism. See class TObj_Persistence for more details.
|
||||
//! The first argument is used only to avoid confusion with
|
||||
//! other constructors.
|
||||
Standard_EXPORT TObj_Object (const TObj_Persistence *,
|
||||
const TDF_Label& theLabel)
|
||||
: myLabel(theLabel) {}
|
||||
|
||||
//! This method is called from persistence to initialize the object fields,
|
||||
//! so successors that have transient fields must initialize them in initFields(),
|
||||
//! and call the same method of parent.
|
||||
void initFields() {}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Virtual methods
|
||||
*/
|
||||
|
||||
//! Returns the model to which the object belongs
|
||||
virtual Standard_EXPORT Handle(TObj_Model) GetModel () const;
|
||||
|
||||
//! Returns iterator for the child objects.
|
||||
//! This method provides tree-like view of the objects hierarchy.
|
||||
//! The references to other objects are not considered as children.
|
||||
//! theType narrows a variety of iterated objects
|
||||
//! The default implementation search for children on 1 sublavel
|
||||
//! of the children sub label
|
||||
virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetChildren
|
||||
(const Handle(Standard_Type)& theType = NULL) const;
|
||||
|
||||
//! Returns the label under which children are stored
|
||||
Standard_EXPORT TDF_Label GetChildLabel() const;
|
||||
|
||||
//! Returns the label for child with rank
|
||||
Standard_EXPORT TDF_Label getChildLabel(const Standard_Integer theRank) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Access to the OCAF-specific data
|
||||
*/
|
||||
|
||||
//! Returns the OCAF label on which object`s data are stored
|
||||
Standard_EXPORT TDF_Label GetLabel() const;
|
||||
|
||||
//! Returns the label which is the root for data OCAF sub-tree
|
||||
Standard_EXPORT TDF_Label GetDataLabel() const;
|
||||
|
||||
//! Returns the label which is the root for reference OCAF sub-tree
|
||||
Standard_EXPORT TDF_Label GetReferenceLabel() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods hanling name of the object
|
||||
*/
|
||||
|
||||
//! Returns the map of names of the objects
|
||||
//! Default implementation returns global Dictionary of the model
|
||||
virtual Standard_EXPORT Handle(TObj_TNameContainer) GetDictionary() const;
|
||||
|
||||
//! Returns the name of the object (empty string if object has no name)
|
||||
virtual Standard_EXPORT Handle(TCollection_HExtendedString) GetName() const;
|
||||
|
||||
//! Returns the Standard_True is object has name and returns name to theName
|
||||
Standard_EXPORT Standard_Boolean GetName
|
||||
(TCollection_ExtendedString& theName) const;
|
||||
|
||||
//! Returns the Standard_True is object has name and returns name to theName
|
||||
Standard_EXPORT Standard_Boolean GetName
|
||||
(TCollection_AsciiString& theName) const;
|
||||
|
||||
//! Sets name of the object. Returns False if theName is not unique.
|
||||
virtual Standard_EXPORT Standard_Boolean SetName
|
||||
(const Handle(TCollection_HExtendedString)& theName) const;
|
||||
|
||||
//! Sets name of the object. Returns False if theName is not unique.
|
||||
Standard_EXPORT Standard_Boolean SetName
|
||||
(const Handle(TCollection_HAsciiString)& theName) const;
|
||||
|
||||
//! Sets name of the object. Returns False if theName is not unique.
|
||||
Standard_EXPORT Standard_Boolean SetName (const Standard_CString name) const;
|
||||
|
||||
//! Returns name for copy
|
||||
//! default implementation returns the same name
|
||||
virtual Standard_EXPORT Handle(TCollection_HExtendedString) GetNameForClone
|
||||
( const Handle(TObj_Object)& ) const
|
||||
{ return GetName(); }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Analysis of dependencies on other objects
|
||||
*/
|
||||
|
||||
//! Returns True if object has reference to indicated object
|
||||
virtual Standard_EXPORT Standard_Boolean HasReference
|
||||
(const Handle(TObj_Object)& theObject) const;
|
||||
|
||||
//! Returns an Iterator containing objects that compose the this one
|
||||
//! theType narrows a variety of iterated objects
|
||||
virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetReferences
|
||||
(const Handle(Standard_Type)& theType = NULL) const;
|
||||
|
||||
//! Remove all references to other objects, by removing all reference attributes
|
||||
virtual Standard_EXPORT void RemoveAllReferences();
|
||||
|
||||
//! Returns iterator for the objects which depend on this one.
|
||||
//! These reffering objects may belong to other models.
|
||||
//! theType narrows a variety of iterated objects
|
||||
virtual Standard_EXPORT Handle(TObj_ObjectIterator) GetBackReferences
|
||||
(const Handle(Standard_Type)& theType = NULL) const;
|
||||
|
||||
//! Registers another object as being dependent on this one.
|
||||
//! Stores back references under sublabel 2 (purely transient data,
|
||||
//! not subject to persistency).
|
||||
virtual Standard_EXPORT void AddBackReference
|
||||
(const Handle(TObj_Object)& theObject);
|
||||
|
||||
//! Removes information on dependent object (back reference).
|
||||
//! If theSingleOnly is true only the first back reference is removed in the
|
||||
//! case of duplicate items.
|
||||
virtual Standard_EXPORT void RemoveBackReference
|
||||
(const Handle(TObj_Object)& theObject,
|
||||
const Standard_Boolean theSingleOnly = Standard_True);
|
||||
|
||||
//! Removes all back reference by removing references from other to me.
|
||||
virtual Standard_EXPORT Standard_Boolean RemoveBackReferences
|
||||
(const TObj_DeletingMode theMode = TObj_FreeOnly);
|
||||
|
||||
//! The default implementation just clear the back references container
|
||||
virtual Standard_EXPORT void ClearBackReferences();
|
||||
|
||||
//! Returns TRUE if obejct has 1 or more back references
|
||||
Standard_EXPORT Standard_Boolean HasBackReferences() const;
|
||||
|
||||
//! Replace reference from old object to new object.
|
||||
//! If it is not possible, may raise exception.
|
||||
//! If new object is null then simple remove reference to old object.
|
||||
virtual Standard_EXPORT void ReplaceReference
|
||||
(const Handle(TObj_Object)& theOldObject,
|
||||
const Handle(TObj_Object)& theNewObject);
|
||||
|
||||
//! Return True if this refers to the model theRoot belongs
|
||||
//! to and a referred label is not a descendant of theRoot.
|
||||
//! In this case theBadReference returns the currently referred label.
|
||||
virtual Standard_EXPORT Standard_Boolean GetBadReference
|
||||
(const TDF_Label& theRoot,
|
||||
TDF_Label& theBadReference) const;
|
||||
|
||||
//! Make that each reference pointing to a descendant label of
|
||||
//! theFromRoot to point to an equivalent label under theToRoot.
|
||||
//! Return False if a resulting reference does not point to
|
||||
//! an TObj_Object
|
||||
//! Example:
|
||||
//! a referred object label = 0:3:24:7:2:7
|
||||
//! theFromRoot = 0:3:24
|
||||
//! theToRoot = 0:2
|
||||
//! a new referred label = 0:2:7:2:7
|
||||
virtual Standard_EXPORT Standard_Boolean RelocateReferences
|
||||
(const TDF_Label& theFromRoot,
|
||||
const TDF_Label& theToRoot,
|
||||
const Standard_Boolean theUpdateBackRefs = Standard_True);
|
||||
|
||||
//! Returns True if the referred object theObject can be deleted
|
||||
//! without deletion of this object.
|
||||
//! Default implementation does nothing and returns False.
|
||||
virtual Standard_EXPORT Standard_Boolean CanRemoveReference
|
||||
(const Handle(TObj_Object)& theObject) const;
|
||||
|
||||
//! Removes reference to the object by replace reference to NULL object
|
||||
virtual Standard_EXPORT void RemoveReference (const Handle(TObj_Object)& theObject);
|
||||
|
||||
//! Invokes from TObj_TReference::BeforeForget().
|
||||
//! theLabel - label on that reference become removed
|
||||
//! Default implementation is empty
|
||||
virtual Standard_EXPORT void BeforeForgetReference( const TDF_Label& /*theLabel*/ )
|
||||
{}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for deleting the object
|
||||
*/
|
||||
|
||||
//! Checks if object can be detached with specified mode
|
||||
virtual Standard_EXPORT Standard_Boolean CanDetach(const TObj_DeletingMode theMode = TObj_FreeOnly);
|
||||
|
||||
//! Deletes the object from the model.
|
||||
//! The dependent objects are either deleted or modified when possible
|
||||
//! (see description of TObj_DeletingMode enumeration for more details)
|
||||
//! Returns True if deletion was successful.
|
||||
//! Checks if object can be deleted.
|
||||
//! Should be redefined for each specific kind of object
|
||||
virtual Standard_EXPORT Standard_Boolean Detach
|
||||
(const TObj_DeletingMode theMode = TObj_FreeOnly);
|
||||
|
||||
//! Deletes the object from the label. Checks if object can be deleted.
|
||||
//! Finds object on the label and detaches it by calling previos method.
|
||||
//! Returns true if there is no object on the label after detaching
|
||||
static Standard_EXPORT Standard_Boolean Detach
|
||||
(const TDF_Label& theLabel,
|
||||
const TObj_DeletingMode theMode = TObj_FreeOnly);
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* methods for object retrieval
|
||||
*/
|
||||
|
||||
//! Returns the Object attached to a given label.
|
||||
//! Returns False if no object of type TObj_Object is stored on the
|
||||
//! specified label.
|
||||
//! If isSuper is true tries to find on the super labels.
|
||||
static Standard_EXPORT Standard_Boolean GetObj
|
||||
(const TDF_Label& theLabel,
|
||||
Handle(TObj_Object)& theResult,
|
||||
const Standard_Boolean isSuper = Standard_False);
|
||||
|
||||
//! Returns the father object, which may be NULL
|
||||
//! theType gives type of father object to search
|
||||
Standard_EXPORT Handle(TObj_Object) GetFatherObject
|
||||
(const Handle(Standard_Type)& theType = NULL) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for checking and Updating object
|
||||
*/
|
||||
|
||||
//! Checks that object alive in model
|
||||
//! Default implementation checks that object has TObject attribute at own label.
|
||||
virtual Standard_EXPORT Standard_Boolean IsAlive() const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Cloning related methods
|
||||
*/
|
||||
|
||||
//! Copy me to other label theTargetLabel
|
||||
//! New object will not have all the reference that has me.
|
||||
//! Coping object with data and childs, but change name by adding string "_copy"
|
||||
//! As result return handle of new object (null handle is something wrong)
|
||||
//! NOTE: BackReferences not coping.
|
||||
//! After clonning all objects it is neccessary to call copy references
|
||||
//! with the same relocation table
|
||||
virtual Standard_EXPORT Handle(TObj_Object) Clone
|
||||
(const TDF_Label& theTargetLabel,
|
||||
Handle(TDF_RelocationTable) theRelocTable = 0);
|
||||
|
||||
//! Coping the references.
|
||||
//! return Standard_False is Target object is different type
|
||||
virtual Standard_EXPORT void CopyReferences
|
||||
(const Handle(TObj_Object)& theTargetObject,
|
||||
const Handle(TDF_RelocationTable)& theRelocTable);
|
||||
|
||||
//! Coping the children from source label to the target.
|
||||
virtual Standard_EXPORT void CopyChildren
|
||||
(TDF_Label& theTargetLabel,
|
||||
const Handle(TDF_RelocationTable)& theRelocTable);
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Public methods to access order of object
|
||||
*/
|
||||
|
||||
//! returns order of object (or tag of their label if order is not initialised)
|
||||
virtual Standard_EXPORT Standard_Integer GetOrder() const;
|
||||
|
||||
//! sets order of object
|
||||
virtual Standard_EXPORT Standard_Boolean SetOrder( const Standard_Integer& theIndx );
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Protected Methods copy data of object to other object
|
||||
*/
|
||||
|
||||
//! Coping the data of me to Target object.
|
||||
//! return Standard_False is Target object is different type
|
||||
virtual Standard_EXPORT Standard_Boolean copyData
|
||||
(const Handle(TObj_Object)& theTargetObject);
|
||||
|
||||
//! Coping the references from source label to the target.
|
||||
Standard_EXPORT void copyReferences
|
||||
(const TDF_Label& theSourceLabel,
|
||||
TDF_Label& theTargetLabel,
|
||||
const Handle(TDF_RelocationTable)& theRelocTable);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Access to object flags
|
||||
*/
|
||||
|
||||
//! Returns flags (bitmask) that define properties of objects of that type
|
||||
//! By default returns flag Visible
|
||||
virtual Standard_EXPORT Standard_Integer GetTypeFlags() const;
|
||||
|
||||
//! Returns mask of seted flags
|
||||
Standard_EXPORT Standard_Integer GetFlags() const;
|
||||
|
||||
//! Sets flags with defined mask.
|
||||
Standard_EXPORT void SetFlags(const Standard_Integer theMask);
|
||||
|
||||
//! tests flags by the mask.
|
||||
Standard_EXPORT Standard_Boolean TestFlags(const Standard_Integer theMask) const;
|
||||
|
||||
//! clears flags by the mask.
|
||||
Standard_EXPORT void ClearFlags(const Standard_Integer theMask = ~0);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Method for updating object afrer restoring
|
||||
*/
|
||||
|
||||
//! Preforms updating the links and dependances of the object which are not
|
||||
//! stored in persistence. Should be redefined if necessary.
|
||||
virtual Standard_EXPORT void AfterRetrieval();
|
||||
|
||||
//! Preforms storing the objects transient fields in OCAF document
|
||||
//! which were outside transaction mechanism.
|
||||
//! Default implementation doesnot nothing
|
||||
virtual Standard_EXPORT void BeforeStoring();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Internal tools for work with OCAF data
|
||||
*/
|
||||
|
||||
//! Returns the theRank2-th sub label of the theRank1-th sublabel of the
|
||||
//! Data label of the object.
|
||||
//! If theRank2 is 0 (default), sub label theRank1 of Data label is returned.
|
||||
//! If requested label does not exist, it is created.
|
||||
Standard_EXPORT TDF_Label getDataLabel
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns the theRank2-th sub label of the theRank1-th sublabel of the
|
||||
//! Reference label of the object.
|
||||
//! If theRank2 is 0 (default), sub label theRank1 of Reference label is returned.
|
||||
//! If requested label does not exist, it is created.
|
||||
Standard_EXPORT TDF_Label getReferenceLabel
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns True if there is an attribute having theGUID on the
|
||||
//! theRank2-th sublabel of theRank1-th sublabel of the Data
|
||||
//! label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed, not
|
||||
//! its sublabel
|
||||
Standard_EXPORT Standard_Boolean isDataAttribute
|
||||
(const Standard_GUID& theGUID,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns the real value from theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! Returns 0.0 if no real value is stored on that label.
|
||||
Standard_EXPORT Standard_Real getReal
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Sets the real value for theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! Returns True if new value is actually different from previous one
|
||||
//! (with specified tolerance)
|
||||
Standard_EXPORT Standard_Boolean setReal
|
||||
(const Standard_Real theValue,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0,
|
||||
const Standard_Real theTolerance = 0.) const;
|
||||
|
||||
//! Returns the integer value from theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! Returns 0 if no integer value is stored on that label.
|
||||
Standard_EXPORT Standard_Integer getInteger
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Sets the integer value for theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! Returns True if new value is actually different from previous one
|
||||
Standard_EXPORT Standard_Boolean setInteger
|
||||
(const Standard_Integer theValue,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns an existing or create a new real array on theRank2-th
|
||||
//! sublabel of theRank1-th sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! A newly created array has 1 and theLength bounds and is initialized
|
||||
//! with theInitialValue
|
||||
//!
|
||||
//! NOTE: do not create new array and returns NULL handle if no array on label
|
||||
//! and theLength less than
|
||||
//!
|
||||
//! WARNING: call setArray() after array contents modification
|
||||
//! in order to assure Undo work
|
||||
Standard_EXPORT Handle(TColStd_HArray1OfReal) getRealArray
|
||||
(const Standard_Integer theLength,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0,
|
||||
const Standard_Real theInitialValue = 0.0) const;
|
||||
|
||||
//! Returns an existing or create a new integer array on theRank2-th
|
||||
//! sublabel of theRank1-th sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! A newly created array has 1 and theLength bounds and is initialized
|
||||
//! with theInitialValue
|
||||
//!
|
||||
//! NOTE: do not create new array and returns NULL handle if no array on label
|
||||
//! and theLength less than
|
||||
//!
|
||||
//! WARNING: call setArray() after array contents modification
|
||||
//! in order to assure Undo work
|
||||
Standard_EXPORT Handle(TColStd_HArray1OfInteger) getIntegerArray
|
||||
(const Standard_Integer theLength,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0,
|
||||
const Standard_Integer theInitialValue = 0) const;
|
||||
|
||||
//! Returns an existing or create a new string array on theRank2-th
|
||||
//! sublabel of theRank1-th sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! A newly created array has 1 and theLength bounds
|
||||
//! NOTE: new created array is NOT initialized.
|
||||
//!
|
||||
//! NOTE: do not create new array and returns NULL handle if no array on label
|
||||
//! and theLength less than
|
||||
//!
|
||||
//! WARNING: call setArray() after array contents modification
|
||||
//! in order to assure Undo work
|
||||
Standard_EXPORT Handle(TColStd_HArray1OfExtendedString) getExtStringArray
|
||||
(const Standard_Integer theLength,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Store theArray on theRank2-th sublabel of theRank1-th sublabel
|
||||
//! of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! If theArray is null then array attribute if any is removed.
|
||||
Standard_EXPORT void setArray
|
||||
(const Handle(TColStd_HArray1OfReal)& theArray,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0);
|
||||
|
||||
//! Store theArray on theRank2-th sublabel of theRank1-th sublabel
|
||||
//! of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! If theArray is null then array attribute if any is removed.
|
||||
Standard_EXPORT void setArray
|
||||
(const Handle(TColStd_HArray1OfInteger)& theArray,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0);
|
||||
|
||||
//! Store theArray on theRank2-th sublabel of theRank1-th sublabel
|
||||
//! of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! If theArray is null then array attribute if any is removed.
|
||||
Standard_EXPORT void setArray
|
||||
(const Handle(TColStd_HArray1OfExtendedString)& theArray,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0);
|
||||
|
||||
//! Sets the string value for theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
Standard_EXPORT void setExtString
|
||||
(const Handle(TCollection_HExtendedString)& theValue,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns the string value from theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
Standard_EXPORT Handle(TCollection_HExtendedString) getExtString
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Sets the ascii string value for theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
Standard_EXPORT void setAsciiString
|
||||
(const Handle(TCollection_HAsciiString)& theValue,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns the string value from theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the Data label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
Standard_EXPORT Handle(TCollection_HAsciiString) getAsciiString
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Returns the reference attribute from theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the References label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
Standard_EXPORT Handle(TObj_Object) getReference
|
||||
(const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0) const;
|
||||
|
||||
//! Sets the reference to theObject on theRank2-th sublabel of theRank1-th
|
||||
//! sublabel of the References label of the object.
|
||||
//! If theRank2 is 0 (default), label theRank1 is supposed (not its sublabel).
|
||||
//! Returns True if new value is actually different from previous one
|
||||
//! If Object is NULL, reference is deleted
|
||||
Standard_EXPORT Standard_Boolean setReference
|
||||
(const Handle(TObj_Object) &theObject,
|
||||
const Standard_Integer theRank1,
|
||||
const Standard_Integer theRank2 = 0);
|
||||
|
||||
//! Adds the reference to theObject on next free sublabel of theRank1-th
|
||||
//! sublabel of the References label of the object and returns the Label.
|
||||
Standard_EXPORT TDF_Label addReference
|
||||
(const Standard_Integer theRank1,
|
||||
const Handle(TObj_Object) &theObject);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
TDF_Label myLabel; //!< Label on which object`s data are stored
|
||||
|
||||
Handle(TObj_HSequenceOfObject) myHSeqBackRef; //!< hsequence of back references.
|
||||
|
||||
friend class TObj_TObject;
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_Object)
|
||||
};
|
||||
|
||||
//! Define handle in separate file
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
33
src/TObj/TObj_ObjectIterator.cxx
Executable file
33
src/TObj/TObj_ObjectIterator.cxx
Executable file
@@ -0,0 +1,33 @@
|
||||
// File: TObj_ObjectIterator.cxx
|
||||
// Created: Tue Nov 23 12:17:26 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_ObjectIterator,MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_ObjectIterator,MMgt_TShared)
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean TObj_ObjectIterator::More () const
|
||||
{ return Standard_False; }
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void TObj_ObjectIterator::Next ()
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Handle(TObj_Object) TObj_ObjectIterator::Value () const
|
||||
{ return 0; }
|
51
src/TObj/TObj_ObjectIterator.hxx
Executable file
51
src/TObj/TObj_ObjectIterator.hxx
Executable file
@@ -0,0 +1,51 @@
|
||||
// File: TObj_ObjectIterator.hxx
|
||||
// Created: Tue Nov 23 12:17:17 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_ObjectIterator_HeaderFile
|
||||
#define TObj_ObjectIterator_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
class Handle(TObj_Object);
|
||||
|
||||
/**
|
||||
* This class provides an iterator by objects in a partition.
|
||||
* (implements TObj_ObjectIterator interface)
|
||||
*/
|
||||
|
||||
class TObj_ObjectIterator : public MMgt_TShared
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Methods to iterate on a objects
|
||||
*/
|
||||
|
||||
//! Returns True if iteration is not finished and method Current()
|
||||
//! will give the object.
|
||||
//! Default implementation returns False
|
||||
virtual Standard_EXPORT Standard_Boolean More () const;
|
||||
|
||||
//! Iterates to the next object
|
||||
//! Default implementation does nothing
|
||||
virtual Standard_EXPORT void Next ();
|
||||
|
||||
//! Returns current object (or null if iteration has finished)
|
||||
//! Default implementation returns null handle
|
||||
virtual Standard_EXPORT Handle(TObj_Object) Value () const;
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_ObjectIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_ObjectIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_ObjectIterator,MMgt_TShared)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
51
src/TObj/TObj_OcafObjectIterator.cxx
Executable file
51
src/TObj/TObj_OcafObjectIterator.cxx
Executable file
@@ -0,0 +1,51 @@
|
||||
// File: TObj_OcafObjectIterator.cxx
|
||||
// Created: Tue Nov 23 12:17:26 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_OcafObjectIterator.hxx>
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_OcafObjectIterator,TObj_LabelIterator)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_OcafObjectIterator,TObj_LabelIterator)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_OcafObjectIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_OcafObjectIterator::TObj_OcafObjectIterator
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(Standard_Type)& theType,
|
||||
const Standard_Boolean theRecursive)
|
||||
: TObj_LabelIterator( theLabel, theRecursive ), myType( theType )
|
||||
{
|
||||
MakeStep();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeStep
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_OcafObjectIterator::MakeStep()
|
||||
{
|
||||
for(;myIterator.More() && myNode.IsNull(); )
|
||||
{
|
||||
TDF_Label L = myIterator.Value();
|
||||
Handle(TObj_Object) anObject;
|
||||
if(TObj_Object::GetObj(L,anObject))
|
||||
{
|
||||
if (myType.IsNull() || anObject->IsKind( myType ))
|
||||
{
|
||||
myObject = anObject;
|
||||
myNode = L;
|
||||
}
|
||||
myIterator.NextBrother();
|
||||
}
|
||||
else
|
||||
myIterator.Next();
|
||||
}
|
||||
}
|
58
src/TObj/TObj_OcafObjectIterator.hxx
Executable file
58
src/TObj/TObj_OcafObjectIterator.hxx
Executable file
@@ -0,0 +1,58 @@
|
||||
// File: TObj_OcafObjectIterator.hxx
|
||||
// Created: Tue Nov 23 12:17:17 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_OcafObjectIterator_HeaderFile
|
||||
#define TObj_OcafObjectIterator_HeaderFile
|
||||
|
||||
#include <TObj_LabelIterator.hxx>
|
||||
|
||||
/**
|
||||
* This class provides an iterator by objects in a partition.
|
||||
* (implements TObj_ObjectIterator interface)
|
||||
*/
|
||||
|
||||
class TObj_OcafObjectIterator : public TObj_LabelIterator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates the iterator on objects in the sub labels of theLabel
|
||||
//! theType narrows a variety of iterated objects
|
||||
Standard_EXPORT TObj_OcafObjectIterator
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(Standard_Type)& theType = NULL,
|
||||
const Standard_Boolean theRecursive = Standard_False);
|
||||
|
||||
protected:
|
||||
/*
|
||||
* Internal methods
|
||||
*/
|
||||
|
||||
//! Shift iterator to the next object
|
||||
virtual Standard_EXPORT void MakeStep();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
|
||||
Handle(Standard_Type) myType; //!< type of objects to iterate on
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_OcafObjectIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_OcafObjectIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_OcafObjectIterator,TObj_LabelIterator)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
182
src/TObj/TObj_Partition.cxx
Executable file
182
src/TObj/TObj_Partition.cxx
Executable file
@@ -0,0 +1,182 @@
|
||||
// File: TObj_Partition.cxx
|
||||
// Created: Tue Nov 23 11:27:33 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Partition.hxx>
|
||||
|
||||
#include <TObj_Model.hxx>
|
||||
#include <TObj_TNameContainer.hxx>
|
||||
|
||||
#include <TDataStd_Name.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_Partition,TObj_Object)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_Partition,TObj_Object)
|
||||
IMPLEMENT_TOBJOCAF_PERSISTENCE(TObj_Partition)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_Partition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_Partition::TObj_Partition (const TDF_Label& theLabel)
|
||||
: TObj_Object( theLabel )
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Create
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Partition::Create
|
||||
(const TDF_Label& theLabel)
|
||||
{
|
||||
Handle(TObj_Partition) aPartition =
|
||||
new TObj_Partition(theLabel);
|
||||
aPartition->SetLastIndex(0);
|
||||
return aPartition;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewLabel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TDF_Label TObj_Partition::NewLabel() const
|
||||
{
|
||||
TDF_Label aLabel;
|
||||
TDF_TagSource aTag;
|
||||
aLabel = aTag.NewChild(GetChildLabel());
|
||||
return aLabel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetNamePrefix
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Partition::SetNamePrefix
|
||||
(const Handle(TCollection_HExtendedString)& thePrefix)
|
||||
{ myPrefix = thePrefix; }
|
||||
|
||||
//=======================================================================
|
||||
//function : NewName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TCollection_HExtendedString) TObj_Partition::GetNewName
|
||||
( const Standard_Boolean theIsToChangeCount )
|
||||
{
|
||||
if ( myPrefix.IsNull() ) return 0;
|
||||
|
||||
Standard_Integer aRank = GetLastIndex()+1;
|
||||
Standard_Integer saveRank = aRank;
|
||||
Handle(TCollection_HExtendedString) aName;
|
||||
do
|
||||
{
|
||||
aName = new TCollection_HExtendedString(myPrefix->String()+aRank++);
|
||||
} while( GetModel()->IsRegisteredName( aName, GetDictionary() ) );
|
||||
|
||||
// the last index is increased taking into account only names that are
|
||||
// actually set; the name requested by the current operation can be
|
||||
// dropped later and this will not cause index to be increased
|
||||
if ( theIsToChangeCount && --aRank > saveRank )
|
||||
SetLastIndex ( aRank );
|
||||
return aName;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetPartition
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Partition) TObj_Partition::GetPartition
|
||||
(const Handle(TObj_Object)& theObject)
|
||||
{
|
||||
Handle(TObj_Partition) aPartition;
|
||||
if(!theObject.IsNull())
|
||||
{
|
||||
TDF_Label aLabel = theObject->GetLabel().Father();
|
||||
|
||||
// find partition which contains the object
|
||||
while(aPartition.IsNull() && !aLabel.IsNull())
|
||||
{
|
||||
Handle(TObj_Object) anObject;
|
||||
if(TObj_Object::GetObj(aLabel,anObject,Standard_True))
|
||||
aPartition = Handle(TObj_Partition)::DownCast(anObject);
|
||||
|
||||
if(aPartition.IsNull())
|
||||
aLabel = aLabel.Father();
|
||||
}
|
||||
}
|
||||
return aPartition;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetLastIndex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer TObj_Partition::GetLastIndex() const
|
||||
{
|
||||
return getInteger(DataTag_LastIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetLastIndex
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Partition::SetLastIndex(const Standard_Integer theIndex)
|
||||
{
|
||||
setInteger(theIndex,DataTag_LastIndex);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : copyData
|
||||
//purpose : protected
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Partition::copyData
|
||||
(const Handle(TObj_Object)& theTargetObject)
|
||||
{
|
||||
Standard_Boolean IsDone;
|
||||
Handle(TObj_Partition) aTargetPartition =
|
||||
Handle(TObj_Partition)::DownCast(theTargetObject);
|
||||
IsDone = aTargetPartition.IsNull() ? Standard_False : Standard_True;
|
||||
if(IsDone)
|
||||
{
|
||||
IsDone = TObj_Object::copyData(theTargetObject);
|
||||
if ( IsDone )
|
||||
{
|
||||
aTargetPartition->myPrefix = myPrefix;
|
||||
}
|
||||
}
|
||||
return IsDone;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetName
|
||||
//purpose : do not register a name in the dictionary
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_Partition::SetName(const Handle(TCollection_HExtendedString)& theName) const
|
||||
{
|
||||
Handle(TCollection_HExtendedString) anOldName = GetName();
|
||||
if( !anOldName.IsNull() && theName->String().IsEqual(anOldName->String()) )
|
||||
return Standard_True;
|
||||
|
||||
TDataStd_Name::Set(GetLabel(),theName->String());
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterRetrieval
|
||||
//purpose : do not register a name in the dictionary
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Partition::AfterRetrieval()
|
||||
{
|
||||
}
|
152
src/TObj/TObj_Partition.hxx
Executable file
152
src/TObj/TObj_Partition.hxx
Executable file
@@ -0,0 +1,152 @@
|
||||
// File: TObj_Partition.hxx
|
||||
// Created: Thu Nov 23 11:26:54 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Partition_HeaderFile
|
||||
#define TObj_Partition_HeaderFile
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
#include <TObj_Persistence.hxx>
|
||||
|
||||
class Handle(TCollection_HExtendedString);
|
||||
class Handle(TObj_Partition);
|
||||
|
||||
/**
|
||||
* This class privides tool handling one of partitions (the set of
|
||||
* homogenious elements) in the OCAF based model`s data structure
|
||||
*/
|
||||
|
||||
class TObj_Partition : public TObj_Object
|
||||
{
|
||||
protected:
|
||||
enum DataTag
|
||||
{
|
||||
DataTag_First = TObj_Object::DataTag_Last,
|
||||
DataTag_LastIndex,
|
||||
DataTag_Last = DataTag_First + 100
|
||||
};
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Constructor is protected;
|
||||
//! static methods are used for creation of this type of objects
|
||||
Standard_EXPORT TObj_Partition (const TDF_Label& theLabel);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Method for create partition
|
||||
*/
|
||||
|
||||
//! Creates a new partition on given label.
|
||||
static Standard_EXPORT Handle(TObj_Partition) Create
|
||||
(const TDF_Label& theLabel);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods hanling name of the object
|
||||
*/
|
||||
|
||||
//! Sets name of the object. partition does not check unique of own name
|
||||
virtual Standard_EXPORT Standard_Boolean SetName
|
||||
(const Handle(TCollection_HExtendedString)& theName) const;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Method for updating object afrer restoring
|
||||
*/
|
||||
|
||||
//! Preforms updating the links and dependances of the object which are not
|
||||
//! stored in persistence. Does not register the partition name
|
||||
virtual Standard_EXPORT void AfterRetrieval();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods handling of the objects in partition
|
||||
*/
|
||||
|
||||
//! Creates and Returns label for new object in partition.
|
||||
Standard_EXPORT TDF_Label NewLabel() const;
|
||||
|
||||
//! Sets prefix for names of the objects in partition.
|
||||
Standard_EXPORT void SetNamePrefix
|
||||
(const Handle(TCollection_HExtendedString)& thePrefix);
|
||||
|
||||
//! Returns prefix for names of the objects in partition.
|
||||
Standard_EXPORT Handle(TCollection_HExtendedString) GetNamePrefix() const
|
||||
{ return myPrefix; }
|
||||
|
||||
//! Generates and returns name for new object in partition.
|
||||
//! if theIsToChangeCount is true partition icrease own counter
|
||||
//! to generate new name next time starting from new counter value
|
||||
Standard_EXPORT Handle(TCollection_HExtendedString) GetNewName
|
||||
( const Standard_Boolean theIsToChangeCount = Standard_True );
|
||||
|
||||
//! Return Last index in partition (reserved);
|
||||
Standard_EXPORT Standard_Integer GetLastIndex() const;
|
||||
|
||||
//! Sets Last index in partition (reserved);
|
||||
Standard_EXPORT void SetLastIndex(const Standard_Integer theIndex);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods to define partition by object
|
||||
*/
|
||||
|
||||
//! Returns the partition in which object is stored. Null partition
|
||||
//! returned if not found
|
||||
static Standard_EXPORT Handle(TObj_Partition) GetPartition
|
||||
(const Handle(TObj_Object)& theObject);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Methods for updating the object
|
||||
*/
|
||||
|
||||
//! Does nothing in the partition.
|
||||
virtual Standard_EXPORT Standard_Boolean Update()
|
||||
{return Standard_True;}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* protected redefined methods
|
||||
*/
|
||||
|
||||
//! Coping the data of me to Target object.
|
||||
//! return Standard_False is Target object is different type
|
||||
Standard_EXPORT virtual Standard_Boolean copyData
|
||||
(const Handle(TObj_Object)& theTargetObject);
|
||||
|
||||
private:
|
||||
/**
|
||||
* fields
|
||||
*/
|
||||
|
||||
//! prefix for naming of objects in the partition
|
||||
Handle(TCollection_HExtendedString) myPrefix;
|
||||
|
||||
protected:
|
||||
//! Persistence of TObj object
|
||||
DECLARE_TOBJOCAF_PERSISTENCE(TObj_Partition,TObj_Object)
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_Partition)
|
||||
|
||||
public:
|
||||
friend class TObj_Model;
|
||||
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_Partition
|
||||
DEFINE_STANDARD_HANDLE(TObj_Partition,TObj_Object)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
71
src/TObj/TObj_Persistence.cxx
Executable file
71
src/TObj/TObj_Persistence.cxx
Executable file
@@ -0,0 +1,71 @@
|
||||
// File: TObj_Persistence.cxx
|
||||
// Created: Tue Nov 23 11:36:45 2004
|
||||
// Author: Andrey BETENEV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Persistence.hxx>
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : getMapOfTypes
|
||||
//purpose : Returns the map of types
|
||||
//=======================================================================
|
||||
|
||||
TObj_DataMapOfStringPointer& TObj_Persistence::getMapOfTypes ()
|
||||
{
|
||||
static TObj_DataMapOfStringPointer myMapOfTypes;
|
||||
return myMapOfTypes;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose : Register the type for persistence
|
||||
//=======================================================================
|
||||
|
||||
TObj_Persistence::TObj_Persistence (const Standard_CString theType)
|
||||
{
|
||||
myType = theType;
|
||||
getMapOfTypes().Bind ( theType, this );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Destructor
|
||||
//purpose : Unregister the type
|
||||
//=======================================================================
|
||||
|
||||
TObj_Persistence::~TObj_Persistence ()
|
||||
{
|
||||
getMapOfTypes().UnBind ( myType );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateNewObject
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_Persistence::CreateNewObject (const Standard_CString theType,
|
||||
const TDF_Label& theLabel)
|
||||
{
|
||||
if ( getMapOfTypes().IsBound ( theType ) )
|
||||
{
|
||||
TObj_Persistence *tool =
|
||||
(TObj_Persistence*) getMapOfTypes().Find ( theType );
|
||||
if ( tool ) return tool->New (theLabel);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : DumpTypes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_Persistence::DumpTypes (Standard_OStream &theOs)
|
||||
{
|
||||
TObj_DataMapOfStringPointer::Iterator it ( getMapOfTypes() );
|
||||
for ( ; it.More(); it.Next() )
|
||||
{
|
||||
theOs << it.Key() << endl;
|
||||
}
|
||||
}
|
106
src/TObj/TObj_Persistence.hxx
Executable file
106
src/TObj/TObj_Persistence.hxx
Executable file
@@ -0,0 +1,106 @@
|
||||
// File: TObj_Persistence.hxx
|
||||
// Created: Tue Nov 23 11:36:03 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_Persistence_HeaderFile
|
||||
#define TObj_Persistence_HeaderFile
|
||||
|
||||
#include <TObj_Container.hxx>
|
||||
|
||||
class TDF_Label;
|
||||
class Handle(TObj_Object);
|
||||
|
||||
/** This class is intended to be a root of tools (one per class)
|
||||
* to manage persistence of objects inherited from TObj_Object
|
||||
* It provides a mechanism to recover correctly typed
|
||||
* objects (subtypes of TObj_Object) out of their persistent names
|
||||
*
|
||||
* This is a special kind of object, it automatically registers itself
|
||||
* in a global map when created, and the only thing it does is to
|
||||
* create a new object of the type that it manages, by request
|
||||
*/
|
||||
|
||||
class TObj_Persistence
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Public methods, to be called externally
|
||||
*/
|
||||
|
||||
//! Creates and returns a new object of the registered type
|
||||
//! If the type is not registered, returns Null handle
|
||||
static Standard_EXPORT Handle(TObj_Object) CreateNewObject
|
||||
(const Standard_CString theType,
|
||||
const TDF_Label& theLabel);
|
||||
|
||||
//! Dumps names of all the types registered for persistence to the
|
||||
//! specified stream
|
||||
static Standard_EXPORT void DumpTypes (Standard_OStream& theOs);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Protected methods, to be used or defined by descendants
|
||||
*/
|
||||
|
||||
//! The constructor registers the object
|
||||
Standard_EXPORT TObj_Persistence (const Standard_CString theType);
|
||||
|
||||
//! The destructor unregisters the object
|
||||
virtual Standard_EXPORT ~TObj_Persistence ();
|
||||
|
||||
//! The method must be redefined in the derived class and return
|
||||
//! new object of the proper type
|
||||
virtual Standard_EXPORT Handle(TObj_Object) New
|
||||
(const TDF_Label& theLabel) const = 0;
|
||||
|
||||
//! Dictionary storing all the registered types. It is implemented as static
|
||||
//! variable inside member function in order to ensure initialization
|
||||
//! at first call
|
||||
static Standard_EXPORT TObj_DataMapOfStringPointer& getMapOfTypes();
|
||||
|
||||
private:
|
||||
Standard_CString myType; //!< Name of managed type (recorded for unregistering)
|
||||
};
|
||||
|
||||
//! Declare subclass and methods of the class inherited from TObj_Object
|
||||
//! necessary for implementation of persistence
|
||||
//! This declaration should be put inside class declaration, under 'protected' modifier
|
||||
#ifdef SOLARIS
|
||||
//! Workaround on SUN to avoid stupid warnings
|
||||
#define _TOBJOCAF_PERSISTENCE_ACCESS_ public:
|
||||
#else
|
||||
#define _TOBJOCAF_PERSISTENCE_ACCESS_
|
||||
#endif
|
||||
#define DECLARE_TOBJOCAF_PERSISTENCE(name,ancestor) \
|
||||
name (const TObj_Persistence *p, \
|
||||
const TDF_Label& aLabel) : ancestor(p,aLabel) \
|
||||
{ initFields(); } /* give the object a chance to initialize its fields */ \
|
||||
\
|
||||
/* Creates an object of a proper type */ \
|
||||
/* First argument is used just to avoid possible conflict with other constructors */ \
|
||||
_TOBJOCAF_PERSISTENCE_ACCESS_ \
|
||||
class Persistence_ : public TObj_Persistence { \
|
||||
/* Friend private class of name, is a tool providing persistence */ \
|
||||
public: \
|
||||
Persistence_ () : TObj_Persistence(#name) {} /* register the tool */ \
|
||||
virtual Handle(TObj_Object) New (const TDF_Label& aLabel) const; \
|
||||
/* Creates an object of a proper type */ \
|
||||
}; \
|
||||
friend class Persistence_; \
|
||||
static Persistence_ myPersistence_; /* Static field implementing persistsnce tool */
|
||||
|
||||
//! Implement mechanism for registration the type for persistence
|
||||
//! This should not be used for abstract classes (while DECLARE should)
|
||||
#define IMPLEMENT_TOBJOCAF_PERSISTENCE(name) \
|
||||
name::Persistence_ name::myPersistence_; \
|
||||
Handle(TObj_Object) name::Persistence_::New (const TDF_Label& aLabel) const { \
|
||||
return new name((const TObj_Persistence*)0, aLabel); \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
49
src/TObj/TObj_ReferenceIterator.cxx
Executable file
49
src/TObj/TObj_ReferenceIterator.cxx
Executable file
@@ -0,0 +1,49 @@
|
||||
// File: TObj_ReferenceIterator.cxx
|
||||
// Created: Tue Nov 23 12:19:22 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
#include <TObj_ReferenceIterator.hxx>
|
||||
#include <TObj_TReference.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_ReferenceIterator,TObj_LabelIterator)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_ReferenceIterator,TObj_LabelIterator)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_ObjectIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_ReferenceIterator::TObj_ReferenceIterator
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(Standard_Type)& theType,
|
||||
const Standard_Boolean theRecursive)
|
||||
: TObj_LabelIterator (theLabel, theRecursive), myType (theType)
|
||||
{
|
||||
MakeStep();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MakeStep
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_ReferenceIterator::MakeStep()
|
||||
{
|
||||
for(;myIterator.More() && myNode.IsNull(); myIterator.Next())
|
||||
{
|
||||
TDF_Label L = myIterator.Value();
|
||||
|
||||
Handle(TObj_TReference) A;
|
||||
if ( L.FindAttribute(TObj_TReference::GetID(), A) )
|
||||
{
|
||||
myObject = A->Get();
|
||||
if (! myType.IsNull() && !myObject.IsNull() && !myObject->IsKind( myType ))
|
||||
continue;
|
||||
|
||||
myNode = L;
|
||||
}
|
||||
}
|
||||
}
|
53
src/TObj/TObj_ReferenceIterator.hxx
Executable file
53
src/TObj/TObj_ReferenceIterator.hxx
Executable file
@@ -0,0 +1,53 @@
|
||||
// File: TObj_ReferenceIterator.hxx
|
||||
// Created: Tue Nov 23 12:18:32 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_ReferenceIterator_HeaderFile
|
||||
#define TObj_ReferenceIterator_HeaderFile
|
||||
|
||||
#include <TObj_LabelIterator.hxx>
|
||||
|
||||
/**
|
||||
* This class provides an iterator by references of the object
|
||||
* (implements TObj_ReferenceIterator interface)
|
||||
*/
|
||||
|
||||
class TObj_ReferenceIterator : public TObj_LabelIterator
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates the iterator on references in partition
|
||||
//! theType narrows a variety of iterated objects
|
||||
Standard_EXPORT TObj_ReferenceIterator
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(Standard_Type)& theType = NULL,
|
||||
const Standard_Boolean theRecursive = Standard_True);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
|
||||
//! Shift iterator to the next object
|
||||
virtual Standard_EXPORT void MakeStep();
|
||||
|
||||
Handle(Standard_Type) myType; //!< Type of objects to iterate on
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_ReferenceIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_ReferenceIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_ReferenceIterator,TObj_LabelIterator)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
76
src/TObj/TObj_SequenceIterator.cxx
Executable file
76
src/TObj/TObj_SequenceIterator.cxx
Executable file
@@ -0,0 +1,76 @@
|
||||
// File: TObj_SequenceIterator.cxx
|
||||
// Created: Tue Nov 23 12:39:22 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_SequenceIterator.hxx>
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_SequenceIterator,TObj_ObjectIterator)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_SequenceIterator,TObj_ObjectIterator)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_SequenceIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_SequenceIterator::TObj_SequenceIterator() :
|
||||
myIndex( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_SequenceIterator
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_SequenceIterator::TObj_SequenceIterator
|
||||
(const Handle(TObj_HSequenceOfObject)& theObjects,
|
||||
const Handle(Standard_Type)& theType)
|
||||
{
|
||||
myIndex = 1;
|
||||
myType = theType;
|
||||
myObjects = theObjects;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : More
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_SequenceIterator::More() const
|
||||
{
|
||||
const Standard_Boolean isMore = (!myObjects.IsNull() &&
|
||||
(myIndex <= myObjects->Length() && myIndex > 0) &&
|
||||
!myObjects->Value(myIndex).IsNull());
|
||||
|
||||
// check type
|
||||
if (isMore && !myType.IsNull() && !myObjects->Value(myIndex)->IsKind( myType ))
|
||||
{
|
||||
TObj_SequenceIterator* me = (TObj_SequenceIterator*) this;
|
||||
me->Next();
|
||||
return More();
|
||||
}
|
||||
|
||||
return isMore;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Next
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_SequenceIterator::Next()
|
||||
{ myIndex++; }
|
||||
|
||||
//=======================================================================
|
||||
//function : Value
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_SequenceIterator::Value() const
|
||||
{
|
||||
return myObjects->Value(myIndex);
|
||||
}
|
72
src/TObj/TObj_SequenceIterator.hxx
Executable file
72
src/TObj/TObj_SequenceIterator.hxx
Executable file
@@ -0,0 +1,72 @@
|
||||
// File: TObj_SequenceIterator.hxx
|
||||
// Created: Tue Nov 23 12:38:17 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_SequenceIterator_HeaderFile
|
||||
#define TObj_SequenceIterator_HeaderFile
|
||||
|
||||
#include <TObj_Container.hxx>
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
|
||||
/**
|
||||
* This class is an iterator on sequence
|
||||
*/
|
||||
|
||||
class TObj_SequenceIterator : public TObj_ObjectIterator
|
||||
{
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates an Empty Iterator
|
||||
Standard_EXPORT TObj_SequenceIterator();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
//! Creates an iterator an initialize it by sequence of objects.
|
||||
Standard_EXPORT TObj_SequenceIterator
|
||||
(const Handle(TObj_HSequenceOfObject)& theObjects,
|
||||
const Handle(Standard_Type)& theType = NULL);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Redefined methods
|
||||
*/
|
||||
|
||||
//! Returns True if there is a current Item in the iteration.
|
||||
virtual Standard_EXPORT Standard_Boolean More () const;
|
||||
|
||||
//! Move to the next Item
|
||||
virtual Standard_EXPORT void Next ();
|
||||
|
||||
//! Returns the current item
|
||||
virtual Standard_EXPORT Handle(TObj_Object) Value () const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Fields
|
||||
*/
|
||||
Standard_Integer myIndex; //!< current index of object in sequence
|
||||
Handle(Standard_Type) myType; //!< type of object
|
||||
Handle(TObj_HSequenceOfObject) myObjects; //!< seqence of objects
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_SequenceIterator)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_SequenceIterator
|
||||
DEFINE_STANDARD_HANDLE(TObj_SequenceIterator,TObj_ObjectIterator)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
23
src/TObj/TObj_SequenceOfIterator.hxx
Executable file
23
src/TObj/TObj_SequenceOfIterator.hxx
Executable file
@@ -0,0 +1,23 @@
|
||||
// File: TObj_SequenceOfIterator.hxx
|
||||
// Created: Thu Nov 23 12:27:24 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_SequenceOfIterator_HeaderFile
|
||||
#define TObj_SequenceOfIterator_HeaderFile
|
||||
|
||||
#include <NCollection_DefineBaseCollection.hxx>
|
||||
#include <NCollection_DefineSequence.hxx>
|
||||
|
||||
#include <TObj_ObjectIterator.hxx>
|
||||
|
||||
DEFINE_BASECOLLECTION (TObj_CollectionOfIterator, Handle(TObj_ObjectIterator))
|
||||
DEFINE_SEQUENCE (TObj_SequenceOfIterator, TObj_CollectionOfIterator,
|
||||
Handle(TObj_ObjectIterator))
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
9
src/TObj/TObj_SequenceOfObject.cxx
Executable file
9
src/TObj/TObj_SequenceOfObject.cxx
Executable file
@@ -0,0 +1,9 @@
|
||||
// File: TObj_SequenceOfObject.cxx
|
||||
// Created: Tue Nov 23 12:39:22 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_SequenceOfObject.hxx>
|
||||
|
||||
IMPLEMENT_HSEQUENCE(TObj_HSequenceOfObject)
|
25
src/TObj/TObj_SequenceOfObject.hxx
Executable file
25
src/TObj/TObj_SequenceOfObject.hxx
Executable file
@@ -0,0 +1,25 @@
|
||||
// File: TObj_SequenceOfObject.hxx
|
||||
// Created: 22.11.04 13:31:14
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_SequenceOfObject_HeaderFile
|
||||
#define TObj_SequenceOfObject_HeaderFile
|
||||
|
||||
#include <NCollection_DefineBaseCollection.hxx>
|
||||
#include <NCollection_DefineSequence.hxx>
|
||||
#include <NCollection_DefineHSequence.hxx>
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <Handle_TObj_Object.hxx>
|
||||
|
||||
DEFINE_BASECOLLECTION (TObj_CollectionOfObject,Handle_TObj_Object)
|
||||
|
||||
DEFINE_SEQUENCE (TObj_SequenceOfObject,
|
||||
TObj_CollectionOfObject,Handle(TObj_Object))
|
||||
|
||||
DEFINE_HSEQUENCE (TObj_HSequenceOfObject,
|
||||
TObj_SequenceOfObject)
|
||||
|
||||
#endif
|
310
src/TObj/TObj_TIntSparseArray.cxx
Executable file
310
src/TObj/TObj_TIntSparseArray.cxx
Executable file
@@ -0,0 +1,310 @@
|
||||
// File : TObj_TIntSparseArray.cxx
|
||||
// Created : 16.03.2007
|
||||
// Author : Michael SAZONOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_TIntSparseArray.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <Standard_ImmutableObject.hxx>
|
||||
#include <TDF_Data.hxx>
|
||||
#include <TDF_AttributeDelta.hxx>
|
||||
#include <TDF_DeltaOnModification.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TIntSparseArray,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TIntSparseArray
|
||||
//purpose : Empty constructor
|
||||
//=======================================================================
|
||||
|
||||
TObj_TIntSparseArray::TObj_TIntSparseArray ()
|
||||
: myVector(100), myOldMap(100), myDoBackup (Standard_True)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TIntSparseArray::GetID()
|
||||
{
|
||||
static Standard_GUID GInterfaceID ("7016dc0c-b118-4433-8ef3-aecdccc79198");
|
||||
return GInterfaceID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TIntSparseArray::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TIntSparseArray) TObj_TIntSparseArray::Set
|
||||
(const TDF_Label& theLabel)
|
||||
{
|
||||
Handle(TObj_TIntSparseArray) aTData;
|
||||
if (! theLabel.FindAttribute( GetID(), aTData))
|
||||
{
|
||||
aTData = new TObj_TIntSparseArray;
|
||||
theLabel.AddAttribute(aTData);
|
||||
}
|
||||
return aTData;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::SetValue (const Standard_Integer theId,
|
||||
const Standard_Integer theValue)
|
||||
{
|
||||
// check that modification is allowed
|
||||
if ( !Label().Data()->IsModificationAllowed() )
|
||||
Standard_ImmutableObject::Raise
|
||||
("Attribute TObj_TIntSparseArray is changed outside transaction");
|
||||
|
||||
if (theId < 1 || theValue < 1)
|
||||
Standard_OutOfRange::Raise ("TObj_TIntSparseArray::SetValue");
|
||||
|
||||
Standard_Integer anOld = AbsentValue;
|
||||
Standard_Boolean isOld = myVector.HasValue(theId);
|
||||
if (isOld)
|
||||
{
|
||||
Standard_Integer& aData = myVector(theId);
|
||||
if (aData == theValue)
|
||||
// no actual modification
|
||||
return;
|
||||
anOld = aData;
|
||||
// set new value
|
||||
aData = theValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the new value
|
||||
myVector.SetValue (theId, theValue);
|
||||
}
|
||||
|
||||
TDF_Label aLabel = Label();
|
||||
if (!aLabel.IsNull())
|
||||
{
|
||||
Handle(TDF_Data) aData = aLabel.Data();
|
||||
Standard_Integer aCurrentTransaction = aData->Transaction();
|
||||
Standard_Integer aMyTransaction = Transaction();
|
||||
|
||||
if (myDoBackup && aMyTransaction < aCurrentTransaction)
|
||||
backupValue(theId, anOld, theValue);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UnsetValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::UnsetValue (const Standard_Integer theId)
|
||||
{
|
||||
// check that modification is allowed
|
||||
if ( !Label().Data()->IsModificationAllowed() )
|
||||
Standard_ImmutableObject::Raise
|
||||
("Attribute TObj_TIntSparseArray is changed outside transaction");
|
||||
|
||||
if (theId < 1)
|
||||
Standard_OutOfRange::Raise ("TObj_TIntSparseArray::UnsetValue");
|
||||
|
||||
Standard_Integer anOld = AbsentValue;
|
||||
Standard_Boolean isOld = myVector.HasValue(theId);
|
||||
if (isOld)
|
||||
{
|
||||
anOld = myVector(theId);
|
||||
// unset the value
|
||||
myVector.UnsetValue(theId);
|
||||
}
|
||||
else
|
||||
// no actual modification
|
||||
return;
|
||||
|
||||
TDF_Label aLabel = Label();
|
||||
if (!aLabel.IsNull())
|
||||
{
|
||||
Handle(TDF_Data) aData = aLabel.Data();
|
||||
Standard_Integer aCurrentTransaction = aData->Transaction();
|
||||
Standard_Integer aMyTransaction = Transaction();
|
||||
|
||||
if (myDoBackup && aMyTransaction < aCurrentTransaction)
|
||||
backupValue(theId, anOld, AbsentValue);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Clear
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::Clear ()
|
||||
{
|
||||
// backup old values
|
||||
TDF_Label aLabel = Label();
|
||||
if (!aLabel.IsNull())
|
||||
{
|
||||
Handle(TDF_Data) aData = aLabel.Data();
|
||||
Standard_Integer aCurrentTransaction = aData->Transaction();
|
||||
Standard_Integer aMyTransaction = Transaction();
|
||||
|
||||
if (myDoBackup && aMyTransaction < aCurrentTransaction)
|
||||
{
|
||||
TObj_TIntSparseArray_VecOfData::Iterator anIt (myVector);
|
||||
for (; anIt.More(); anIt.Next())
|
||||
{
|
||||
Standard_Integer anId = anIt.Key();
|
||||
Standard_Integer aVal = anIt.Value();
|
||||
backupValue(anId, aVal, AbsentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
myVector.Clear();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : backupValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::backupValue (const Standard_Integer theId,
|
||||
const Standard_Integer theCurrValue,
|
||||
const Standard_Integer theNewValue)
|
||||
{
|
||||
// save the current value if it has not been saved in previous time
|
||||
if ( !myOldMap.IsBound( theId ) )
|
||||
myOldMap.Bind(theId, theCurrValue);
|
||||
else
|
||||
{
|
||||
// if value in Undo is the same as the new one, the item in Undo map may be cleared
|
||||
Standard_Integer aUData = myOldMap.Value(theId);
|
||||
if (aUData == theNewValue)
|
||||
myOldMap.UnBind(theId);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TIntSparseArray::NewEmpty () const
|
||||
{
|
||||
return new TObj_TIntSparseArray;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BackupCopy
|
||||
//purpose : Moves <this> delta into a new other attribute.
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TIntSparseArray::BackupCopy() const
|
||||
{
|
||||
Handle(TObj_TIntSparseArray) aCopy =
|
||||
Handle(TObj_TIntSparseArray)::DownCast(NewEmpty());
|
||||
|
||||
// save delta data in a copy
|
||||
if (!myOldMap.IsEmpty())
|
||||
aCopy->myOldMap.Exchange ( (TObj_TIntSparseArray_MapOfData&)myOldMap );
|
||||
|
||||
return aCopy;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose : Restores contents of this with theDelta
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::Restore(const Handle(TDF_Attribute)& theDelta)
|
||||
{
|
||||
Handle(TObj_TIntSparseArray) aDelta =
|
||||
Handle(TObj_TIntSparseArray)::DownCast(theDelta);
|
||||
if (aDelta.IsNull())
|
||||
return;
|
||||
|
||||
// restore the values from aDelta->myOldMap
|
||||
if (!aDelta->myOldMap.IsEmpty())
|
||||
{
|
||||
TObj_TIntSparseArray_MapOfData::Iterator anIt (aDelta->myOldMap);
|
||||
for (; anIt.More(); anIt.Next())
|
||||
{
|
||||
Standard_Integer anId = anIt.Key();
|
||||
Standard_Integer anOld = anIt.Value();
|
||||
if (anOld == AbsentValue)
|
||||
UnsetValue (anId);
|
||||
else
|
||||
SetValue (anId, anOld);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose : copy this
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)&) const
|
||||
{
|
||||
Handle(TObj_TIntSparseArray) aInto =
|
||||
Handle(TObj_TIntSparseArray)::DownCast(theInto);
|
||||
if(aInto.IsNull())
|
||||
return;
|
||||
|
||||
aInto->myVector.Assign(myVector);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BeforeCommitTransaction
|
||||
//purpose : It is called just before Commit or Abort transaction
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::BeforeCommitTransaction()
|
||||
{
|
||||
if (!myOldMap.IsEmpty())
|
||||
{
|
||||
Backup();
|
||||
ClearDelta();
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : DeltaOnModification
|
||||
//purpose : Applies aDelta to <me>
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TIntSparseArray::DeltaOnModification
|
||||
(const Handle(TDF_DeltaOnModification)& theDelta)
|
||||
{
|
||||
// we do not call Backup here, because a backup data is formed inside Restore.
|
||||
// Backup is called rather from BeforeCommitTransaction
|
||||
Restore(theDelta->Attribute());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterUndo
|
||||
//purpose : After application of a TDF_Delta.
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TIntSparseArray::AfterUndo
|
||||
(const Handle(TDF_AttributeDelta)&,
|
||||
const Standard_Boolean)
|
||||
{
|
||||
// we must be sure that a delta in <me> is cleared
|
||||
ClearDelta();
|
||||
return Standard_True;
|
||||
}
|
150
src/TObj/TObj_TIntSparseArray.hxx
Executable file
150
src/TObj/TObj_TIntSparseArray.hxx
Executable file
@@ -0,0 +1,150 @@
|
||||
// File : TObj_TIntSparseArray.hxx
|
||||
// Created : 16.03.2007
|
||||
// Author : Michael SAZONOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TIntSparseArray_HeaderFile
|
||||
#define TObj_TIntSparseArray_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
#include <NCollection_SparseArray.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
|
||||
typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
|
||||
typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
|
||||
|
||||
class Handle(TObj_TIntSparseArray);
|
||||
class Standard_GUID;
|
||||
class Handle(TDF_RelocationTable);
|
||||
|
||||
/**
|
||||
* OCAF Attribute to store a set of positive integer values in the OCAF tree.
|
||||
* Each value is identified by ID (positive integer).
|
||||
* The supporting underlying data structure is NCollection_SparseArray of integers.
|
||||
*/
|
||||
|
||||
class TObj_TIntSparseArray : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TIntSparseArray();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of this attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
//! Creates TObj_TIntSparseArray attribute on given label.
|
||||
static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
|
||||
(const TDF_Label& theLabel);
|
||||
|
||||
public:
|
||||
//! Methods for access to data
|
||||
|
||||
//! Returns the number of stored values in the set
|
||||
Standard_EXPORT Standard_Integer Size() const
|
||||
{ return myVector.Size(); }
|
||||
|
||||
typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
|
||||
|
||||
//! Returns iterator on objects contained in the set
|
||||
Iterator GetIterator() const { return Iterator(myVector); }
|
||||
|
||||
//! Returns true if the value with the given ID is present.
|
||||
Standard_Boolean HasValue (const Standard_Integer theId) const
|
||||
{ return myVector.HasValue(theId); }
|
||||
|
||||
//! Returns the value by its ID.
|
||||
//! Raises an exception if no value is stored with this ID
|
||||
Standard_Integer Value (const Standard_Integer theId) const
|
||||
{ return myVector.Value(theId); }
|
||||
|
||||
//! Sets the value with the given ID.
|
||||
//! Raises an exception if theId is not positive
|
||||
Standard_EXPORT void SetValue (const Standard_Integer theId,
|
||||
const Standard_Integer theValue);
|
||||
|
||||
//! Unsets the value with the given ID.
|
||||
//! Raises an exception if theId is not positive
|
||||
Standard_EXPORT void UnsetValue(const Standard_Integer theId);
|
||||
|
||||
//! Clears the set
|
||||
Standard_EXPORT void Clear ();
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Moves this delta into a new other attribute.
|
||||
Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const;
|
||||
|
||||
//! Restores the set using info saved in backup attribute theDelta.
|
||||
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
//! It is called just before Commit or Abort transaction
|
||||
//! and does Backup() to create a delta
|
||||
Standard_EXPORT void BeforeCommitTransaction();
|
||||
|
||||
//! Applies theDelta to this.
|
||||
Standard_EXPORT void DeltaOnModification
|
||||
(const Handle(TDF_DeltaOnModification)& theDelta);
|
||||
|
||||
//! Clears my modification delta; called after application of theDelta
|
||||
Standard_EXPORT Standard_Boolean AfterUndo
|
||||
(const Handle(TDF_AttributeDelta)& theDelta,
|
||||
const Standard_Boolean toForce);
|
||||
|
||||
public:
|
||||
//! Methods to handle the modification delta
|
||||
|
||||
//! Sets the flag pointing to the necessity to maintain a modification delta.
|
||||
//! It is called by the retrieval driver
|
||||
void SetDoBackup (const Standard_Boolean toDo)
|
||||
{ myDoBackup = toDo; }
|
||||
|
||||
void ClearDelta ()
|
||||
{ myOldMap.Clear(); }
|
||||
|
||||
private:
|
||||
//! Internal constant to recognize items in the backup array
|
||||
//! correspondent to absent values
|
||||
enum
|
||||
{
|
||||
AbsentValue = -1
|
||||
};
|
||||
|
||||
//! backup one value
|
||||
void backupValue (const Standard_Integer theId,
|
||||
const Standard_Integer theCurrValue,
|
||||
const Standard_Integer theNewValue);
|
||||
|
||||
TObj_TIntSparseArray_VecOfData myVector;
|
||||
TObj_TIntSparseArray_MapOfData myOldMap;
|
||||
Standard_Boolean myDoBackup;
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TIntSparseArray)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TIntSparseArray
|
||||
DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
98
src/TObj/TObj_TModel.cxx
Executable file
98
src/TObj/TObj_TModel.cxx
Executable file
@@ -0,0 +1,98 @@
|
||||
// File: TObj_TModel.cxx
|
||||
// Created: Thu Nov 23 12:49:09 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_TModel.hxx>
|
||||
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TDF_RelocationTable.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TModel,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TModel,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TModel::GetID()
|
||||
{
|
||||
static Standard_GUID GModelID ("bbdab6a6-dca9-11d4-ba37-0060b0ee18ea");
|
||||
return GModelID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TModel
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_TModel::TObj_TModel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TModel::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TModel::NewEmpty() const
|
||||
{
|
||||
return new TObj_TModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Model
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Model) TObj_TModel::Model() const
|
||||
{
|
||||
return myModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TModel::Set(const Handle(TObj_Model)& theModel)
|
||||
{
|
||||
Backup();
|
||||
myModel = theModel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TModel::Restore(const Handle(TDF_Attribute)& theWith)
|
||||
{
|
||||
Handle(TObj_TModel) R = Handle(TObj_TModel)::DownCast (theWith);
|
||||
myModel = R->Model();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TModel::Paste (const Handle(TDF_Attribute)& theInto ,
|
||||
const Handle(TDF_RelocationTable)& /* RT */) const
|
||||
{
|
||||
Handle(TObj_TModel) R = Handle(TObj_TModel)::DownCast (theInto);
|
||||
R->Set(myModel);
|
||||
}
|
79
src/TObj/TObj_TModel.hxx
Executable file
79
src/TObj/TObj_TModel.hxx
Executable file
@@ -0,0 +1,79 @@
|
||||
// File: TObj_TModel.hxx
|
||||
// Created: Thu Nov 23 12:42:45 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TModel_HeaderFile
|
||||
#define TObj_TModel_HeaderFile
|
||||
|
||||
#include <TDF_Attribute.hxx>
|
||||
#include <Handle_TObj_Model.hxx>
|
||||
|
||||
class Handle(TDF_RelocationTable);
|
||||
class Handle(TObj_TModel);
|
||||
|
||||
/**
|
||||
* Attribute to store OCAF-based models in OCAF tree
|
||||
* The persistency mechanism of the TObj_TModel allowes to save
|
||||
* and restore various types of models without recompilation of the schema
|
||||
*/
|
||||
|
||||
class TObj_TModel : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Standard methods of attribute
|
||||
*/
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TModel();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of TObj_TModel attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
public:
|
||||
//! Methods for setting and obtaining the Model object
|
||||
|
||||
//! Sets the the Model object
|
||||
Standard_EXPORT void Set(const Handle(TObj_Model)& theModel);
|
||||
|
||||
//! Returns the Model object
|
||||
Standard_EXPORT Handle(TObj_Model) Model() const;
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TModel attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Restores the backuped contents from <theWith> into this one. It is used
|
||||
//! when aborting a transaction.
|
||||
Standard_EXPORT void Restore (const Handle(TDF_Attribute)& theWith);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
private:
|
||||
//! Fields
|
||||
Handle(TObj_Model) myModel; //!< The Model object stored by the attribute
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TModel)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TModel
|
||||
DEFINE_STANDARD_HANDLE(TObj_TModel,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
157
src/TObj/TObj_TNameContainer.cxx
Executable file
157
src/TObj/TObj_TNameContainer.cxx
Executable file
@@ -0,0 +1,157 @@
|
||||
// File: TObj_TNameContainer.cxx
|
||||
// Created: Tue Nov 23 12:51:24 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_TNameContainer.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TNameContainer,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TNameContainer,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TNameContainer
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_TNameContainer::TObj_TNameContainer()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TNameContainer::GetID()
|
||||
{
|
||||
static Standard_GUID theID ("3bbefb47-e618-11d4-ba38-0060b0ee18ea");
|
||||
return theID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TNameContainer::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TNameContainer) TObj_TNameContainer::Set(const TDF_Label& theLabel)
|
||||
{
|
||||
Handle(TObj_TNameContainer) A;
|
||||
if (!theLabel.FindAttribute(TObj_TNameContainer::GetID(), A))
|
||||
{
|
||||
A = new TObj_TNameContainer;
|
||||
theLabel.AddAttribute(A);
|
||||
}
|
||||
return A;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RecordName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TNameContainer::RecordName(const Handle(TCollection_HExtendedString)& theName,
|
||||
const TDF_Label& theLabel)
|
||||
{
|
||||
if(!IsRegistered(theName))
|
||||
{
|
||||
Backup();
|
||||
myMap.Bind(new TCollection_HExtendedString(theName->String()),theLabel);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TNameContainer::RemoveName(const Handle(TCollection_HExtendedString)& theName)
|
||||
{
|
||||
if(IsRegistered(theName))
|
||||
{
|
||||
Backup();
|
||||
myMap.UnBind(theName);
|
||||
}
|
||||
}
|
||||
|
||||
void TObj_TNameContainer::Clear()
|
||||
{
|
||||
Backup();
|
||||
myMap.Clear();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CheckName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TNameContainer::IsRegistered(const Handle(TCollection_HExtendedString)& theName) const
|
||||
{
|
||||
return myMap.IsBound(theName);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TNameContainer::NewEmpty () const
|
||||
{
|
||||
return new TObj_TNameContainer();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TNameContainer::Restore(const Handle(TDF_Attribute)& theWith)
|
||||
{
|
||||
Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theWith);
|
||||
|
||||
myMap = R->Get();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TNameContainer::Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& /* RT */) const
|
||||
{
|
||||
Handle(TObj_TNameContainer) R = Handle(TObj_TNameContainer)::DownCast (theInto);
|
||||
R->Set(myMap);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const TObj_DataMapOfNameLabel& TObj_TNameContainer::Get() const
|
||||
{
|
||||
return myMap;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TNameContainer::Set(const TObj_DataMapOfNameLabel& theMap)
|
||||
{
|
||||
Backup();
|
||||
myMap = theMap;
|
||||
}
|
99
src/TObj/TObj_TNameContainer.hxx
Executable file
99
src/TObj/TObj_TNameContainer.hxx
Executable file
@@ -0,0 +1,99 @@
|
||||
// File: TObj_TNameContainer.hxx
|
||||
// Created: Tue Nov 23 12:50:48 2004
|
||||
// Author: Pavel DURANDIN
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TNameContainer_HeaderFile
|
||||
#define TObj_TNameContainer_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_Container.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
|
||||
class Handle(TCollection_HExtendedString);
|
||||
class Handle(TObj_TNameContainer);
|
||||
|
||||
/**
|
||||
* This class provides OCAF Attribute to storing the unique names of object in
|
||||
* model.
|
||||
*/
|
||||
|
||||
class TObj_TNameContainer : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
//! Standard methods of OCAF attribute
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TNameContainer();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of TObj_TNameContainer attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
public:
|
||||
//! Method for create TObj_TNameContainer object
|
||||
|
||||
//! Creates TObj_DataMapOfNameLabel attribute on given label if not exist
|
||||
static Standard_EXPORT Handle(TObj_TNameContainer) Set(const TDF_Label& theLabel);
|
||||
|
||||
public:
|
||||
//! Methods for adding and removing names
|
||||
|
||||
//! Records name with label attached
|
||||
Standard_EXPORT void RecordName(const Handle(TCollection_HExtendedString)& theName,
|
||||
const TDF_Label& theLabel);
|
||||
|
||||
//! Remove name from the map
|
||||
Standard_EXPORT void RemoveName(const Handle(TCollection_HExtendedString)& theName);
|
||||
|
||||
//! Return True is theName is registered in the Map
|
||||
Standard_EXPORT Standard_Boolean IsRegistered(const Handle(TCollection_HExtendedString)& theName) const;
|
||||
|
||||
//! Remove all names registered in container
|
||||
Standard_EXPORT void Clear();
|
||||
|
||||
public:
|
||||
//! Methods for setting and obtaining TObj_TNameContainer
|
||||
|
||||
//! Sets the TObj_DataMapOfNameLabel object
|
||||
Standard_EXPORT void Set(const TObj_DataMapOfNameLabel& theElem);
|
||||
|
||||
//! Returns the TObj_DataMapOfNameLabel object
|
||||
Standard_EXPORT const TObj_DataMapOfNameLabel& Get() const;
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TNameContainer attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Restores the backuped contents from <theWith> into this one. It is used
|
||||
//! when aborting a transaction.
|
||||
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
private:
|
||||
//! Fields
|
||||
TObj_DataMapOfNameLabel myMap; //!< The map of the names
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TNameContainer)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TObject
|
||||
DEFINE_STANDARD_HANDLE(TObj_TNameContainer,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
177
src/TObj/TObj_TObject.cxx
Executable file
177
src/TObj/TObj_TObject.cxx
Executable file
@@ -0,0 +1,177 @@
|
||||
// File: TObj_TObject.cxx
|
||||
// Created: Tue Nov 23 12:53:21 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_TObject.hxx>
|
||||
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TDF_AttributeDelta.hxx>
|
||||
#include <TDF_ChildIterator.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TObject,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TObject,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TObject
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_TObject::TObj_TObject()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TObject::GetID()
|
||||
{
|
||||
static Standard_GUID GInterfaceID ("bbdab6a7-dca9-11d4-ba37-0060b0ee18ea");
|
||||
return GInterfaceID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TObject::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TObject::Set(const Handle(TObj_Object)& theElem)
|
||||
{
|
||||
Backup();
|
||||
myElem = theElem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TObject) TObj_TObject::Set(const TDF_Label& theLabel,
|
||||
const Handle(TObj_Object)& theElem)
|
||||
{
|
||||
Handle(TObj_TObject) A;
|
||||
if (!theLabel.FindAttribute(TObj_TObject::GetID(), A))
|
||||
{
|
||||
A = new TObj_TObject;
|
||||
theLabel.AddAttribute(A);
|
||||
}
|
||||
A->Set(theElem);
|
||||
return A;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_TObject::Get() const
|
||||
{
|
||||
return myElem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TObject::NewEmpty () const
|
||||
{
|
||||
return new TObj_TObject();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TObject::Restore(const Handle(TDF_Attribute)& theWith)
|
||||
{
|
||||
Handle(TObj_TObject) R = Handle(TObj_TObject)::DownCast (theWith);
|
||||
myElem = R->Get();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TObject::Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& /* RT */) const
|
||||
{
|
||||
Handle(TObj_TObject) R = Handle(TObj_TObject)::DownCast (theInto);
|
||||
R->Set(myElem);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BeforeForget
|
||||
//purpose : Tell TObj_Object to die,
|
||||
// i.e. (myElem->IsAlive() == false) after that
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TObject::BeforeForget()
|
||||
{
|
||||
if (!myElem.IsNull())
|
||||
{
|
||||
// attempt to delete all data from sublabels of object to remove dependences
|
||||
TDF_Label aObjLabel = myElem->myLabel;
|
||||
if (!aObjLabel.IsNull())
|
||||
{
|
||||
TDF_ChildIterator aLI(aObjLabel);
|
||||
TDF_Label aSubLabel;
|
||||
for(; aLI.More(); aLI.Next())
|
||||
{
|
||||
aSubLabel = aLI.Value();
|
||||
if (!aSubLabel.IsNull())
|
||||
aSubLabel.ForgetAllAttributes(Standard_True);
|
||||
}
|
||||
}
|
||||
// remove back references before document die
|
||||
myElem->RemoveBackReferences(TObj_Forced);
|
||||
TDF_Label aNullLabel;
|
||||
myElem->myLabel = aNullLabel;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterUndo
|
||||
//purpose : Tell TObj_Object to rise from the dead,
|
||||
// i.e. (myElem->IsAlive() == true) after that
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TObject::AfterUndo
|
||||
(const Handle(TDF_AttributeDelta)& anAttDelta,
|
||||
const Standard_Boolean /*forceIt*/)
|
||||
{
|
||||
if (!myElem.IsNull())
|
||||
{
|
||||
TDF_Label aLabel = anAttDelta->Label();
|
||||
Handle(TDF_Attribute) anAttr;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
Handle(TDF_Attribute) me;
|
||||
me = this;
|
||||
if(!aLabel.IsNull() && aLabel.FindAttribute(GetID(), anAttr))
|
||||
aTObject = Handle(TObj_TObject)::DownCast(anAttr);
|
||||
|
||||
if(!aTObject.IsNull() && aTObject->Get() == myElem)
|
||||
myElem->myLabel = aLabel;
|
||||
else
|
||||
{
|
||||
TDF_Label aNullLabel;
|
||||
myElem->myLabel = aNullLabel;
|
||||
}
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
99
src/TObj/TObj_TObject.hxx
Executable file
99
src/TObj/TObj_TObject.hxx
Executable file
@@ -0,0 +1,99 @@
|
||||
// File: TObj_TObject.hxx
|
||||
// Created: Tue Nov 23 12:51:43 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TObject_HeaderFile
|
||||
#define TObj_TObject_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TObj_Object.hxx>
|
||||
|
||||
#include <TDF_Attribute.hxx>
|
||||
|
||||
class Handle(TObj_TObject);
|
||||
class Standard_GUID;
|
||||
class TDF_Label;
|
||||
class Handle(TDF_RelocationTable);
|
||||
|
||||
/**
|
||||
* Purpose: OCAF Attribute to storing objects (interfaces) of OCAF-based
|
||||
* modelers in the OCAF tree.
|
||||
* The persistency mechanism of the TObj_TObject allowes to save
|
||||
* and restore objects of various subtypes without recompilation of the schema
|
||||
*/
|
||||
|
||||
class TObj_TObject : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
//! Standard methods of OCAF attribute
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TObject();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of TObj_TObject attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
public:
|
||||
//! Method for create TObj_TObject object
|
||||
|
||||
//! Creates TObj_TObject attribute on given label
|
||||
static Standard_EXPORT Handle(TObj_TObject) Set(const TDF_Label& theLabel,
|
||||
const Handle(TObj_Object)& theElem);
|
||||
|
||||
public:
|
||||
//! Methods for setting and obtaining TObj_Object
|
||||
|
||||
//! Sets the TObj_Object object
|
||||
Standard_EXPORT void Set(const Handle(TObj_Object)& theElem);
|
||||
|
||||
//! Returns the TObj_Object object
|
||||
Standard_EXPORT Handle(TObj_Object) Get() const;
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TObject attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Restores the backuped contents from <theWith> into this one. It is used
|
||||
//! when aborting a transaction.
|
||||
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
//! Tell TObj_Object to die,
|
||||
//! i.e. (myElem->IsAlive() == false) after that
|
||||
Standard_EXPORT void BeforeForget();
|
||||
|
||||
//! Tell TObj_Object to rise from the dead,
|
||||
//! i.e. (myElem->IsAlive() == true) after that
|
||||
Standard_EXPORT Standard_Boolean AfterUndo
|
||||
(const Handle(TDF_AttributeDelta)& anAttDelta,
|
||||
const Standard_Boolean forceIt);
|
||||
|
||||
private:
|
||||
//! Fields
|
||||
Handle(TObj_Object) myElem; //!< The object interface stored by the attribute
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TObject)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TObject
|
||||
DEFINE_STANDARD_HANDLE(TObj_TObject,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
318
src/TObj/TObj_TReference.cxx
Executable file
318
src/TObj/TObj_TReference.cxx
Executable file
@@ -0,0 +1,318 @@
|
||||
// File: TObj_TReference.cxx
|
||||
// Created: Tue Nov 23 12:55:42 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_Object.hxx>
|
||||
#include <TObj_TReference.hxx>
|
||||
#include <TObj_TObject.hxx>
|
||||
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TDF_RelocationTable.hxx>
|
||||
#include <TDF_DeltaOnAddition.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TReference,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TReference,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TReference
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_TReference::TObj_TReference()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TReference::GetID()
|
||||
{
|
||||
static Standard_GUID theGUID ("3bbefb44-e618-11d4-ba38-0060b0ee18ea");
|
||||
return theGUID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TReference::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TReference) TObj_TReference::Set
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(TObj_Object)& theObject,
|
||||
const Handle(TObj_Object)& theMaster)
|
||||
{
|
||||
Handle(TObj_TReference) A;
|
||||
if (!theLabel.FindAttribute(TObj_TReference::GetID(), A))
|
||||
{
|
||||
A = new TObj_TReference;
|
||||
theLabel.AddAttribute(A);
|
||||
}
|
||||
else
|
||||
{
|
||||
Handle(TObj_Object) anObj = A->Get();
|
||||
if ( ! anObj.IsNull() ) anObj->RemoveBackReference(theMaster);
|
||||
}
|
||||
A->Set(theObject, theMaster->GetLabel());
|
||||
if ( ! theObject.IsNull() )
|
||||
theObject->AddBackReference(theMaster);
|
||||
return A;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::Set(const Handle(TObj_Object)& theElem,
|
||||
const TDF_Label& theMasterLabel)
|
||||
{
|
||||
Backup();
|
||||
if ( theElem.IsNull() )
|
||||
myLabel.Nullify();
|
||||
else
|
||||
myLabel = theElem->GetLabel();
|
||||
|
||||
myMasterLabel = theMasterLabel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose : for persistent only.
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::Set(const TDF_Label& theLabel,
|
||||
const TDF_Label& theMasterLabel)
|
||||
{
|
||||
Backup();
|
||||
myLabel = theLabel;
|
||||
myMasterLabel = theMasterLabel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_Object) TObj_TReference::Get() const
|
||||
{
|
||||
Handle(TObj_TObject) aTObject;
|
||||
Handle(TObj_Object) anObject;
|
||||
// Take TObj_TObject from label and get from it TObj_Object
|
||||
if ( myLabel.IsNull() || ! myLabel.FindAttribute(TObj_TObject::GetID(), aTObject) )
|
||||
{
|
||||
return anObject;
|
||||
}
|
||||
anObject = Handle(TObj_Object)::DownCast(aTObject->Get());
|
||||
return anObject;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TReference::NewEmpty () const
|
||||
{
|
||||
return new TObj_TReference();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::Restore(const Handle(TDF_Attribute)& theWith)
|
||||
{
|
||||
Handle(TObj_TReference) aReference = Handle(TObj_TReference)::DownCast (theWith);
|
||||
myLabel = aReference->myLabel;
|
||||
myMasterLabel = aReference->myMasterLabel;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& RT) const
|
||||
{
|
||||
Handle(TObj_TReference) aReference = Handle(TObj_TReference)::DownCast (theInto);
|
||||
Handle(TObj_TObject) aObject, aMasterTObj;
|
||||
if (myLabel.IsNull())
|
||||
{
|
||||
// unvalidity if it neccessary
|
||||
aReference->myLabel.Nullify();
|
||||
return;
|
||||
}
|
||||
|
||||
// get new referenced object
|
||||
TDF_Label aRefLabel = myLabel;
|
||||
if(!RT->HasRelocation(myLabel, aRefLabel))
|
||||
aRefLabel = myLabel;
|
||||
aRefLabel.FindAttribute(TObj_TObject::GetID(), aObject);
|
||||
Handle(TObj_Object) anIObject;
|
||||
if ( ! aObject.IsNull() )
|
||||
anIObject = aObject->Get();
|
||||
|
||||
// find correct master label
|
||||
Handle(TObj_Object) aMasterObj;
|
||||
TObj_Object::GetObj(aReference->Label(), aMasterObj, Standard_True);
|
||||
TDF_Label aMasterLabel;
|
||||
if ( ! aMasterObj.IsNull() ) aMasterLabel = aMasterObj->GetLabel();
|
||||
if ( aMasterLabel.IsNull() ||
|
||||
! aMasterLabel.FindAttribute(TObj_TObject::GetID(), aMasterTObj))
|
||||
return;
|
||||
|
||||
// set master and referenced label
|
||||
aReference->Set(anIObject, aMasterLabel);
|
||||
|
||||
// update back references
|
||||
if ( !anIObject.IsNull() )
|
||||
anIObject->AddBackReference(aMasterTObj->Get());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BeforeForget
|
||||
//purpose : for correct tranzaction mechanism.
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::BeforeForget()
|
||||
{
|
||||
// check if master object exist
|
||||
if(myMasterLabel.IsNull())
|
||||
return;
|
||||
|
||||
// removing back reference
|
||||
Handle(TObj_Object) aMasterObject;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
if (!myMasterLabel.FindAttribute(TObj_TObject::GetID(), aTObject ))
|
||||
return;
|
||||
aMasterObject = aTObject->Get();
|
||||
|
||||
Handle(TObj_Object) anObj = Get();
|
||||
if(anObj.IsNull())
|
||||
return;
|
||||
|
||||
aMasterObject->BeforeForgetReference( GetLabel() );
|
||||
anObj->RemoveBackReference( aMasterObject );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BeforeUndo
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TReference::BeforeUndo(const Handle(TDF_AttributeDelta)& theDelta,
|
||||
const Standard_Boolean /*isForced*/)
|
||||
{
|
||||
if (!theDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition)))
|
||||
return Standard_True;
|
||||
|
||||
if(myMasterLabel.IsNull())
|
||||
return Standard_True;
|
||||
|
||||
Handle(TObj_Object) anObject = Get();
|
||||
if( anObject.IsNull() )
|
||||
return Standard_True;
|
||||
|
||||
Handle(TObj_Object) aMasterObject;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
if (!myMasterLabel.FindAttribute(TObj_TObject::GetID(), aTObject ))
|
||||
return Standard_True;
|
||||
aMasterObject = aTObject->Get();
|
||||
|
||||
if( !anObject.IsNull() )
|
||||
anObject->RemoveBackReference( aMasterObject );
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterUndo
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TReference::AfterUndo(const Handle(TDF_AttributeDelta)& theDelta,
|
||||
const Standard_Boolean /*isForced*/)
|
||||
{
|
||||
if (!theDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnRemoval)))
|
||||
return Standard_True;
|
||||
|
||||
if(myMasterLabel.IsNull())
|
||||
return Standard_True;
|
||||
|
||||
Handle(TObj_Object) anObject = Get();
|
||||
if( anObject.IsNull() )
|
||||
return Standard_True;
|
||||
|
||||
Handle(TObj_Object) aMasterObject;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
|
||||
if (!myMasterLabel.FindAttribute(TObj_TObject::GetID(), aTObject ))
|
||||
return Standard_True;
|
||||
aMasterObject = aTObject->Get();
|
||||
|
||||
if( !anObject.IsNull() )
|
||||
anObject->AddBackReference( aMasterObject );
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterResume
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TReference::AfterResume()
|
||||
{
|
||||
if(myMasterLabel.IsNull())
|
||||
return;
|
||||
|
||||
Handle(TObj_Object) aMasterObject;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
if (!myMasterLabel.FindAttribute(TObj_TObject::GetID(), aTObject ))
|
||||
return;
|
||||
aMasterObject = aTObject->Get();
|
||||
Handle(TObj_Object) anObject = Get();
|
||||
|
||||
if ( !anObject.IsNull() )
|
||||
anObject->AddBackReference( aMasterObject );
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AfterRetrieval
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean TObj_TReference::AfterRetrieval(const Standard_Boolean /*forceIt*/)
|
||||
{
|
||||
if(myMasterLabel.IsNull())
|
||||
return Standard_True;
|
||||
|
||||
Handle(TObj_Object) anObject = Get();
|
||||
Handle(TObj_Object) aMasterObject;
|
||||
Handle(TObj_TObject) aTObject;
|
||||
if (!myMasterLabel.FindAttribute(TObj_TObject::GetID(), aTObject ))
|
||||
return Standard_False;
|
||||
|
||||
aMasterObject = aTObject->Get();
|
||||
if ( !anObject.IsNull() )
|
||||
anObject->AddBackReference( aMasterObject );
|
||||
|
||||
return Standard_True;
|
||||
}
|
126
src/TObj/TObj_TReference.hxx
Executable file
126
src/TObj/TObj_TReference.hxx
Executable file
@@ -0,0 +1,126 @@
|
||||
// File: TObj_TReference.hxx
|
||||
// Created: Tue Nov 23 12:54:28 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TReference_HeaderFile
|
||||
#define TObj_TReference_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
|
||||
class Handle(TObj_TReference);
|
||||
class Handle(TObj_Object);
|
||||
class Standard_GUID;
|
||||
class Handle(TDF_RelocationTable);
|
||||
|
||||
/**
|
||||
* Attribute for storing references to the objects which implement
|
||||
* TObj_Object interface in the OCAF tree.
|
||||
* Its persistency mechanism provides transparent method for storing
|
||||
* cross-model references.
|
||||
* Each reference, when created, registers itself in the referred object,
|
||||
* to support back references
|
||||
*/
|
||||
|
||||
class TObj_TReference : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
//! Standard methods of OCAF attribute
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TReference();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of TObj_TReference attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
public:
|
||||
//! Method for create TObj_TReference object
|
||||
|
||||
//! Creates reference on TDF_Label <theLabel> to the object <theObject> and
|
||||
//! creates backreference from the object <theObject> to <theMaster> one.
|
||||
static Standard_EXPORT Handle(TObj_TReference) Set
|
||||
(const TDF_Label& theLabel,
|
||||
const Handle(TObj_Object)& theObject,
|
||||
const Handle(TObj_Object)& theMaster);
|
||||
|
||||
public:
|
||||
//! Methods for setting and obtaining referenced object
|
||||
|
||||
//! Sets the reference to the theObject
|
||||
Standard_EXPORT void Set(const Handle(TObj_Object)& theObject,
|
||||
const TDF_Label& theMasterLabel);
|
||||
|
||||
//! Sets the reference to the theObject at indicated Label.
|
||||
//! It is method for persistent only. Don`t use anywhere else.
|
||||
Standard_EXPORT void Set(const TDF_Label& theLabel,
|
||||
const TDF_Label& theMasterLabel);
|
||||
|
||||
//! Returns the referenced theObject
|
||||
Standard_EXPORT Handle(TObj_Object) Get() const;
|
||||
|
||||
//! Returns the Label of master object.
|
||||
Standard_EXPORT TDF_Label GetMasterLabel() const {return myMasterLabel;}
|
||||
|
||||
//! Returns the referred label.
|
||||
Standard_EXPORT TDF_Label GetLabel() const {return myLabel;}
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TReference attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Restores the backuped contents from <theWith> into this one. It is used
|
||||
//! when aborting a transaction.
|
||||
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
//! Remove back references of it reference if it is in other document.
|
||||
virtual Standard_EXPORT void BeforeForget();
|
||||
|
||||
//! It is necessary for tranzaction mechanism (Undo/Redo).
|
||||
virtual Standard_EXPORT Standard_Boolean BeforeUndo
|
||||
(const Handle(TDF_AttributeDelta)& theDelta,
|
||||
const Standard_Boolean isForced = Standard_False);
|
||||
|
||||
//! It is necessary for tranzaction mechanism (Undo/Redo).
|
||||
virtual Standard_EXPORT Standard_Boolean AfterUndo
|
||||
(const Handle(TDF_AttributeDelta)& theDelta,
|
||||
const Standard_Boolean isForced = Standard_False);
|
||||
|
||||
//! Check if back reference exists for reference.
|
||||
virtual Standard_EXPORT void AfterResume();
|
||||
|
||||
//! Called after retrieval reference from file.
|
||||
virtual Standard_EXPORT Standard_Boolean AfterRetrieval
|
||||
(const Standard_Boolean forceIt = Standard_False);
|
||||
|
||||
private:
|
||||
//! Fields
|
||||
TDF_Label myLabel; //!< Label that indicate referenced object
|
||||
TDF_Label myMasterLabel; //!< Label of object that have this reference.
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TReference)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TReference
|
||||
DEFINE_STANDARD_HANDLE(TObj_TReference,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
127
src/TObj/TObj_TXYZ.cxx
Executable file
127
src/TObj/TObj_TXYZ.cxx
Executable file
@@ -0,0 +1,127 @@
|
||||
// File: TObj_TXYZ.cxx
|
||||
// Created: Tue Nov 23 12:57:32 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#include <TObj_TXYZ.hxx>
|
||||
#include <Standard_GUID.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE(TObj_TXYZ,TDF_Attribute)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(TObj_TXYZ,TDF_Attribute)
|
||||
|
||||
//=======================================================================
|
||||
//function : TObj_TXYZ
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
TObj_TXYZ::TObj_TXYZ()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TXYZ::GetID()
|
||||
{
|
||||
static Standard_GUID theGUID ("3bbefb50-e618-11d4-ba38-0060b0ee18ea");
|
||||
return theGUID;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ID
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const Standard_GUID& TObj_TXYZ::ID() const
|
||||
{
|
||||
return GetID();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TObj_TXYZ) TObj_TXYZ::Set (const TDF_Label& theLabel,
|
||||
const gp_XYZ& theXYZ)
|
||||
{
|
||||
Handle(TObj_TXYZ) A;
|
||||
if (!theLabel.FindAttribute(TObj_TXYZ::GetID(), A))
|
||||
{
|
||||
A = new TObj_TXYZ;
|
||||
theLabel.AddAttribute(A);
|
||||
}
|
||||
A->Set(theXYZ);
|
||||
return A;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TXYZ::Set (const gp_XYZ& theXYZ)
|
||||
{
|
||||
Backup();
|
||||
myXYZ = theXYZ;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Get
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_XYZ TObj_TXYZ::Get () const
|
||||
{
|
||||
return myXYZ;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NewEmpty
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(TDF_Attribute) TObj_TXYZ::NewEmpty () const
|
||||
{
|
||||
return new TObj_TXYZ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Restore
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TXYZ::Restore (const Handle(TDF_Attribute)& theWith)
|
||||
{
|
||||
Handle(TObj_TXYZ) R = Handle(TObj_TXYZ)::DownCast(theWith);
|
||||
myXYZ = R->Get();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Paste
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void TObj_TXYZ::Paste (const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& /* RT */) const
|
||||
{
|
||||
Handle(TObj_TXYZ) R = Handle(TObj_TXYZ)::DownCast (theInto);
|
||||
R->Set(myXYZ);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_OStream& TObj_TXYZ::Dump(Standard_OStream& theOS) const
|
||||
{
|
||||
gp_XYZ aXYZ = Get();
|
||||
Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
|
||||
anOS << "X: " << aXYZ.X() << "\tY: " << aXYZ.Y() << "\tZ: " << aXYZ.Z();
|
||||
return anOS;
|
||||
}
|
89
src/TObj/TObj_TXYZ.hxx
Executable file
89
src/TObj/TObj_TXYZ.hxx
Executable file
@@ -0,0 +1,89 @@
|
||||
// File: TObj_TXYZ.hxx
|
||||
// Created: Tue Nov 23 12:57:15 2004
|
||||
// Author: Pavel TELKOV
|
||||
// Copyright: Open CASCADE 2007
|
||||
// The original implementation Copyright: (C) RINA S.p.A
|
||||
|
||||
#ifndef TObj_TXYZ_HeaderFile
|
||||
#define TObj_TXYZ_HeaderFile
|
||||
|
||||
#include <TObj_Common.hxx>
|
||||
|
||||
#include <gp_XYZ.hxx>
|
||||
#include <TDF_Attribute.hxx>
|
||||
|
||||
|
||||
class Handle(TObj_TXYZ);
|
||||
class Standard_GUID;
|
||||
class TDF_Label;
|
||||
class Handle(TDF_RelocationTable);
|
||||
|
||||
/*
|
||||
* Attribute for storing gp_XYZ
|
||||
*/
|
||||
|
||||
class TObj_TXYZ : public TDF_Attribute
|
||||
{
|
||||
public:
|
||||
//! Standard methods of OCAF attribute
|
||||
|
||||
//! Empty constructor
|
||||
Standard_EXPORT TObj_TXYZ();
|
||||
|
||||
//! This method is used in implementation of ID()
|
||||
static Standard_EXPORT const Standard_GUID& GetID();
|
||||
|
||||
//! Returns the ID of TObj_TXYZ attribute.
|
||||
Standard_EXPORT const Standard_GUID& ID() const;
|
||||
|
||||
public:
|
||||
//! Method for create TObj_TXYZ object
|
||||
|
||||
//! Creates attribute and sets the XYZ
|
||||
static Standard_EXPORT Handle(TObj_TXYZ) Set (const TDF_Label& theLabel,
|
||||
const gp_XYZ& theXYZ);
|
||||
public:
|
||||
//! Methods for setting and obtaining XYZ
|
||||
|
||||
//! Sets the XYZ
|
||||
Standard_EXPORT void Set(const gp_XYZ& theXYZ);
|
||||
|
||||
//! Returns the XYZ
|
||||
Standard_EXPORT gp_XYZ Get() const;
|
||||
|
||||
public:
|
||||
//! Redefined OCAF abstract methods
|
||||
|
||||
//! Returns an new empty TObj_TXYZ attribute. It is used by the
|
||||
//! copy algorithm.
|
||||
Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
|
||||
|
||||
//! Restores the backuped contents from <theWith> into this one. It is used
|
||||
//! when aborting a transaction.
|
||||
Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith);
|
||||
|
||||
//! This method is used when copying an attribute from a source structure
|
||||
//! into a target structure.
|
||||
Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
|
||||
const Handle(TDF_RelocationTable)& theRT) const;
|
||||
|
||||
//! This method dumps the attribute value into the stream
|
||||
Standard_EXPORT virtual Standard_OStream& Dump(Standard_OStream& theOS) const;
|
||||
|
||||
private:
|
||||
//! Fields
|
||||
gp_XYZ myXYZ; //!< The object interface stored by the attribute
|
||||
|
||||
public:
|
||||
//! CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI(TObj_TXYZ)
|
||||
};
|
||||
|
||||
//! Define handle class for TObj_TXYZ
|
||||
DEFINE_STANDARD_HANDLE(TObj_TXYZ,TDF_Attribute)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
Reference in New Issue
Block a user