1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +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:
szy
2017-06-29 17:51:43 +03:00
committed by bugmaster
parent dc2cc1350e
commit 030ba6489b
8 changed files with 237 additions and 49 deletions

View File

@@ -106,6 +106,8 @@ void BinLDrivers_DocumentStorageDriver::Write (const Handle(CDM_Document)& theDo
myDrivers = AttributeDrivers (myMsgDriver);
Handle(TDF_Data) aData = aDoc->GetData();
FirstPass (aData->Root());
if(aDoc->EmptyLabelsSavingMode())
myEmptyLabels.Clear(); //
// 1. Write info section (including types table)
WriteInfoSection (aDoc, theOStream);

View File

@@ -232,17 +232,17 @@ static Standard_Integer DDocStd_Save (Draw_Interpretor& di,
//=======================================================================
static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
Standard_Integer nb,
const char** a)
{
Standard_Integer nb,
const char** a)
{
if (nb >= 3) {
Handle(TDocStd_Document) D;
if (!DDocStd::GetDocument(a[1],D)) return 1;
TCollection_ExtendedString path (a[2]);
Handle(TDocStd_Application) A = DDocStd::GetApplication();
PCDM_StoreStatus theStatus;
Standard_Boolean anUseStream = Standard_False;
Standard_Boolean anUseStream(Standard_False), isSaveEmptyLabels(Standard_False);
for ( Standard_Integer i = 3; i < nb; i++ )
{
if (!strcmp (a[i], "-stream"))
@@ -250,9 +250,11 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
di << "standard SEEKABLE stream is used\n";
anUseStream = Standard_True;
break;
} else {
isSaveEmptyLabels = ((atoi (a[3])) != 0);
D->SetEmptyLabelsSavingMode(isSaveEmptyLabels);
}
}
if (anUseStream)
{
std::ofstream aFileStream;
@@ -263,35 +265,35 @@ static Standard_Integer DDocStd_SaveAs (Draw_Interpretor& di,
{
theStatus = A->SaveAs(D,path);
}
if (theStatus != PCDM_SS_OK ) {
switch ( theStatus ) {
case PCDM_SS_DriverFailure: {
di << "Error saving document: Could not store , no driver found to make it\n";
break ;
}
case PCDM_SS_WriteFailure: {
di << "Error saving document: Write access failure\n";
break;
}
case PCDM_SS_Failure: {
di << "Error saving document: Write failure\n" ;
break;
}
case PCDM_SS_Doc_IsNull: {
di << "Error saving document: No document to save\n";
break ;
}
case PCDM_SS_No_Obj: {
di << "Error saving document: No objects written\n";
break;
}
case PCDM_SS_Info_Section_Error: {
di << "Error saving document: Write info section failure\n" ;
break;
}
default:
break;
case PCDM_SS_DriverFailure: {
di << "Error saving document: Could not store , no driver found to make it\n";
break ;
}
case PCDM_SS_WriteFailure: {
di << "Error saving document: Write access failure\n";
break;
}
case PCDM_SS_Failure: {
di << "Error saving document: Write failure\n" ;
break;
}
case PCDM_SS_Doc_IsNull: {
di << "Error saving document: No document to save\n";
break ;
}
case PCDM_SS_No_Obj: {
di << "Error saving document: No objects written\n";
break;
}
case PCDM_SS_Info_Section_Error: {
di << "Error saving document: Write info section failure\n" ;
break;
}
default:
break;
}
return 1;
} else {
@@ -531,7 +533,7 @@ void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands)
__FILE__, DDocStd_Open, g);
theCommands.Add("SaveAs",
"SaveAs DOC path [-stream]",
"SaveAs DOC path [saveEmptyLabels: 0|1] [-stream]",
__FILE__, DDocStd_SaveAs, g);
theCommands.Add("Save",

View File

@@ -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),
myData (new TDF_Data()),
myUndoLimit(0),
mySaveTime(0),
myIsNestedTransactionMode(0)
myIsNestedTransactionMode(0),
mySaveEmptyLabels(Standard_False)
{
TDF_Transaction* pTr = new TDF_Transaction (myData,"UNDO");
myUndoTransaction = *pTr; delete pTr;
TDocStd_Owner::SetDocument(myData,this);
#ifdef SRN_DELTA_COMPACT
myFromUndo.Nullify();
myFromUndo.Nullify();
myFromRedo.Nullify();
#endif
}

View File

@@ -218,24 +218,30 @@ public:
//! 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 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
Standard_EXPORT virtual void ChangeStorageFormat (const TCollection_ExtendedString& newStorageFormat);
//! Sets nested transaction mode if isAllowed == Standard_True
void SetNestedTransactionMode (const Standard_Boolean isAllowed = Standard_True);
//! Returns Standard_True if mode is set
Standard_Boolean IsNestedTransactionMode() const;
Standard_Boolean IsNestedTransactionMode() const;
//! 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
Standard_Boolean ModificationMode() const;
Standard_Boolean ModificationMode() const;
//! Prepares document for closing
Standard_EXPORT virtual void BeforeClose();
@@ -277,7 +283,7 @@ private:
Standard_Boolean myIsNestedTransactionMode;
TDF_DeltaList myUndoFILO;
Standard_Boolean myOnlyTransactionModification;
Standard_Boolean mySaveEmptyLabels;
};

View File

@@ -106,3 +106,22 @@ inline Standard_Integer TDocStd_Document::GetSavedTime () const
{
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;
}

View File

@@ -34,6 +34,8 @@
#include <XmlObjMgt_DOMString.hxx>
#include <XmlObjMgt_Persistent.hxx>
#include <XmlLDrivers.hxx>
#include <TDocStd_Owner.hxx>
#include <TDocStd_Document.hxx>
IMPLEMENT_DOMSTRING (TagString, "tag")
IMPLEMENT_DOMSTRING (LabelString, "label")
@@ -131,7 +133,7 @@ Standard_Integer XmlMDF::WriteSubTree
count += WriteSubTree(aChildLab, aLabElem, theRelocTable, theDrivers);
}
if (count > 0)
if (count > 0 || TDocStd_Owner::GetDocument(theLabel.Data())->EmptyLabelsSavingMode())
{
theElement.appendChild(aLabElem);