Small code improvements

This commit is contained in:
jfa 2005-09-13 11:09:57 +00:00
parent b82f9072d0
commit 168917eddd
3 changed files with 55 additions and 53 deletions

View File

@ -167,7 +167,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
// Function : getEntry // Function : getEntry
// Purpose : // Purpose :
//================================================================ //================================================================
static char* getEntry( GEOM::GEOM_Object_ptr object ) static string getEntry( GEOM::GEOM_Object_ptr object )
{ {
SUIT_Session* session = SUIT_Session::session(); SUIT_Session* session = SUIT_Session::session();
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() ); SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@ -179,7 +179,7 @@ static char* getEntry( GEOM::GEOM_Object_ptr object )
SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
_PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
if ( SO ) if ( SO )
return (char*)(SO->GetID().c_str()); return SO->GetID();
} }
} }
return ""; return "";
@ -189,7 +189,7 @@ static char* getEntry( GEOM::GEOM_Object_ptr object )
// Function : getName // Function : getName
// Purpose : // Purpose :
//================================================================ //================================================================
static const char* getName( GEOM::GEOM_Object_ptr object ) static string getName( GEOM::GEOM_Object_ptr object )
{ {
SUIT_Session* session = SUIT_Session::session(); SUIT_Session* session = SUIT_Session::session();
SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() ); SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@ -206,7 +206,7 @@ static const char* getName( GEOM::GEOM_Object_ptr object )
if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
{ {
_PTR(AttributeName) aNameAttr( anAttr ); _PTR(AttributeName) aNameAttr( anAttr );
return aNameAttr->Value().c_str(); return aNameAttr->Value();
} }
} }
} }
@ -319,8 +319,8 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie
string entry = getEntry( theObj ); string entry = getEntry( theObj );
if ( entry != "" ) { if ( entry != "" ) {
Display( new SALOME_InteractiveObject( Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), updateViewer ); updateViewer);
} }
} }
@ -364,8 +364,8 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
string entry = getEntry( theObj ); string entry = getEntry( theObj );
if ( entry != "" ) if ( entry != "" )
{ {
Erase( new SALOME_InteractiveObject( Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
entry.c_str(), "GEOM", strdup( getName( theObj ) ) ), forced, updateViewer ); forced, updateViewer);
} }
} }
@ -1116,4 +1116,3 @@ void GEOM_Displayer::clearTemporary( SalomeApp_SelectionMgr* theSelMgr )
theSelMgr->setSelectedObjects( toSelect, true ); theSelMgr->setSelectedObjects( toSelect, true );
} }

View File

