#include <QString>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopoDS_Iterator.hxx>
+
namespace SMESH
{
GEOM::GEOM_Gen_var GetGEOMGen( GEOM::GEOM_Object_ptr go )
}
+ //================================================================================
+ /*!
+ * \brief Return type of shape contained in a group
+ */
+ //================================================================================
+
+ TopAbs_ShapeEnum _getGroupType(const TopoDS_Shape& group)
+ {
+ if ( group.ShapeType() != TopAbs_COMPOUND )
+ return group.ShapeType();
+
+ // iterate on a compound
+ TopoDS_Iterator it( group );
+ if ( it.More() )
+ return _getGroupType( it.Value() );
+
+ return TopAbs_SHAPE;
+ }
+
+
+ //================================================================================
+ /*!
+ * \brief Check if a subGeom contains sub-shapes of a mainGeom
+ */
+ //================================================================================
+
+ bool ContainsSubShape( GEOM::GEOM_Object_ptr mainGeom,
+ GEOM::GEOM_Object_ptr subGeom )
+ {
+ if ( CORBA::is_nil( mainGeom ) ||
+ CORBA::is_nil( subGeom ))
+ return false;
+
+ GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
+ if ( geomGen->_is_nil() ) return false;
+
+ GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
+ if ( op->_is_nil() ) return false;
+
+ GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom ); /* _var not _wrap as
+ mainObj already exists! */
+ while ( !mainObj->_is_nil() )
+ {
+ CORBA::String_var entry1 = mainObj->GetEntry();
+ CORBA::String_var entry2 = mainGeom->GetEntry();
+ if ( std::string( entry1.in() ) == entry2.in() )
+ return true;
+ mainObj = op->GetMainShape( mainObj );
+ }
+ if ( subGeom->GetShapeType() == GEOM::COMPOUND )
+ {
+ // is subGeom a compound of sub-shapes?
+ GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
+ if ( sop->_is_nil() ) return false;
+ GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( subGeom,
+ GEOM::SHAPE,/*sorted=*/false);
+ if ( ids->length() > 0 )
+ {
+ GEOM_Client geomClient;
+ TopoDS_Shape subShape = geomClient.GetShape( geomGen, subGeom );
+ TopoDS_Shape mainShape = geomClient.GetShape( geomGen, mainGeom );
+ if ( subShape.IsNull() || mainShape.IsNull() )
+ return false;
+
+ TopAbs_ShapeEnum subType = _getGroupType( subShape );
+ TopTools_IndexedMapOfShape subMap;
+ TopExp::MapShapes( subShape, subType, subMap );
+ for ( TopExp_Explorer exp( mainShape, subType ); exp.More(); exp.Next() )
+ if ( subMap.Contains( exp.Current() ))
+ return true;
+
+ }
+ }
+ return false;
+ }
+
} // end of namespace SMESH
SMESHGUI_EXPORT bool GetGeomEntries( Handle(SALOME_InteractiveObject)& hypIO,
QString& subGeom, QString& meshGeom);
+
+ SMESHGUI_EXPORT bool ContainsSubShape( GEOM::GEOM_Object_ptr mainShape,
+ GEOM::GEOM_Object_ptr subShape );
}
#endif // SMESHGUI_GEOMGENUTILS_H
else if (myCurrentLineEdit == myGeomGroupLine)
{
myGeomObjects = new GEOM::ListOfGO();
+ myGeomObjects->length( aNbSel );
- // The mesh SObject
- _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
-
- if (aNbSel == 0 || !aMeshSO)
+ if ( aNbSel == 0 || myMesh->_is_nil() )
{
- myGeomObjects->length(0);
updateButtons();
myIsBusy = false;
return;
}
- myGeomObjects->length(aNbSel);
-
- GEOM::GEOM_Object_var aGeomGroup;
+ GEOM::GEOM_Object_var mainGeom = myMesh->GetShapeToMesh();
int i = 0;
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for (; anIt.More(); anIt.Next())
+ for ( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
{
- CORBA::Object_var aGroupObj = SMESH::IObjectToObject(anIt.Value());
- if (CORBA::is_nil(aGroupObj))
- continue;
- // Check if the object is a geometry group
- aGeomGroup = GEOM::GEOM_Object::_narrow(aGroupObj);
- if (CORBA::is_nil(aGeomGroup))
- continue;
-
// Check if group constructed on the same shape as a mesh or on its child
-
- // The main shape of the group
- GEOM::GEOM_Object_var aGroupMainShape;
- if (aGeomGroup->GetType() == 37)
- {
- GEOM::GEOM_IGroupOperations_wrap anOp =
- SMESH::GetGEOMGen( aGeomGroup )->GetIGroupOperations();
- aGroupMainShape = anOp->GetMainShape( aGeomGroup );
- // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
- }
- else
- {
- aGroupMainShape = aGeomGroup;
- aGroupMainShape->Register();
- }
- CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
- _PTR(SObject) aGroupMainShapeSO =
- SMESH::getStudy()->FindObjectID( entry.in() );
-
- _PTR(SObject) anObj, aRef;
- bool isRefOrSubShape = false;
- if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
- if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
- isRefOrSubShape = true;
- } else {
- _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
- _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
- while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
- if (aRef->GetID() == aFather->GetID())
- isRefOrSubShape = true;
- else
- aFather = aFather->GetFather();
- }
- }
- }
- if (isRefOrSubShape)
- myGeomObjects[i++] = aGeomGroup;
+ GEOM::GEOM_Object_var geomGroup = SMESH::GetGeom( anIt.Value() );
+ if ( SMESH::ContainsSubShape( mainGeom, geomGroup ))
+ myGeomObjects[ i++ ] = geomGroup;
}
myGeomObjects->length(i);
QPushButton* myAddBtn;
QPushButton* myRemoveBtn;
QPushButton* mySortBtn;
-
+
QGroupBox* mySelectBox;
QCheckBox* mySelectSubMesh;
QPushButton* mySubMeshBtn;
QCheckBox* mySelectGroup;
QPushButton* myGroupBtn;
QLineEdit* myGroupLine;
-
+
QtxColorButton* myColorBtn;
-
+
QCheckBox* mySelectGeomGroup;
QToolButton* myGeomGroupBtn;
QLineEdit* myGeomGroupLine;
QPushButton* myApplyBtn;
QPushButton* myCloseBtn;
QPushButton* myHelpBtn;
-
+
SMESHGUI_ShapeByMeshOp* myShapeByMeshOp;
-
+
SMESH::SMESH_Mesh_var myMesh;
QList<SMESH_Actor*> myActorsList;
SMESH::SMESH_Group_var myGroup;
SMESH::Filter_var myFilter;
QList<int> myIdList;
GEOM::ListOfGO_var myGeomObjects;
-
+
int mySelectionMode;
- //Handle(SMESH_TypeFilter) myMeshFilter;
- //Handle(SMESH_TypeFilter) mySubMeshFilter;
- //Handle(SMESH_TypeFilter) myGroupFilter;
SUIT_SelectionFilter* myMeshFilter;
SMESH_LogicalFilter* mySubMeshFilter;
SMESH_LogicalFilter* myGroupFilter;
SUIT_SelectionFilter* myGeomFilter;
-
+
SMESHGUI_FilterDlg* myFilterDlg;
-
+
bool myCreate, myIsBusy;
-
+
QString myHelpFileName;
-
+
QMap<QAction*, int> myActions;
bool myNameChanged; //added by skl for IPAL19574
// study
if (_PTR(Study) aStudy = SMESH::getStudy()) {
// mesh
- if (_PTR(SObject) meshSO = aStudy->FindObjectID( myMeshID.toUtf8().data() )) {
+ if (_PTR(SObject) meshSO = aStudy->FindObjectID( myMeshID.toUtf8().data() ))
+ {
// shape to mesh
- _PTR(SObject) anObj, shapeToMesh;
- if (meshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(shapeToMesh)) {
- // loop on selected
- QStringList::iterator name = names.begin(), id = ids.begin(), idEnd = ids.end();
- for (; id != idEnd; ++id, ++name ) {
- // shape SO
- if (_PTR(SObject) shapeSO = aStudy->FindObjectID( id->toUtf8().data() )) {
- // check if shape SO is a child of shape to mesh
- while ( shapeSO && shapeSO->GetID() != shapeToMesh->GetID() )
- if ( shapeSO->Depth() < 2 )
- shapeSO.reset();
- else
- shapeSO = shapeSO->GetFather();
- if ( shapeSO ) {
- //printf( "selectionDone() %s %s\n", (*id).latin1(), (*name).latin1() );
- if ( !goodIds.contains( *id )) {
- goodIds.append( *id );
- goodNames.append( *name );
- }
- }
- }
+ GEOM::GEOM_Object_var mainGeom = SMESH::GetGeom( meshSO );
+ // loop on selected
+ QStringList::iterator name = names.begin(), id = ids.begin(), idEnd = ids.end();
+ for (; id != idEnd; ++id, ++name )
+ {
+ if ( goodIds.contains( *id ))
+ continue;
+ // shape SO
+ _PTR(SObject) shapeSO = aStudy->FindObjectID( id->toUtf8().data() );
+ GEOM::GEOM_Object_var subGeom = SMESH::GetGeom( shapeSO );
+ if ( SMESH::ContainsSubShape( mainGeom, subGeom ))
+ {
+ goodIds.append( *id );
+ goodNames.append( *name );
}
}
}
virtual void startOperation();
virtual void selectionDone();
virtual SUIT_SelectionFilter* createFilter( const int ) const;
- //virtual bool isValid( SUIT_Operation* ) const;
private slots:
bool onApply();
void onButtonClick();
-
-// void onSelectColor();
-
-
private:
void init();
-// void setGroupColor( const SALOMEDS::Color& );
-// SALOMEDS::Color getGroupColor() const;
-
-// void setGroupQColor( const QColor& );
-// QColor getGroupQColor() const;
-
-// void setDefaultGroupColor();
private:
QString myMeshID;
QStringList myElemGeoIDs, myNodeGeoIDs;
- //GEOM::ListOfGO_var myElemGObj;
};
class SMESHGUI_EXPORT SMESHGUI_GroupOnShapeDlg : public SMESHGUI_Dialog
private:
- //QLineEdit* myGrpNameLine;
-
QPushButton* myMeshBtn;
QLineEdit* myMeshLine;
QPushButton* myElemGeomBtn;
- QListWidget* myElemGeomList;
+ QListWidget* myElemGeomList;
QPushButton* myNodeGeomBtn;
- QListWidget* myNodeGeomList;
-
-// QPushButton* myColorBtn;
-
-// bool myCreate, myIsBusy;
-
-// QString myHelpFileName;
+ QListWidget* myNodeGeomList;
friend class SMESHGUI_GroupOnShapeOp;
};
return 0;
}
-//================================================================================
-/*!
- * \brief Return type of shape contained in a group
- */
-//================================================================================
-
-TopAbs_ShapeEnum getGroupType(const TopoDS_Shape& group)
-{
- if ( group.ShapeType() != TopAbs_COMPOUND )
- return group.ShapeType();
-
- // iterate on a compound
- TopoDS_Iterator it( group );
- if ( it.More() )
- return getGroupType( it.Value() );
-
- return TopAbs_SHAPE;
-}
-
//================================================================================
/*!
* \brief check if selected shape is a sub-shape of the shape to mesh
QStringList aGEOMs;
myDlg->selectedObject(SMESHGUI_MeshDlg::Geom, aGEOMs);
- if (aGEOMs.count() > 0) {
- GEOM::GEOM_Gen_var geomGen = mainGeom->GetGen();
- if (geomGen->_is_nil()) return false;
+ // check all selected shapes
+ for ( QString& aSubGeomEntry : aGEOMs )
+ {
+ _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID( aSubGeomEntry.toUtf8().data() );
+ if ( !pSubGeom ) return false;
- GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
- if (op->_is_nil()) return false;
+ GEOM::GEOM_Object_var subGeom =
+ GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
- // check all selected shapes
- QStringList::const_iterator aSubShapesIter = aGEOMs.begin();
- for ( ; aSubShapesIter != aGEOMs.end(); aSubShapesIter++)
- {
- QString aSubGeomEntry = (*aSubShapesIter);
- _PTR(SObject) pSubGeom = SMESH::getStudy()->FindObjectID(aSubGeomEntry.toUtf8().data());
- if (!pSubGeom) return false;
-
- GEOM::GEOM_Object_var aSubGeomVar =
- GEOM::GEOM_Object::_narrow(_CAST(SObject,pSubGeom)->GetObject());
- if (aSubGeomVar->_is_nil()) return false;
-
- // skl for NPAL14695 - implementation of searching of mainObj
- GEOM::GEOM_Object_var mainObj = op->GetMainShape(aSubGeomVar); /* _var not _wrap as
- mainObj already exists! */
- while( !mainObj->_is_nil())
- {
- CORBA::String_var entry1 = mainObj->GetEntry();
- CORBA::String_var entry2 = mainGeom->GetEntry();
- if (std::string( entry1.in() ) == entry2.in() )
- return true;
- mainObj = op->GetMainShape(mainObj);
- }
- if ( aSubGeomVar->GetShapeType() == GEOM::COMPOUND )
- {
- // is aSubGeomVar a compound of sub-shapes?
- GEOM::GEOM_IShapesOperations_wrap sop = geomGen->GetIShapesOperations();
- if (sop->_is_nil()) return false;
- GEOM::ListOfLong_var ids = sop->GetAllSubShapesIDs( aSubGeomVar,
- GEOM::SHAPE,/*sorted=*/false);
- if ( ids->length() > 0 )
- {
- GEOM_Client geomClient;
- TopoDS_Shape subShape = geomClient.GetShape( geomGen, aSubGeomVar );
- TopoDS_Shape mainShape = geomClient.GetShape( geomGen, mainGeom );
- if ( subShape.IsNull() || mainShape.IsNull() )
- return false;
-
- TopAbs_ShapeEnum subType = getGroupType( subShape );
- TopTools_IndexedMapOfShape subMap;
- TopExp::MapShapes( subShape, subType, subMap );
- for ( TopExp_Explorer exp( mainShape, subType ); exp.More(); exp.Next() )
- if ( subMap.Contains( exp.Current() ))
- return true;
- }
- }
- }
+ if ( SMESH::ContainsSubShape( mainGeom, subGeom ))
+ return true;
}
return false;