mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-06-30 12:14:08 +03:00
0028862: Unification of empty labels saving procedure.
Added a possibility to save empty labels to a persistent document in case of need.
This commit is contained in:
parent
dc2cc1350e
commit
030ba6489b
@ -106,6 +106,8 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theDo
|
|||||||
myDrivers = AttributeDrivers (myMsgDriver);
|
myDrivers = AttributeDrivers (myMsgDriver);
|
||||||
Handle(TDF_Data) aData = aDoc->GetData();
|
Handle(TDF_Data) aData = aDoc->GetData();
|
||||||
FirstPass (aData->Root());
|
FirstPass (aData->Root());
|
||||||
|
if(aDoc->EmptyLabelsSavingMode())
|
||||||
|
myEmptyLabels.Clear(); //
|
||||||
|
|
||||||
// 1. Write info section (including types table)
|
// 1. Write info section (including types table)
|
||||||
WriteInfoSection (aDoc, theOStream);
|
WriteInfoSection (aDoc, theOStream);
|
||||||
|
@ -232,17 +232,17 @@ static Standard_Integer DDocStd_Save (Draw_Interpretor& di,
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
|
static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
|
||||||
Standard_Integer nb,
|
Standard_Integer nb,
|
||||||
const char** a)
|
const char** a)
|
||||||
{
|
{
|
||||||
if (nb >= 3) {
|
if (nb >= 3) {
|
||||||
Handle(TDocStd_Document) D;
|
Handle(TDocStd_Document) D;
|
||||||
if (!DDocStd::GetDocument(a[1],D)) return 1;
|
if (!DDocStd::GetDocument(a[1],D)) return 1;
|
||||||
TCollection_ExtendedString path (a[2]);
|
TCollection_ExtendedString path (a[2]);
|
||||||
Handle(TDocStd_Application) A = DDocStd::GetApplication();
|
Handle(TDocStd_Application) A = DDocStd::GetApplication();
|
||||||
PCDM_StoreStatus theStatus;
|
PCDM_StoreStatus theStatus;
|
||||||
|
|
||||||
Standard_Boolean anUseStream = Standard_False;
|
Standard_Boolean anUseStream(Standard_False), isSaveEmptyLabels(Standard_False);
|
||||||
for ( Standard_Integer i = 3; i < nb; i++ )
|
for ( Standard_Integer i = 3; i < nb; i++ )
|
||||||
{
|
{
|
||||||
if (!strcmp (a[i], "-stream"))
|
if (!strcmp (a[i], "-stream"))
|
||||||
@ -250,9 +250,11 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
|
|||||||
di << "standard SEEKABLE stream is used\n";
|
di << "standard SEEKABLE stream is used\n";
|
||||||
anUseStream = Standard_True;
|
anUseStream = Standard_True;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
isSaveEmptyLabels = ((atoi (a[3])) != 0);
|
||||||
|
D->SetEmptyLabelsSavingMode(isSaveEmptyLabels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anUseStream)
|
if (anUseStream)
|
||||||
{
|
{
|
||||||
std::ofstream aFileStream;
|
std::ofstream aFileStream;
|
||||||
@ -263,35 +265,35 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
|
|||||||
{
|
{
|
||||||
theStatus = A->SaveAs(D,path);
|
theStatus = A->SaveAs(D,path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theStatus != PCDM_SS_OK ) {
|
if (theStatus != PCDM_SS_OK ) {
|
||||||
switch ( theStatus ) {
|
switch ( theStatus ) {
|
||||||
case PCDM_SS_DriverFailure: {
|
case PCDM_SS_DriverFailure: {
|
||||||
di << "Error saving document: Could not store , no driver found to make it\n";
|
di << "Error saving document: Could not store , no driver found to make it\n";
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
case PCDM_SS_WriteFailure: {
|
case PCDM_SS_WriteFailure: {
|
||||||
di << "Error saving document: Write access failure\n";
|
di << "Error saving document: Write access failure\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PCDM_SS_Failure: {
|
case PCDM_SS_Failure: {
|
||||||
di << "Error saving document: Write failure\n" ;
|
di << "Error saving document: Write failure\n" ;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PCDM_SS_Doc_IsNull: {
|
case PCDM_SS_Doc_IsNull: {
|
||||||
di << "Error saving document: No document to save\n";
|
di << "Error saving document: No document to save\n";
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
case PCDM_SS_No_Obj: {
|
case PCDM_SS_No_Obj: {
|
||||||
di << "Error saving document: No objects written\n";
|
di << "Error saving document: No objects written\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PCDM_SS_Info_Section_Error: {
|
case PCDM_SS_Info_Section_Error: {
|
||||||
di << "Error saving document: Write info section failure\n" ;
|
di << "Error saving document: Write info section failure\n" ;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@ -531,7 +533,7 @@ void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands)
|
|||||||
__FILE__, DDocStd_Open, g);
|
__FILE__, DDocStd_Open, g);
|
||||||
|
|
||||||
theCommands.Add("SaveAs",
|
theCommands.Add("SaveAs",
|
||||||
"SaveAs DOC path [-stream]",
|
"SaveAs DOC path [saveEmptyLabels: 0|1] [-stream]",
|
||||||
__FILE__, DDocStd_SaveAs, g);
|
__FILE__, DDocStd_SaveAs, g);
|
||||||
|
|
||||||
theCommands.Add("Save",
|
theCommands.Add("Save",
|
||||||
|
@ -71,19 +71,20 @@ Handle(TDocStd_Document) TDocStd_Document::Get (const TDF_Label& acces)
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
|
|
||||||
TDocStd_Document::TDocStd_Document(const TCollection_ExtendedString& aStorageFormat) :
|
TDocStd_Document::TDocStd_Document(const TCollection_ExtendedString& aStorageFormat) :
|
||||||
myStorageFormat(aStorageFormat),
|
myStorageFormat(aStorageFormat),
|
||||||
myData (new TDF_Data()),
|
myData (new TDF_Data()),
|
||||||
myUndoLimit(0),
|
myUndoLimit(0),
|
||||||
mySaveTime(0),
|
mySaveTime(0),
|
||||||
myIsNestedTransactionMode(0)
|
myIsNestedTransactionMode(0),
|
||||||
|
mySaveEmptyLabels(Standard_False)
|
||||||
{
|
{
|
||||||
TDF_Transaction* pTr = new TDF_Transaction (myData,"UNDO");
|
TDF_Transaction* pTr = new TDF_Transaction (myData,"UNDO");
|
||||||
myUndoTransaction = *pTr; delete pTr;
|
myUndoTransaction = *pTr; delete pTr;
|
||||||
TDocStd_Owner::SetDocument(myData,this);
|
TDocStd_Owner::SetDocument(myData,this);
|
||||||
|
|
||||||
#ifdef SRN_DELTA_COMPACT
|
#ifdef SRN_DELTA_COMPACT
|
||||||
myFromUndo.Nullify();
|
myFromUndo.Nullify();
|
||||||
myFromRedo.Nullify();
|
myFromRedo.Nullify();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -218,24 +218,30 @@ public:
|
|||||||
//! to change format (advanced programming)
|
//! to change format (advanced programming)
|
||||||
//! ================
|
//! ================
|
||||||
Standard_EXPORT virtual void Update (const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Address aModifContext) Standard_OVERRIDE;
|
Standard_EXPORT virtual void Update (const Handle(CDM_Document)& aToDocument, const Standard_Integer aReferenceIdentifier, const Standard_Address aModifContext) Standard_OVERRIDE;
|
||||||
|
|
||||||
Standard_EXPORT virtual TCollection_ExtendedString StorageFormat() const Standard_OVERRIDE;
|
Standard_EXPORT virtual TCollection_ExtendedString StorageFormat() const Standard_OVERRIDE;
|
||||||
|
|
||||||
|
//! Sets saving mode for empty labels. If Standard_True, empty labels will be saved.
|
||||||
|
Standard_EXPORT void SetEmptyLabelsSavingMode (const Standard_Boolean isAllowed);
|
||||||
|
|
||||||
|
//! Returns saving mode for empty labels.
|
||||||
|
Standard_EXPORT Standard_Boolean EmptyLabelsSavingMode() const;
|
||||||
|
|
||||||
//! methods for the nested transaction mode
|
//! methods for the nested transaction mode
|
||||||
Standard_EXPORT virtual void ChangeStorageFormat (const TCollection_ExtendedString& newStorageFormat);
|
Standard_EXPORT virtual void ChangeStorageFormat (const TCollection_ExtendedString& newStorageFormat);
|
||||||
|
|
||||||
//! Sets nested transaction mode if isAllowed == Standard_True
|
//! Sets nested transaction mode if isAllowed == Standard_True
|
||||||
void SetNestedTransactionMode (const Standard_Boolean isAllowed = Standard_True);
|
void SetNestedTransactionMode (const Standard_Boolean isAllowed = Standard_True);
|
||||||
|
|
||||||
//! Returns Standard_True if mode is set
|
//! Returns Standard_True if mode is set
|
||||||
Standard_Boolean IsNestedTransactionMode() const;
|
Standard_Boolean IsNestedTransactionMode() const;
|
||||||
|
|
||||||
//! if theTransactionOnly is True changes is denied outside transactions
|
//! if theTransactionOnly is True changes is denied outside transactions
|
||||||
void SetModificationMode (const Standard_Boolean theTransactionOnly);
|
void SetModificationMode (const Standard_Boolean theTransactionOnly);
|
||||||
|
|
||||||
//! returns True if changes allowed only inside transactions
|
//! returns True if changes allowed only inside transactions
|
||||||
Standard_Boolean ModificationMode() const;
|
Standard_Boolean ModificationMode() const;
|
||||||
|
|
||||||
//! Prepares document for closing
|
//! Prepares document for closing
|
||||||
Standard_EXPORT virtual void BeforeClose();
|
Standard_EXPORT virtual void BeforeClose();
|
||||||
|
|
||||||
@ -277,7 +283,7 @@ private:
|
|||||||
Standard_Boolean myIsNestedTransactionMode;
|
Standard_Boolean myIsNestedTransactionMode;
|
||||||
TDF_DeltaList myUndoFILO;
|
TDF_DeltaList myUndoFILO;
|
||||||
Standard_Boolean myOnlyTransactionModification;
|
Standard_Boolean myOnlyTransactionModification;
|
||||||
|
Standard_Boolean mySaveEmptyLabels;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,3 +106,22 @@ inline Standard_Integer TDocStd_Document::GetSavedTime () const
|
|||||||
{
|
{
|
||||||
return mySaveTime;
|
return mySaveTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : SetEmptyLabelsSavingMode
|
||||||
|
//purpose : Sets saving mode for empty labels. If Standard_True,
|
||||||
|
// empty labels will be saved.
|
||||||
|
//=======================================================================
|
||||||
|
inline void TDocStd_Document::SetEmptyLabelsSavingMode (const Standard_Boolean isAllowed)
|
||||||
|
{
|
||||||
|
mySaveEmptyLabels = isAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : EmptyLabelsSavingMode
|
||||||
|
//purpose : Returns saving mode for empty labels
|
||||||
|
//=======================================================================
|
||||||
|
inline Standard_Boolean TDocStd_Document::EmptyLabelsSavingMode() const
|
||||||
|
{
|
||||||
|
return mySaveEmptyLabels;
|
||||||
|
}
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#include <XmlObjMgt_DOMString.hxx>
|
#include <XmlObjMgt_DOMString.hxx>
|
||||||
#include <XmlObjMgt_Persistent.hxx>
|
#include <XmlObjMgt_Persistent.hxx>
|
||||||
#include <XmlLDrivers.hxx>
|
#include <XmlLDrivers.hxx>
|
||||||
|
#include <TDocStd_Owner.hxx>
|
||||||
|
#include <TDocStd_Document.hxx>
|
||||||
|
|
||||||
IMPLEMENT_DOMSTRING (TagString, "tag")
|
IMPLEMENT_DOMSTRING (TagString, "tag")
|
||||||
IMPLEMENT_DOMSTRING (LabelString, "label")
|
IMPLEMENT_DOMSTRING (LabelString, "label")
|
||||||
@ -131,7 +133,7 @@ Standard_Integer XmlMDF::WriteSubTree
|
|||||||
count += WriteSubTree(aChildLab, aLabElem, theRelocTable, theDrivers);
|
count += WriteSubTree(aChildLab, aLabElem, theRelocTable, theDrivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0 || TDocStd_Owner::GetDocument(theLabel.Data())->EmptyLabelsSavingMode())
|
||||||
{
|
{
|
||||||
theElement.appendChild(aLabElem);
|
theElement.appendChild(aLabElem);
|
||||||
|
|
||||||
|
78
tests/caf/basic/Y1
Normal file
78
tests/caf/basic/Y1
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#INTERFACE CAF
|
||||||
|
# Persistence functionality
|
||||||
|
#
|
||||||
|
# Testing feature: Saving empty labels (BinOcaf format)
|
||||||
|
#
|
||||||
|
# Testing command: SaveAs, Open
|
||||||
|
#
|
||||||
|
|
||||||
|
puts "caf001-Y1"
|
||||||
|
set QA_DUP 0
|
||||||
|
|
||||||
|
set Lab1 [Label D 0:1:1]
|
||||||
|
set Lab2 [Label D 0:1:2]
|
||||||
|
set Lab3 [Label D 0:1:3]
|
||||||
|
## set List1 {0:1:1 0:1:2 0:1:3}
|
||||||
|
## set List2 {0:1:2}
|
||||||
|
|
||||||
|
set aFile1 ${imagedir}/caf001-y1-1.cbf
|
||||||
|
set aFile2 ${imagedir}/caf001-y1-2.cbf
|
||||||
|
|
||||||
|
#1. Open a new Document in BinOcaf format
|
||||||
|
# NewDocument D BinOcaf
|
||||||
|
|
||||||
|
#2. Put integer attribute at the label Lab2
|
||||||
|
SetInteger D $Lab2 321
|
||||||
|
SetReal D $Lab2 871.33
|
||||||
|
|
||||||
|
#3. Save the Document with flag saveEmptyLabels = 1
|
||||||
|
catch {SaveAs D ${aFile1} 1}
|
||||||
|
if { ![file exists ${aFile1}] } {
|
||||||
|
puts "There is not ${aFile} file; SaveAs command: Error writing binary file"
|
||||||
|
puts "Save ERROR"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#4. Save the Document with flag saveEmptyLabels = 0
|
||||||
|
catch {SaveAs D ${aFile2} 0}
|
||||||
|
if { ![file exists ${aFile2}] } {
|
||||||
|
puts "There is not ${aFile} file; SaveAs command: Error writing binary file"
|
||||||
|
puts "Save ERROR"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#5. Open the just saved binary files
|
||||||
|
Close D
|
||||||
|
catch {Open ${aFile1} D1}
|
||||||
|
catch {Open ${aFile2} D2}
|
||||||
|
|
||||||
|
|
||||||
|
#5. Get list of child labels of main label (0:1)
|
||||||
|
set List1 [Children D1 0:1]
|
||||||
|
set List2 [Children D2 0:1]
|
||||||
|
|
||||||
|
#6. Check length of the list of labels in aFile1 (to be len == 3)
|
||||||
|
set len1 [llength ${List1}]
|
||||||
|
if {$len1 != 3} {
|
||||||
|
puts "ERROR: Incorrect number of saved labels in cbf file, n = $len1"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#7. Check length of the list of labels in aFile2 (to be len == 1)
|
||||||
|
set len2 [llength ${List2}]
|
||||||
|
if {$len2 != 1} {
|
||||||
|
puts "ERROR: Incorrect number of saved labels in cbf file, n = $len2"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file delete ${aFile1}
|
||||||
|
file delete ${aFile2}
|
||||||
|
Close D1
|
||||||
|
Close D2
|
||||||
|
|
||||||
|
puts "Saving empty labels: OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
78
tests/caf/basic/Y2
Normal file
78
tests/caf/basic/Y2
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#INTERFACE CAF
|
||||||
|
# Persistence functionality
|
||||||
|
#
|
||||||
|
# Testing feature: Saving empty labels (XmlOcaf format)
|
||||||
|
#
|
||||||
|
# Testing command: SaveAs, Open
|
||||||
|
#
|
||||||
|
|
||||||
|
puts "caf001-Y2"
|
||||||
|
set QA_DUP 0
|
||||||
|
|
||||||
|
set Lab1 [Label D 0:1:1]
|
||||||
|
set Lab2 [Label D 0:1:2]
|
||||||
|
set Lab3 [Label D 0:1:3]
|
||||||
|
## set List1 {0:1:1 0:1:2 0:1:3}
|
||||||
|
## set List2 {0:1:2}
|
||||||
|
|
||||||
|
set aFile1 ${imagedir}/caf001-y1-1.xml
|
||||||
|
set aFile2 ${imagedir}/caf001-y1-2.xml
|
||||||
|
|
||||||
|
#1. Change Document format to XmlOcaf format
|
||||||
|
Format D XmlOcaf
|
||||||
|
|
||||||
|
#2. Put integer attribute at the label Lab2
|
||||||
|
SetInteger D $Lab2 321
|
||||||
|
SetReal D $Lab2 871.33
|
||||||
|
|
||||||
|
#3. Save the Document with flag saveEmptyLabels = 1
|
||||||
|
catch {SaveAs D ${aFile1} 1}
|
||||||
|
if { ![file exists ${aFile1}] } {
|
||||||
|
puts "There is not ${aFile} file; SaveAs command: Error writing xml file with empty labels"
|
||||||
|
puts "Save ERROR"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#4. Save the Document with flag saveEmptyLabels = 0
|
||||||
|
catch {SaveAs D ${aFile2} 0}
|
||||||
|
if { ![file exists ${aFile2}] } {
|
||||||
|
puts "There is not ${aFile} file; SaveAs command: Error writing xml file"
|
||||||
|
puts "Save ERROR"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#5. Open the just saved xml files
|
||||||
|
Close D
|
||||||
|
catch {Open ${aFile1} D1}
|
||||||
|
catch {Open ${aFile2} D2}
|
||||||
|
|
||||||
|
|
||||||
|
#5. Get list of child labels of main label (0:1)
|
||||||
|
set List1 [Children D1 0:1]
|
||||||
|
set List2 [Children D2 0:1]
|
||||||
|
|
||||||
|
#6. Check length of the list of labels in aFile1 (to be len == 3)
|
||||||
|
set len1 [llength ${List1}]
|
||||||
|
if {$len1 != 3} {
|
||||||
|
puts "ERROR: Incorrect number of saved labels in cbf file, n = $len1"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
#7. Check length of the list of labels in aFile2 (to be len == 1)
|
||||||
|
set len2 [llength ${List2}]
|
||||||
|
if {$len2 != 1} {
|
||||||
|
puts "ERROR: Incorrect number of saved labels in cbf file, n = $len2"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file delete ${aFile1}
|
||||||
|
file delete ${aFile2}
|
||||||
|
Close D1
|
||||||
|
Close D2
|
||||||
|
|
||||||
|
puts "Saving empty labels: OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user