@ -448,23 +448,27 @@ bool GEOMToolsGUI::Import()
QString fileType; QString fileType;
QString file = getFileName(app->desktop(), "", aMap, tr("GEOM_MEN_IMPORT"), true, fileType ); QString fileName = getFileName(app->desktop(), "", aMap,
if( file.isEmpty() || fileType.isEmpty() ) tr("GEOM_MEN_IMPORT"), true, fileType);
if (fileName.isEmpty() || fileType.isEmpty())
return false; return false;
GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() ); GEOM_Operation* anOp = new GEOM_Operation (app, aInsOp.in());
try { try {
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
app->putInfo( tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file( file, /*withExten=*/true )) ); app->putInfo(tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file(fileName, /*withExten=*/true)));
anOp->start(); anOp->start();
anObj = aInsOp->Import( file.latin1(), fileType.latin1() ); CORBA::String_var fileN = fileName.latin1();
CORBA::String_var fileT = fileType.latin1();
anObj = aInsOp->Import(fileN, fileT);
if ( !anObj->_is_nil() && aInsOp->IsDone() ) { if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
anObj->SetName( GEOMBase::GetDefaultName( QObject::tr( "GEOM_IMPORT" ) ).latin1() ); anObj->SetName(GEOMBase::GetDefaultName(QObject::tr("GEOM_IMPORT")).latin1());
QString aPublishObjName = GEOMBase::GetDefaultName( SUIT_Tools::file( file, /*withExten=*/true )); QString aPublishObjName =
GEOMBase::GetDefaultName(SUIT_Tools::file(fileName, /*withExten=*/true));
SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy(aStudy); SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy(aStudy);
GeometryGUI::GetGeomGen()->PublishInStudy(aDSStudy, GeometryGUI::GetGeomGen()->PublishInStudy(aDSStudy,

View File

@ -137,20 +137,16 @@ GEOM::GEOM_Object_ptr GEOM_IInsertOperations_i::Import
void GEOM_IInsertOperations_i::ImportTranslators void GEOM_IInsertOperations_i::ImportTranslators
(GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns) (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
{ {
// Get sequences of available formats
Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
if (!GetOperations()->ImportTranslators(aFormats, aPatterns) ||
aFormats->Length() != aPatterns->Length())
{
aFormats->Clear(); aPatterns->Clear();
}
const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
// allocate the CORBA arrays // allocate the CORBA arrays
GEOM::string_array_var aFormatsArray = new GEOM::string_array(); GEOM::string_array_var aFormatsArray = new GEOM::string_array();
GEOM::string_array_var aPatternsArray = new GEOM::string_array(); GEOM::string_array_var aPatternsArray = new GEOM::string_array();
// Get sequences of available formats
Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
if (GetOperations()->ImportTranslators(aFormats, aPatterns)) {
const int formSize = aFormats->Length();
if (formSize == aPatterns->Length()) {
aFormatsArray->length(formSize); aFormatsArray->length(formSize);
aPatternsArray->length(formSize); aPatternsArray->length(formSize);
@ -160,6 +156,8 @@ void GEOM_IInsertOperations_i::ImportTranslators
aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
} }
}
}
// initialize out-parameters with local arrays // initialize out-parameters with local arrays
theFormats = aFormatsArray._retn(); theFormats = aFormatsArray._retn();
@ -174,17 +172,16 @@ void GEOM_IInsertOperations_i::ImportTranslators
void GEOM_IInsertOperations_i::ExportTranslators void GEOM_IInsertOperations_i::ExportTranslators
(GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns) (GEOM::string_array_out theFormats, GEOM::string_array_out thePatterns)
{ {
// Get sequences of available formats
Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
if (!GetOperations()->ExportTranslators(aFormats, aPatterns)) return;
const int formSize = aFormats->Length(), pattSize = aPatterns->Length();
if (formSize != pattSize) return;
// allocate the CORBA arrays // allocate the CORBA arrays
GEOM::string_array_var aFormatsArray = new GEOM::string_array(); GEOM::string_array_var aFormatsArray = new GEOM::string_array();
GEOM::string_array_var aPatternsArray = new GEOM::string_array(); GEOM::string_array_var aPatternsArray = new GEOM::string_array();
// Get sequences of available formats
Handle(TColStd_HSequenceOfAsciiString) aFormats = new TColStd_HSequenceOfAsciiString;
Handle(TColStd_HSequenceOfAsciiString) aPatterns = new TColStd_HSequenceOfAsciiString;
if (GetOperations()->ExportTranslators(aFormats, aPatterns)) {
const int formSize = aFormats->Length();
if (formSize == aPatterns->Length()) {
aFormatsArray->length(formSize); aFormatsArray->length(formSize);
aPatternsArray->length(formSize); aPatternsArray->length(formSize);
@ -194,6 +191,8 @@ void GEOM_IInsertOperations_i::ExportTranslators
aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString()); aFormatsArray[i-1] = CORBA::string_dup(aFormats->Value(i).ToCString());
aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString()); aPatternsArray[i-1] = CORBA::string_dup(aPatterns->Value(i).ToCString());
} }
}
}
// initialize out-parameters with local arrays // initialize out-parameters with local arrays
theFormats = aFormatsArray._retn(); theFormats = aFormatsArray._retn();