X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Gen_i.cxx;h=6b962a028b003449a14ee77f41dc4c2aa5b7b537;hp=a5b429431e02180979ebc07fd9e0fe2934d18fbe;hb=896b180efc0351e28d18fd39bb948eaa8faf5620;hpb=5651bafb1c68eeddb0f9cc9f77fb3cd97aa6e1eb diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index a5b429431..6b962a028 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -45,14 +45,14 @@ #include #include -#ifdef WNT +#ifdef WIN32 #include #include #else #include #endif -#ifdef WNT +#ifdef WIN32 #define LibHandle HMODULE #define LoadLib( name ) LoadLibrary( name ) #define GetProc GetProcAddress @@ -93,7 +93,7 @@ #include "SMESH_Mesh_i.hxx" #include "SMESH_PreMeshInfo.hxx" #include "SMESH_PythonDump.hxx" -//#include "memoire.h" +#include "SMESH_TryCatch.hxx" // to include after OCC headers! #include CORBA_SERVER_HEADER(SMESH_Group) #include CORBA_SERVER_HEADER(SMESH_Filter) @@ -315,7 +315,7 @@ SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb, CORBA::String_var str_host = session->getHostname(); CORBA::Long s_pid = session->getPID(); string my_host = Kernel_Utils::GetHostname(); -#ifdef WNT +#ifdef WIN32 long my_pid = (long)_getpid(); #else long my_pid = (long) getpid(); @@ -355,20 +355,20 @@ SMESH_Gen_i::~SMESH_Gen_i() if ( myShapeReader ) delete myShapeReader; } - //============================================================================= /*! - * SMESH_Gen_i::createHypothesis + * SMESH_Gen_i::getHypothesisCreator * - * Create hypothesis of given type + * Get hypothesis creator */ //============================================================================= -SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName, - const char* theLibName) +GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHypName, + const char* theLibName, + std::string& thePlatformLibName) throw (SALOME::SALOME_Exception) { - /* It's Need to tranlate lib name for WIN32 or X platform */ std::string aPlatformLibName; + /* It's Need to tranlate lib name for WIN32 or X platform */ if ( theLibName && theLibName[0] != '\0' ) { int libNameLen = strlen(theLibName); @@ -378,7 +378,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName !strcmp( theLibName+libNameLen-3, ".so" )) { //the old format -#ifdef WNT +#ifdef WIN32 aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll"; #else aPlatformLibName = theLibName; @@ -387,21 +387,21 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName else { //try to use new format -#ifdef WNT - aPlatformLibName = theLibName + ".dll"; +#ifdef WIN32 + aPlatformLibName = theLibName; + aPlatformLibName += ".dll"; #else aPlatformLibName = "lib" + std::string( theLibName ) + ".so"; #endif } } + thePlatformLibName = aPlatformLibName; Unexpect aCatch(SALOME_SalomeException); if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName); - // create a new hypothesis object servant - SMESH_Hypothesis_i* myHypothesis_i = 0; - SMESH::SMESH_Hypothesis_var hypothesis_i; - + typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* ); + GenericHypothesisCreator_i* aCreator; try { // check, if creator for this hypothesis type already exists @@ -413,7 +413,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName if (!libHandle) { // report any error, if occured -#ifndef WNT +#ifndef WIN32 const char* anError = dlerror(); throw(SALOME_Exception(anError)); #else @@ -423,7 +423,6 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName // get method, returning hypothesis creator if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ..."); - typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName); GetHypothesisCreator procHandle = (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" ); if (!procHandle) @@ -434,26 +433,47 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName // get hypothesis creator if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName); - GenericHypothesisCreator_i* aCreator = procHandle(theHypName); + aCreator = procHandle(theHypName); if (!aCreator) { throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin"))); } - // map hypothesis creator to a hypothesis name myHypCreatorMap[string(theHypName)] = aCreator; + return aCreator; + } + else + { + return myHypCreatorMap[string(theHypName)]; } - - // create a new hypothesis object, store its ref. in studyContext - if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName); - myHypothesis_i = - myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen); - myHypothesis_i->SetLibName(aPlatformLibName.c_str()); // for persistency assurance } catch (SALOME_Exception& S_ex) { THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); } + return aCreator; +} + +//============================================================================= +/*! + * SMESH_Gen_i::createHypothesis + * + * Create hypothesis of given type + */ +//============================================================================= +SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName, + const char* theLibName) +{ + SMESH_Hypothesis_i* myHypothesis_i = 0; + SMESH::SMESH_Hypothesis_var hypothesis_i; + std::string aPlatformLibName; + typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* ); + GenericHypothesisCreator_i* aCreator = getHypothesisCreator(theHypName, theLibName, aPlatformLibName); + // create a new hypothesis object, store its ref. in studyContext + if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName); + myHypothesis_i = + myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen); + myHypothesis_i->SetLibName(aPlatformLibName.c_str()); // for persistency assurance if (!myHypothesis_i) return hypothesis_i._retn(); @@ -620,7 +640,7 @@ void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_wrap so = anIter->Value(); CORBA::Object_var ior = SObjectToObject( so ); if ( SMESH_Mesh_i* mesh = SMESH::DownCast( ior )) - mesh->CheckGeomGroupModif(); + mesh->CheckGeomModif(); } } } @@ -1088,7 +1108,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName, std::string medfilename(theFileName); medfilename += ".med"; std::string cmd; -#ifdef WNT +#ifdef WIN32 cmd = "%PYTHONBIN% "; #else cmd = "python "; @@ -1098,7 +1118,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName, cmd += "\""; system(cmd.c_str()); SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str()); -#ifdef WNT +#ifdef WIN32 cmd = "%PYTHONBIN% "; #else cmd = "python "; @@ -1722,7 +1742,7 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, ASSERT( meshServant ); if ( meshServant ) { // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation" - meshServant->CheckGeomGroupModif(); + meshServant->CheckGeomModif(); // get local TopoDS_Shape TopoDS_Shape myLocShape; if(theMesh->HasShapeToMesh()) @@ -1731,9 +1751,7 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, myLocShape = SMESH_Mesh::PseudoShape(); // call implementation compute ::SMESH_Mesh& myLocMesh = meshServant->GetImpl(); -#ifdef WITH_SMESH_CANCEL_COMPUTE myGen.PrepareCompute( myLocMesh, myLocShape); -#endif bool ok = myGen.Compute( myLocMesh, myLocShape); meshServant->CreateGroupServants(); // algos can create groups (issue 0020918) myLocMesh.GetMeshDS()->Modified(); @@ -1763,7 +1781,6 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh, GEOM::GEOM_Object_ptr theShapeObject ) { -#ifdef WITH_SMESH_CANCEL_COMPUTE SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( theMesh ).in() ); ::SMESH_Mesh& myLocMesh = meshServant->GetImpl(); TopoDS_Shape myLocShape; @@ -1772,7 +1789,6 @@ void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh, else myLocShape = SMESH_Mesh::PseudoShape(); myGen.CancelCompute( myLocMesh, myLocShape); -#endif } //============================================================================= @@ -1808,7 +1824,7 @@ SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh ASSERT( meshServant ); if ( meshServant ) { // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation" - meshServant->CheckGeomGroupModif(); + meshServant->CheckGeomModif(); // get local TopoDS_Shape TopoDS_Shape myLocShape; if(theMesh->HasShapeToMesh()) @@ -2004,7 +2020,7 @@ SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh, ASSERT( meshServant ); if ( meshServant ) { // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation" - meshServant->CheckGeomGroupModif(); + meshServant->CheckGeomModif(); // get local TopoDS_Shape TopoDS_Shape myLocShape; if(theMesh->HasShapeToMesh()) @@ -2638,6 +2654,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes(); if ( SMESH::DownCast( meshPart )) { + srcMesh_i->Load(); srcElemIt = srcMeshDS->elementsIterator(); srcNodeIt = srcMeshDS->nodesIterator(); } @@ -2704,10 +2721,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, const SMDS_MeshElement * newElem; switch ( elem->GetEntityType() ) { case SMDSEntity_Polyhedra: - newElem = editor.GetMeshDS()-> - AddPolyhedralVolumeWithID( nodes, - static_cast(elem)->GetQuantities(), - ID); + if ( toKeepIDs ) + newElem = editor.GetMeshDS()-> + AddPolyhedralVolumeWithID( nodes, + static_cast(elem)->GetQuantities(), + ID); + else + newElem = editor.GetMeshDS()-> + AddPolyhedralVolume( nodes, + static_cast(elem)->GetQuantities()); break; case SMDSEntity_Ball: newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID, @@ -2883,8 +2905,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() ) // san -- in case differs from theComponent's study, // use that of the component - if ( myCurrentStudy->_is_nil() || - theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() ) + if ( theComponent->GetStudy()->StudyId() != GetCurrentStudyID() ) SetCurrentStudy( theComponent->GetStudy() ); // Store study contents as a set of python commands @@ -2927,7 +2948,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, //Remove the files if they exist: BugID: 11225 -#ifndef WNT /* unix functionality */ +#ifndef WIN32 /* unix functionality */ TCollection_AsciiString cmd("rm -f \""); #else /* windows */ TCollection_AsciiString cmd("del /F \""); @@ -3008,9 +3029,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, string libname = string( myHyp->GetLibName() ); // BUG SWP13062 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for - // WNT and ".so" for X-system) must be deleted + // WIN32 and ".so" for X-system) must be deleted int libname_len = libname.length(); -#ifdef WNT +#ifdef WIN32 if( libname_len > 4 ) libname.resize( libname_len - 4 ); #else @@ -3077,9 +3098,9 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, string libname = string( myHyp->GetLibName() ); // BUG SWP13062 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for - // WNT and ".so" for X-system) must be deleted + // WIN32 and ".so" for X-system) must be deleted int libname_len = libname.length(); -#ifdef WNT +#ifdef WIN32 if( libname_len > 4 ) libname.resize( libname_len - 4 ); #else @@ -3933,8 +3954,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, { INFOS( "SMESH_Gen_i::Load" ); - if ( myCurrentStudy->_is_nil() || - theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() ) + if ( theComponent->GetStudy()->StudyId() != GetCurrentStudyID() ) SetCurrentStudy( theComponent->GetStudy() ); /* if( !theComponent->_is_nil() ) @@ -5045,13 +5065,42 @@ void SMESH_Gen_i::Move( const SMESH::sobject_list& what, useCaseBuilder->AppendTo( where, sobj ); // append to the end of list } } +//================================================================================= +// function : IsApplicable +// purpose : Return true if algorithm can be applied +//================================================================================= +CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType, + const char* theLibName, + GEOM::GEOM_Object_ptr theGeomObject, + CORBA::Boolean toCheckAll) +{ + SMESH_TRY; + + std::string aPlatformLibName; + typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char*); + GenericHypothesisCreator_i* aCreator = getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName); + if (aCreator) + { + TopoDS_Shape shape = GeomObjectToShape( theGeomObject ); + if ( !shape.IsNull() ) + return aCreator->IsApplicable( shape, toCheckAll ); + } + else + { + return false; + } + + SMESH_CATCH( SMESH::doNothing ); + return true; +} //================================================================================= // function : importData // purpose : imports mesh data file (the med one) into the SMESH internal data structure //================================================================================= -Engines::ListOfIdentifiers* SMESH_Gen_i::importData( - CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options) +Engines::ListOfIdentifiers* SMESH_Gen_i::importData(CORBA::Long studyId, + Engines::DataContainer_ptr data, + const Engines::ListOfOptions& options) { Engines::ListOfIdentifiers_var aResultIds = new Engines::ListOfIdentifiers; list aResultList;