1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0025534: TObj_Application unicode path issue.

This commit is contained in:
mpv 2016-09-05 13:27:40 +03:00 committed by bugmaster
parent f1fb0901d6
commit 1f9fb70723
6 changed files with 67 additions and 76 deletions

View File

@ -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. * 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. 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()*. 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.

View File

@ -67,38 +67,36 @@ Standard_CString TObj_Application::ResourcesName()
//======================================================================= //=======================================================================
Standard_Boolean TObj_Application::SaveDocument Standard_Boolean TObj_Application::SaveDocument
(const Handle(TDocStd_Document)& theSourceDoc, (const Handle(TDocStd_Document)& theSourceDoc,
const char* theTargetFile) const TCollection_ExtendedString theTargetFile)
{ {
myIsError = Standard_False; myIsError = Standard_False;
TCollection_ExtendedString aPath ((const Standard_CString)theTargetFile); PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, theTargetFile);
PCDM_StoreStatus aStatus = SaveAs (theSourceDoc, aPath);
myIsError = aStatus != PCDM_SS_OK; myIsError = aStatus != PCDM_SS_OK;
if (myIsError) if (myIsError)
{ {
switch (aStatus) switch (aStatus)
{ {
case PCDM_SS_DriverFailure: case PCDM_SS_DriverFailure:
ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SDriverFailure") << theTargetFile);
break; break;
case PCDM_SS_WriteFailure: case PCDM_SS_WriteFailure:
ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SWriteFailure") << theTargetFile);
break; break;
case PCDM_SS_Failure: case PCDM_SS_Failure:
ErrorMessage (Message_Msg("TObj_Appl_SFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SFailure") << theTargetFile);
break; break;
case PCDM_SS_Doc_IsNull: case PCDM_SS_Doc_IsNull:
ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SDocIsNull") << theTargetFile);
break; break;
case PCDM_SS_No_Obj: case PCDM_SS_No_Obj:
ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SNoObj") << theTargetFile);
break; break;
case PCDM_SS_Info_Section_Error: case PCDM_SS_Info_Section_Error:
ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SInfoSectionError") << theTargetFile);
break; break;
default: default:
ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_SUnknownFailure") << theTargetFile);
break; break;
} }
} }
@ -114,17 +112,15 @@ Standard_Boolean TObj_Application::SaveDocument
//======================================================================= //=======================================================================
Standard_Boolean TObj_Application::LoadDocument Standard_Boolean TObj_Application::LoadDocument
(const char* theSourceFile, (const TCollection_ExtendedString theSourceFile,
Handle(TDocStd_Document)& theTargetDoc) Handle(TDocStd_Document)& theTargetDoc)
{ {
myIsError = Standard_False; myIsError = Standard_False;
TCollection_ExtendedString aPath ((const Standard_CString)theSourceFile);
PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException; PCDM_ReaderStatus aStatus = PCDM_RS_ReaderException;
{ {
try try
{ {
aStatus = Open (aPath, theTargetDoc); aStatus = Open (theSourceFile, theTargetDoc);
} }
catch (Standard_Failure) catch (Standard_Failure)
{ {
@ -140,55 +136,55 @@ Standard_Boolean TObj_Application::LoadDocument
switch (aStatus) switch (aStatus)
{ {
case PCDM_RS_UnknownDocument: case PCDM_RS_UnknownDocument:
ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RUnknownDocument") << theSourceFile);
break; break;
case PCDM_RS_AlreadyRetrieved: case PCDM_RS_AlreadyRetrieved:
ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrieved") << theSourceFile);
break; break;
case PCDM_RS_AlreadyRetrievedAndModified: case PCDM_RS_AlreadyRetrievedAndModified:
ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RAlreadyRetrievedAndModified") << theSourceFile);
break; break;
case PCDM_RS_NoDriver: case PCDM_RS_NoDriver:
ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile);
break; break;
case PCDM_RS_UnknownFileDriver: case PCDM_RS_UnknownFileDriver:
ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RNoDriver") << theSourceFile);
break; break;
case PCDM_RS_OpenError: case PCDM_RS_OpenError:
ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << aPath); ErrorMessage (Message_Msg("TObj_Appl_ROpenError") << theSourceFile);
break; break;
case PCDM_RS_NoVersion: case PCDM_RS_NoVersion:
ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RNoVersion") << theSourceFile);
break; break;
case PCDM_RS_NoModel: case PCDM_RS_NoModel:
ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RNoModel") << theSourceFile);
break; break;
case PCDM_RS_NoDocument: case PCDM_RS_NoDocument:
ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RNoDocument") << theSourceFile);
break; break;
case PCDM_RS_FormatFailure: case PCDM_RS_FormatFailure:
ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RFormatFailure") << theSourceFile);
break; break;
case PCDM_RS_TypeNotFoundInSchema: case PCDM_RS_TypeNotFoundInSchema:
ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RTypeNotFound") << theSourceFile);
break; break;
case PCDM_RS_UnrecognizedFileFormat: case PCDM_RS_UnrecognizedFileFormat:
ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RBadFileFormat") << theSourceFile);
break; break;
case PCDM_RS_MakeFailure: case PCDM_RS_MakeFailure:
ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RMakeFailure") << theSourceFile);
break; break;
case PCDM_RS_PermissionDenied: case PCDM_RS_PermissionDenied:
ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RPermissionDenied") << theSourceFile);
break; break;
case PCDM_RS_DriverFailure: case PCDM_RS_DriverFailure:
ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RDriverFailure") << theSourceFile);
break; break;
case PCDM_RS_ReaderException: case PCDM_RS_ReaderException:
ErrorMessage (Message_Msg("TObj_Appl_RException") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RException") << theSourceFile);
break; break;
default: default:
ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << aPath); ErrorMessage (Message_Msg("TObj_Appl_RUnknownFail") << theSourceFile);
break; break;
} }
} }

View File

@ -46,13 +46,13 @@ public:
//! Saving the OCAF document to a file //! Saving the OCAF document to a file
virtual Standard_EXPORT Standard_Boolean SaveDocument virtual Standard_EXPORT Standard_Boolean SaveDocument
(const Handle(TDocStd_Document)& theSourceDoc, (const Handle(TDocStd_Document)& theSourceDoc,
const char* theTargetFile); const TCollection_ExtendedString theTargetFile);
//! Loading the OCAF document from a file //! Loading the OCAF document from a file
virtual Standard_EXPORT Standard_Boolean LoadDocument virtual Standard_EXPORT Standard_Boolean LoadDocument
(const char* theSourceFile, (const TCollection_ExtendedString theSourceFile,
Handle(TDocStd_Document)& theTargetDoc); Handle(TDocStd_Document)& theTargetDoc);
//! Create the OCAF document from scratch //! Create the OCAF document from scratch
virtual Standard_EXPORT Standard_Boolean CreateNewDocument virtual Standard_EXPORT Standard_Boolean CreateNewDocument

View File

@ -108,7 +108,7 @@ void TObj_Model::CloseDocument (const Handle(TDocStd_Document)& theDoc)
//purpose : Loads the model from the file //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 // Return status
Standard_Boolean aStatus = Standard_True; Standard_Boolean aStatus = Standard_True;
@ -144,7 +144,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile)
else else
{ {
// retrieve TDocStd_Document from <theFile> // retrieve TDocStd_Document from <theFile>
Messenger()->Send(Message_Msg("TObj_M_LoadDocument") << (Standard_CString)theFile, Messenger()->Send(Message_Msg("TObj_M_LoadDocument") << theFile,
Message_Info); Message_Info);
aStatus = anApplication->LoadDocument(theFile,aDoc); aStatus = anApplication->LoadDocument(theFile,aDoc);
@ -168,7 +168,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile)
{ {
if (!aDoc.IsNull()) CloseDocument (aDoc); if (!aDoc.IsNull()) CloseDocument (aDoc);
myLabel.Nullify(); myLabel.Nullify();
Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile, Messenger()->Send(Message_Msg("TObj_M_WrongFile") << theFile,
Message_Alarm); Message_Alarm);
aStatus = Standard_False; aStatus = Standard_False;
} }
@ -198,7 +198,7 @@ Standard_Boolean TObj_Model::Load (const char* theFile)
aString = aString + ": " + anExc->GetMessageString(); aString = aString + ": " + anExc->GetMessageString();
Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString); Messenger()->Send(Message_Msg("TObj_Appl_Exception") << aString);
#endif #endif
Messenger()->Send(Message_Msg("TObj_M_WrongFile") << (Standard_CString)theFile, Messenger()->Send(Message_Msg("TObj_M_WrongFile") << theFile,
Message_Alarm); Message_Alarm);
} }
} }
@ -220,19 +220,19 @@ Standard_Boolean TObj_Model::Load (const char* theFile)
// or null if the model was not saved yet // 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(); Handle(TDocStd_Document) aDoc = GetDocument();
if ( aDoc.IsNull() if ( aDoc.IsNull()
|| !aDoc->IsStored()) || !aDoc->IsStored())
{ {
return Handle(TCollection_HAsciiString)(); return Handle(TCollection_HExtendedString)();
} }
TCollection_AsciiString aPath (aDoc->GetPath()); TCollection_ExtendedString aPath(aDoc->GetPath());
return !aPath.IsEmpty() return !aPath.IsEmpty()
? new TCollection_HAsciiString (aPath) ? new TCollection_HExtendedString(aPath)
: Handle(TCollection_HAsciiString)(); : Handle(TCollection_HExtendedString)();
} }
//======================================================================= //=======================================================================
@ -243,12 +243,12 @@ Handle(TCollection_HAsciiString) TObj_Model::GetFile() const
Standard_Boolean TObj_Model::Save () Standard_Boolean TObj_Model::Save ()
{ {
Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel()); Handle(TDocStd_Document) aDoc = TDocStd_Document::Get(GetLabel());
if ( aDoc.IsNull() ) if (aDoc.IsNull())
return Standard_False; return Standard_False;
TCollection_AsciiString anOldPath( aDoc->GetPath() );
if ( !anOldPath.IsEmpty() ) if (!aDoc->GetPath().IsEmpty() )
return SaveAs( anOldPath.ToCString() ); return SaveAs(aDoc->GetPath());
return Standard_True; return Standard_True;
} }
@ -257,7 +257,7 @@ Standard_Boolean TObj_Model::Save ()
//purpose : Save the model to a file //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(); TObj_Assistant::ClearTypeMap();
// OCAF document // OCAF document
@ -265,19 +265,12 @@ Standard_Boolean TObj_Model::SaveAs (const char* theFile)
if ( aDoc.IsNull() ) if ( aDoc.IsNull() )
return Standard_False; return Standard_False;
// checking that file is present on disk // checking that file is present on disk is not needed because could try to save as new
/* do not check, because could try to save as new document to existent file // 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 // checking write access permission
FILE *aF = OSD_OpenFile (theFile, "w"); FILE *aF = OSD_OpenFile (theFile, "w");
if (aF == NULL) { if (aF == NULL) {
Messenger()->Send (Message_Msg("TObj_M_NoWriteAccess") << (Standard_CString)theFile, Messenger()->Send (Message_Msg("TObj_M_NoWriteAccess") << theFile,
Message_Alarm); Message_Alarm);
return Standard_False; return Standard_False;
} }
@ -751,16 +744,12 @@ void TObj_Model::SetModified (const Standard_Boolean theModified)
//purpose : Check whether the document contains the Ocaf data //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; return Standard_True;
TCollection_AsciiString aFile ((Standard_CString) theFile); OSD_Path aPath (theFile);
if (aFile.IsEmpty())
return Standard_True;
OSD_Path aPath (aFile);
OSD_File osdfile (aPath); OSD_File osdfile (aPath);
if ( !osdfile.Exists() ) if ( !osdfile.Exists() )
return Standard_True; return Standard_True;

View File

@ -64,8 +64,8 @@ class TObj_Model : public MMgt_TShared
Standard_EXPORT ~TObj_Model (); Standard_EXPORT ~TObj_Model ();
//! Check whether the document contains the OCAF data. //! Check whether the document contains the OCAF data.
//! This implementation checks theFile on NULL only. Standard_EXPORT virtual Standard_Boolean
Standard_EXPORT virtual Standard_Boolean checkDocumentEmpty (const char* theFile); checkDocumentEmpty(const TCollection_ExtendedString theFile);
public: public:
/** /**
@ -84,11 +84,12 @@ class TObj_Model : public MMgt_TShared
* Implementation of Load/Save for OCAF based models * Implementation of Load/Save for OCAF based models
*/ */
//! Load the OCAF model from a file //! Load the OCAF model from a file. If the filename is empty or file does
virtual Standard_EXPORT Standard_Boolean Load (const char* theFile); //! 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 //! 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 //! Save the model to the same file
Standard_EXPORT Standard_Boolean Save (); 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, //! Returns the full file name this model is to be saved to,
//! or null if the model was not saved yet //! 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: public:
/** /**

View File

@ -159,7 +159,8 @@ static Standard_Integer newModel (Draw_Interpretor& di, Standard_Integer argc, c
if (!DDocStd::GetDocument(argv[1],D,Standard_False)) { if (!DDocStd::GetDocument(argv[1],D,Standard_False)) {
Handle(TObjDRAW_Model) aModel = new TObjDRAW_Model(); Handle(TObjDRAW_Model) aModel = new TObjDRAW_Model();
aModel->Load(0); // initializes the new model: filename is empty
aModel->Load("");
D = aModel->GetDocument(); D = aModel->GetDocument();
DD = new DDocStd_DrawDocument(D); DD = new DDocStd_DrawDocument(D);
TDataStd_Name::Set(D->GetData()->Root(),argv[1]); TDataStd_Name::Set(D->GetData()->Root(),argv[1]);