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=32b6fecfc3269f69e250eba997bad4cad24e7829;hb=896b180efc0351e28d18fd39bb948eaa8faf5620;hpb=e33e8e2029a4e91779b9c1d5f480979fa7b51d0b diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 32b6fecfc..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 @@ -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) @@ -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); @@ -395,14 +395,13 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName #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 @@ -424,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) @@ -435,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(); @@ -621,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(); } } } @@ -1723,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()) @@ -1732,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(); @@ -1764,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; @@ -1773,7 +1789,6 @@ void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh, else myLocShape = SMESH_Mesh::PseudoShape(); myGen.CancelCompute( myLocMesh, myLocShape); -#endif } //============================================================================= @@ -1809,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()) @@ -2005,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()) @@ -2639,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(); } @@ -2705,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, @@ -2884,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 @@ -3934,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() ) @@ -5046,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;