using namespace std;
using SMESH::TPythonDump;
+using SMESH::TVar;
int SMESH_Mesh_i::_idGenerator = 0;
return CORBA::string_dup( ver.c_str() );
}
+//================================================================================
+/*!
+ * Return the list of med versions compatibles for write/append,
+ * encoded in 10*major+minor (for instance, code for med 3.2.1 is 32)
+ */
+//================================================================================
+SMESH::long_array* SMESH_Mesh_i::GetMEDVersionsCompatibleForAppend()
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ std::vector<int> mvok = MED::GetMEDVersionsAppendCompatible();
+ long nbver = mvok.size();
+ aResult->length( nbver );
+ for ( int i = 0; i < nbver; i++ )
+ aResult[i] = mvok[i];
+ return aResult._retn();
+}
+
//=============================================================================
/*!
* ImportUNVFile
//use PseudoShape in case if mesh has no shape
if(HasShapeToMesh())
myLocSubShape = _gen_i->GeomObjectToShape( aSubShape);
- else
+ else
myLocSubShape = _impl->GetShapeToMesh();
-
+
const int hypId = anHyp->GetId();
std::string error;
status = _impl->AddHypothesis( myLocSubShape, hypId, &error );
TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
if ( !aShape.IsNull() )
{
- aNewGroup =
+ aNewGroup =
SMESH::SMESH_GroupOnGeom::_narrow( createGroup( theElemType, theName, aShape ));
if ( _gen_i->CanPublishInStudy( aNewGroup ) )
//=============================================================================
/*!
- \brief Intersect list of groups. New group is created. All mesh elements that
+ \brief Intersect list of groups. New group is created. All mesh elements that
are present in all initial groups simultaneously are added to the new one.
\param theGroups list of groups
\param theName name of group to be created
}
//=============================================================================
-/*!
+/*!
* New group is created. All mesh elements that are present in
* a main group but is not present in a tool group are added to the new one
*/
//=============================================================================
/*!
- \brief Cut lists of groups. New group is created. All mesh elements that are
+ \brief Cut lists of groups. New group is created. All mesh elements that are
present in main groups but do not present in tool groups are added to the new one
\param theMainGroups list of main groups
\param theToolGroups list of tool groups
*/
//=============================================================================
SMESH::SMESH_Group_ptr
-SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
- const SMESH::ListOfGroups& theToolGroups,
+SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups,
+ const SMESH::ListOfGroups& theToolGroups,
const char* theName )
throw (SALOME::SALOME_Exception)
{
return aResGrp._retn();
}
+//================================================================================
+/*!
+ * \brief Distribute all faces of the mesh between groups using sharp edges and optionally
+ * existing 1D elements as group boundaries.
+ * \param [in] theSharpAngle - edge is considered sharp if an angle between normals of
+ * adjacent faces is more than \a sharpAngle in degrees.
+ * \param [in] theCreateEdges - to create 1D elements for detected sharp edges.
+ * \param [in] theUseExistingEdges - to use existing edges as group boundaries
+ * \return ListOfGroups - the created groups
+ */
+//================================================================================
+
+SMESH::ListOfGroups*
+SMESH_Mesh_i::FaceGroupsSeparatedByEdges( CORBA::Double theSharpAngle,
+ CORBA::Boolean theCreateEdges,
+ CORBA::Boolean theUseExistingEdges )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( theSharpAngle < 0 || theSharpAngle > 180 )
+ THROW_SALOME_CORBA_EXCEPTION("Invalid sharp angle, it must be between 0 and 180 degrees",
+ SALOME::BAD_PARAM);
+
+ SMESH::ListOfGroups_var resultGroups = new SMESH::ListOfGroups;
+
+ TPythonDump pyDump;
+
+ SMESH_TRY;
+ if ( _preMeshInfo )
+ _preMeshInfo->FullLoadFromFile();
+
+ SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
+
+ std::vector< SMESH_MeshAlgos::Edge > edges =
+ SMESH_MeshAlgos::FindSharpEdges( meshDS, theSharpAngle, theUseExistingEdges );
+
+ if ( theCreateEdges )
+ {
+ std::vector<const SMDS_MeshNode *> nodes(2);
+ for ( size_t i = 0; i < edges.size(); ++i )
+ {
+ nodes[0] = edges[i]._node1;
+ nodes[1] = edges[i]._node2;
+ if ( meshDS->FindElement( nodes, SMDSAbs_Edge ))
+ continue;
+ if ( edges[i]._medium )
+ meshDS->AddEdge( edges[i]._node1, edges[i]._node2, edges[i]._medium );
+ else
+ meshDS->AddEdge( edges[i]._node1, edges[i]._node2 );
+ }
+ }
+
+ std::vector< std::vector< const SMDS_MeshElement* > > faceGroups =
+ SMESH_MeshAlgos::SeparateFacesByEdges( meshDS, edges );
+
+ SMESH::SMESH_MeshEditor_var( GetMeshEditor() ); // create _editor
+
+ resultGroups->length( faceGroups.size() );
+ for ( size_t iG = 0; iG < faceGroups.size(); ++iG )
+ {
+ SMESH::SMESH_Group_var group = CreateGroup( SMESH::FACE,
+ _editor->GenerateGroupName("Group").c_str());
+ resultGroups[iG] = SMESH::SMESH_Group::_duplicate( group );
+
+ SMESHDS_GroupBase* groupBaseDS =
+ SMESH::DownCast<SMESH_GroupBase_i*>( group )->GetGroupDS();
+ SMDS_MeshGroup& groupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup();
+
+ std::vector< const SMDS_MeshElement* >& faces = faceGroups[ iG ];
+ for ( size_t i = 0; i < faces.size(); ++i )
+ groupCore.Add( faces[i] );
+ }
+
+ pyDump << resultGroups << " = " << SMESH::SMESH_Mesh_var(_this())
+ << ".FaceGroupsSeparatedByEdges( "
+ << TVar( theSharpAngle ) << ", "
+ << theCreateEdges << ", "
+ << theUseExistingEdges << " )";
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+ return resultGroups._retn();
+
+}
+
//================================================================================
/*!
* \brief Remember GEOM group data
if(MYDEBUG) MESSAGE( "createSubMesh" );
TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
- const int subMeshId = mySubMesh->GetId();
+ int subMeshId = 0;
+
+ SMESH_subMesh_i * subMeshServant;
+ if ( mySubMesh )
+ {
+ subMeshId = mySubMesh->GetId();
+ subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
+ }
+ else // "invalid sub-mesh"
+ {
+ // The invalid sub-mesh is created for the case where a valid sub-shape not found
+ // by SMESH_Gen_i::CopyMeshWithGeom(). The invalid sub-mesh has GetId() < 0.
+ if ( _mapSubMesh.empty() )
+ subMeshId = -1;
+ else
+ subMeshId = _mapSubMesh.begin()->first - 1;
+ subMeshServant = new SMESH_Invalid_subMesh_i(myPOA, _gen_i, this, subMeshId, theSubShapeObject);
+ }
- SMESH_subMesh_i * subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
SMESH::SMESH_subMesh_var subMesh = subMeshServant->_this();
_mapSubMesh [subMeshId] = mySubMesh;
else { nextId = 0; } // avoid "unused variable" warning
// to track changes of GEOM groups
- addGeomGroupData( theSubShapeObject, subMesh );
+ if ( subMeshId > 0 )
+ addGeomGroupData( theSubShapeObject, subMesh );
return subMesh._retn();
}
if ( theSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
{
- if ( _mapSubMesh.find( subMeshId ) != _mapSubMesh.end())
+ if ( _mapSubMesh.find( subMeshId ) != _mapSubMesh.end() &&
+ _mapSubMesh[ subMeshId ])
{
TopoDS_Shape S = _mapSubMesh[ subMeshId ]->GetSubShape();
if ( !S.IsNull() )
SMESH_Mesh_i* _mesh;
TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
- virtual void HypothesisModified () { _mesh->onHypothesisModified(); }
+ virtual void HypothesisModified (int theHypID) { _mesh->onHypothesisModified( theHypID ); }
virtual void Load () { _mesh->Load(); }
};
}
*/
//================================================================================
-void SMESH_Mesh_i::onHypothesisModified()
+void SMESH_Mesh_i::onHypothesisModified(int theHypID)
{
if ( _preMeshInfo )
_preMeshInfo->ForgetOrLoad();
SMESH::SMESH_Mesh_var mesh = _this();
_gen_i->UpdateIcons( mesh );
+
+ // mark a hypothesis as valid after edition
+ SALOMEDS::SComponent_wrap smeshComp = _gen_i->PublishComponent();
+ SALOMEDS::SObject_wrap hypRoot;
+ if ( !smeshComp->_is_nil() &&
+ smeshComp->FindSubObject( _gen_i->GetHypothesisRootTag(), hypRoot.inout() ))
+ {
+ SALOMEDS::ChildIterator_wrap anIter = _gen_i->getStudyServant()->NewChildIterator( hypRoot );
+ for ( ; anIter->More(); anIter->Next() )
+ {
+ SALOMEDS::SObject_wrap hypSO = anIter->Value();
+ CORBA::Object_var obj = _gen_i->SObjectToObject( hypSO );
+ SMESH::SMESH_Hypothesis_var hyp = SMESH::SMESH_Hypothesis::_narrow( obj );
+ if ( !hyp->_is_nil() && hyp->GetId() == theHypID )
+ _gen_i->HighLightInvalid( hyp, false );
+ }
+ }
}
//=============================================================================
void SMESH_Mesh_i::ExportMED(const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension)
throw(SALOME::SALOME_Exception)
_preMeshInfo->FullLoadFromFile();
string aMeshName = prepareMeshNameAndGroups(file, overwrite);
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension );
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension );
TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
<< file << "', "
<< "auto_groups=" <<auto_groups << ", "
- << "minor=" << minor << ", "
+ << "minor=" << version << ", "
<< "overwrite=" << overwrite << ", "
<< "meshPart=None, "
<< "autoDimension=" << autoDimension << " )";
void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
const char* file,
CORBA::Boolean auto_groups,
- CORBA::Long minor,
+ CORBA::Long version,
CORBA::Boolean overwrite,
CORBA::Boolean autoDimension,
const GEOM::ListOfFields& fields,
- const char* geomAssocFields)
+ const char* geomAssocFields,
+ CORBA::Double ZTolerance)
throw (SALOME::SALOME_Exception)
{
- //MESSAGE("MED minor version: "<< minor);
+ MESSAGE("MED version: "<< version);
SMESH_TRY;
if ( _preMeshInfo )
_preMeshInfo->FullLoadFromFile();
SMESH::DownCast< SMESH_Mesh_i* >( meshPart ))
{
aMeshName = prepareMeshNameAndGroups(file, overwrite);
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
- 0, autoDimension, /*addODOnVertices=*/have0dField);
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
+ 0, autoDimension, /*addODOnVertices=*/have0dField,
+ ZTolerance);
meshDS = _impl->GetMeshDS();
}
else
}
SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart );
- _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor,
- partDS, autoDimension, /*addODOnVertices=*/have0dField);
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version,
+ partDS, autoDimension, /*addODOnVertices=*/have0dField, ZTolerance);
meshDS = tmpDSDeleter._obj = partDS;
}
<< meshPart << ", r'"
<< file << "', "
<< auto_groups << ", "
- << minor << ", "
+ << version << ", "
<< overwrite << ", "
<< autoDimension << ", "
<< goList << ", '"
- << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
+ << ( geomAssocFields ? geomAssocFields : "" ) << "',"
+ << TVar( ZTolerance )
+ << " )";
SMESH_CATCH( SMESH::throwCorbaException );
}
return aResult._retn();
}
-
+
//=============================================================================
/*!
* Returns type of elements for given submesh
SMESH_CATCH( SMESH::throwCorbaException );
- return type;
+ return type;
}
-
+
//=============================================================================
/*!
// find inverse elements
SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
- aResult->length( aNode->NbInverseElements() );
+ aResult->length( aNode->NbInverseElements() );
for( int i = 0; eIt->more(); ++i )
{
const SMDS_MeshElement* elem = eIt->next();
//=============================================================================
/*!
- * For given element returns ID of result shape after
+ * For given element returns ID of result shape after
* ::FindShape() from SMESH_MeshEditor
* If there is not element for given ID - returns -1
*/
int nbGrp = NbGroups();
if ( !nbGrp )
return;
-
+
SMESH::ListOfGroups* grpList = 0;
// avoid dump of "GetGroups"
{
aWriter->Write();
char* str = aWriter->GetOutputString();
int size = aWriter->GetOutputStringLength();
-
- //Allocate octect buffer of required size
+
+ //Allocate octet buffer of required size
CORBA::Octet* OctetBuf = SALOMEDS::TMPFile::allocbuf(size);
- //Copy ostrstream content to the octect buffer
+ //Copy ostrstream content to the octet buffer
memcpy(OctetBuf, str, size);
//Create and return TMPFile
SeqFile = new SALOMEDS::TMPFile(size, size, OctetBuf, 1);
}
return isShared;
}
-
+
//-----------------------------------------------------------------------------
//! check algorithms
static bool checkAlgo(const SMESHDS_Hypothesis* theA1,
return strcmp( theA1->GetName(), theA2->GetName() ) == 0;
}
-
+
//-----------------------------------------------------------------------------
//! Check if sub-shape hypotheses are concurrent
bool IsConcurrent(const SMESH_DimHyp* theOther) const
return ( this->_subMesh->GetId() < theOther->_subMesh->GetId() );
}
-
+
}; // end of SMESH_DimHyp
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-void addDimHypInstance(const int theDim,
+void addDimHypInstance(const int theDim,
const TopoDS_Shape& theShape,
const SMESH_Algo* theAlgo,
const SMESH_subMesh* theSubMesh,
dimHyp->_hypotheses.push_front(theAlgo);
listOfdimHyp.push_back( dimHyp );
}
-
+
SMESH_DimHyp* dimHyp = const_cast<SMESH_DimHyp*>( listOfdimHyp.back() );
dimHyp->_hypotheses.insert( dimHyp->_hypotheses.end(),
theHypList.begin(), theHypList.end() );
if ( find_first_of( theListOfId.begin(), theListOfId.end(),
otherListOfId.begin(), otherListOfId.end() ) == theListOfId.end() )
continue;
-
+
// union two lists (from source into target)
TListOfInt::iterator it2 = otherListOfId.begin();
for ( ; it2 != otherListOfId.end(); it2++ ) {
addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr );
}
} // end iterations on submesh
-
+
// iterate on created dimension-hypotheses and check for concurrents
for ( int i = 0; i < 4; i++ ) {
const TDimHypList& listOfDimHyp = dimHypListArr[i];
}
}
}
-
+
removeDimHyps(dimHypListArr);
-
+
// now, minimize the number of concurrent groups
// Here we assume that lists of submeshes can have same submesh
// in case of multi-dimension algorithms, as result
mesh.SetMeshOrder( subMeshOrder );
res = true;
-
+
SMESH::SMESH_Mesh_var me = _this();
_gen_i->UpdateIcons( me );
// END Implementation of SMESH_MeshPartDS
//
//================================================================================
-
-