mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-16 10:08:36 +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);
|
||||||
|
@ -242,7 +242,7 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
|
|||||||
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;
|
||||||
@ -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",
|
||||||
|
@ -76,7 +76,8 @@ 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;
|
||||||
|
@ -221,6 +221,12 @@ public:
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@ -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