1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESHGUI_SelectionProxy.h"
25 #include "SMDS_Mesh.hxx"
26 #include "SMDS_VolumeTool.hxx"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESH_Actor.h"
31 #include "SMESH_ControlsDef.hxx"
33 #include <SALOMEconfig.h>
34 #include CORBA_SERVER_HEADER(SMESH_Filter)
35 #include CORBA_SERVER_HEADER(SMESH_Group)
37 #include <SALOMEDSClient_Study.hxx>
38 #include <SUIT_ResourceMgr.h>
40 ////////////////////////////////////////////////////////////////////////////////
41 /// \class SMESH::SelectionProxy
42 /// \brief Provide operations over the selected object.
44 /// The selection proxy class is aimed to use in dialogs to access mesh object
45 /// data either from actor or directly from CORBA reference, depending on what
46 /// of them is accessible.
47 /// This is useful in situations when some information is needed, but an actor
48 /// was not created yet.
50 /// Selection proxy can be constructed in two ways:
51 /// - From interactive object: this performs full proxy initialization including
52 /// pick-up of an actor from the current viewer if it exists.
53 /// - From mesh source object (CORBA reference); for performance reasons in this
54 /// case full initialization is not immediately done and performed only when
56 ////////////////////////////////////////////////////////////////////////////////
59 \brief Default constructor. Creates null proxy.
61 SMESH::SelectionProxy::SelectionProxy(): myActor(0), myDirty(false)
67 \param io Interactive object.
69 SMESH::SelectionProxy::SelectionProxy( const Handle(SALOME_InteractiveObject)& io ): myActor(0), myDirty(true)
71 myObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( io );
77 \param object Mesh source.
79 SMESH::SelectionProxy::SelectionProxy( SMESH::SMESH_IDSource_ptr object ): myActor(0), myDirty(true)
81 if ( !CORBA::is_nil( object ) )
82 myObject = SMESH::SMESH_IDSource::_duplicate( object );
86 \brief Copy constructor.
87 \param other Proxy being copied.
89 SMESH::SelectionProxy::SelectionProxy( const SelectionProxy& other )
92 myObject = other.myObject;
93 myActor = other.myActor;
94 myDirty = other.myDirty;
98 \brief Perform internal initialization.
101 void SMESH::SelectionProxy::init()
104 myIO = new SALOME_InteractiveObject(); // create dummy IO to avoid crashes when accessing it
106 if ( !CORBA::is_nil( myObject ) )
108 if ( !myIO->hasEntry() )
110 _PTR(SObject) sobj = SMESH::ObjectToSObject( myObject.in() );
112 myIO = new SALOME_InteractiveObject( sobj->GetID().c_str(), "SMESH", sobj->GetName().c_str() );
114 if ( !myActor && myIO->hasEntry() )
115 myActor = SMESH::FindActorByEntry( myIO->getEntry() );
121 \brief Assignment operator.
122 \param other Proxy being copied.
124 SMESH::SelectionProxy& SMESH::SelectionProxy::operator= ( const SMESH::SelectionProxy& other )
127 myObject = other.myObject;
128 myActor = other.myActor;
129 myDirty = other.myDirty;
134 \brief Equality comparison operator.
135 \param other Proxy to compare with.
136 \return \c true if two proxies are equal; \c false otherwise.
138 bool SMESH::SelectionProxy::operator== ( const SMESH::SelectionProxy& other )
140 return !CORBA::is_nil( myObject ) && !CORBA::is_nil( other.myObject ) &&
141 myObject->_is_equivalent( other.myObject );
145 \brief Re-initialize proxy.
147 void SMESH::SelectionProxy::refresh()
153 \brief Check if proxy is null.
154 \return \c true if proxy is null; \c false otherwise.
156 bool SMESH::SelectionProxy::isNull() const
158 return CORBA::is_nil( myObject );
162 \brief Boolean conversion operator.
163 \return \c true if proxy is not null; \c false otherwise.
165 SMESH::SelectionProxy::operator bool() const
171 \brief Get interactive object.
172 \return Interactive object referenced by proxy.
174 const Handle(SALOME_InteractiveObject)& SMESH::SelectionProxy::io() const
177 const_cast<SMESH::SelectionProxy*>(this)->init();
182 \brief Get mesh object.
183 \return Mesh object (mesh, sub-mesh, group, etc.) referenced by proxy.
185 SMESH::SMESH_IDSource_ptr SMESH::SelectionProxy::object() const
187 return SMESH::SMESH_IDSource::_duplicate( myObject );
192 \return Actor referenced by proxy.
194 SMESH_Actor* SMESH::SelectionProxy::actor() const
197 const_cast<SMESH::SelectionProxy*>(this)->init();
202 \brief Get object's validity.
204 Mesh object is valid if it is not null and information stored in it is valid.
206 \return \c true if object is valid; \c false otherwise.
208 bool SMESH::SelectionProxy::isValid() const
210 return !isNull() && myObject->IsMeshInfoCorrect();
214 \brief Load mesh object from study file.
216 void SMESH::SelectionProxy::load()
220 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
221 if ( !CORBA::is_nil( mesh ) )
228 \return Mesh object's name.
230 QString SMESH::SelectionProxy::name() const
234 value = io()->getName();
240 \return Mesh object's type.
242 SMESH::SelectionProxy::Type SMESH::SelectionProxy::type() const
244 Type value = Unknown;
247 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
248 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( myObject );
249 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
250 SMESH::SMESH_Group_var sGroup = SMESH::SMESH_Group::_narrow( myObject );
251 SMESH::SMESH_GroupOnGeom_var gGroup = SMESH::SMESH_GroupOnGeom::_narrow( myObject );
252 SMESH::SMESH_GroupOnFilter_var fGroup = SMESH::SMESH_GroupOnFilter::_narrow( myObject );
254 if ( !CORBA::is_nil( mesh ) )
256 else if ( !CORBA::is_nil( submesh ) )
258 else if ( !CORBA::is_nil( sGroup ) )
260 else if ( !CORBA::is_nil( gGroup ) )
262 else if ( !CORBA::is_nil( fGroup ) )
264 else if ( !CORBA::is_nil( group ) )
271 \brief Get mesh information.
272 \return Statistics on stored mesh object.
274 SMESH::MeshInfo SMESH::SelectionProxy::meshInfo() const
276 SMESH::MeshInfo info;
279 SMESH::smIdType_array_var data = myObject->GetMeshInfo();
280 for ( uint type = SMESH::Entity_Node; type < SMESH::Entity_Last; type++ )
282 if ( type < data->length() )
283 info.addInfo( type, data[ type ] );
290 \brief Get parent mesh.
291 \return Proxy object that stores parent mesh object.
292 \note For proxy that stores a mesh, returns its copy.
294 SMESH::SelectionProxy SMESH::SelectionProxy::mesh() const
296 SMESH::SelectionProxy parent;
298 parent = SMESH::SelectionProxy( (SMESH::SMESH_Mesh_var) myObject->GetMesh() ); // cast to var to avoid leaks
303 \brief Check if parent mesh has shape to mesh.
304 \return \c true if Parent mesh is built on a shape; \c false otherwise.
305 \note For group or submesh, this method checks that parent mesh has a shape.
307 bool SMESH::SelectionProxy::hasShapeToMesh() const
312 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
313 if ( !CORBA::is_nil( mesh ) )
314 result = mesh->HasShapeToMesh();
320 \brief Get referenced GEOM object.
321 \return GEOM object referenced by selection proxy.
323 The result contains valid pointer only if proxy refers to mesh, sub-mesh
324 or group created on a geometry.
326 GEOM::GEOM_Object_ptr SMESH::SelectionProxy::shape() const
328 GEOM::GEOM_Object_var shape;
331 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
332 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( myObject );
333 SMESH::SMESH_GroupOnGeom_var group = SMESH::SMESH_GroupOnGeom::_narrow( myObject );
334 if ( !CORBA::is_nil( mesh ) )
335 shape = mesh->GetShapeToMesh();
336 else if ( !CORBA::is_nil( submesh ) )
337 shape = submesh->GetSubShape();
338 else if ( !CORBA::is_nil( group ) )
339 shape = group->GetShape();
341 return shape._retn();
345 \brief Get name of referenced GEOM object.
346 \return Name of GEOM object referenced by selection proxy.
348 The result contains non-empty name only if proxy refers to mesh, sub-mesh
349 or group created on a geometry, and if that geometry has valid name.
351 QString SMESH::SelectionProxy::shapeName() const
356 GEOM::GEOM_Object_var gobj = shape();
357 _PTR(SObject) sobj = SMESH::ObjectToSObject( gobj );
359 name = QString::fromStdString( sobj->GetName() );
365 \brief Get type of referenced GEOM object.
366 \return Type of GEOM object referenced by selection proxy.
368 The result contains valid type only if proxy refers to mesh, sub-mesh
369 or group created on a geometry.
371 int SMESH::SelectionProxy::shapeType() const
376 GEOM::GEOM_Object_var gobj = shape();
377 if ( !CORBA::is_nil( gobj ) )
378 type = gobj->GetShapeType();
384 \brief Check if mesh has been loaded from study file.
385 \return \c true if mesh was loaded; \c false otherwise.
387 bool SMESH::SelectionProxy::isMeshLoaded() const
389 bool result = true; // set default to true to avoid side effects
392 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
393 if ( !CORBA::is_nil( mesh ) )
394 result = mesh->IsLoaded();
400 \brief Check if node with given ID is present in the mesh.
401 \param id Mesh node ID.
402 \return \c true if mesh contains node; \c false otherwise.
404 bool SMESH::SelectionProxy::hasNode( int id )
411 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
416 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
417 if ( !CORBA::is_nil( mesh ) )
419 SMESH::double_array_var coords = mesh->GetNodeXYZ( id );
420 result = coords->length() >= 3;
428 \brief Get node coordinates.
429 \param id Mesh node ID.
430 \param xyz Returned node coordinates.
431 \return \c true if result is valid; \c false otherwise.
433 bool SMESH::SelectionProxy::nodeCoordinates( int id, SMESH::XYZ& xyz )
442 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
445 xyz = SMESH::XYZ( node->X(), node->Y(), node->Z() );
451 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
452 if ( !CORBA::is_nil( mesh ) )
454 SMESH::double_array_var coords = mesh->GetNodeXYZ( id );
455 if ( coords->length() >= 3 )
457 xyz = SMESH::XYZ( coords[0], coords[1], coords[2] );
467 \brief Get node connectivity.
468 \param id Mesh node ID.
469 \param connectivity Returned node connectivity.
470 \return \c true if result is valid; \c false otherwise.
472 bool SMESH::SelectionProxy::nodeConnectivity( int id, SMESH::Connectivity& connectivity )
475 connectivity.clear();
480 const SMDS_MeshNode* node = actor()->GetObject()->GetMesh()->FindNode( id );
483 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
484 while ( it && it->more() )
486 const SMDS_MeshElement* ne = it->next();
487 connectivity[ ne->GetType() ] << ne->GetID();
494 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
495 if ( !CORBA::is_nil( mesh ) )
497 SMESH::smIdType_array_var elements = mesh->GetNodeInverseElements( id, SMESH::ALL );
498 for ( int i = 0, n = elements->length(); i < n; i++ )
500 SMESH::ElementType type = mesh->GetElementType( elements[i], true );
501 connectivity[ type ] << elements[i];
511 \brief Get node position on a shape.
512 \param id Mesh node ID.
513 \param position Returned node position.
514 \return \c true if result is valid; \c false otherwise.
516 bool SMESH::SelectionProxy::nodePosition( int id, Position& position )
519 position = Position();
522 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
523 if ( !CORBA::is_nil( mesh ) )
525 SMESH::NodePosition_var pos = mesh->GetNodePosition( id );
526 position.setShapeId( pos->shapeID );
527 if ( pos->shapeID > 0 )
529 position.setShapeType( pos->shapeType );
530 if ( pos->shapeType == GEOM::EDGE && pos->params.length() > 0 )
532 position.setU( pos->params[0] );
534 if ( pos->shapeType == GEOM::FACE && pos->params.length() > 1 )
536 position.setU( pos->params[0] );
537 position.setV( pos->params[1] );
547 \brief Get groups given node belongs to.
548 \param id Mesh node ID.
549 \return List of groups containing given node.
551 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::nodeGroups( int id ) const
553 QList<SMESH::SelectionProxy> result;
556 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
557 if ( !CORBA::is_nil( mesh ) )
559 SMESH::ListOfGroups_var groups = mesh->GetGroups();
560 for ( uint i = 0 ; i < groups->length(); i++ )
562 if ( groups[i]->GetType() == SMESH::NODE && groups[i]->Contains( id ) )
564 result << SMESH::SelectionProxy( groups[i].in() );
573 \brief Check if element with given ID is present in the mesh.
574 \param id Mesh element ID.
575 \return \c true if mesh contains element; \c false otherwise.
577 bool SMESH::SelectionProxy::hasElement( int id )
584 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
585 result = element != 0;
589 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
590 if ( !CORBA::is_nil( mesh ) )
592 SMESH::smIdType_array_var nodes = mesh->GetElemNodes( id );
593 result = nodes->length() > 0;
601 \brief Get type of given mesh element.
602 \param id Mesh element ID.
603 \return Element type.
605 SMESH::ElementType SMESH::SelectionProxy::elementType( int id ) const
607 SMESH::ElementType value = SMESH::ALL;
612 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
615 value = (SMESH::ElementType)element->GetType();
620 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
621 if ( !CORBA::is_nil( mesh ) )
623 value = mesh->GetElementType( id, true );
631 \brief Get entity type of given mesh element.
632 \param id Mesh element ID.
635 int SMESH::SelectionProxy::elementEntityType( int id ) const
637 SMESH::EntityType value = SMESH::Entity_Last;
642 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
645 value = (SMESH::EntityType)element->GetEntityType();
650 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
651 if ( !CORBA::is_nil( mesh ) )
653 value = mesh->GetElementGeomType( id );
661 \brief Get element connectivity.
662 \param id Mesh element ID.
663 \param connectivity Return element connectivity.
664 \return \c true if result is valid; \c false otherwise.
666 bool SMESH::SelectionProxy::elementConnectivity( SMESH::smIdType id, Connectivity& connectivity )
669 connectivity.clear();
672 QSet<SMESH::smIdType> nodes; // order of nodes is important
675 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
677 if ( SMDS_NodeIteratorPtr it = element->nodeIterator())
681 SMESH::smIdType n = it->next()->GetID();
682 if ( !nodes.contains( n ))
684 connectivity[ SMDSAbs_Node ] << n;
693 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
694 if ( !CORBA::is_nil( mesh ) )
696 SMESH::smIdType_array_var nn = mesh->GetElemNodes( id );
697 for ( int i = 0, nb = nn->length(); i < nb; i++ )
699 if ( !nodes.contains( nn[i] ))
701 connectivity[ SMDSAbs_Node ] << nn[i];
713 \brief Get volume element connectivity.
714 \param id Mesh element ID.
715 \param connectivity Return nodal connectivity of each facet numbered from 1
716 \param nbNodes Return number of unique nodes.
717 \return \c true if result is valid; \c false otherwise.
719 bool SMESH::SelectionProxy::perFaceConnectivity( int id, Connectivity& connectivity, int& nbNodes )
722 connectivity.clear();
729 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
730 SMDS_VolumeTool volTool;
731 if ( volTool.Set( element ))
733 for ( int iF = 0; iF < volTool.NbFaces(); ++iF )
735 const SMDS_MeshNode** nn = volTool.GetFaceNodes( iF );
736 int nbN = volTool.NbFaceNodes( iF );
737 for ( int iN = 0; iN < nbN; ++iN )
739 connectivity[ iF+1 ] << ( nn[ iN ]->GetID() );
740 nodeSet << ( nn[ iN ]->GetID() );
748 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
749 if ( !CORBA::is_nil( mesh ) )
751 CORBA::Long nbFaces = mesh->ElemNbFaces( id );
752 for ( CORBA::Long iF = 0; iF < nbFaces; ++iF )
754 SMESH::smIdType_array_var nodes = mesh->GetElemFaceNodes( id, iF );
755 for ( CORBA::ULong iN = 0; iN < nodes->length(); ++iN )
757 connectivity[ iF+1 ] << nodes[iN];
758 nodeSet << nodes[iN];
761 result = ( nbFaces > 0 );
764 nbNodes = nodeSet.size();
770 \brief Get element position on a shape.
771 \param id Mesh element ID.
772 \param position Returned element position.
773 \return \c true if result is valid; \c false otherwise.
775 bool SMESH::SelectionProxy::elementPosition( int id, Position& position )
778 position = Position();
781 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
782 if ( !CORBA::is_nil( mesh ) )
784 SMESH::ElementPosition_var pos = mesh->GetElementPosition( id );
785 position.setShapeId( pos->shapeID );
786 if ( pos->shapeID > 0 )
788 position.setShapeType( pos->shapeType );
797 \brief Get gravity center of given element.
798 \param id Mesh element ID.
799 \param xyz Returned gravity center.
800 \return \c true if result is valid; \c false otherwise.
802 bool SMESH::SelectionProxy::elementGravityCenter( int id, SMESH::XYZ& xyz )
810 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
813 SMDS_ElemIteratorPtr it = element->nodesIterator();
816 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( it->next() );
817 xyz.add( node->X(), node->Y(), node->Z() );
819 xyz.divide( element->NbNodes() );
825 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
826 if ( !CORBA::is_nil( mesh ) )
828 SMESH::smIdType_array_var nodes = mesh->GetElemNodes( id );
829 for ( int i = 0, n = nodes->length(); i < n; i++ )
831 SMESH::double_array_var coords = mesh->GetNodeXYZ( nodes[i] );
832 if ( coords->length() >= 3 )
834 xyz.add( coords[0], coords[1], coords[2] );
837 xyz.divide( nodes->length() );
846 \brief Get normal vector to given element (face).
847 \param id Mesh element ID.
848 \param xyz Returned normal vector.
849 \return \c true if result is valid; \c false otherwise.
851 bool SMESH::SelectionProxy::elementNormal( int id, SMESH::XYZ& xyz )
859 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
860 if ( element && element->GetType() == SMDSAbs_Face )
862 xyz = SMESH::getNormale( SMDS_Mesh::DownCast<SMDS_MeshFace>( element ) );
868 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
869 if ( !CORBA::is_nil( mesh ) )
871 SMESH::double_array_var normal = mesh->GetFaceNormal( id, true );
872 if ( normal->length() >= 3 )
874 xyz = SMESH::XYZ( normal[0], normal[1], normal[2] );
884 \brief Get quality control's value for given element.
885 \param id Mesh element ID.
886 \param control Quality control type.
887 \param precision Precision for control's value.
888 \param value Returned quality control's value.
889 \return \c true if result is valid; \c false otherwise.
891 bool SMESH::SelectionProxy::elementControl( int id, int control, double precision, double& value ) const
899 SMESH::Controls::NumericalFunctorPtr functor;
902 case SMESH::FT_AspectRatio:
903 functor.reset( new SMESH::Controls::AspectRatio() );
905 case SMESH::FT_AspectRatio3D:
906 functor.reset( new SMESH::Controls::AspectRatio3D() );
908 case SMESH::FT_Warping:
909 functor.reset( new SMESH::Controls::Warping() );
911 case SMESH::FT_MinimumAngle:
912 functor.reset( new SMESH::Controls::MinimumAngle() );
914 case SMESH::FT_Taper:
915 functor.reset( new SMESH::Controls::Taper() );
918 functor.reset( new SMESH::Controls::Skew() );
921 functor.reset( new SMESH::Controls::Area() );
923 case SMESH::FT_Volume3D:
924 functor.reset( new SMESH::Controls::Volume() );
926 case SMESH::FT_MaxElementLength2D:
927 functor.reset( new SMESH::Controls::MaxElementLength2D() );
929 case SMESH::FT_MaxElementLength3D:
930 functor.reset( new SMESH::Controls::MaxElementLength3D() );
932 case SMESH::FT_Length:
933 functor.reset( new SMESH::Controls::Length() );
935 case SMESH::FT_Length2D:
936 functor.reset( new SMESH::Controls::Length2D() );
938 case SMESH::FT_Length3D:
939 functor.reset( new SMESH::Controls::Length3D() );
941 case SMESH::FT_BallDiameter:
942 functor.reset( new SMESH::Controls::BallDiameter() );
944 case SMESH::FT_ScaledJacobian:
945 functor.reset( new SMESH::Controls::ScaledJacobian() );
950 const SMDS_MeshElement* element = actor()->GetObject()->GetMesh()->FindElement( id );
951 if ( element && functor && element->GetType() == functor->GetType() )
953 functor->SetMesh( actor()->GetObject()->GetMesh() );
954 if ( functor->IsApplicable( element ))
956 functor->SetPrecision( precision );
957 value = functor->GetValue( id );
964 SMESH::SMESH_Gen_var smeshGen = SMESHGUI::GetSMESHGen();
965 if ( smeshGen->_is_nil() )
967 SMESH::FilterManager_var manager = smeshGen->CreateFilterManager();
968 if ( manager->_is_nil() )
970 SMESH::NumericalFunctor_var functor;
973 case SMESH::FT_AspectRatio:
974 functor = manager->CreateAspectRatio();
976 case SMESH::FT_AspectRatio3D:
977 functor = manager->CreateAspectRatio3D();
979 case SMESH::FT_Warping:
980 functor = manager->CreateWarping();
982 case SMESH::FT_MinimumAngle:
983 functor = manager->CreateMinimumAngle();
985 case SMESH::FT_Taper:
986 functor = manager->CreateTaper();
989 functor = manager->CreateSkew();
992 functor = manager->CreateArea();
994 case SMESH::FT_Volume3D:
995 functor = manager->CreateVolume3D();
997 case SMESH::FT_MaxElementLength2D:
998 functor = manager->CreateMaxElementLength2D();
1000 case SMESH::FT_MaxElementLength3D:
1001 functor = manager->CreateMaxElementLength3D();
1003 case SMESH::FT_Length:
1004 functor = manager->CreateLength();
1006 case SMESH::FT_Length2D:
1007 functor = manager->CreateLength2D();
1009 case SMESH::FT_Length3D:
1010 functor = manager->CreateLength3D();
1012 case SMESH::FT_BallDiameter:
1013 functor = manager->CreateBallDiameter();
1015 case SMESH::FT_ScaledJacobian:
1016 functor = manager->CreateScaledJacobian();
1021 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
1022 if ( !functor->_is_nil() && !mesh->_is_nil() )
1024 functor->SetMesh( mesh );
1025 if ( functor->IsApplicable( id ))
1027 functor->SetPrecision( precision );
1028 value = functor->GetValue( id );
1032 manager->UnRegister();
1039 \brief Get groups given element belongs to.
1040 \param id Mesh element ID.
1041 \return List of groups containing element.
1043 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::elementGroups( int id ) const
1045 QList<SMESH::SelectionProxy> result;
1048 SMESH::SMESH_Mesh_var mesh = myObject->GetMesh();
1049 if ( !CORBA::is_nil( mesh ) )
1051 SMESH::ListOfGroups_var groups = mesh->GetGroups();
1052 for ( uint i = 0 ; i < groups->length(); i++ )
1054 if ( groups[i]->GetType() != SMESH::NODE && groups[i]->Contains( id ) )
1056 result << SMESH::SelectionProxy( groups[i].in() );
1065 \brief Get MED file information.
1066 \return MED file information.
1068 The result contains valid data only if proxy refers to mesh object
1069 which has been imported from the MED file.
1071 SMESH::MedInfo SMESH::SelectionProxy::medFileInfo() const
1073 SMESH::MedInfo info;
1076 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
1077 if ( !CORBA::is_nil( mesh ) )
1079 SMESH::MedFileInfo_var inf = mesh->GetMEDFileInfo();
1080 info.setFileName( inf->fileName.in() );
1081 info.setSize( inf->fileSize );
1082 info.setVersion( inf->major, inf->minor, inf->release );
1089 \brief Get child sub-meshes.
1090 \return List of sub-meshes for mesh object; empty list for other types.
1092 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::submeshes() const
1094 QList<SMESH::SelectionProxy> lst;
1097 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
1098 if ( !CORBA::is_nil( mesh ) )
1100 SMESH::submesh_array_var array = mesh->GetSubMeshes();
1101 for ( uint i = 0 ; i < array->length(); i++ )
1102 lst << SMESH::SelectionProxy( array[i].in() );
1109 \brief Get child groups.
1110 \return List of groups for mesh object; empty list for other types.
1112 QList<SMESH::SelectionProxy> SMESH::SelectionProxy::groups() const
1114 QList<SMESH::SelectionProxy> lst;
1117 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( myObject );
1118 if ( !CORBA::is_nil( mesh ) )
1120 SMESH::ListOfGroups_var array = mesh->GetGroups();
1121 for ( uint i = 0 ; i < array->length(); i++ )
1122 lst << SMESH::SelectionProxy( array[i].in() );
1129 \brief Get element type (for group). For other mesh objects result is undefined.
1130 \return Group's element type.
1132 SMESH::ElementType SMESH::SelectionProxy::groupElementType() const
1134 SMESH::ElementType value = SMESH::ALL;
1137 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1138 if ( !CORBA::is_nil( group ) )
1139 value = group->GetType();
1145 \brief Get color (for group). For other mesh objects result is undefined.
1146 \return Group's color.
1148 QColor SMESH::SelectionProxy::color() const
1153 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1154 if ( !CORBA::is_nil( group ) )
1156 SALOMEDS::Color c = group->GetColor();
1157 result = QColor::fromRgbF( c.R, c.G, c.B );
1164 \brief Get size (for group). For other mesh objects result is undefined.
1165 \param autoCompute Compute size if it is unavailable. Defaults to \c false.
1166 \return Group's size.
1168 SMESH::smIdType SMESH::SelectionProxy::size( bool autoCompute ) const
1170 // note: size is not computed for group on filter for performance reasons, see IPAL52831
1171 SMESH::smIdType result = -1;
1174 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1175 if ( !CORBA::is_nil( group ) )
1177 if ( type() == GroupFilter )
1178 // for group on filter we check if value is already computed and cached
1179 autoCompute |= group->IsMeshInfoCorrect();
1181 // for other groups we force autoCompute to true
1184 result = group->Size();
1191 \brief Get number of underlying nodes (for group of elements). For other
1192 mesh objects result is undefined.
1193 \param autoCompute Compute size if it is unavailable. Defaults to \c false.
1194 \return Number of nodes contained in group.
1196 SMESH::smIdType SMESH::SelectionProxy::nbNodes( bool autoCompute ) const
1198 // note: nb of nodes is not computed automatically for performance reasons
1199 SMESH::smIdType result = -1;
1202 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1203 if ( !CORBA::is_nil( group ) && ( autoCompute || isMeshLoaded() ) )
1205 int groupSize = size( autoCompute );
1206 if ( groupSize >= 0 )
1208 int limit = SMESHGUI::resourceMgr()->integerValue( "SMESH", "info_groups_nodes_limit", 100000 );
1209 if ( group->IsNodeInfoAvailable() || limit <= 0 || groupSize <= limit )
1210 result = group->GetNumberOfNodes();
1218 \brief Get list of nodes / elements IDs for the mesh group.
1219 \return List of IDs for group object; empty list for other types.
1221 QSet<uint> SMESH::SelectionProxy::ids() const
1226 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow( myObject );
1227 if ( !CORBA::is_nil( group ) )
1229 SMESH::smIdType_array_var seq = group->GetListOfID();
1230 for ( int i = 0, n = seq->length(); i < n; i++ )
1231 result << (uint)seq[i];
1237 ////////////////////////////////////////////////////////////////////////////////
1238 /// \class SMESH::MeshInfo
1239 /// \brief Store statistics on mesh object.
1240 ////////////////////////////////////////////////////////////////////////////////
1245 SMESH::MeshInfo::MeshInfo()
1250 \brief Add information on given entity type.
1251 \param type Entity type.
1252 \param value Number of entities.
1254 void SMESH::MeshInfo::addInfo( int type, long value )
1256 myInfo[type] = value;
1260 \brief Get number of entities of given type.
1261 \param type Entity type.
1262 \return Number of entities.
1264 uint SMESH::MeshInfo::info( int type ) const
1266 return myInfo.value( type, 0U );
1270 \brief Access operator.
1271 \param type Entity type.
1272 \return Number of entities.
1274 uint SMESH::MeshInfo::operator[] ( int type )
1276 return (uint)info( type );
1280 \brief Get total number of entities for types in given range.
1281 \param fromType Lower entity type.
1282 \param toType Upper entity type.
1283 \return Number of entities.
1285 uint SMESH::MeshInfo::count( int fromType, int toType ) const
1288 for ( int type = fromType; type <= toType; type++ )
1289 value += info( type );
1293 ////////////////////////////////////////////////////////////////////////////////
1294 /// \class SMESH::MedInfo
1295 /// \brief Provide operations over the selected object
1296 ////////////////////////////////////////////////////////////////////////////////
1301 SMESH::MedInfo::MedInfo()
1306 \brief Get validity status.
1308 MED file information is valid if at least stored file name is not null.
1310 \return \c true if MED file info is valid; \c false otherwise.
1312 bool SMESH::MedInfo::isValid() const
1314 return !myFileName.isEmpty();
1318 \brief Get file name for mesh imported from MED file.
1319 \return MED file name.
1321 QString SMESH::MedInfo::fileName() const
1327 \brief Set file name for mesh imported from MED file.
1328 \param fileName MED file name.
1330 void SMESH::MedInfo::setFileName( const QString& fileName )
1332 myFileName = fileName;
1336 \brief Get file size for mesh imported from MED file.
1337 \return MED file size.
1339 uint SMESH::MedInfo::size() const
1345 \brief Set file size for mesh imported from MED file.
1346 \param size MED file size.
1348 void SMESH::MedInfo::setSize( uint size )
1354 \brief Get version of format for mesh imported from MED file.
1355 \return MED file format version.
1357 QString SMESH::MedInfo::version() const
1359 QString v = QString( "%1" ).arg( myMajor );
1360 if ( myMinor > 0 || myRelease > 0 ) v += QString( ".%1" ).arg( myMinor );
1361 else if ( myMajor > 0 ) v += ".0";
1362 if ( myRelease > 0 ) v += QString( ".%1" ).arg( myRelease );
1367 \brief Set version of format for mesh imported from MED file.
1368 \param major Major version number.
1369 \param minor Minor version number.
1370 \param release Release version number.
1372 void SMESH::MedInfo::setVersion( uint major, uint minor, uint release )
1376 myRelease = release;
1379 ////////////////////////////////////////////////////////////////////////////////
1380 /// \class SMESH::Position
1381 /// \brief Describes position of mesh node or element on a reference shape.
1382 ////////////////////////////////////////////////////////////////////////////////
1385 \brief Constructor. Creates invalid position.
1387 SMESH::Position::Position():
1388 myShapeId(-1), myShapeType(-1), myU(0), myV(0), myHasU(false), myHasV(false)
1393 \brief Check if position is valid.
1394 \return \c true if position is valid; \c false otherwise.
1396 bool SMESH::Position::isValid() const
1398 return myShapeId > 0 && myShapeType != -1;
1402 \brief Get reference shape ID.
1403 \return Shape / sub-shape ID.
1405 int SMESH::Position::shapeId() const
1411 \brief Set reference shape ID.
1412 \param id Shape / sub-shape ID.
1414 void SMESH::Position::setShapeId( int id )
1420 \brief Get reference shape type.
1423 int SMESH::Position::shapeType() const
1429 \brief Set reference shape type.
1430 \param type Shape type.
1432 void SMESH::Position::setShapeType( int type )
1438 \brief Check if there is U position on a shape.
1439 \return \c true if U position is valid; \c false otherwise.
1441 bool SMESH::Position::hasU() const
1447 \brief Get U position on a shape.
1450 double SMESH::Position::u() const
1456 \brief Set U position on a shape.
1459 void SMESH::Position::setU( double u )
1466 \brief Check if there is V position on a shape.
1467 \return \c true if V position is valid; \c false otherwise.
1469 bool SMESH::Position::hasV() const
1475 \brief Get V position on a shape.
1478 double SMESH::Position::v() const
1484 \brief Set V position on a shape.
1487 void SMESH::Position::setV( double v)
1493 ////////////////////////////////////////////////////////////////////////////////
1494 /// \class SMESH::XYZ
1495 /// \brief Simple structure to manage 3D coordinate.
1496 ////////////////////////////////////////////////////////////////////////////////
1499 \brief Default constructor.
1503 myX = myY = myZ = 0.0;
1507 \brief Base constructor.
1508 \param parameter x X coordinate.
1509 \param parameter y Y coordinate.
1510 \param parameter z Z coordinate.
1512 SMESH::XYZ::XYZ( double x, double y, double z )
1520 \brief Construction from geometrical point.
1521 \param parameter p Geometrical point.
1523 SMESH::XYZ::XYZ( const gp_XYZ& p )
1532 \param parameter x X coordinate.
1533 \param parameter y Y coordinate.
1534 \param parameter z Z coordinate.
1536 void SMESH::XYZ::add( double x, double y, double z )
1544 \brief Divide point to given coefficient.
1545 \param parameter a Divider coefficient.
1547 void SMESH::XYZ::divide( double a )
1558 \brief Get X coordinate.
1559 \return X coordinate.
1561 double SMESH::XYZ::x() const
1567 \brief Get Y coordinate.
1568 \return Y coordinate.
1570 double SMESH::XYZ::y() const
1576 \brief Get Z coordinate.
1577 \return Z coordinate.
1579 double SMESH::XYZ::z() const
1585 \brief Conversion to geometrical point.
1586 \return Geometrical point.
1588 SMESH::XYZ::operator gp_XYZ() const
1590 return gp_XYZ( myX, myY, myZ );