diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 33694be620..58db74b63e 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1050,3 +1050,7 @@ The following obsolete features have been removed: * 3D viewer printing API *V3d_View::Print()* has been removed. This functionality was available on Windows platforms only. Applications should use general image dump API *V3d_View::ToPixMap()* and manage printing using platform-specific API at application level. Text resolution can be managed by rendering parameter *Graphic3d_RenderingParams::Resolution*, returned by *V3d_View::ChangeRenderingParams()*. + +@subsection upgrade_occt710_correction_of_TObj_Model Correction in TObj_Model class + +Methods *TObj_Model::SaveAs* and *TObj_Model::Load* receive *TCollection_ExtendedString* filename arguments instead of char*. This shows that the filename may be not-ASCII explicitly. Also it makes OCAF API related to this functionality more conform. diff --git a/src/TObj/TObj_Application.cxx b/src/TObj/TObj_Application.cxx index 8b887f1864..cb6391e9e0 100644 --- a/src/TObj/TObj_Application.cxx +++ b/src/TObj/TObj_Application.cxx @@ -67,38 +67,36 @@ Standard_CString TObj_Application::ResourcesName() //======================================================================= Standard_Boolean TObj_Application::SaveDocument - (const Handle(TDocStd_Document)& theSourceDoc, - const char* theTargetFile) + (const Handle(TDocStd_Document)& theSourceDoc, + const TCollection_ExtendedString theTargetFile) { myIsError = Standard_False; - TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile); - - PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, aPath); + PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, theTargetFile); myIsError = aStatus != PCDM_SS_OK; if (myIsError) { switch (aStatus) { case PCDM_SS_DriverFailure: - ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << theTargetFile); break; case PCDM_SS_WriteFailure: - ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << theTargetFile); break; case PCDM_SS_Failure: - ErrorMessage (Message_Msg("TObj_Appl_SFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SFailure") << theTargetFile); break; case PCDM_SS_Doc_IsNull: - ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << theTargetFile); break; case PCDM_SS_No_Obj: - ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << theTargetFile); break; case PCDM_SS_Info_Section_Error: - ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << theTargetFile); break; default: - ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << theTargetFile); break; } } @@ -114,17 +112,15 @@ Standard_Boolean TObj_Application::SaveDocument //======================================================================= Standard_Boolean TObj_Application::LoadDocument - (const char* theSourceFile, - Handle(TDocStd_Document)& theTargetDoc) + (const TCollection_ExtendedString theSourceFile, + Handle(TDocStd_Document)& theTargetDoc) { myIsError = Standard_False; - TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile); - PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException; { try { - aStatus = Open (aPath, theTargetDoc); + aStatus = Open (theSourceFile, theTargetDoc); } catch (Standard_Failure) { @@ -140,55 +136,55 @@ Standard_Boolean TObj_Application::LoadDocument switch (aStatus) { case PCDM_RS_UnknownDocument: - ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << theSourceFile); break; case PCDM_RS_AlreadyRetrieved: - ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << theSourceFile); break; case PCDM_RS_AlreadyRetrievedAndModified: - ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << theSourceFile); break; case PCDM_RS_NoDriver: - ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile); break; case PCDM_RS_UnknownFileDriver: - ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile); break; case PCDM_RS_OpenError: - ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << theSourceFile); break; case PCDM_RS_NoVersion: - ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << theSourceFile); break; case PCDM_RS_NoModel: - ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << theSourceFile); break; case PCDM_RS_NoDocument: - ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << theSourceFile); break; case PCDM_RS_FormatFailure: - ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << theSourceFile); break; case PCDM_RS_TypeNotFoundInSchema: - ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << theSourceFile); break; case PCDM_RS_UnrecognizedFileFormat: - ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << theSourceFile); break; case PCDM_RS_MakeFailure: - ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << theSourceFile); break; case PCDM_RS_PermissionDenied: - ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << theSourceFile); break; case PCDM_RS_DriverFailure: - ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << theSourceFile); break; case PCDM_RS_ReaderException: - ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RException") << theSourceFile); break; default: - ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath); + ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << theSourceFile); break; } } diff --git a/src/TObj/TObj_Application.hxx b/src/TObj/TObj_Application.hxx index 7d01d64693..91fc01e0bd 100644 --- a/src/TObj/TObj_Application.hxx +++ b/src/TObj/TObj_Application.hxx @@ -46,13 +46,13 @@ public: //! Saving the OCAF document to a file virtual Standard_EXPORT Standard_Boolean SaveDocument - (const Handle(TDocStd_Document)& theSourceDoc, - const char* theTargetFile); + (const Handle(TDocStd_Document)& theSourceDoc, + const TCollection_ExtendedString theTargetFile); //! Loading the OCAF document from a file virtual Standard_EXPORT Standard_Boolean LoadDocument - (const char* theSourceFile, - Handle(TDocStd_Document)& theTargetDoc); + (const TCollection_ExtendedString theSourceFile, + Handle(TDocStd_Document)& theTargetDoc); //! Create the OCAF document from scratch virtual Standard_EXPORT Standard_Boolean CreateNewDocument diff --git a/src/TObj/TObj_Model.cxx b/src/TObj/TObj_Model.cxx index 2d6a52429e..e631269999 100644 --- a/src/TObj/TObj_Model.cxx +++ b/src/TObj/TObj_Model.cxx @@ -108,7 +108,7 @@ void TObj_Model::CloseDocument (const Handle(TDocStd_Document)& theDoc) //purpose : Loads the model from the file //======================================================================= -Standard_Boolean TObj_Model::Load (const char* theFile) +Standard_Boolean TObj_Model::Load (const TCollection_ExtendedString theFile) { // Return status Standard_Boolean aStatus = Standard_True; @@ -144,7 +144,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile) else { // retrieve TDocStd_Document from - Messenger()->Send(Message_Msg("TObj_M_LoadDocument") << (Standard_CString)theFile, + Messenger()->Send(Message_Msg("TObj_M_LoadDocument") << theFile, Message_Info); aStatus = anApplication->LoadDocument(theFile,aDoc); @@ -168,7 +168,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile) { if (!aDoc.IsNull()) CloseDocument (aDoc); myLabel.Nullify(); - Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile, + Messenger()->Send(Message_Msg("TObj_M_WrongFile") << theFile, Message_Alarm); aStatus = Standard_False; } @@ -198,7 +198,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile) aString = aString + ": " + anExc->GetMessageString(); Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString); #endif - Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile, + Messenger()->Send(Message_Msg("TObj_M_WrongFile") << theFile, Message_Alarm); } } @@ -220,19 +220,19 @@ Standard_Boolean TObj_Model::Load (const char* theFile) // or null if the model was not saved yet //======================================================================= -Handle(TCollection_HAsciiString) TObj_Model::GetFile() const +Handle(TCollection_HExtendedString) TObj_Model::GetFile() const { Handle(TDocStd_Document) aDoc = GetDocument(); if ( aDoc.IsNull() || !aDoc->IsStored()) { - return Handle(TCollection_HAsciiString)(); + return Handle(TCollection_HExtendedString)(); } - TCollection_AsciiString aPath (aDoc->GetPath()); + TCollection_ExtendedString aPath(aDoc->GetPath()); return !aPath.IsEmpty() - ? new TCollection_HAsciiString (aPath) - : Handle(TCollection_HAsciiString)(); + ? new TCollection_HExtendedString(aPath) + : Handle(TCollection_HExtendedString)(); } //======================================================================= @@ -243,12 +243,12 @@ Handle(TCollection_HAsciiString) TObj_Model::GetFile() const Standard_Boolean TObj_Model::Save () { Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel()); - if ( aDoc.IsNull() ) + if (aDoc.IsNull()) return Standard_False; - TCollection_AsciiString anOldPath( aDoc->GetPath() ); - if ( !anOldPath.IsEmpty() ) - return SaveAs( anOldPath.ToCString() ); + + if (!aDoc->GetPath().IsEmpty() ) + return SaveAs(aDoc->GetPath()); return Standard_True; } @@ -257,7 +257,7 @@ Standard_Boolean TObj_Model::Save () //purpose : Save the model to a file //======================================================================= -Standard_Boolean TObj_Model::SaveAs (const char* theFile) +Standard_Boolean TObj_Model::SaveAs (const TCollection_ExtendedString theFile) { TObj_Assistant::ClearTypeMap(); // OCAF document @@ -265,19 +265,12 @@ Standard_Boolean TObj_Model::SaveAs (const char* theFile) 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 that file is present on disk is not needed because could try to save as new + // document to existent file // checking write access permission FILE *aF = OSD_OpenFile (theFile, "w"); if (aF == NULL) { - Messenger()->Send (Message_Msg("TObj_M_NoWriteAccess") << (Standard_CString)theFile, + Messenger()->Send (Message_Msg("TObj_M_NoWriteAccess") << theFile, Message_Alarm); return Standard_False; } @@ -751,16 +744,12 @@ void TObj_Model::SetModified (const Standard_Boolean theModified) //purpose : Check whether the document contains the Ocaf data //======================================================================= -Standard_Boolean TObj_Model::checkDocumentEmpty (const char* theFile) +Standard_Boolean TObj_Model::checkDocumentEmpty (const TCollection_ExtendedString theFile) { - if (!theFile) + if (theFile.IsEmpty()) return Standard_True; - TCollection_AsciiString aFile ((Standard_CString) theFile); - if (aFile.IsEmpty()) - return Standard_True; - - OSD_Path aPath (aFile); + OSD_Path aPath (theFile); OSD_File osdfile (aPath); if ( !osdfile.Exists() ) return Standard_True; diff --git a/src/TObj/TObj_Model.hxx b/src/TObj/TObj_Model.hxx index f22292913b..bff5aece50 100644 --- a/src/TObj/TObj_Model.hxx +++ b/src/TObj/TObj_Model.hxx @@ -64,8 +64,8 @@ class TObj_Model : public MMgt_TShared 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); + Standard_EXPORT virtual Standard_Boolean + checkDocumentEmpty(const TCollection_ExtendedString theFile); public: /** @@ -84,11 +84,12 @@ class TObj_Model : public MMgt_TShared * Implementation of Load/Save for OCAF based models */ - //! Load the OCAF model from a file - virtual Standard_EXPORT Standard_Boolean Load (const char* theFile); + //! Load the OCAF model from a file. If the filename is empty or file does + //! not exists, it just initializes model by empty data. + virtual Standard_EXPORT Standard_Boolean Load (const TCollection_ExtendedString theFile); //! Save the model to a file - virtual Standard_EXPORT Standard_Boolean SaveAs (const char* theFile); + virtual Standard_EXPORT Standard_Boolean SaveAs (const TCollection_ExtendedString theFile); //! Save the model to the same file Standard_EXPORT Standard_Boolean Save (); @@ -110,7 +111,7 @@ class TObj_Model : public MMgt_TShared //! 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; + virtual Standard_EXPORT Handle(TCollection_HExtendedString) GetFile() const; public: /** diff --git a/src/TObjDRAW/TObjDRAW.cxx b/src/TObjDRAW/TObjDRAW.cxx index f2f7170423..5f1d9dbc00 100644 --- a/src/TObjDRAW/TObjDRAW.cxx +++ b/src/TObjDRAW/TObjDRAW.cxx @@ -159,7 +159,8 @@ static Standard_Integer newModel (Draw_Interpretor& di, Standard_Integer argc, c if (!DDocStd::GetDocument(argv[1],D,Standard_False)) { Handle(TObjDRAW_Model) aModel = new TObjDRAW_Model(); - aModel->Load(0); + // initializes the new model: filename is empty + aModel->Load(""); D = aModel->GetDocument(); DD = new DDocStd_DrawDocument(D); TDataStd_Name::Set(D->GetData()->Root(),argv[1]);